Is there any way to convert C code to JavaScript and from JavaScript to C? I found V8 juice
which can generate JavaScript-side
classes from C++, but it's only one way (C++ to JavaScript).
I'm not looking for a software.
This is absolutely possible, but all attempts to do so never quite made the golden bridge from C to javascript, if we would, C++ would not exist since C would just be the best language to use at any level of programming.
JavaScript is an interpreted language, not a compiled language. A program such as C++ or Java needs to be compiled before it is run. The source code is passed through a program called a compiler, which translates it into bytecode that the machine understands and can execute.
JavaScript appears to be almost 4 times faster than C++! I let both of the languages to do the same job on my i5-430M laptop, performing a = a + b for 100000000 times. C++ takes about 410 ms, while JavaScript takes only about 120 ms.
You can translate JavaScript to Python using Js2Py. It supports whole JavaScript and you can use it to translate large JavaScript modules like esprima. js (a JavaScript 6 parser).
Very, very tricky --- Javascript is a heavily dynamic language where pretty much everything can be changed at run time: names of variables, functions, types, etc. As such it maps very badly onto C. And that's not even considering eval()
, which will let you construct arbitrary chunks of Javascript in strings and run them.
Any Javascript translator would have to be able to cope with such things, which means it would have to translate the Javascript into C at run-time --- which makes it a JIT, which you're already using.
You may want to look at writing C bindings for Javascript instead. These will allow your Javascript code to call out to C code and vice versa. This would allow people to write plugins in C, compile them into .so
shared libraries, which you can now load and run from your Javascript code. This means you don't need to translate anything.
Javascript's not my area so I can't recommend any particular mechanism, I'm afraid --- but I'd be very surprised if V8Juice, which you've already found, didn't let you do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With