JSCPP
JSCPP copied to clipboard
CPP -> JS compiler
Is it possible not to execute C++ code but only translate it to JS, which could be written to a file and then executed?
This was my first thought when I started this project. However, given how many machine/platform/C++ specific behaviors exist in C++, most of the operations need to done with complex logic.
For example, a=b+c
involves type compatibility checking, + operator overriding, integer promotion, integer to float promotion, unsigned to signed promotion, overflow checking, implicit type conversion, assignment operator overriding and maybe some other things. So I am not confident enough to be able to compile C++ into a human-readable JavaScript source file.
If we don't aim for readability, then Emscripten already does that pretty efficiently with asm.js.
Thank you, I've read about Emscripten, and then my first thought was: could we emscript Emscripten with Emscripten to get Emscripten in browser? Sounds a bit crazy, and perharps the resulting emscripted Emscripten would be too big and/or slow to use it for real purposes... Or Emscripten is not emscriptable. Moreover, in that case we should emscript a C++ compilre.
Emscripten uses LLVM, so you'd need to compile that first. :P
You guys are right. Emscripten runs offline since it requires a local C++ compiler to generate LLVM for it first. Although they seem to have an example of Emscriptened Clang Compiler and llvm.js but I cannot get these two working together (and it is slow).
One possible way could be to use CFRONT (https://github.com/mingodad/cfront-3) generating Javascript
instead of C
CFRONT itself compiled to WASM
, the later is something I'm thinking to experiment with.
Just found this project https://github.com/filhodanuvem/cloudblocks that says:
Transpiler from C to Javascript made as a final project in UFJF university.
It uses a bison
grammar I'll look at it to see how far it goes.