參閱上一篇: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