Typescript: Support compile to asm.js

Created on 21 Nov 2014  路  6Comments  路  Source: microsoft/TypeScript

basically what was once here: http://typescript.codeplex.com/discussions/438243

Can it be done? :)))

Duplicate

Most helpful comment

Typescript to Haxe: https://github.com/jeremyfa/node-ts2hx
Haxe to C++ : http://old.haxe.org/doc/start/cpp
C++ to LLVM : http://llvm.org/
LLVM to ASM : https://github.com/kripken/emscripten
Good luck =)

All 6 comments

See #375

@Ap0ph1s. ASM is hard. And it has a large number or restrictions. I wish it was that easy to just tell typescript to compile to it. But from what I've read, it seems better to write your code in C and then compile down to ASM. :|

Just curious, for what do want to use ASM for, or is it more like you are writing ASM and want to use TypeScript to do it?

Having an --asmjs option with the compiler would help to optimize TypeScript code for online games.
I like the original idea.
Also, this would help to create a kind of buzz in the web community and help people to convert to the One True Language: TypeScript for all.

Typescript to Haxe: https://github.com/jeremyfa/node-ts2hx
Haxe to C++ : http://old.haxe.org/doc/start/cpp
C++ to LLVM : http://llvm.org/
LLVM to ASM : https://github.com/kripken/emscripten
Good luck =)

Personally, I don't see much of a benefit of using TypeScript instead of JavaScript. Especially now that the ES6 standard also added class-based object-oriented programming to the language, all you'd really get from adopting TypeScript today would be the addition of static typing... and interfaces. Besides making your code look more like eg. Java code, I really don't see the benefit at all... except when using static typing to optimize the JavaScript code it produces... which is where asm.js comes in.

In environments where high performance is essential (eg. 3D rendering in the browser for browser games or GIS web apps), the current approach is to write the core code (that does the heavy lifting) in C/C++ (compiled to asm.js) and everything else in JavaScript. That means you need a really good understanding of both JavaScript (which I do) and C/C++ (which I don't) to be able to write proper code or maintain existing code for such apps, both inside and outside of the the core code.

How great would it be to be able to use one - TypeScript - codebase for such projects and compile to asm where possible and to regular JavaScript where not possible? Or to put it differently : how great would it be for a JavaScript programmer to be able to program in highly readable superset of JavaScript and have it compiled - where possible - to a highly optimized subset of JavaScript?

It seems like a win-win for everyone, really, especially if you leave it optional whether or not to compile to asm.js for developers who don't work in high performance environments and prefer readability to performance.

IMO, compilation of (a subset of) TypeScript to asm.js would be major improvement over TypeScript as it exists today. For me, it would totally be a game changer and make the difference between supporting and not supporting the adoptation of TypeScript at the company I work for...

Those also interested in converting staticly typed variations of JavaScript to asm.js, WebAssembly or C might want to take a look at ThinScript, TurboScript or AssemblyScript.

ThinScript compiles to JavaScript, WebAssembly, and C. TurboScript compiles only to JavaScript and WebAssembly. AssemblyScript compiles to WebAssembly only.

Each of these languages have been inspired by TypeScript, and the latter is a subset of TypeScript.

I'd like to thank @RReverser for pointing me in the direction of these languages.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wmaurer picture wmaurer  路  3Comments

jbondc picture jbondc  路  3Comments

dlaberge picture dlaberge  路  3Comments

blendsdk picture blendsdk  路  3Comments

weswigham picture weswigham  路  3Comments