3 ms·
imho an intermediate bytecode makes no sense, as silentbicycle explained. 3 alternatives: 1) make every browser vendor implement multiple runtimes 2) x-to-js
by stefs 16y ago
imho an intermediate bytecode makes no sense, as silentbicycle explained.
3 alternatives:
1) make every browser vendor implement multiple runtimes
2) x-to-js translators
3) interpreters in implemented in javascript
ad 1) multiple runtimes: not a good idea, because of multiple reasons.
first, versioning hell. javascript is ~15 years old, and browser vendors are still not able to provide 100% compatibility. you'd have versioning hell, only worse. second, it would hurt javascript performance, because browser vendors would have to split ressources. third: which languages should be supported? you just couldn't please everyone, so there would be ongoing "why is language x supported but not y?" problems.
ad 2) translators: are in use now. see coffeescript, gwt and ghcjs, ...
pros:
- almost native javascript speed
- already possible
cons:
- small translation overhead (depending on if it's JITted or precompiled)
- not everything is possible. if the javascript runtime doesn't support tail call optimization, the translation won't have it either. certain magic just doesn't translate.
ad 3) interpreters implemented in js
afaik there are some, e.g. js brainfuck interpreters.
pros:
- the sky's the limit
- already possible
cons:
- slow (adds an emulation layer).
that said, i'm against additional browser-provided runtimes except NACL. you could use javascript for your day to day work and NACL for your special needs. i'm not sure if NACL would be a complete stand-in for JS thought - would it be possible to communicate with the DOM (or at least JS)? if yes, there you have it - problem solved.
- silentbicycle 16y agoI think a standardized bytecode for Javascript could make sense, but designing a VM for JS and then trying to port (say) Ruby or ML to it later would be awkward, and I don't think most web devs are aware of that. Compiling to Javascript is a practical choice now. I'm not a fan of the language, but that avoids a lot of its pain points. I also wonder why these discussions seem to assume we're going to stay with the web stack as-is forever, but that's neither here nor there.
- nickik 16y agoJS is just not a good language as a compiler target. If you hade an Bytcode with all the right low level types and features it would be easier to optimise for the VM implementers (mozilla, google ...), you could modify JS without changing the VMs, languages would not be blocked by the speed of JS, faster languages would be possible. It would be easier to make languages that are very diffrent from JS work in the browser. Your solution work but a haskell interpreter in js will never have good performence but if you could make a GHC backend that comipiles to "web bytecode".