Compiling a role name into a message to self
Vassili Bykov
smalltalkbigot at gmail.com
Fri Nov 23 18:26:44 UTC 2007
Modifying the compiler may be too much work for what you are
describing. Smalltalk message sends are already late-bound enough.
Have a variable named something like "player", used like so:
player currentStar displayLarge
Meaning "player" would hold an instance of something called, say,
PlayerAgent, whose responsibility is to manage the mapping of roles to
players and return players in response to messages naming their roles.
How exactly it does that depends on how the roles are used. If there
are few roles known in advance, the agent can simply have instance
variables with accessors, one per role. For too many roles this can
become tedious, so the agent can instead hold the players in a
Dictionary and look them up in response to #doesNotUnderstand:.
Cheers,
--Vassili
On Nov 21, 2007 1:19 PM, Trygve Reenskaug <trygver at ifi.uio.no> wrote:
>
> No response on my first SOS.
>
>
>
> I am now in my first dive into the compiler; there's a lot to learn.
> I first found the pragmas, but they do not seem to fit my purpose.
> I next found the message selector macro facility in MessageNode/special .
> Very neat, but I need to do something with a variable name, not a selector.
> There are a host of different kinds of variables- local, instance, class,
> pool, ... It would be nice with yet another one: "computed" or "aliased". A
> special syntax for a variable name that will lead to inlining a method for
> finding the object currently accessed through the name.
>
> I would really appreciate help from someone familiar with compiler work.
>
> Thanks
> --Trygve.
>
>
> On 19.11.2007 19:03, Trygve Reenskaug wrote:
> I am just completing an experiment where I am programming with roles. A role
> name stands for one or more objects; the actual binding occur at run time.
> Example:
> (self playerForRole: #currentStar) displayLarge
> It would be much more readable if I could write something like
> ¤currentStar displayLarge or §currentStar displayLarge or :-)
> currentStar displayLarge or ...
> currentStar is a role name, self playerForRole: searches down the stack to
> find the appropriate object binding .
>
> I suppose I have to choose an appropriate syntax and doctor the compiler.
> Any ideas?
>
> Thanks
> --Trygve
> --
>
> Trygve Reenskaug mailto: trygver at ifi.uio.no
> Morgedalsvn. 5A http://folk.uio.no/trygver
> N-0378 Oslo Tel: (+47) 22 49 57 27
> Norway
>
>
>
> --
>
> Trygve Reenskaug mailto: trygver at ifi.uio.no
> Morgedalsvn. 5A http://folk.uio.no/trygver
> N-0378 Oslo Tel: (+47) 22 49 57 27
> Norway
>
>
>
>
>
More information about the Squeak-dev
mailing list
|