greybel-interpreter 1.7.1 → 1.7.3
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/context.d.ts +9 -9
- package/dist/context.js +19 -22
- package/dist/cps.d.ts +3 -3
- package/dist/cps.js +110 -71
- package/dist/handler/output.d.ts +4 -4
- package/dist/handler/output.js +2 -2
- package/dist/handler-container.d.ts +1 -1
- package/dist/handler-container.js +2 -1
- package/dist/index.d.ts +43 -42
- package/dist/index.js +47 -47
- package/dist/interpreter.d.ts +9 -9
- package/dist/interpreter.js +55 -62
- package/dist/operations/assign.d.ts +5 -5
- package/dist/operations/assign.js +9 -11
- package/dist/operations/block.d.ts +4 -4
- package/dist/operations/block.js +6 -8
- package/dist/operations/break.d.ts +4 -4
- package/dist/operations/break.js +6 -8
- package/dist/operations/call.d.ts +5 -5
- package/dist/operations/call.js +12 -14
- package/dist/operations/chunk.d.ts +6 -6
- package/dist/operations/chunk.js +8 -10
- package/dist/operations/continue.d.ts +4 -4
- package/dist/operations/continue.js +6 -8
- package/dist/operations/debugger-statement.d.ts +5 -5
- package/dist/operations/debugger-statement.js +6 -8
- package/dist/operations/envar.d.ts +5 -5
- package/dist/operations/envar.js +6 -8
- package/dist/operations/evaluate.d.ts +6 -5
- package/dist/operations/evaluate.js +109 -112
- package/dist/operations/for.d.ts +6 -6
- package/dist/operations/for.js +15 -17
- package/dist/operations/function-reference.d.ts +5 -5
- package/dist/operations/function-reference.js +8 -10
- package/dist/operations/function.d.ts +5 -5
- package/dist/operations/function.js +17 -20
- package/dist/operations/if-statement.d.ts +6 -6
- package/dist/operations/if-statement.js +12 -15
- package/dist/operations/import.d.ts +7 -7
- package/dist/operations/import.js +15 -18
- package/dist/operations/include.d.ts +5 -5
- package/dist/operations/include.js +4 -6
- package/dist/operations/list.d.ts +5 -5
- package/dist/operations/list.js +6 -8
- package/dist/operations/literal.d.ts +5 -5
- package/dist/operations/literal.js +12 -14
- package/dist/operations/map.d.ts +5 -5
- package/dist/operations/map.js +8 -10
- package/dist/operations/negated-binary.d.ts +5 -5
- package/dist/operations/negated-binary.js +7 -9
- package/dist/operations/new-instance.d.ts +5 -5
- package/dist/operations/new-instance.js +8 -10
- package/dist/operations/noop.d.ts +5 -5
- package/dist/operations/noop.js +6 -8
- package/dist/operations/not.d.ts +5 -5
- package/dist/operations/not.js +6 -8
- package/dist/operations/operation.d.ts +3 -3
- package/dist/operations/operation.js +2 -1
- package/dist/operations/reference.d.ts +4 -4
- package/dist/operations/reference.js +4 -6
- package/dist/operations/resolve.d.ts +6 -6
- package/dist/operations/resolve.js +27 -30
- package/dist/operations/return.d.ts +5 -5
- package/dist/operations/return.js +8 -10
- package/dist/operations/while.d.ts +6 -6
- package/dist/operations/while.js +9 -11
- package/dist/types/base.d.ts +1 -1
- package/dist/types/base.js +2 -1
- package/dist/types/boolean.d.ts +2 -2
- package/dist/types/boolean.js +4 -7
- package/dist/types/default.d.ts +7 -7
- package/dist/types/default.js +9 -8
- package/dist/types/function.d.ts +5 -5
- package/dist/types/function.js +27 -30
- package/dist/types/interface.d.ts +4 -4
- package/dist/types/interface.js +10 -13
- package/dist/types/list.d.ts +4 -4
- package/dist/types/list.js +21 -24
- package/dist/types/map.d.ts +5 -5
- package/dist/types/map.js +26 -29
- package/dist/types/nil.d.ts +2 -2
- package/dist/types/nil.js +4 -7
- package/dist/types/number.d.ts +4 -4
- package/dist/types/number.js +8 -11
- package/dist/types/string.d.ts +4 -4
- package/dist/types/string.js +19 -22
- package/dist/types/with-intrinsics.d.ts +4 -4
- package/dist/types/with-intrinsics.js +2 -5
- package/dist/utils/deep-equal.d.ts +1 -1
- package/dist/utils/deep-equal.js +4 -3
- package/dist/utils/error.d.ts +23 -0
- package/dist/utils/error.js +29 -0
- package/dist/utils/object-value.d.ts +2 -2
- package/dist/utils/object-value.js +6 -8
- package/dist/utils/path.d.ts +1 -1
- package/dist/utils/path.js +2 -1
- package/package.json +2 -2
package/dist/context.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ASTBase } from 'greyscript-core';
|
|
2
|
-
import CPS from './cps';
|
|
3
|
-
import HandlerContainer from './handler-container';
|
|
4
|
-
import Operation from './operations/operation';
|
|
5
|
-
import CustomValue from './types/base';
|
|
6
|
-
import CustomMap from './types/map';
|
|
7
|
-
import CustomNil from './types/nil';
|
|
8
|
-
import ObjectValue from './utils/object-value';
|
|
9
|
-
import Path from './utils/path';
|
|
2
|
+
import { CPS } from './cps';
|
|
3
|
+
import { HandlerContainer } from './handler-container';
|
|
4
|
+
import { Operation } from './operations/operation';
|
|
5
|
+
import { CustomValue } from './types/base';
|
|
6
|
+
import { CustomMap } from './types/map';
|
|
7
|
+
import { CustomNil } from './types/nil';
|
|
8
|
+
import { ObjectValue } from './utils/object-value';
|
|
9
|
+
import { Path } from './utils/path';
|
|
10
10
|
export declare enum ContextType {
|
|
11
11
|
Api = 0,
|
|
12
12
|
Global = 1,
|
|
@@ -71,7 +71,7 @@ export interface ContextForkOptions {
|
|
|
71
71
|
target?: string;
|
|
72
72
|
injected?: boolean;
|
|
73
73
|
}
|
|
74
|
-
export
|
|
74
|
+
export declare class OperationContext {
|
|
75
75
|
target: string;
|
|
76
76
|
stackItem: ASTBase;
|
|
77
77
|
debugger: Debugger;
|
package/dist/context.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FunctionState = exports.LoopState = exports.ProcessState = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
|
|
7
|
-
const handler_container_1 =
|
|
8
|
-
const base_1 =
|
|
9
|
-
const default_1 =
|
|
10
|
-
const map_1 =
|
|
11
|
-
const path_1 =
|
|
3
|
+
exports.OperationContext = exports.FunctionState = exports.LoopState = exports.ProcessState = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
|
|
4
|
+
const handler_container_1 = require("./handler-container");
|
|
5
|
+
const base_1 = require("./types/base");
|
|
6
|
+
const default_1 = require("./types/default");
|
|
7
|
+
const map_1 = require("./types/map");
|
|
8
|
+
const path_1 = require("./utils/path");
|
|
12
9
|
var ContextType;
|
|
13
10
|
(function (ContextType) {
|
|
14
11
|
ContextType[ContextType["Api"] = 0] = "Api";
|
|
@@ -24,14 +21,14 @@ var ContextState;
|
|
|
24
21
|
ContextState[ContextState["Temporary"] = 0] = "Temporary";
|
|
25
22
|
ContextState[ContextState["Default"] = 1] = "Default";
|
|
26
23
|
})(ContextState = exports.ContextState || (exports.ContextState = {}));
|
|
27
|
-
class Scope extends map_1.
|
|
24
|
+
class Scope extends map_1.CustomMap {
|
|
28
25
|
constructor(context) {
|
|
29
26
|
super();
|
|
30
27
|
this.context = context;
|
|
31
28
|
}
|
|
32
29
|
get(path) {
|
|
33
|
-
if (path instanceof base_1.
|
|
34
|
-
return this.get(new path_1.
|
|
30
|
+
if (path instanceof base_1.CustomValue) {
|
|
31
|
+
return this.get(new path_1.Path([path]));
|
|
35
32
|
}
|
|
36
33
|
if (path.count() === 0) {
|
|
37
34
|
return this;
|
|
@@ -44,8 +41,8 @@ class Scope extends map_1.default {
|
|
|
44
41
|
else if (this.context.api.scope.has(path)) {
|
|
45
42
|
return this.context.api.scope.get(path);
|
|
46
43
|
}
|
|
47
|
-
else if (path.count() === 1 && map_1.
|
|
48
|
-
return map_1.
|
|
44
|
+
else if (path.count() === 1 && map_1.CustomMap.getIntrinsics().has(current)) {
|
|
45
|
+
return map_1.CustomMap.getIntrinsics().get(current);
|
|
49
46
|
}
|
|
50
47
|
else if (this.context.previous !== null) {
|
|
51
48
|
return this.context.previous.get(path);
|
|
@@ -66,7 +63,7 @@ class Debugger {
|
|
|
66
63
|
}
|
|
67
64
|
debug(...segments) {
|
|
68
65
|
console.debug(...segments);
|
|
69
|
-
return default_1.
|
|
66
|
+
return default_1.DefaultType.Void;
|
|
70
67
|
}
|
|
71
68
|
setBreakpoint(breakpoint) {
|
|
72
69
|
this.breakpoint = breakpoint;
|
|
@@ -125,7 +122,7 @@ class LoopState {
|
|
|
125
122
|
exports.LoopState = LoopState;
|
|
126
123
|
class FunctionState {
|
|
127
124
|
constructor() {
|
|
128
|
-
this.value = default_1.
|
|
125
|
+
this.value = default_1.DefaultType.Void;
|
|
129
126
|
this.isReturn = false;
|
|
130
127
|
this.context = null;
|
|
131
128
|
this.super = null;
|
|
@@ -143,7 +140,7 @@ class OperationContext {
|
|
|
143
140
|
this.isProtected = options.isProtected || false;
|
|
144
141
|
this.injected = options.injected || false;
|
|
145
142
|
this.debugger = options.debugger || new Debugger();
|
|
146
|
-
this.handler = options.handler || new handler_container_1.
|
|
143
|
+
this.handler = options.handler || new handler_container_1.HandlerContainer();
|
|
147
144
|
this.cps = options.cps || null;
|
|
148
145
|
this.processState = options.processState || new ProcessState();
|
|
149
146
|
this.environmentVariables = options.environmentVariables || new Map();
|
|
@@ -252,8 +249,8 @@ class OperationContext {
|
|
|
252
249
|
}
|
|
253
250
|
set(path, value) {
|
|
254
251
|
var _a;
|
|
255
|
-
if (path instanceof base_1.
|
|
256
|
-
this.set(new path_1.
|
|
252
|
+
if (path instanceof base_1.CustomValue) {
|
|
253
|
+
this.set(new path_1.Path([path]), value);
|
|
257
254
|
return;
|
|
258
255
|
}
|
|
259
256
|
if (this.state === ContextState.Temporary) {
|
|
@@ -265,8 +262,8 @@ class OperationContext {
|
|
|
265
262
|
}
|
|
266
263
|
get(path) {
|
|
267
264
|
var _a;
|
|
268
|
-
if (path instanceof base_1.
|
|
269
|
-
return this.get(new path_1.
|
|
265
|
+
if (path instanceof base_1.CustomValue) {
|
|
266
|
+
return this.get(new path_1.Path([path]));
|
|
270
267
|
}
|
|
271
268
|
if (path.count() === 0) {
|
|
272
269
|
return this.scope;
|
|
@@ -299,7 +296,6 @@ class OperationContext {
|
|
|
299
296
|
return newContext;
|
|
300
297
|
}
|
|
301
298
|
}
|
|
302
|
-
exports.default = OperationContext;
|
|
303
299
|
OperationContext.lookupApiType = [ContextType.Api];
|
|
304
300
|
OperationContext.lookupGlobalsType = [
|
|
305
301
|
ContextType.Global
|
|
@@ -308,3 +304,4 @@ OperationContext.lookupLocalsType = [
|
|
|
308
304
|
ContextType.Global,
|
|
309
305
|
ContextType.Function
|
|
310
306
|
];
|
|
307
|
+
exports.OperationContext = OperationContext;
|
package/dist/cps.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ASTBase } from 'greyscript-core';
|
|
2
|
-
import HandlerContainer from './handler-container';
|
|
3
|
-
import Operation from './operations/operation';
|
|
2
|
+
import { HandlerContainer } from './handler-container';
|
|
3
|
+
import { Operation } from './operations/operation';
|
|
4
4
|
export declare class CPSContext {
|
|
5
5
|
readonly target: string;
|
|
6
6
|
readonly handler: HandlerContainer;
|
|
7
7
|
constructor(target: string, handler: HandlerContainer);
|
|
8
8
|
}
|
|
9
|
-
export
|
|
9
|
+
export declare class CPS {
|
|
10
10
|
private readonly context;
|
|
11
11
|
private __visit;
|
|
12
12
|
constructor(context: CPSContext);
|
package/dist/cps.js
CHANGED
|
@@ -8,37 +8,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.CPSContext = void 0;
|
|
12
|
+
exports.CPS = exports.CPSContext = void 0;
|
|
16
13
|
const greybel_core_1 = require("greybel-core");
|
|
17
14
|
const greyscript_core_1 = require("greyscript-core");
|
|
18
|
-
const assign_1 =
|
|
19
|
-
const break_1 =
|
|
20
|
-
const call_1 =
|
|
21
|
-
const chunk_1 =
|
|
22
|
-
const continue_1 =
|
|
23
|
-
const debugger_statement_1 =
|
|
24
|
-
const envar_1 =
|
|
25
|
-
const evaluate_1 =
|
|
26
|
-
const for_1 =
|
|
27
|
-
const function_1 =
|
|
28
|
-
const function_reference_1 =
|
|
29
|
-
const if_statement_1 =
|
|
30
|
-
const import_1 =
|
|
31
|
-
const include_1 =
|
|
32
|
-
const list_1 =
|
|
33
|
-
const literal_1 =
|
|
34
|
-
const map_1 =
|
|
35
|
-
const negated_binary_1 =
|
|
36
|
-
const new_instance_1 =
|
|
37
|
-
const noop_1 =
|
|
38
|
-
const not_1 =
|
|
39
|
-
const resolve_1 =
|
|
40
|
-
const return_1 =
|
|
41
|
-
const while_1 =
|
|
15
|
+
const assign_1 = require("./operations/assign");
|
|
16
|
+
const break_1 = require("./operations/break");
|
|
17
|
+
const call_1 = require("./operations/call");
|
|
18
|
+
const chunk_1 = require("./operations/chunk");
|
|
19
|
+
const continue_1 = require("./operations/continue");
|
|
20
|
+
const debugger_statement_1 = require("./operations/debugger-statement");
|
|
21
|
+
const envar_1 = require("./operations/envar");
|
|
22
|
+
const evaluate_1 = require("./operations/evaluate");
|
|
23
|
+
const for_1 = require("./operations/for");
|
|
24
|
+
const function_1 = require("./operations/function");
|
|
25
|
+
const function_reference_1 = require("./operations/function-reference");
|
|
26
|
+
const if_statement_1 = require("./operations/if-statement");
|
|
27
|
+
const import_1 = require("./operations/import");
|
|
28
|
+
const include_1 = require("./operations/include");
|
|
29
|
+
const list_1 = require("./operations/list");
|
|
30
|
+
const literal_1 = require("./operations/literal");
|
|
31
|
+
const map_1 = require("./operations/map");
|
|
32
|
+
const negated_binary_1 = require("./operations/negated-binary");
|
|
33
|
+
const new_instance_1 = require("./operations/new-instance");
|
|
34
|
+
const noop_1 = require("./operations/noop");
|
|
35
|
+
const not_1 = require("./operations/not");
|
|
36
|
+
const resolve_1 = require("./operations/resolve");
|
|
37
|
+
const return_1 = require("./operations/return");
|
|
38
|
+
const while_1 = require("./operations/while");
|
|
39
|
+
const error_1 = require("./utils/error");
|
|
42
40
|
class CPSContext {
|
|
43
41
|
constructor(target, handler) {
|
|
44
42
|
this.target = target;
|
|
@@ -51,34 +49,34 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
|
|
|
51
49
|
const defaultVisit = visit.bind(null, context, stack);
|
|
52
50
|
switch (item.type) {
|
|
53
51
|
case greyscript_core_1.ASTType.MapConstructorExpression:
|
|
54
|
-
return new map_1.
|
|
52
|
+
return new map_1.MapOperation(item, currentTarget).build(defaultVisit);
|
|
55
53
|
case greyscript_core_1.ASTType.ListConstructorExpression:
|
|
56
|
-
return new list_1.
|
|
54
|
+
return new list_1.List(item, currentTarget).build(defaultVisit);
|
|
57
55
|
case greyscript_core_1.ASTType.AssignmentStatement:
|
|
58
|
-
return new assign_1.
|
|
56
|
+
return new assign_1.Assign(item, currentTarget).build(defaultVisit);
|
|
59
57
|
case greyscript_core_1.ASTType.MemberExpression:
|
|
60
58
|
case greyscript_core_1.ASTType.Identifier:
|
|
61
59
|
case greyscript_core_1.ASTType.IndexExpression:
|
|
62
|
-
return new resolve_1.
|
|
60
|
+
return new resolve_1.Resolve(item, currentTarget).build(defaultVisit);
|
|
63
61
|
case greyscript_core_1.ASTType.FunctionDeclaration:
|
|
64
|
-
return new function_1.
|
|
62
|
+
return new function_1.FunctionOperation(item, currentTarget).build(defaultVisit);
|
|
65
63
|
case greyscript_core_1.ASTType.InvalidCodeExpression:
|
|
66
|
-
return new noop_1.
|
|
64
|
+
return new noop_1.Noop(item, currentTarget).build(defaultVisit);
|
|
67
65
|
case greyscript_core_1.ASTType.WhileStatement:
|
|
68
|
-
return new while_1.
|
|
66
|
+
return new while_1.While(item, currentTarget).build(defaultVisit);
|
|
69
67
|
case greyscript_core_1.ASTType.ForGenericStatement:
|
|
70
|
-
return new for_1.
|
|
68
|
+
return new for_1.For(item, currentTarget).build(defaultVisit);
|
|
71
69
|
case greyscript_core_1.ASTType.IfStatement:
|
|
72
70
|
case greyscript_core_1.ASTType.IfShortcutStatement:
|
|
73
|
-
return new if_statement_1.
|
|
71
|
+
return new if_statement_1.IfStatement(item, currentTarget).build(defaultVisit);
|
|
74
72
|
case greyscript_core_1.ASTType.ReturnStatement:
|
|
75
|
-
return new return_1.
|
|
73
|
+
return new return_1.Return(item, currentTarget).build(defaultVisit);
|
|
76
74
|
case greyscript_core_1.ASTType.BreakStatement:
|
|
77
|
-
return new break_1.
|
|
75
|
+
return new break_1.Break(item, currentTarget).build(defaultVisit);
|
|
78
76
|
case greyscript_core_1.ASTType.ContinueStatement:
|
|
79
|
-
return new continue_1.
|
|
77
|
+
return new continue_1.Continue(item, currentTarget).build(defaultVisit);
|
|
80
78
|
case greyscript_core_1.ASTType.CallExpression:
|
|
81
|
-
return new call_1.
|
|
79
|
+
return new call_1.Call(item, currentTarget).build(defaultVisit);
|
|
82
80
|
case greyscript_core_1.ASTType.CallStatement:
|
|
83
81
|
return defaultVisit(item.expression);
|
|
84
82
|
case greybel_core_1.ASTType.FeatureImportExpression: {
|
|
@@ -86,83 +84,124 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
|
|
|
86
84
|
const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, importExpr.path);
|
|
87
85
|
if (stack.includes(target)) {
|
|
88
86
|
console.warn('Found circluar dependency. Using noop operation.');
|
|
89
|
-
return new noop_1.
|
|
87
|
+
return new noop_1.Noop(item, target);
|
|
90
88
|
}
|
|
91
89
|
const code = yield context.handler.resourceHandler.get(target);
|
|
92
90
|
if (code == null) {
|
|
93
|
-
throw new
|
|
91
|
+
throw new error_1.PrepareError(`Cannot find import ${currentTarget}.`, {
|
|
92
|
+
target: currentTarget,
|
|
93
|
+
item
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const subVisit = visit.bind(null, context, [...stack, target]);
|
|
98
|
+
const importStatement = yield new import_1.Import(importExpr, target, code).build(subVisit);
|
|
99
|
+
return importStatement;
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
throw new error_1.PrepareError(err.message, {
|
|
103
|
+
target: currentTarget,
|
|
104
|
+
item
|
|
105
|
+
});
|
|
94
106
|
}
|
|
95
|
-
const subVisit = visit.bind(null, context, [...stack, target]);
|
|
96
|
-
const importStatement = yield new import_1.default(importExpr, target, code).build(subVisit);
|
|
97
|
-
return importStatement;
|
|
98
107
|
}
|
|
99
108
|
case greybel_core_1.ASTType.FeatureIncludeExpression: {
|
|
100
109
|
const includeExpr = item;
|
|
101
110
|
const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, includeExpr.path);
|
|
102
111
|
if (stack.includes(target)) {
|
|
103
112
|
console.warn('Found circluar dependency. Using noop operation.');
|
|
104
|
-
return new noop_1.
|
|
113
|
+
return new noop_1.Noop(item, target);
|
|
105
114
|
}
|
|
106
115
|
const code = yield context.handler.resourceHandler.get(target);
|
|
107
116
|
if (code == null) {
|
|
108
|
-
throw new
|
|
117
|
+
throw new error_1.PrepareError(`Cannot find include ${currentTarget}.`, {
|
|
118
|
+
target: currentTarget,
|
|
119
|
+
item
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const subVisit = visit.bind(null, context, [...stack, target]);
|
|
124
|
+
const importStatement = yield new include_1.Include(includeExpr, target, code).build(subVisit);
|
|
125
|
+
return importStatement;
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
throw new error_1.PrepareError(err.message, {
|
|
129
|
+
target: currentTarget,
|
|
130
|
+
item
|
|
131
|
+
});
|
|
109
132
|
}
|
|
110
|
-
const subVisit = visit.bind(null, context, [...stack, target]);
|
|
111
|
-
const importStatement = yield new include_1.default(includeExpr, target, code).build(subVisit);
|
|
112
|
-
return importStatement;
|
|
113
133
|
}
|
|
114
134
|
case greyscript_core_1.ASTType.ImportCodeExpression: {
|
|
115
135
|
const importExpr = item;
|
|
136
|
+
if (importExpr.fileSystemDirectory === null) {
|
|
137
|
+
console.warn(`Ignoring dependency in ${currentTarget}. Using noop operation.`);
|
|
138
|
+
return new noop_1.Noop(item, currentTarget);
|
|
139
|
+
}
|
|
116
140
|
const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, importExpr.fileSystemDirectory);
|
|
117
141
|
if (stack.includes(target)) {
|
|
118
|
-
console.warn(
|
|
119
|
-
return new noop_1.
|
|
142
|
+
console.warn(`Found circluar dependency in ${currentTarget}. Using noop operation.`);
|
|
143
|
+
return new noop_1.Noop(item, target);
|
|
120
144
|
}
|
|
121
145
|
const code = yield context.handler.resourceHandler.get(target);
|
|
122
146
|
if (code == null) {
|
|
123
|
-
throw new
|
|
147
|
+
throw new error_1.PrepareError(`Cannot find native import ${currentTarget}.`, {
|
|
148
|
+
target: currentTarget,
|
|
149
|
+
item
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const subVisit = visit.bind(null, context, [...stack, target]);
|
|
154
|
+
const importStatement = yield new include_1.Include(importExpr, target, code).build(subVisit);
|
|
155
|
+
return importStatement;
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
throw new error_1.PrepareError(err.message, {
|
|
159
|
+
target: currentTarget,
|
|
160
|
+
item
|
|
161
|
+
});
|
|
124
162
|
}
|
|
125
|
-
const subVisit = visit.bind(null, context, [...stack, target]);
|
|
126
|
-
const importStatement = yield new include_1.default(importExpr, target, code).build(subVisit);
|
|
127
|
-
return importStatement;
|
|
128
163
|
}
|
|
129
164
|
case greybel_core_1.ASTType.FeatureDebuggerExpression:
|
|
130
|
-
return new debugger_statement_1.
|
|
165
|
+
return new debugger_statement_1.DebuggerStatement(item, currentTarget);
|
|
131
166
|
case greybel_core_1.ASTType.FeatureEnvarExpression:
|
|
132
|
-
return new envar_1.
|
|
167
|
+
return new envar_1.EnvarExpression(item, currentTarget);
|
|
133
168
|
case greyscript_core_1.ASTType.BooleanLiteral:
|
|
134
169
|
case greyscript_core_1.ASTType.StringLiteral:
|
|
135
170
|
case greyscript_core_1.ASTType.NumericLiteral:
|
|
136
171
|
case greyscript_core_1.ASTType.NilLiteral:
|
|
137
|
-
return new literal_1.
|
|
172
|
+
return new literal_1.Literal(item, currentTarget).build(defaultVisit);
|
|
138
173
|
case greyscript_core_1.ASTType.EmptyExpression:
|
|
139
|
-
return new noop_1.
|
|
174
|
+
return new noop_1.Noop(item, currentTarget).build(defaultVisit);
|
|
140
175
|
case greyscript_core_1.ASTType.IsaExpression:
|
|
141
176
|
case greyscript_core_1.ASTType.BinaryExpression:
|
|
142
177
|
case greyscript_core_1.ASTType.LogicalExpression:
|
|
143
|
-
return new evaluate_1.
|
|
178
|
+
return new evaluate_1.Evaluate(item, currentTarget).build(defaultVisit);
|
|
144
179
|
case greyscript_core_1.ASTType.NegationExpression:
|
|
145
|
-
return new not_1.
|
|
180
|
+
return new not_1.Not(item, currentTarget).build(defaultVisit);
|
|
146
181
|
case greyscript_core_1.ASTType.BinaryNegatedExpression:
|
|
147
|
-
return new negated_binary_1.
|
|
182
|
+
return new negated_binary_1.NegatedBinary(item, currentTarget).build(defaultVisit);
|
|
148
183
|
case greyscript_core_1.ASTType.UnaryExpression: {
|
|
149
184
|
const unaryExpr = item;
|
|
150
185
|
if (unaryExpr.operator === 'new') {
|
|
151
|
-
return new new_instance_1.
|
|
186
|
+
return new new_instance_1.NewInstance(unaryExpr).build(defaultVisit);
|
|
152
187
|
}
|
|
153
188
|
else if (unaryExpr.operator === '@') {
|
|
154
|
-
return new function_reference_1.
|
|
189
|
+
return new function_reference_1.FunctionReference(unaryExpr).build(defaultVisit);
|
|
155
190
|
}
|
|
156
|
-
throw new
|
|
191
|
+
throw new error_1.RuntimeError('Unknown unary expression.', {
|
|
192
|
+
target: currentTarget
|
|
193
|
+
});
|
|
157
194
|
}
|
|
158
195
|
case greyscript_core_1.ASTType.Chunk:
|
|
159
|
-
return new chunk_1.
|
|
196
|
+
return new chunk_1.Chunk(item, currentTarget).build(defaultVisit);
|
|
160
197
|
case greyscript_core_1.ASTType.Comment:
|
|
161
|
-
return new noop_1.
|
|
198
|
+
return new noop_1.Noop(item, currentTarget);
|
|
162
199
|
case greyscript_core_1.ASTType.ParenthesisExpression:
|
|
163
200
|
return defaultVisit(item.expression);
|
|
164
201
|
default:
|
|
165
|
-
throw new
|
|
202
|
+
throw new error_1.RuntimeError(`Unexpected AST type ${item.type}.`, {
|
|
203
|
+
target: currentTarget
|
|
204
|
+
});
|
|
166
205
|
}
|
|
167
206
|
});
|
|
168
207
|
class CPS {
|
|
@@ -174,4 +213,4 @@ class CPS {
|
|
|
174
213
|
return this.__visit(item);
|
|
175
214
|
}
|
|
176
215
|
}
|
|
177
|
-
exports.
|
|
216
|
+
exports.CPS = CPS;
|
package/dist/handler/output.d.ts
CHANGED
|
@@ -5,14 +5,14 @@ export interface KeyEvent {
|
|
|
5
5
|
export declare abstract class OutputHandler {
|
|
6
6
|
abstract print(message: string, appendNewLine?: boolean): void;
|
|
7
7
|
abstract progress(timeout: number): PromiseLike<void>;
|
|
8
|
-
abstract waitForInput(isPassword: boolean): PromiseLike<string>;
|
|
9
|
-
abstract waitForKeyPress(): PromiseLike<KeyEvent>;
|
|
8
|
+
abstract waitForInput(isPassword: boolean, message?: string): PromiseLike<string>;
|
|
9
|
+
abstract waitForKeyPress(message?: string): PromiseLike<KeyEvent>;
|
|
10
10
|
abstract clear(): void;
|
|
11
11
|
}
|
|
12
12
|
export declare class DefaultOutputHandler extends OutputHandler {
|
|
13
13
|
print(message: string, appendNewLine?: boolean): void;
|
|
14
14
|
progress(timeout: number): PromiseLike<void>;
|
|
15
|
-
waitForInput(_isPassword: boolean): PromiseLike<string>;
|
|
16
|
-
waitForKeyPress(): PromiseLike<KeyEvent>;
|
|
15
|
+
waitForInput(_isPassword: boolean, _message?: string): PromiseLike<string>;
|
|
16
|
+
waitForKeyPress(_message?: string): PromiseLike<KeyEvent>;
|
|
17
17
|
clear(): void;
|
|
18
18
|
}
|
package/dist/handler/output.js
CHANGED
|
@@ -18,10 +18,10 @@ class DefaultOutputHandler extends OutputHandler {
|
|
|
18
18
|
setTimeout(resolve, timeout);
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
waitForInput(_isPassword) {
|
|
21
|
+
waitForInput(_isPassword, _message) {
|
|
22
22
|
return Promise.resolve('test');
|
|
23
23
|
}
|
|
24
|
-
waitForKeyPress() {
|
|
24
|
+
waitForKeyPress(_message) {
|
|
25
25
|
return Promise.resolve({
|
|
26
26
|
keyCode: 13,
|
|
27
27
|
code: 'Enter'
|
|
@@ -6,7 +6,7 @@ export interface HandlerContainerOptions {
|
|
|
6
6
|
outputHandler?: OutputHandler;
|
|
7
7
|
errorHandler?: ErrorHandler;
|
|
8
8
|
}
|
|
9
|
-
export
|
|
9
|
+
export declare class HandlerContainer {
|
|
10
10
|
readonly resourceHandler: ResourceHandler;
|
|
11
11
|
readonly outputHandler: OutputHandler;
|
|
12
12
|
readonly errorHandler: ErrorHandler;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HandlerContainer = void 0;
|
|
3
4
|
const error_1 = require("./handler/error");
|
|
4
5
|
const output_1 = require("./handler/output");
|
|
5
6
|
const resource_1 = require("./handler/resource");
|
|
@@ -11,4 +12,4 @@ class HandlerContainer {
|
|
|
11
12
|
this.errorHandler = (options === null || options === void 0 ? void 0 : options.errorHandler) || new error_1.DefaultErrorHandler();
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
|
-
exports.
|
|
15
|
+
exports.HandlerContainer = HandlerContainer;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
|
-
export { ContextForkOptions, ContextOptions, ContextState, ContextType, Debugger, FunctionState, LoopState,
|
|
2
|
-
export {
|
|
1
|
+
export { ContextForkOptions, ContextOptions, ContextState, ContextType, Debugger, FunctionState, LoopState, OperationContext, ProcessState, Scope } from './context';
|
|
2
|
+
export { CPS, CPSContext } from './cps';
|
|
3
3
|
export { DefaultErrorHandler, ErrorHandler } from './handler/error';
|
|
4
4
|
export { DefaultOutputHandler, KeyEvent, OutputHandler } from './handler/output';
|
|
5
5
|
export { DefaultResourceHandler, ResourceHandler } from './handler/resource';
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
-
export { Clause,
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export { CPSVisit,
|
|
29
|
-
export {
|
|
30
|
-
export { IdentifierSegment, IndexSegment, OperationSegment,
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
export {
|
|
36
|
-
export { Argument, Callback,
|
|
37
|
-
export {
|
|
38
|
-
export {
|
|
39
|
-
export {
|
|
40
|
-
export {
|
|
41
|
-
export {
|
|
42
|
-
export {
|
|
6
|
+
export { HandlerContainer } from './handler-container';
|
|
7
|
+
export { Interpreter, InterpreterOptions } from './interpreter';
|
|
8
|
+
export { Assign } from './operations/assign';
|
|
9
|
+
export { Block, IsEOL } from './operations/block';
|
|
10
|
+
export { Break } from './operations/break';
|
|
11
|
+
export { Call } from './operations/call';
|
|
12
|
+
export { Chunk } from './operations/chunk';
|
|
13
|
+
export { Continue } from './operations/continue';
|
|
14
|
+
export { DebuggerStatement } from './operations/debugger-statement';
|
|
15
|
+
export { Evaluate, GenericProcessorHandler, handle, handleInterface, handleList, handleMap, handleNumber, handleString, ListProcessorHandler, MapProcessorHandler, NumberProcessorHandler, ProcessorHandler, ProcessorHandlerFunction, StringProcessorHandler } from './operations/evaluate';
|
|
16
|
+
export { For } from './operations/for';
|
|
17
|
+
export { FunctionOperation } from './operations/function';
|
|
18
|
+
export { Clause, IfStatement } from './operations/if-statement';
|
|
19
|
+
export { Import } from './operations/import';
|
|
20
|
+
export { Include } from './operations/include';
|
|
21
|
+
export { List } from './operations/list';
|
|
22
|
+
export { Literal } from './operations/literal';
|
|
23
|
+
export { MapOperation } from './operations/map';
|
|
24
|
+
export { NegatedBinary } from './operations/negated-binary';
|
|
25
|
+
export { NewInstance } from './operations/new-instance';
|
|
26
|
+
export { Noop } from './operations/noop';
|
|
27
|
+
export { Not } from './operations/not';
|
|
28
|
+
export { CPSVisit, Operation } from './operations/operation';
|
|
29
|
+
export { Reference } from './operations/reference';
|
|
30
|
+
export { IdentifierSegment, IndexSegment, OperationSegment, Resolve, ResolveResult, Segment } from './operations/resolve';
|
|
31
|
+
export { Return } from './operations/return';
|
|
32
|
+
export { While } from './operations/while';
|
|
33
|
+
export { CustomValue } from './types/base';
|
|
34
|
+
export { CustomBoolean } from './types/boolean';
|
|
35
|
+
export { DefaultType } from './types/default';
|
|
36
|
+
export { Argument, Callback, CustomFunction } from './types/function';
|
|
37
|
+
export { CustomInterface, CustomInterfaceIterator } from './types/interface';
|
|
38
|
+
export { CustomList, CustomListIterator } from './types/list';
|
|
39
|
+
export { CustomMap, CustomMapIterator } from './types/map';
|
|
40
|
+
export { CustomNil } from './types/nil';
|
|
41
|
+
export { CustomNumber } from './types/number';
|
|
42
|
+
export { CustomString, CustomStringIterator } from './types/string';
|
|
43
43
|
export { CustomObject, CustomValueWithIntrinsics } from './types/with-intrinsics';
|
|
44
|
-
export {
|
|
45
|
-
export {
|
|
46
|
-
export {
|
|
44
|
+
export { deepEqual } from './utils/deep-equal';
|
|
45
|
+
export { PrepareError, RuntimeError } from './utils/error';
|
|
46
|
+
export { ObjectValue } from './utils/object-value';
|
|
47
|
+
export { Path } from './utils/path';
|