TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Architecture for a JavaScript to C compiler

90 pointsby timrufflesover 6 years ago

8 comments

snekover 6 years ago
I don't understand why people keep making js-to-native compilers. the result is always less performance that what modern js engines can do to the original source code, because all those runtime behaviours the author mentions build up really fast. js engines actually run the code and figure out the types and such to create highly optimized machine code.
评论 #19159394 未加载
评论 #19159464 未加载
评论 #19159626 未加载
评论 #19160748 未加载
评论 #19160638 未加载
评论 #19159938 未加载
评论 #19160669 未加载
truth_seekerover 6 years ago
I wonder how much optimization will it bring to compared to existing JS runtimes such as V8.<p>Thanks to competing world for web browsers, JS runtimes not only efficiently parse to optimized native code but also provide really good JIT compilation benefits.<p>Speculative optimization for V8 - <a href="https:&#x2F;&#x2F;ponyfoo.com&#x2F;articles&#x2F;an-introduction-to-speculative-optimization-in-v8" rel="nofollow">https:&#x2F;&#x2F;ponyfoo.com&#x2F;articles&#x2F;an-introduction-to-speculative-...</a><p>Parallel and Concurrent GC - <a href="https:&#x2F;&#x2F;v8.dev&#x2F;blog&#x2F;trash-talk" rel="nofollow">https:&#x2F;&#x2F;v8.dev&#x2F;blog&#x2F;trash-talk</a><p>Good summary on 10 years of V8 - <a href="https:&#x2F;&#x2F;v8.dev&#x2F;blog&#x2F;10-years" rel="nofollow">https:&#x2F;&#x2F;v8.dev&#x2F;blog&#x2F;10-years</a>
评论 #19160654 未加载
rkeene2over 6 years ago
A lot of research and hard work has gone into TclQuadCode [0], which compiles Tcl (which is even more dynamic than JavaScript) into machine code via LLVM.<p>The authors indicated at one point it took around 5 PhDs to get it going.<p>[0] <a href="https:&#x2F;&#x2F;core.tcl.tk&#x2F;tclquadcode&#x2F;dir?ci=trunk" rel="nofollow">https:&#x2F;&#x2F;core.tcl.tk&#x2F;tclquadcode&#x2F;dir?ci=trunk</a>
评论 #19159553 未加载
ndesaulniersover 6 years ago
I actually think this is possible; and started prototyping it (because esprima is awesome, and not to many other languages have an equivalent that&#x27;s so easy to use).<p>Some thoughts: I think it&#x27;s easier to target C++ than C, since C++ can help you write more type generic code. I think it&#x27;s easy to generate tagged unions, then for optimizations try to prove monomorphism. Finally, it may be simpler to start off with support for typescript, and fail to compile if there are any ANY types. I do think it&#x27;s possible though. JS&#x2F;TS -&gt; C++ -&gt; WASM (yes, I was out of my mind when I thought of this)
评论 #19159861 未加载
maxxxxxover 6 years ago
With all the dynamic stuff Javascript has it seems really difficult to create performant C code.<p>There is a PHP to .NET compiler which probably has similar problems. On second thought that one is probably easier because .NEt has a dynamic runtime.
评论 #19159405 未加载
tannhaeuserover 6 years ago
Congrats to completing this project. What&#x27;s the status and further plans for it? I didn&#x27;t find a license.
ridiculous_fishover 6 years ago
How are exceptions handled with this design? For example the `n &lt; 3` may throw (it invokes the valueOf method).
评论 #19159621 未加载
maxgraeyover 6 years ago
I wonder why people still try write transpiler from JS to C&#x2F;C++ or LLVM (which make sense at least). But this not performant way and usually produce much bigger overhead than jit vm which use speculative optimizations.<p>Some projects: 1. <a href="https:&#x2F;&#x2F;github.com&#x2F;fabiosantoscode&#x2F;js2cpp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;fabiosantoscode&#x2F;js2cpp</a> 2. <a href="https:&#x2F;&#x2F;github.com&#x2F;raphamorim&#x2F;js2c" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;raphamorim&#x2F;js2c</a> 3. <a href="https:&#x2F;&#x2F;github.com&#x2F;ammer&#x2F;js2c" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ammer&#x2F;js2c</a> 4. <a href="https:&#x2F;&#x2F;github.com&#x2F;NectarJS&#x2F;nectarjs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;NectarJS&#x2F;nectarjs</a> 5. <a href="https:&#x2F;&#x2F;github.com&#x2F;ovr&#x2F;StaticScript" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ovr&#x2F;StaticScript</a>