参阅上一篇:Fabrice Bellard(个人网站:bellard.org)介绍
Fabrice Bellard(个人网站:bellard.org)是计算机领域最具影响力的程序员之一,其贡献跨越多个技术领域并持续推动开源生态发展。
QuickJS
小型嵌入式JavaScript引擎,强调低内存占用与ES6规范支持,适用于IoT设备与脚本扩展开发。
从 bellard.org 下载 quickjs-2025-04-26.tar.xz 到 D:\tcc\ , 然后解压。
从 bellard.org 下载 quickjs-cosmo-2025-04-26.zip 到 D:\tcc\ , 然后解压。看 readme.txt
D:\tcc\quickjs-cosmo-2025-04-26> rename qjs qjs.exeD:\tcc\quickjs-cosmo-2025-04-26> qjs -h
QuickJS version 2025-04-26
usage: qjs [options] [file [args]]
-h --help list options
-e --eval EXPR evaluate EXPR
-i --interactive go to interactive mode
-m --module load as ES6 module (default=autodetect)--script load as ES6 script (default=autodetect)
-I --include file include an additional file--std make 'std' and 'os' available to the loaded script
-T --trace trace memory allocation
-d --dump dump the memory usage stats--memory-limit n limit the memory usage to 'n' bytes (SI suffixes allowed)--stack-size n limit the stack size to 'n' bytes (SI suffixes allowed)--no-unhandled-rejection ignore unhandled promise rejections
-s strip all the debug info--strip-source strip the source code
-q --quit just instantiate the interpreter and quit
计算圆周率 pi ,用 BigInt :
copy D:\tcc\quickjs-2025-04-26\examples\pi_bigint.js D:\tcc\quickjs-cosmo-2025-04-26\
cd D:\tcc\quickjs-cosmo-2025-04-26
qjs pi_bigint.js 100
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
为了计算 斐波那契数列(Fibonacci sequence),编写 fib_bigint.js 如下
/** Fibonacci sequence computation in Javascript using the BigInt type*/
"use strict";function calc_fib(n)
{var a = BigInt(0);var b = BigInt(1);var c = BigInt(0);if (n <= 0)return a;for (var i = 2; i <= n; i++) {c = a + b;a = b;b = c;}return b;
}function main(args) {var r, n, n_bits, out;if (args.length < 1) {print("usage: qjs fib_bigint.js n_digits");return;}n = args[0] | 0;if (n <=0) return;var r = calc_fib(n);var result = r.toString();print(result);
}var args;
if (typeof scriptArgs != "undefined") {args = scriptArgs;args.shift();
} else if (typeof arguments != "undefined") {args = arguments;
} else {/* default: 100 digits */args=[100];
}main(args);
cd D:\tcc\quickjs-cosmo-2025-04-26
运行 qjs fib_bigint.js 365
8531073606282249384383143963212896619394786170594625964346924608389878465365
校验,运行 python fibonacci.py 365
F(365): 8531073606282249384383143963212896619394786170594625964346924608389878465365