[self-interest] Re: Another question about Self grammar

Jecel Assumpcao Jr jecel at lsi.usp.br
Thu Mar 25 06:32:57 UTC 1999

Dru Nelson wrote:
> In a Self expression, the use of the parentheses specifies an object,
> or a higher precedence expression. However, as mentioned earlier, most
> people just parse these as objects. Later in the compiler phase,
> it can be determined that these parenthesized expressions have no
> temporaries and are just a single expression.

It is important to note that "compiler phase" means very different
things in Smalltalk and Self, which causes a lot of confusion. The
above paragraph is true for Self 1.0 if the phrase is used in the
Self sense, and is true for Self 4.0 when used in the Smalltalk sense.

Just to make it very clear,


  - parser reads source text and outputs "compiler node" objects

  - compiler reads the node objects and generates bytecodes


  - parser reads source text and outputs bytecodes

  - compiler reads bytecodes and outputs Sparc machine language code

> Example:
> x + ( (bag getItemNamed: 'dog') squared)
> This whole line is a single expression.
> Is what I am saying correct?

Right. Self 1.0 would generate something like this:

   expression: selfSend 'x'
               pushLiteral obj1
               send '+'

   obj1:       pushLiteral obj2
               send 'squared'

   obj2:       selfSend 'bag'
               pushLiteral 'dog'
               send 'getItemNamed:'

So you had all the overhead of creating the inner method objects
obj1 and obj2. In Self 4.0, the same source would be parsed as:

   expression: selfSend 'x'
               selfSend 'bag'
               pushLiteral 'dog'
               send 'getItemNamed:'
               send 'squared'
               send '+'

While very different in terms of bytecodes, by the time they became
Sparc machine instructions both versions generated the same code.
So this change did not affect Self programmers one bit.

-- Jecel
P.S.: it seems that no matter what the question, I always get into
the implementation side of the language. The idea for this list was
to be a place for general discussions and for people wanting to learn
how to program in Self or even with just an interest in what it is
all about. I could set up a separate list for the gory implementation
details, but so far the traffic here has been so light that it didn't
seem worth it.

eGroup home: http://www.eGroups.com/list/self-interest
Free Web-based e-mail groups by eGroups.com

More information about the Self-interest mailing list