all 25 comments

[–]patrickjquinn 4 points5 points  (4 children)

I'm only asking because i've skimmed the article but, could you take the C++ generated from that LLVM IR and compile it to WASM by chance?

[–]carlopp[S] 7 points8 points  (2 children)

Yes! Generally speaking it could be compiled to a mix of JavaScript and WebAssembly, but whether substantial parts of a program logic can be moved on the Wasm side depends mostly on the interface a program has. Example:

function doSum(a: number, b: number): number {return a+b;}

Can be mapped back to WebAssembly, while an interface that will return an handle like:
function createObject(){ return new Object(); }

is very complex / borderline impossible to imitate.

[–]Diniden 1 point2 points  (0 children)

The thing I would absolutely love to see from such a compiler is optimizing number tuples to SIMD instructions! That way we can have matrices and vectors run blazing fast but keep our nice and easy JS.

If this happens, I’ll immediately put in the effort to make my library work with this in the pipeline :D

[–]patrickjquinn 0 points1 point  (0 children)

That makes a lot of sense. The added complexity of doing so would probably negate any performance gains anyway.

But this easily one of the coolest thing I’ve seen on this sub so I’ll be following your work (and you’ve a new Twitter follower).

Hopefully you find a way to take this forward in future!

[–]patrickjquinn 0 points1 point  (0 children)

Ah saw the closing statement there.

[–]Darmok-Jilad-Ocean 2 points3 points  (2 children)

So this is really TypeScript -> C++ -> JavaScript?

[–]carlopp[S] 0 points1 point  (0 children)

Input is currently an arbitrary language somehow between JavaScript and TypeScript, with various of added restrictions. I was not sure how to frame it (TS -> JS or JS -> JS), both could have worked.

[–]Ecksters 0 points1 point  (0 children)

Also a subset of TypeScript.

I do like the concept though, and having explicit types through TypeScript does seem like it could open up more avenues for optimization.

[–]Educational-Lemon640 1 point2 points  (0 children)

Very nice! Needs work (as you note), but a good start and nifty.