[Vm-dev] Re: [squeak-dev] compiled squeakjs

Ryan Macnak rmacnak at gmail.com
Mon Jan 19 00:26:28 UTC 2015


On Sun, Jan 18, 2015 at 12:59 PM, <florin.mateoc at gmail.com> wrote:

> Ryan,
>
> Can you please explain what you do for initialization (especially for
> large arrays, sets, etc)? Assuming that Newspeak also has something like
> Smalltalk's nil, do you fill them at creation time with nil?
>

We eagerly assign nil to all slots. For regular objects, it is important
that slots for a given class are always initialized in the same order,
otherwise a JS engine like V8 won't consider all the instances to be of the
same Map (hidden class), things will seem more polymorphic than they are,
and optimizations won't happen. For arrays, I don't know whether this is
more harmful to performance because we pollute type data about the array's
elements with UndefinedObject or this is more helpful because we don't need
checks for undefined in #at:. Certainly in terms of implementation effort,
eager initialization is much better than sprinkling checks in all the
places that access slots.


> I was thinking of avoiding that and testing the receiver at every
> invocation for JavaScript's undefined instead. Of course, this just moves
> the pain point, I am not sure which is better. Also, the test for nil can
> be avoided when the receiver is "this" or "super" or some literal - one can
> optimize this even in other cases with some static analysis.
>

We do very little static analysis beyond the standard cheats for #ifTrue:
and friends. Generally, it makes implementing reflection much more
difficult. dart2js is a good example of a compiler with this problem.

I also don't understand the line:
> "NS2JS and NS2V8 both map Newspeak's basic types onto JavaScript's basic
> types by installing functions on the prototypes of Number, String, etc. We
> apply strict mode, so these functions do not operate on boxed values."
>
> E.g. the following snippet works:
>
> "use strict"
> Number.prototype.test = function() {return 5};
> var n = 2;
> n.test()
>
> So what does it mean that "these functions do not operate on boxed values"?
>

When the function test is not in strict mode, every invocation requires the
allocation of a number object to use as the receiver. In strict mode, the
receiver is the number value directly. (ECMAScript 5.1 10.4.3)

Ryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20150118/feae6d16/attachment-0001.htm


More information about the Vm-dev mailing list