<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jan 19, 2017 at 3:55 AM, David T. Lewis <span dir="ltr"><<a href="mailto:lewis@mail.msen.com" target="_blank">lewis@mail.msen.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
For named primitives, we can load and run a primitive function from a specific<br>
module, as in the case of <primitive: 'primitiveFileSize' module: 'FilePlugin'>.<br>
<br>
We can also load a primitive with module name unspecified, as in the case of<br>
<primitive: 'primitiveScreenDepth'>. In that case we load and run the function<br>
from the main interpreter module.<br>
<br>
I want to implement the anonymous named primitive #primitiveUtcWithOffset in<br>
SqueakJS, but I am a total JavaScript noob so I am looking for an example of<br>
some other anonymous named primitive to use as a pattern.<br>
<br>
At first glance, I do not see any anonymous named primitives implemented in vm.js,<br></blockquote><div><br></div><div>Indeed, SqueakJS does not implement any of the currently used module-less named primitives.</div><div><br></div><div>It does, however, implement some obsolete ones, e.g. '<span style="color:rgb(121,93,163);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;white-space:pre-wrap">m23PrimitiveTransformPoint</span>' which was later moved to <span style="color:rgb(24,54,145);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;white-space:pre-wrap">Matrix2x3Plugin</span>.</div><div><br></div><div>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'>.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
so I want to ask - does the basic functionality of looking up and executing e.g.<br>
#primitiveScreenDepth from the <primitive: 'primitiveScreenDepth'> pragma work?<br></blockquote><div><br></div><div>Yes. Simply name your JavaScript method 'primitiveUtcWithOffset' and put it in the '<span style="color:rgb(24,54,145);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;white-space:pre-wrap">Squeak.Primitives</span>' class. I'd suggest putting it in the 'time' section <a href="https://github.com/bertfreudenberg/SqueakJS/blob/432dafd615a8e48019dbfc5e62a6599e4648ca3b/vm.js#L6486" target="_blank">https://github.com/<wbr>bertfreudenberg/SqueakJS/blob/<wbr>432dafd615a8e48019dbfc5e62a659<wbr>9e4648ca3b/vm.js#L6486</a></div><div><br></div><div>Note that quite a few indexed primitives do not exist as a full method. E.g. prim 135 is currently implemented as</div><div><br></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container" style="box-sizing:border-box;border-collapse:collapse;color:rgb(51,51,51);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:14px"><tbody style="box-sizing:border-box"><tr style="box-sizing:border-box"></tr><tr style="box-sizing:border-box"><td id="gmail-LC4426" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre"><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">135</span>: <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">this</span>.<span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">popNandPushIfOK</span>(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">1</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">this</span>.<span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">millisecondClockValue</span>());</td></tr></tbody></table><br></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div>basically to reduce tedious boiler-plate code. Just in case you're wondering why some of the primitives appear to be missing ;)<br></div><div><br></div><div>- Bert  - </div><div><br></div><div>PS: <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;white-space:pre">makeStArray</span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;white-space:pre">:</span> might prove useful</div></div></div></div>