2 ms·
Well, then I should use some regular expressions, a parser generator, AST walker and syntax analyzer, with the help of a few directive comments, to turn my stri
by xigency 11y ago
Well, then I should use some regular expressions, a parser generator, AST walker and syntax analyzer, with the help of a few directive comments, to turn my strict subset of JavaScript code into C, and then use emscripten to generate WebAssembly.
Then I will have faster (and smaller) code on platforms that support WebAssembly and regular JavaScript on platforms that don't.
What a wonderful way to deploy JavaScript to WebAssembly for enlightened developers, which doesn't involve a "compiler."
Obviously, we are thinking of different scenarios. My subset of JavaScript may be different than yours, which might be different than asm.js. Asm.js would be great except it isn't idiomatic and having a fixed heap isn't always great. That doesn't mean there aren't middle grounds which are as of yet unexplored. This is sort of a limited area, which is probably why no one's started a project on this yet.
By the window['foo'] argument, minifiers are unnecessary because then you can't use eval().
- PeCaN 11y ago> turn my strict subset of JavaScript code into C, and then use emscripten to generate WebAssembly. Well, the problem there is that your subset would be... C. JavaScript without automatic memory management, closures, prototype inheritance[1], and dynamic types isn't really JS anymore. > By the window['foo'] argument, minifiers are unnecessary because then you can't use eval(). Most minifiers don't touch object properties or global variables for this reason. Closure compiler is the only one that does and it's quite strict (and doesn't work on a lot of JS code because of it). 1. Assuming objects are hash tables in your implementation, you might be able to do inheritance by reference counting a list of parent hash tables but that could get messy.
- xigency 11y agoThe code that I have to work with is static. It just happens to be JavaScript. Aside from writing some type casts and a linked list implementation, the standard implementation for a project like this doesn't have to be large. And yes, it boils down to a trivial C compiler. Also, Uglify 2 modifies global properties if you tell it to, and neither uglify nor closure compiler do well with object properties, which can be renamed. All of these arguments assume that a developer is unaware or not understanding of the mechanisms that their code uses. It seems no one is interested in using anything other than emscripten/LLVM.
- esailija 11y agoThere was an experiment ("strong mode")[1] of a subset of JavaScript that is way higher level than asm.js but it failed [2]. 1. https://developers.google.com/v8/experiments#strong-mode https://developers.google.com/v8/experiments#strong-mode 2. https://groups.google.com/forum/#!msg/strengthen-js/ojj3TDxbHpQ/5ENNAiUzEgAJ https://groups.google.com/forum/#!msg/strengthen-js/ojj3TDxb...
- hutzlibu 11y agoThat is interesting, thx. ... but it seems to me, they failed, because they wanted to mix strong typed js with weak typed ... "the main problem here was the interoperability with weak classes: we need to allow inheriting strong from weak classes and vice versa"