|
|
|
|
|
by klibertp
4243 days ago
|
|
> Why would normal JS developers be writing in asm.js? Do you even understand why asm.js exists? asm.js is a compiler target, true. Is it really that much C specific? Isn't it possible to compile parts of JavaScript to asm.js? For example the parts which deal with drawing - computing points of - complex things on a canvas? That would be a good reason for JS devs to use asm.js - of course via a compiler, but if that's not available, I can imagine some people doing this by hand. Remember that people used to code in real asm all the time a few centuries ago. |
|
No, but I'd say it's low-level language specific. C, C++, Pascal, Swift, Go, D and the like. Not C# or Java.
> Isn't it possible to compile parts of JavaScript to asm.js?
Yes... asm.js, which is a subset of JS, can be compiled to asm.js. You can compile any language to itself. There's no real point in doing so, however.
More seriously, no, not really. JS is a dynamic language. It can't be compiled ahead-of-time.
> For example the parts which deal with drawing - computing points of - complex things on a canvas?
No, you couldn't compile that to native code. If you tried, I doubt it'd be faster than your browser's existing JIT.
> That would be a good reason for JS devs to use asm.js - of course via a compiler, but if that's not available, I can imagine some people doing this by hand. Remember that people used to code in real asm all the time a few centuries ago.
You could hand-write asm.js, but it'd be difficult. Manually manipulating the heap and stack isn't fun. There's no memory allocator included. It would make far more sense to just write in C, compile it, and write glue code, or just to write easily JIT-ed JS in the first place.