greyscript-interpreter 0.1.0 → 0.3.0
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/cps.d.ts +5 -2
- package/dist/cps.js +73 -5
- package/dist/index.d.ts +3 -1
- package/dist/index.js +7 -2
- package/dist/interpreter.d.ts +4 -3
- package/dist/interpreter.js +7 -39
- package/dist/operations/import.d.ts +4 -0
- package/dist/operations/import.js +25 -0
- package/dist/operations/include.d.ts +2 -10
- package/dist/operations/include.js +1 -15
- package/package.json +3 -3
package/dist/cps.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import { CPSVisitCallback } from 'greybel-interpreter';
|
|
2
|
-
export declare const
|
|
1
|
+
import { CPSContext, CPSVisitCallback, CPS as GreybelCPS } from 'greybel-interpreter';
|
|
2
|
+
export declare const defaultCPSVisit: CPSVisitCallback;
|
|
3
|
+
export declare class CPS extends GreybelCPS {
|
|
4
|
+
constructor(context: CPSContext, cpsVisit?: CPSVisitCallback);
|
|
5
|
+
}
|
package/dist/cps.js
CHANGED
|
@@ -9,12 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.CPS = exports.defaultCPSVisit = void 0;
|
|
13
13
|
const greybel_interpreter_1 = require("greybel-interpreter");
|
|
14
|
+
const greybel_core_1 = require("greybel-core");
|
|
14
15
|
const greyscript_core_1 = require("greyscript-core");
|
|
15
16
|
const miniscript_core_1 = require("miniscript-core");
|
|
16
17
|
const include_1 = require("./operations/include");
|
|
17
|
-
const
|
|
18
|
+
const import_1 = require("./operations/import");
|
|
19
|
+
const defaultCPSVisit = (cpsVisit, context, stack, item) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
20
|
const currentTarget = stack[stack.length - 1];
|
|
19
21
|
switch (item.type) {
|
|
20
22
|
case greyscript_core_1.ASTType.ImportCodeExpression: {
|
|
@@ -33,7 +35,7 @@ const cpsVisit = (internalCPSVisit, context, stack, item) => __awaiter(void 0, v
|
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
try {
|
|
36
|
-
const subVisit =
|
|
38
|
+
const subVisit = cpsVisit.bind(null, cpsVisit, context, [
|
|
37
39
|
...stack,
|
|
38
40
|
target
|
|
39
41
|
]);
|
|
@@ -50,9 +52,75 @@ const cpsVisit = (internalCPSVisit, context, stack, item) => __awaiter(void 0, v
|
|
|
50
52
|
}, err);
|
|
51
53
|
}
|
|
52
54
|
}
|
|
55
|
+
case greybel_core_1.ASTType.FeatureImportExpression: {
|
|
56
|
+
const importExpr = item;
|
|
57
|
+
const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, importExpr.path);
|
|
58
|
+
if (stack.includes(target)) {
|
|
59
|
+
console.warn(`Found circular dependency between "${currentTarget}" and "${target}" at line ${item.start.line}. Using noop instead to prevent overflow.`);
|
|
60
|
+
return new greybel_interpreter_1.Noop(item, target);
|
|
61
|
+
}
|
|
62
|
+
const code = yield context.handler.resourceHandler.get(target);
|
|
63
|
+
if (code == null) {
|
|
64
|
+
const range = new miniscript_core_1.ASTRange(item.start, item.end);
|
|
65
|
+
throw new greybel_interpreter_1.PrepareError(`Cannot find import "${currentTarget}"`, {
|
|
66
|
+
target: currentTarget,
|
|
67
|
+
range
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const subVisit = cpsVisit.bind(null, cpsVisit, context, [...stack, target]);
|
|
72
|
+
const importStatement = yield new import_1.Import(importExpr, currentTarget, target, code).build(subVisit);
|
|
73
|
+
return importStatement;
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
if (err instanceof greybel_interpreter_1.PrepareError) {
|
|
77
|
+
throw err;
|
|
78
|
+
}
|
|
79
|
+
throw new greybel_interpreter_1.PrepareError(err.message, {
|
|
80
|
+
target,
|
|
81
|
+
range: new miniscript_core_1.ASTRange(item.start, item.end)
|
|
82
|
+
}, err);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
case greybel_core_1.ASTType.FeatureIncludeExpression: {
|
|
86
|
+
const includeExpr = item;
|
|
87
|
+
const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, includeExpr.path);
|
|
88
|
+
if (stack.includes(target)) {
|
|
89
|
+
console.warn(`Found circular dependency between "${currentTarget}" and "${target}" at line ${item.start.line}. Using noop instead to prevent overflow.`);
|
|
90
|
+
return new greybel_interpreter_1.Noop(item, target);
|
|
91
|
+
}
|
|
92
|
+
const code = yield context.handler.resourceHandler.get(target);
|
|
93
|
+
if (code == null) {
|
|
94
|
+
const range = new miniscript_core_1.ASTRange(item.start, item.end);
|
|
95
|
+
throw new greybel_interpreter_1.PrepareError(`Cannot find include "${currentTarget}"`, {
|
|
96
|
+
target: currentTarget,
|
|
97
|
+
range
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const subVisit = cpsVisit.bind(null, cpsVisit, context, [...stack, target]);
|
|
102
|
+
const importStatement = yield new include_1.Include(includeExpr, currentTarget, target, code).build(subVisit);
|
|
103
|
+
return importStatement;
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
if (err instanceof greybel_interpreter_1.PrepareError) {
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
throw new greybel_interpreter_1.PrepareError(err.message, {
|
|
110
|
+
target,
|
|
111
|
+
range: new miniscript_core_1.ASTRange(item.start, item.end)
|
|
112
|
+
}, err);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
53
115
|
default: {
|
|
54
|
-
return (0, greybel_interpreter_1.defaultCPSVisit)(
|
|
116
|
+
return (0, greybel_interpreter_1.defaultCPSVisit)(cpsVisit, context, stack, item);
|
|
55
117
|
}
|
|
56
118
|
}
|
|
57
119
|
});
|
|
58
|
-
exports.
|
|
120
|
+
exports.defaultCPSVisit = defaultCPSVisit;
|
|
121
|
+
class CPS extends greybel_interpreter_1.CPS {
|
|
122
|
+
constructor(context, cpsVisit = exports.defaultCPSVisit) {
|
|
123
|
+
super(context, cpsVisit);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.CPS = CPS;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Interpreter = exports.
|
|
3
|
+
exports.Include = exports.Import = exports.Interpreter = exports.defaultCPSVisit = exports.CPS = void 0;
|
|
4
4
|
var cps_1 = require("./cps");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "CPS", { enumerable: true, get: function () { return cps_1.CPS; } });
|
|
6
|
+
Object.defineProperty(exports, "defaultCPSVisit", { enumerable: true, get: function () { return cps_1.defaultCPSVisit; } });
|
|
6
7
|
var interpreter_1 = require("./interpreter");
|
|
7
8
|
Object.defineProperty(exports, "Interpreter", { enumerable: true, get: function () { return interpreter_1.Interpreter; } });
|
|
9
|
+
var import_1 = require("./operations/import");
|
|
10
|
+
Object.defineProperty(exports, "Import", { enumerable: true, get: function () { return import_1.Import; } });
|
|
11
|
+
var include_1 = require("./operations/include");
|
|
12
|
+
Object.defineProperty(exports, "Include", { enumerable: true, get: function () { return include_1.Include; } });
|
package/dist/interpreter.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Interpreter as GreybelInterpreter
|
|
1
|
+
import { Interpreter as GreybelInterpreter } from 'greybel-interpreter';
|
|
2
|
+
import { CPS } from './cps';
|
|
2
3
|
export declare class Interpreter extends GreybelInterpreter {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
createCPS(): CPS;
|
|
5
|
+
parse(code: string): import("miniscript-core").ASTBase | import("greyscript-core").ASTChunkGreyScript;
|
|
5
6
|
}
|
package/dist/interpreter.js
CHANGED
|
@@ -2,48 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Interpreter = void 0;
|
|
4
4
|
const greybel_interpreter_1 = require("greybel-interpreter");
|
|
5
|
-
const greyscript_core_1 = require("greyscript-core");
|
|
6
5
|
const cps_1 = require("./cps");
|
|
6
|
+
const greyscript_core_1 = require("greyscript-core");
|
|
7
7
|
class Interpreter extends greybel_interpreter_1.Interpreter {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
this.target = target;
|
|
13
|
-
const cpsCtx = new greybel_interpreter_1.CPSContext(target, this.handler);
|
|
14
|
-
this.cps = new greybel_interpreter_1.CPS(cpsCtx, cps_1.cpsVisit);
|
|
15
|
-
this.apiContext = new greybel_interpreter_1.OperationContext({
|
|
16
|
-
target,
|
|
17
|
-
isProtected: true,
|
|
18
|
-
debugger: this.debugger,
|
|
19
|
-
handler: this.handler,
|
|
20
|
-
cps: this.cps,
|
|
21
|
-
environmentVariables: this.environmentVariables
|
|
22
|
-
});
|
|
23
|
-
this.globalContext = this.apiContext.fork({
|
|
24
|
-
type: greybel_interpreter_1.ContextType.Global,
|
|
25
|
-
state: greybel_interpreter_1.ContextState.Default
|
|
26
|
-
});
|
|
27
|
-
return this;
|
|
8
|
+
createCPS() {
|
|
9
|
+
const cpsCtx = new greybel_interpreter_1.CPSContext(this.target, this.handler);
|
|
10
|
+
return new cps_1.CPS(cpsCtx);
|
|
28
11
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const chunk = parser.parseChunk();
|
|
33
|
-
return this.cps.visit(chunk);
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
if (err instanceof greybel_interpreter_1.PrepareError) {
|
|
37
|
-
this.handler.errorHandler.raise(err);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this.handler.errorHandler.raise(new greybel_interpreter_1.PrepareError(err.message, {
|
|
41
|
-
range: err.range,
|
|
42
|
-
target: this.target
|
|
43
|
-
}));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return Promise.resolve(new greybel_interpreter_1.Noop(null));
|
|
12
|
+
parse(code) {
|
|
13
|
+
const parser = new greyscript_core_1.Parser(code);
|
|
14
|
+
return parser.parseChunk();
|
|
47
15
|
}
|
|
48
16
|
}
|
|
49
17
|
exports.Interpreter = Interpreter;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Import = void 0;
|
|
13
|
+
const greybel_interpreter_1 = require("greybel-interpreter");
|
|
14
|
+
const greyscript_core_1 = require("greyscript-core");
|
|
15
|
+
class Import extends greybel_interpreter_1.Import {
|
|
16
|
+
build(visit) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const parser = new greyscript_core_1.Parser(this.code);
|
|
19
|
+
this.chunk = parser.parseChunk();
|
|
20
|
+
this.top = yield visit(this.chunk);
|
|
21
|
+
return this;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Import = Import;
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import { CPSVisit,
|
|
2
|
-
|
|
3
|
-
export declare class Include extends Operation {
|
|
4
|
-
readonly item: ASTBase;
|
|
5
|
-
newTarget: string;
|
|
6
|
-
code: string;
|
|
7
|
-
chunk: ASTBase;
|
|
8
|
-
top: Operation;
|
|
9
|
-
constructor(item: ASTBase, target: string, newTarget: string, code: string);
|
|
1
|
+
import { CPSVisit, Include as GreybelInclude, Operation } from 'greybel-interpreter';
|
|
2
|
+
export declare class Include extends GreybelInclude {
|
|
10
3
|
build(visit: CPSVisit): Promise<Operation>;
|
|
11
|
-
handle(ctx: OperationContext): Promise<CustomValue>;
|
|
12
4
|
}
|
|
@@ -12,13 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.Include = void 0;
|
|
13
13
|
const greybel_interpreter_1 = require("greybel-interpreter");
|
|
14
14
|
const greyscript_core_1 = require("greyscript-core");
|
|
15
|
-
class Include extends greybel_interpreter_1.
|
|
16
|
-
constructor(item, target, newTarget, code) {
|
|
17
|
-
super(null, target);
|
|
18
|
-
this.newTarget = newTarget;
|
|
19
|
-
this.item = item;
|
|
20
|
-
this.code = code;
|
|
21
|
-
}
|
|
15
|
+
class Include extends greybel_interpreter_1.Include {
|
|
22
16
|
build(visit) {
|
|
23
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
18
|
const parser = new greyscript_core_1.Parser(this.code);
|
|
@@ -27,13 +21,5 @@ class Include extends greybel_interpreter_1.Operation {
|
|
|
27
21
|
return this;
|
|
28
22
|
});
|
|
29
23
|
}
|
|
30
|
-
handle(ctx) {
|
|
31
|
-
const importCtx = ctx.fork({
|
|
32
|
-
type: greybel_interpreter_1.ContextType.External,
|
|
33
|
-
state: greybel_interpreter_1.ContextState.Temporary,
|
|
34
|
-
target: this.newTarget
|
|
35
|
-
});
|
|
36
|
-
return this.top.handle(importCtx);
|
|
37
|
-
}
|
|
38
24
|
}
|
|
39
25
|
exports.Include = Include;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "greyscript-interpreter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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.0
|
|
52
|
-
"greybel-interpreter": "^3.0
|
|
51
|
+
"greyscript-core": "^1.2.0",
|
|
52
|
+
"greybel-interpreter": "^3.2.0"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|
|
55
55
|
"greyscript",
|