greyscript-interpreter 1.5.6 → 1.6.1
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.
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { BytecodeGenerator as GreybelBytecodeGenerator } from 'greybel-interpreter';
|
|
1
|
+
import { BytecodeConverterOptions, BytecodeGenerator as GreybelBytecodeGenerator } from 'greybel-interpreter';
|
|
2
2
|
import { ASTImportCodeExpression } from 'greyscript-core';
|
|
3
3
|
import { ASTBase } from 'miniscript-core';
|
|
4
4
|
export declare class BytecodeGenerator extends GreybelBytecodeGenerator {
|
|
5
|
+
protected evaluatedImportCodes: Set<string>;
|
|
6
|
+
constructor(options: BytecodeConverterOptions);
|
|
5
7
|
parse(code: string): ASTBase | import("greyscript-core").ASTChunkGreyScript;
|
|
6
8
|
protected processNode(node: ASTBase): Promise<void>;
|
|
7
9
|
protected processImportCodeExpression(node: ASTImportCodeExpression): Promise<void>;
|
|
@@ -14,6 +14,10 @@ const greybel_interpreter_1 = require("greybel-interpreter");
|
|
|
14
14
|
const greyscript_core_1 = require("greyscript-core");
|
|
15
15
|
const miniscript_core_1 = require("miniscript-core");
|
|
16
16
|
class BytecodeGenerator extends greybel_interpreter_1.BytecodeGenerator {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super(options);
|
|
19
|
+
this.evaluatedImportCodes = new Set();
|
|
20
|
+
}
|
|
17
21
|
parse(code) {
|
|
18
22
|
try {
|
|
19
23
|
const parser = new greyscript_core_1.Parser(code);
|
|
@@ -48,16 +52,18 @@ class BytecodeGenerator extends greybel_interpreter_1.BytecodeGenerator {
|
|
|
48
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
53
|
const currentTarget = this.target.peek();
|
|
50
54
|
const importTarget = yield this.handler.resourceHandler.getTargetRelativeTo(currentTarget, node.directory);
|
|
55
|
+
if (this.evaluatedImportCodes.has(importTarget)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
51
58
|
if (this.target.includes(importTarget)) {
|
|
52
59
|
console.warn(`Found circular dependency between "${currentTarget}" and "${importTarget}" at line ${node.start.line}. Using noop instead to prevent overflow.`);
|
|
53
60
|
return;
|
|
54
61
|
}
|
|
55
62
|
const code = yield this.handler.resourceHandler.get(importTarget);
|
|
56
63
|
if (code == null) {
|
|
57
|
-
const range = new miniscript_core_1.ASTRange(node.start, node.end);
|
|
58
64
|
throw new greybel_interpreter_1.PrepareError(`Cannot find import "${currentTarget}"`, {
|
|
59
65
|
target: currentTarget,
|
|
60
|
-
range
|
|
66
|
+
range: new miniscript_core_1.ASTRange(node.start, node.end)
|
|
61
67
|
});
|
|
62
68
|
}
|
|
63
69
|
try {
|
|
@@ -65,6 +71,7 @@ class BytecodeGenerator extends greybel_interpreter_1.BytecodeGenerator {
|
|
|
65
71
|
const childNodes = this.parse(code);
|
|
66
72
|
yield this.processNode(childNodes);
|
|
67
73
|
this.target.pop();
|
|
74
|
+
this.evaluatedImportCodes.add(importTarget);
|
|
68
75
|
}
|
|
69
76
|
catch (err) {
|
|
70
77
|
if (err instanceof greybel_interpreter_1.PrepareError) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "greyscript-interpreter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Interpreter",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"typescript": "^5.0.4"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"greyscript-core": "~1.5.
|
|
52
|
-
"greybel-interpreter": "~4.5.
|
|
51
|
+
"greyscript-core": "~1.5.9",
|
|
52
|
+
"greybel-interpreter": "~4.5.8"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|
|
55
55
|
"greyscript",
|