Node.JS script
A command
parameter ending in .js
or .mjs
will automatically
be executed through node.js.
Each snippet will be run in its individual process.
The example below execute the Z3 constraint solver.
compileCode: {
langs: [
...,
{
lang: "z3wasm",
extension: "z3",
inputLang: "lisp",
command: "./langs/z3.mjs",
},
];
}
where z3.mjs
is a node script that reads input.z3
, options.json
from the current working directory,
executes Z3 and prints the result to the console.
./langs/z3.mjs
import { readFileSync } from "node:fs";
import z3 from "z3-solver";
async function run() {
const { Z3 } = await z3.init();
const input = readFileSync(`./input.z3`, { encoding: "utf8" });
const options = JSON.parse(
readFileSync(`./options.json`, { encoding: "utf8" })
);
const { timeout = 10000 } = options;
...
console.log(output)
if (error)
console.error(error)
}
(async () => {
try {
await run();
process.exit(0);
} catch (e) {
process.exit(1);
}
})();
```z3wasm
(declare-const a Int)
(declare-fun f (Int Bool) Int)
(assert (= a 10))
(assert (= (f a true) 100))
(check-sat)
```
http://localhost:3000
(declare-const a Int)
(declare-fun f (Int Bool) Int)
(assert (= a 10))
(assert (= (f a true) 100))
(check-sat)
Output
sat