Javascript bytecode

Walter Bright newshound2 at digitalmars.com
Wed Dec 19 12:06:18 PST 2012


On 12/19/2012 7:44 AM, Andrei Alexandrescu wrote:
> I thought the claim was about ASTs vs. bytecode, which slowly segued into source
> code vs. byte code.

Originally, the claim was how modules should be imported in some binary format 
rather than as source code.


> Are e in agreement there is a cost of translating JS source
> code to AST format? (The cost may be negligible to some applications but it's
> there.)

There is a cost, and it is a killer if you've got an 8 bit CPU with a 2K EPROM 
as a target. This is no longer relevant.


> There's also the serialization aspect. Serializing and deserializing an AST
> takes extra effort because pointers must be fixed. Bytecode can be designed to
> avoid most of that cost.

Bytecode does not avoid that cost, in fact, bytecode *is* a serialized AST 
format. (And, btw, the first thing a JIT compiler does is convert bytecode back 
into an AST.)


> On these two accounts alone, one may as well choose bytecode if it ever needs to
> be read and written. Defining a strategy for pointer serialization is comparable
> work.

You're not saving anything.


> That's not answering the question.

Analogies are legitimate answers to questions about motivation.



More information about the Digitalmars-d mailing list