[self-interest] Re: Self bytecodes

Stefan Matthias Aust sma at netsurf.de
Mon May 31 20:38:34 UTC 1999


>It all seems fine, but I donĀ“t understand something seemingly
>straightforward: knowing that in a send the receiver and arguments are
>popped off stack and the result is pushed onto stack, how is the number
>of arguments of a send determined, so that my interpreter could know how
>many pops it should make? 

You can derive that from the selector symbol.  Unary selectors (that are
selectors composed from letters - especially the first character must be a
lowercase letter - without ':' in it) need no arguments at all.  Binary
selectors (that are all selectors which neither start with a letter or with
an '_') have exactly one argument.  For keyword selectors (which are
composed of sequences of letters (and digits) that end with a colon ':')
simply count the number of colons.

A different problem is to know when to pop returned objects from the stack
which aren't used.  I think, you cannot detect that and simply adjust the
stack when you leave the method.  Here's an example:  3+4. nil

This will generate something along:  push 3, push 4, send #+, push nil.

The + method for integers will pop both 3 and 4 from the stack and push the
result, 7.  However, this object isn't needed and will use one stack slot
upton the method returns (with nil).

There might be a way to notice that "7" isn't used anywhere in the method,
but that's probably to much work for an interpreter.  A compiler that will
create and analyse a complete parse tree for each method can do this.


bye
--
Stefan Matthias Aust // Truth Until Paradox!

------------------------------------------------------------------------

eGroups.com home: http://www.egroups.com/group/self-interest
http://www.egroups.com - Simplifying group communications






More information about the Self-interest mailing list