<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 10, 2014 at 12:27 AM, Bert Freudenberg <span dir="ltr">&lt;<a href="mailto:bert@freudenbergs.de" target="_blank">bert@freudenbergs.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br>Is there interest that I add the JavaScript code generator to the VMMaker repository? The code is currently in the SqueakJS repo (*), but I could additionally keep a copy on <a href="http://source.squeak.org" target="_blank">source.squeak.org</a>.<br>
<br>
This is (unsurprisingly) somewhat of a kludge. I had to work around pointer arithmetic (because unlike Smalltalk&#39;s VM simulator I cannot override + or at:put: in JavaScript) and emulate type casts (short int*? JS will laugh in your face. It doesn&#39;t even have integers. Double-precision float is all you need). Bit shifts are interesting, too, because shifting by 32 does not result in 0 as you might expect. And division gives you a float, and mod is off by 1 with the wrong sign etc.<br>
<br>
And then there&#39;s cCode:inSmalltalk:. Fun one. I ended up having a translation table with a JS snippet for every C snippet. And a bit of magic sprinkled on top. Don&#39;t judge, it serves its purpose, namely generating the plugins that do not depend on libraries or other external code. And that&#39;s actually not that few, 17 total:<br>
<br>
        <a href="https://github.com/bertfreudenberg/SqueakJS/tree/master/plugins" target="_blank">https://github.com/bertfreudenberg/SqueakJS/tree/master/plugins</a><br>
<br>
But it works, and is almost as efficient as my hand-written code. I was able to get rid of 1200 lines of my own BitBlt code that almost worked, and use the actual BitBlt implementation with all its nooks and crannies. And having a LargeIntegersPlugin makes a real difference in performance. And ZipPlugin too. Etc.<br>
<br>
The generated code even looks quite nice, modulo excessive parens.<br>
<br>
However, the JS code generator remains ugly, and is less than general. I wonder if some of the C-isms should be replaced with more general patterns. The memory access functions are a step in the right direction I think. Although I think they always should use a base (oop+baseHeaderSize would be my preference) and offset. This would make it rather simple to map to JS, and with today&#39;s optimizing C compilers and modern CPUs, does it really make a difference to write ptr++ instead of ptr[i++]?<br>
<br>
Anyway, I&#39;m not really complaining, Slang was intended as just being C with, so it&#39;s no wonder people use it like that. The type declarations help immensely in figuring out what&#39;s going on automatically most of the time, and I kludged the rest. Without modifying a single line in the original plugins, so far. Of course, if the plugin code changes I may have to adjust the code generator.<br>
<br>
Err, that turned out longer and more rambling than I intended. I really just wanted to know if I should copy it to the main VMMaker repo?<br></blockquote><div><br></div><div>Of course you should.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
- Bert -<br>
<br>
(*) <a href="https://github.com/bertfreudenberg/SqueakJS/tree/master/utils/VMMakerJS.package/JSCodeGenerator.class" target="_blank">https://github.com/bertfreudenberg/SqueakJS/tree/master/utils/VMMakerJS.package/JSCodeGenerator.class</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div>
</div></div>