cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.46k stars 160 forks source link

Support for asm.js #44

Closed renaudpawlak closed 8 years ago

renaudpawlak commented 8 years ago

It should be possible in JSweet to write asm.js modules.

The good news is that Java, by supporting integers and floats, could be a good environment to generate type-checked asm code (so is C++). Of course there would be the limitations imposed by asm.js (only numbers, no strings, no objects, ...). NOTE: on contrary, TypeScript, with its sole number is not well armed to type check asm.js, as said here.

So, the idea would be to have an annotation to generate the "use asm" directive. That could be a specific annotation or a generic one. Let us imagine a generic @StringDirective annotation. We could have something like:

@StringDirective("use asm")
class MyAsmModule {
    public void static m() {
        int first = 5;
        int second = first;
        float f = first;
   }
}

Which would generate as the following TypeScript code:

class MyAsmModule {
    "use asm"
    m() : void {
        var first = 5;
        var second = first | 0;
        var f = first | 0.0;
   }
}

NOTE: my knowledge of asm.js being still quite recent, I may be getting some things wrong so please correct me if it is the case.

renaudpawlak commented 8 years ago

This does not make much sense for now regarding other priorities. We should take a look at the webassembly project and see whether it makes sense to support anything in JSweet. But for now it is not a priority.