Micro QuickJS JavaScript 引擎的公共代码仓库
MicroQuickJS(又名 MQuickJS)是一款面向嵌入式系统的 JavaScript 引擎。它只需低至 10 kB 的 RAM 即可编译和运行 JavaScript 程序。整个引擎(包括 C 库)仅需约 100 kB 的 ROM(ARM Thumb-2 代码)。其运行速度与 QuickJS 相当。
MQuickJS 仅支持接近 ES5 的 JavaScript 的一个子集。它实现了一种更严格的模式,在该模式下,一些容易出错或低效的 JavaScript 构造会被禁止。
尽管 MQuickJS 与 QuickJS 共享大量代码,但其内部实现有所不同,以消耗更少的内存。具体来说,它依赖于追踪式垃圾回收器(tracing garbage collector),VM 不使用 CPU 栈,并且字符串以 UTF-8 存储。
REPL 是 mqjs。用法:
usage: mqjs [options] [file [args]]
-h --help list options
-e --eval EXPR evaluate EXPR
-i --interactive go to interactive mode
-I --include file include an additional file
-d --dump dump the memory usage stats
--memory-limit n limit the memory usage to 'n' bytes
--no-column no column number in debug information
-o FILE save the bytecode to FILE
-m32 force 32 bit bytecode output (use with -o)
-b --allow-bytecode allow bytecode in input file编译并运行一个使用 10 kB RAM 的程序:
./mqjs --memory-limit 10k tests/mandelbrot.js除了正常的脚本执行外,mqjs 还可以将编译后的字节码输出到持久存储(文件或 ROM):
./mqjs -o mandelbrot.bin tests/mandelbrot.js然后你可以像运行普通脚本一样运行编译后的字节码:
./mqjs -b mandelbrot.bin字节码格式取决于 CPU 的字节序和字长(32 位或 64 位)。在 64 位 CPU 上,可以使用 -m32 选项生成可在嵌入式 32 位系统上运行的 32 位字节码。
如果你想节省一些存储空间,可以使用 --no-column 选项来移除列号调试信息(只保留行号)。
MQuickJS 仅支持 JavaScript 的一个子集(主要是 ES5)。它始终处于更严格的模式,在该模式下某些 erro
暂无开放 Issues,或尚未同步最近议题。