Translating C to JavaScript [closed]
Asked Answered
T

2

22

I've got a bunch of math/dsp algorithms in C. Single functions, one function per file, no fancy linking or includes or preprocessor directives, only c99 and standard library calls (mainly memset and memmoves to handle array copying etc). Translating them is not a big problem, but it takes time. I was wondering if there was some C -> Javascript translation tool, in order to speed up the work.

Please mind I don't need a perfect translation, I will put my hand on the final result anyway. What I need is a simple tool that helps with the basic, "boring" things.

Anyone heard of such a thing?

Edit: seems that emscripten will do the trick.

Trichinopoly answered 18/11, 2010 at 1:21 Comment(2)
The way that C allows pointers to be used, such a tool would surely fail on all but the most contrived examples.Laminar
I'm noot looking for a perfect translator that can understand the pointer logic, I'm looking for a mildly-stupid workhorse that can do the boring parts automatically.Trichinopoly
S
26

Update: it seems The Times They Are a-Changin' :)

See this article: DOOM Ported to JavaScript and HTML5

Zakai compiled the DOOM source code from C to JavaScript using Emscripten and Clang and optimized it with Closure Compiler.

And here is the Project page. Have fun! :)

Sagittal answered 18/11, 2010 at 7:52 Comment(8)
ahah i found the way: translate c to Java with this: axiomsol.com, then translate Java to Javascript with GWT (just joking).Trichinopoly
Anyway: 1) You parse C and, if you realze it's an integer division (you look at the types of the operands), you Math.floor the result in js 2) You don't care what is useless, you pass the parameter anyway in the translated script. It's redundant, not incorrect. Mind I don't look for a translator that optimizes, I'm gonna do do the optimizations. 3) Looks more complex, but you can always lokk at the array type and calculate how many elements you're copying. 3b) Objects in C? You're talking about structures or you're thinking about OO techniques in C?Trichinopoly
See my update, it seem some folks got it working for DOOM :)Sagittal
I see you found the project. Why isn't your accepted answer on the top? I already missed it :)Sagittal
The trick used it emulating a CPU. It's... really inefficient! But it works :)Bernadine
Unfortunately, your link to the ultimate proof of concept was taken down by id SoftwareRumormonger
@Trichinopoly +1 :)Naca
readwrite updated their link structure, heres the new link readwrite.com/2011/05/31/doom-ported-to-javascript-andOasis
T
19

FYI, Emscripten does exactly that.

Trichinopoly answered 16/3, 2011 at 9:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.