@metta-ts/node 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-FIH2Z2UY.js → chunk-F6KAEMEJ.js} +5 -3
- package/dist/cli.js +19 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +4 -3
|
@@ -222,12 +222,13 @@ var ParallelFlatMatcher = class {
|
|
|
222
222
|
};
|
|
223
223
|
|
|
224
224
|
// src/index.ts
|
|
225
|
-
function readImports(src, baseDir) {
|
|
225
|
+
function readImports(src, baseDir, importRoot = baseDir) {
|
|
226
226
|
const m = /* @__PURE__ */ new Map();
|
|
227
227
|
const base = resolve(baseDir);
|
|
228
|
+
const root = resolve(importRoot);
|
|
228
229
|
for (const name of collectImports(src)) {
|
|
229
230
|
const p = resolve(base, name.endsWith(".metta") ? name : name + ".metta");
|
|
230
|
-
if (p !==
|
|
231
|
+
if (p !== root && !p.startsWith(root + sep)) continue;
|
|
231
232
|
if (existsSync(p))
|
|
232
233
|
m.set(
|
|
233
234
|
name,
|
|
@@ -239,8 +240,9 @@ function readImports(src, baseDir) {
|
|
|
239
240
|
function runFile(path, fuel, opts) {
|
|
240
241
|
const src = readFileSync(path, "utf8");
|
|
241
242
|
const tops = parseAll(src, standardTokenizer());
|
|
243
|
+
const fileDir = dirname(resolve(path));
|
|
242
244
|
const withPar = opts?.parEvalImpl === void 0 ? { ...opts, parEvalImpl: makeParEvalImpl(fuel ?? DEFAULT_FUEL) } : opts;
|
|
243
|
-
return evalSequential(tops, fuel, readImports(src, dirname(
|
|
245
|
+
return evalSequential(tops, fuel, readImports(src, fileDir, dirname(fileDir)), withPar);
|
|
244
246
|
}
|
|
245
247
|
|
|
246
248
|
export {
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
runFile
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-F6KAEMEJ.js";
|
|
5
5
|
|
|
6
6
|
// src/cli.ts
|
|
7
7
|
import { parseArgs } from "util";
|
|
@@ -23,21 +23,32 @@ function main() {
|
|
|
23
23
|
allowPositionals: true,
|
|
24
24
|
options: {
|
|
25
25
|
"max-steps": { type: "string" },
|
|
26
|
-
"max-stack-depth": { type: "string" }
|
|
26
|
+
"max-stack-depth": { type: "string" },
|
|
27
|
+
"hash-cons": { type: "boolean" },
|
|
28
|
+
"flat-atomspace": { type: "boolean" }
|
|
27
29
|
}
|
|
28
30
|
});
|
|
29
31
|
const file = positionals[0];
|
|
30
32
|
if (file === void 0) {
|
|
31
|
-
process.stderr.write(
|
|
33
|
+
process.stderr.write(
|
|
34
|
+
"usage: metta-ts [--max-steps=N] [--max-stack-depth=N] [--hash-cons] [--flat-atomspace] <file.metta>\n"
|
|
35
|
+
);
|
|
32
36
|
process.exit(2);
|
|
33
37
|
}
|
|
34
38
|
const fuel = values["max-steps"] !== void 0 ? Number(values["max-steps"]) : void 0;
|
|
35
39
|
const maxStackDepth = values["max-stack-depth"] !== void 0 ? Number(values["max-stack-depth"]) : void 0;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
maxStackDepth !== void 0 ? { maxStackDepth } :
|
|
40
|
-
|
|
40
|
+
const hashCons = values["hash-cons"] === true || process.env.METTA_TS_HASHCONS === "1" || process.env.METTA_TS_HASHCONS === "true";
|
|
41
|
+
const flatAtomspace = values["flat-atomspace"] === true || process.env.METTA_TS_FLAT_ATOMSPACE === "1" || process.env.METTA_TS_FLAT_ATOMSPACE === "true";
|
|
42
|
+
const opts = maxStackDepth !== void 0 || hashCons || flatAtomspace ? {
|
|
43
|
+
...maxStackDepth !== void 0 ? { maxStackDepth } : {},
|
|
44
|
+
...hashCons || flatAtomspace ? {
|
|
45
|
+
experimental: {
|
|
46
|
+
...hashCons ? { hashCons: true } : {},
|
|
47
|
+
...flatAtomspace ? { flatAtomspace: true } : {}
|
|
48
|
+
}
|
|
49
|
+
} : {}
|
|
50
|
+
} : void 0;
|
|
51
|
+
for (const r of runFile(file, fuel, opts)) {
|
|
41
52
|
process.stdout.write("[" + r.results.map(format).join(", ") + "]\n");
|
|
42
53
|
}
|
|
43
54
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ declare class ParallelFlatMatcher {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/** Pre-read every `import!` target referenced in `src`, resolving names against `baseDir`. */
|
|
24
|
-
declare function readImports(src: string, baseDir: string): Map<string, Atom[]>;
|
|
24
|
+
declare function readImports(src: string, baseDir: string, importRoot?: string): Map<string, Atom[]>;
|
|
25
25
|
/** Run a `.metta` file from disk, resolving `import!` relative to the file's directory. `fuel` is the step
|
|
26
26
|
* ceiling; `opts` carries interpreter settings such as the initial `maxStackDepth`. */
|
|
27
27
|
declare function runFile(path: string, fuel?: number, opts?: RunOptions): QueryResult[];
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metta-ts/node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,13 +12,14 @@
|
|
|
12
12
|
".": {
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
14
|
"default": "./dist/index.js"
|
|
15
|
-
}
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
16
17
|
},
|
|
17
18
|
"files": [
|
|
18
19
|
"dist"
|
|
19
20
|
],
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"@metta-ts/core": "1.0.
|
|
22
|
+
"@metta-ts/core": "1.0.2"
|
|
22
23
|
},
|
|
23
24
|
"author": "MesTTo",
|
|
24
25
|
"engines": {
|