[Newbies] Re: How do i list the execution order of objects inside a method?

David Corking lists at dcorking.com
Wed Jan 30 12:34:58 UTC 2013


mircea wrote:

> 2. Select a piece of code and debug it, right click and select debug "

That is a Pharo thing. I am not sure how to do the same thing in Squeak.

> But what happens if the code does not exist, class names are not valid,
> method names are just examples.
>
> If i were to analyze something like an example someone has posted somewhere.
>
> In Squeak I can't say, but in Pharo, the Compiler can be "stupid" and
> compile more or less everything :)

In Squeak, the Compiler is just as stupid. The objects in the compiled
bytecode are just symbols that are resolved at run time. The warnings
the compiler gives you about missing methods and classes are just
warnings - ignore them and the compiler will compile the code anyway.

> So to get this "execution order" and no run-time errors... i would need to
> get behind the complier and before the code actually runs.

Unlike your other correspondents, I am no computer scientist, but as I
understand, this is exactly what the Abstract Syntax Tree can do for
you.

I think of compilation has 3 steps.
1. A parser makes an abstract syntax tree that represents each message
in your source code as a node in the tree, according to Smalltalk's
precedence rules.
2. The compiler walks that tree in order, turning each message into
bytecode (with some optimizations.)
3. The compiler saves that bytecode into the class as a CompiledMethod.

Then that CompiledMethod can be executed (by the VM) whenever it is needed.

If you evaluate a DoIt, then instead of step 3, the code actually
runs. Since you don't want that, I suggest you might find it easier to
avoid DoIts for now. If it was me, I might consider starting with
simple methods, and later moving on to block closures.

Although the CompiledMethod is always accessible before the code
actually runs, I can see from your explanation that you probably
actually want to get behind the compiler after step 1, and get hold of
an AST before the compiler discards it. This is what the StackOverflow
answer gives you (and Roassal or other projects give you tools to
visualize trees.)

If you think about the Debugger, it has to do the same tasks: parse
your source code into execution order, then step by step animate and
then execute. That is why we suggested looking into Debugger code.

I would love to help you in your endeavour as a spare time project,
but I don't have the Smalltalk expertise needed. I am good at using
the Debugger to crash!

Have fun! David


More information about the Beginners mailing list