State-of-the-art JS compilers: no bytecode, no intermediate representation other than source

19 July 2011

A brief note; some­thing I dis­cov­ered re­cently found surprising: JavaScript compilers, which these days end up es­sen­tially com­pil­ing the same source code into machine code mul­ti­ple times (the same func­tion might some­times take ints and some­times take floats, for example), do it by going back to the source code and re-parsing the source. In particular, they don’t start from an in­ter­me­di­ate rep­re­sen­ta­tion like an AST or bytecode. This applies both the v8 and Firefox. (Actually it’s not clear that Firefox ac­tu­ally op­er­ates this way, but Eich says that it could.) I wonder if they have es­sen­tially two ver­sions of the parser, one for un­ver­i­fied source code (better de­bug­ging information, but slower) and another for source code known to be syn­tac­ti­cally correct? And what does this mean for Parrot?