知乎一个回答说用到 LLVM
https://www.zhihu.com/question/20686820/answer/15891597```
网页中运行代码是如何实现的?
楼主可以看看一个更强大的网站:
repl.it你会发现网页不仅仅可以运行 js ,还有 Python 、Ruby 、Basic 、Lua 、Scheme 等超过 15 种程序语言。其主要的机理是用到神器:LLVM 。 将目标语言转为 LLVM 的实现,再由 LLVM 转为 JavaScript 由浏览器执行。
LLVM (formerly Low Level Virtual Machine) is a compiler infrastructure written in C++; it is designed for compile-time, link-time, run-time, and "idle-time" optimization of programs written in arbitrary programming languages. Originally implemented for C and C++, the language-agnostic design (and the success) of LLVM has since spawned a wide variety of front ends: languages with compilers which use LLVM include Objective-C, Fortran, Ada, Haskell, Java bytecode, Python, Ruby, ActionScript, GLSL, D, and Rust.
直接摘录英文了,中文翻译没办法看。
LLVM 维基:
http://en.wikipedia.org/wiki/LLVMLLVM 官网:
http://llvm.org/Repl.it 中各语言的实现源码:
https://github.com/replit```