[Vm-dev] SqueakJS named primitives in the interpreter module

Bert Freudenberg bert at freudenbergs.de
Thu Jan 19 13:19:25 UTC 2017


On Thu, Jan 19, 2017 at 3:55 AM, David T. Lewis <lewis at mail.msen.com> wrote:

>
> For named primitives, we can load and run a primitive function from a
> specific
> module, as in the case of <primitive: 'primitiveFileSize' module:
> 'FilePlugin'>.
>
> We can also load a primitive with module name unspecified, as in the case
> of
> <primitive: 'primitiveScreenDepth'>. In that case we load and run the
> function
> from the main interpreter module.
>
> I want to implement the anonymous named primitive #primitiveUtcWithOffset
> in
> SqueakJS, but I am a total JavaScript noob so I am looking for an example
> of
> some other anonymous named primitive to use as a pattern.
>
> At first glance, I do not see any anonymous named primitives implemented
> in vm.js,
>

Indeed, SqueakJS does not implement any of the currently used module-less
named primitives.

It does, however, implement some obsolete ones, e.g. '
m23PrimitiveTransformPoint' which was later moved to Matrix2x3Plugin.

The lookup is quite trivial: If you specify an empty module name, it just
looks up the method in the VM's primitive handler class itself, instead of
a named module. E.g. in SqueakJS you could call the beep primitive either
by index or by name, <primitive: 140> works as well as <primitive:
'primitiveBeep'>.


> so I want to ask - does the basic functionality of looking up and
> executing e.g.
> #primitiveScreenDepth from the <primitive: 'primitiveScreenDepth'> pragma
> work?
>

Yes. Simply name your JavaScript method 'primitiveUtcWithOffset' and put it
in the 'Squeak.Primitives' class. I'd suggest putting it in the 'time'
section https://github.com/bertfreudenberg/SqueakJS/blob/
432dafd615a8e48019dbfc5e62a6599e4648ca3b/vm.js#L6486

Note that quite a few indexed primitives do not exist as a full method.
E.g. prim 135 is currently implemented as

case 135: return this.popNandPushIfOK(1, this.millisecondClockValue());

basically to reduce tedious boiler-plate code. Just in case you're
wondering why some of the primitives appear to be missing ;)

- Bert  -

PS: makeStArray: might prove useful
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20170119/739ae2f2/attachment.html>


More information about the Vm-dev mailing list