VMMakerJS

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

VMMakerJS

Bert Freudenberg
 
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 source.squeak.org.

This is (unsurprisingly) somewhat of a kludge. I had to work around pointer arithmetic (because unlike Smalltalk'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'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.

And then there'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't judge, it serves its purpose, namely generating the plugins that do not depend on libraries or other external code. And that's actually not that few, 17 total:

        https://github.com/bertfreudenberg/SqueakJS/tree/master/plugins

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.

The generated code even looks quite nice, modulo excessive parens.

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's optimizing C compilers and modern CPUs, does it really make a difference to write ptr++ instead of ptr[i++]?

Anyway, I'm not really complaining, Slang was intended as just being C with, so it's no wonder people use it like that. The type declarations help immensely in figuring out what'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.

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?

- Bert -

(*) https://github.com/bertfreudenberg/SqueakJS/tree/master/utils/VMMakerJS.package/JSCodeGenerator.class

smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: VMMakerJS

Eliot Miranda-2
 


On Fri, Oct 10, 2014 at 12:27 AM, Bert Freudenberg <[hidden email]> wrote:
 
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 source.squeak.org.

This is (unsurprisingly) somewhat of a kludge. I had to work around pointer arithmetic (because unlike Smalltalk'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'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.

And then there'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't judge, it serves its purpose, namely generating the plugins that do not depend on libraries or other external code. And that's actually not that few, 17 total:

        https://github.com/bertfreudenberg/SqueakJS/tree/master/plugins

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.

The generated code even looks quite nice, modulo excessive parens.

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's optimizing C compilers and modern CPUs, does it really make a difference to write ptr++ instead of ptr[i++]?

Anyway, I'm not really complaining, Slang was intended as just being C with, so it's no wonder people use it like that. The type declarations help immensely in figuring out what'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.

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?

Of course you should.
 

- Bert -

(*) https://github.com/bertfreudenberg/SqueakJS/tree/master/utils/VMMakerJS.package/JSCodeGenerator.class



--
best,
Eliot
Reply | Threaded
Open this post in threaded view
|

Re: VMMakerJS

David T. Lewis
 
On Fri, Oct 10, 2014 at 12:30:27AM -0700, Eliot Miranda wrote:
>  
> On Fri, Oct 10, 2014 at 12:27 AM, Bert Freudenberg <[hidden email]> wrote:
> >
> > 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?
> >
>
> Of course you should.
>

+1000

Absolutely. Yes please.

Reply | Threaded
Open this post in threaded view
|

re: VMMakerJS

ccrraaiigg
In reply to this post by Bert Freudenberg
 

> ...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?

     Yes, and well done!


-C

--
Craig Latta
netjam.org
+31   6 2757 7177 (SMS ok)
+ 1 415  287 3547 (no SMS)

Reply | Threaded
Open this post in threaded view
|

re: VMMakerJS

Bert Freudenberg
 
Thanks for the encouragement. It's up.

- Bert -




smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

re: VMMakerJS

David T. Lewis
 
On Fri, Oct 10, 2014 at 03:52:49PM +0200, Bert Freudenberg wrote:
>  
> Thanks for the encouragement. It's up.
>
> - Bert -
>

I added SqueakJS to the configuration map for VMMaker, so it will
be included when installing VMM trunk from SqueakMap or doing
VMMaker class>>updateFromServer. It should load cleanly into the
oscog branch also, although I did not check.

Dave

Reply | Threaded
Open this post in threaded view
|

re: VMMakerJS

Bert Freudenberg
 
On 11.10.2014, at 16:23, David T. Lewis <[hidden email]> wrote:

> On Fri, Oct 10, 2014 at 03:52:49PM +0200, Bert Freudenberg wrote:
>>
>> Thanks for the encouragement. It's up.
>>
>> - Bert -
>
> I added SqueakJS to the configuration map for VMMaker, so it will
> be included when installing VMM trunk from SqueakMap or doing
> VMMaker class>>updateFromServer. It should load cleanly into the
> oscog branch also, although I did not check.
>
> Dave
Oh, awesome :)

- Bert -


smime.p7s (5K) Download Attachment