greybel-interpreter 1.6.3 → 1.6.5
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 +2 -0
- package/dist/context.js +3 -1
- package/dist/cps.js +3 -0
- package/dist/interpreter.d.ts +2 -0
- package/dist/interpreter.js +4 -2
- package/dist/operations/block.d.ts +2 -1
- package/dist/operations/block.js +2 -2
- package/dist/operations/chunk.js +1 -1
- package/dist/operations/envar.d.ts +10 -0
- package/dist/operations/envar.js +23 -0
- package/dist/operations/for.js +1 -1
- package/dist/operations/function.js +1 -1
- package/dist/operations/if-statement.js +2 -2
- package/dist/operations/noop.d.ts +0 -2
- package/dist/operations/noop.js +0 -3
- package/dist/operations/while.js +1 -1
- package/package.json +1 -1
package/dist/context.d.ts
CHANGED
|
@@ -63,6 +63,7 @@ export interface ContextOptions {
|
|
|
63
63
|
handler?: HandlerContainer;
|
|
64
64
|
cps?: CPS;
|
|
65
65
|
processState?: ProcessState;
|
|
66
|
+
environmentVariables?: Map<string, string>;
|
|
66
67
|
}
|
|
67
68
|
export interface ContextForkOptions {
|
|
68
69
|
type: ContextType;
|
|
@@ -74,6 +75,7 @@ export default class OperationContext {
|
|
|
74
75
|
target: string;
|
|
75
76
|
stackItem: ASTBase;
|
|
76
77
|
debugger: Debugger;
|
|
78
|
+
environmentVariables: Map<string, string>;
|
|
77
79
|
handler: HandlerContainer;
|
|
78
80
|
previous: OperationContext;
|
|
79
81
|
readonly type: ContextType;
|
package/dist/context.js
CHANGED
|
@@ -146,6 +146,7 @@ class OperationContext {
|
|
|
146
146
|
this.handler = options.handler || new handler_container_1.default();
|
|
147
147
|
this.cps = options.cps || null;
|
|
148
148
|
this.processState = options.processState || new ProcessState();
|
|
149
|
+
this.environmentVariables = options.environmentVariables || new Map();
|
|
149
150
|
this.api = this.lookupApi();
|
|
150
151
|
this.globals = this.lookupGlobals();
|
|
151
152
|
this.locals = this.lookupLocals() || this;
|
|
@@ -286,7 +287,8 @@ class OperationContext {
|
|
|
286
287
|
debugger: this.debugger,
|
|
287
288
|
handler: this.handler,
|
|
288
289
|
cps: this.cps,
|
|
289
|
-
processState: this.processState
|
|
290
|
+
processState: this.processState,
|
|
291
|
+
environmentVariables: this.environmentVariables
|
|
290
292
|
});
|
|
291
293
|
if (options.type !== ContextType.Function) {
|
|
292
294
|
if (options.type !== ContextType.Loop) {
|
package/dist/cps.js
CHANGED
|
@@ -38,6 +38,7 @@ const not_1 = __importDefault(require("./operations/not"));
|
|
|
38
38
|
const resolve_1 = __importDefault(require("./operations/resolve"));
|
|
39
39
|
const return_1 = __importDefault(require("./operations/return"));
|
|
40
40
|
const while_1 = __importDefault(require("./operations/while"));
|
|
41
|
+
const envar_1 = __importDefault(require("./operations/envar"));
|
|
41
42
|
class CPSContext {
|
|
42
43
|
constructor(target, handler) {
|
|
43
44
|
this.target = target;
|
|
@@ -114,6 +115,8 @@ const visit = (context, currentTarget, item) => __awaiter(void 0, void 0, void 0
|
|
|
114
115
|
}
|
|
115
116
|
case greybel_core_1.ASTType.FeatureDebuggerExpression:
|
|
116
117
|
return new debugger_statement_1.default(item, currentTarget);
|
|
118
|
+
case greybel_core_1.ASTType.FeatureEnvarExpression:
|
|
119
|
+
return new envar_1.default(item, currentTarget);
|
|
117
120
|
case greyscript_core_1.ASTType.BooleanLiteral:
|
|
118
121
|
case greyscript_core_1.ASTType.StringLiteral:
|
|
119
122
|
case greyscript_core_1.ASTType.NumericLiteral:
|
package/dist/interpreter.d.ts
CHANGED
|
@@ -14,11 +14,13 @@ export interface InterpreterOptions {
|
|
|
14
14
|
params?: Array<string>;
|
|
15
15
|
handler?: HandlerContainer;
|
|
16
16
|
debugger?: Debugger;
|
|
17
|
+
environmentVariables?: Map<string, string>;
|
|
17
18
|
}
|
|
18
19
|
export default class Interpreter extends EventEmitter {
|
|
19
20
|
target: string;
|
|
20
21
|
api: ObjectValue;
|
|
21
22
|
params: Array<string>;
|
|
23
|
+
environmentVariables: Map<string, string>;
|
|
22
24
|
handler: HandlerContainer;
|
|
23
25
|
debugger: Debugger;
|
|
24
26
|
apiContext: OperationContext;
|
package/dist/interpreter.js
CHANGED
|
@@ -56,6 +56,7 @@ class Interpreter extends events_1.default {
|
|
|
56
56
|
this.debugger = options.debugger || new context_1.Debugger();
|
|
57
57
|
this.api = options.api || new object_value_1.default();
|
|
58
58
|
this.params = options.params || [];
|
|
59
|
+
this.environmentVariables = options.environmentVariables || new Map();
|
|
59
60
|
this.apiContext = null;
|
|
60
61
|
this.globalContext = null;
|
|
61
62
|
this.setTarget(options.target || 'unknown');
|
|
@@ -72,7 +73,8 @@ class Interpreter extends events_1.default {
|
|
|
72
73
|
isProtected: true,
|
|
73
74
|
debugger: this.debugger,
|
|
74
75
|
handler: this.handler,
|
|
75
|
-
cps: this.cps
|
|
76
|
+
cps: this.cps,
|
|
77
|
+
environmentVariables: this.environmentVariables
|
|
76
78
|
});
|
|
77
79
|
this.globalContext = this.apiContext.fork({
|
|
78
80
|
type: context_1.ContextType.Global,
|
|
@@ -114,7 +116,7 @@ class Interpreter extends events_1.default {
|
|
|
114
116
|
catch (err) {
|
|
115
117
|
this.handler.errorHandler.raise(err);
|
|
116
118
|
}
|
|
117
|
-
return Promise.resolve(new noop_1.default());
|
|
119
|
+
return Promise.resolve(new noop_1.default(null));
|
|
118
120
|
}
|
|
119
121
|
inject(code, context) {
|
|
120
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ASTBase } from 'greyscript-core';
|
|
1
2
|
import OperationContext from '../context';
|
|
2
3
|
import CustomValue from '../types/base';
|
|
3
4
|
import Operation, { CPSVisit } from './operation';
|
|
@@ -6,7 +7,7 @@ export interface IsEOL {
|
|
|
6
7
|
}
|
|
7
8
|
export default class Block extends Operation {
|
|
8
9
|
readonly stack: Array<Operation>;
|
|
9
|
-
constructor(stack: Array<Operation>);
|
|
10
|
+
constructor(item: ASTBase, stack: Array<Operation>);
|
|
10
11
|
build(_visit: CPSVisit): Promise<Block>;
|
|
11
12
|
handle(ctx: OperationContext): Promise<CustomValue>;
|
|
12
13
|
}
|
package/dist/operations/block.js
CHANGED
|
@@ -16,8 +16,8 @@ const context_1 = require("../context");
|
|
|
16
16
|
const default_1 = __importDefault(require("../types/default"));
|
|
17
17
|
const operation_1 = __importDefault(require("./operation"));
|
|
18
18
|
class Block extends operation_1.default {
|
|
19
|
-
constructor(stack) {
|
|
20
|
-
super(
|
|
19
|
+
constructor(item, stack) {
|
|
20
|
+
super(item, 'block');
|
|
21
21
|
this.stack = stack;
|
|
22
22
|
}
|
|
23
23
|
build(_visit) {
|
package/dist/operations/chunk.js
CHANGED
|
@@ -23,7 +23,7 @@ class Chunk extends operation_1.default {
|
|
|
23
23
|
build(visit) {
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
25
|
const stack = yield Promise.all(this.item.body.map((child) => visit(child)));
|
|
26
|
-
this.block = new block_1.default(stack);
|
|
26
|
+
this.block = new block_1.default(this.item, stack);
|
|
27
27
|
return this;
|
|
28
28
|
});
|
|
29
29
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ASTFeatureEnvarExpression } from 'greybel-core';
|
|
2
|
+
import context from '../context';
|
|
3
|
+
import CustomValue from '../types/base';
|
|
4
|
+
import Operation, { CPSVisit } from './operation';
|
|
5
|
+
export default class EnvarExpression extends Operation {
|
|
6
|
+
readonly item: ASTFeatureEnvarExpression;
|
|
7
|
+
constructor(item: ASTFeatureEnvarExpression, target?: string);
|
|
8
|
+
build(_visit: CPSVisit): Promise<Operation>;
|
|
9
|
+
handle(ctx: context): Promise<CustomValue>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const string_1 = __importDefault(require("../types/string"));
|
|
7
|
+
const operation_1 = __importDefault(require("./operation"));
|
|
8
|
+
class EnvarExpression extends operation_1.default {
|
|
9
|
+
constructor(item, target) {
|
|
10
|
+
super(null, target);
|
|
11
|
+
this.item = item;
|
|
12
|
+
}
|
|
13
|
+
build(_visit) {
|
|
14
|
+
return Promise.resolve(this);
|
|
15
|
+
}
|
|
16
|
+
handle(ctx) {
|
|
17
|
+
if (ctx.environmentVariables.has(this.item.name)) {
|
|
18
|
+
return Promise.resolve(new string_1.default(ctx.environmentVariables.get(this.item.name)));
|
|
19
|
+
}
|
|
20
|
+
throw new Error('Unknown environment variable.');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.default = EnvarExpression;
|
package/dist/operations/for.js
CHANGED
|
@@ -26,7 +26,7 @@ class For extends operation_1.default {
|
|
|
26
26
|
build(visit) {
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
const stack = yield Promise.all(this.item.body.map((child) => visit(child)));
|
|
29
|
-
this.block = new block_1.default(stack);
|
|
29
|
+
this.block = new block_1.default(this.item, stack);
|
|
30
30
|
this.variable = this.item.variable;
|
|
31
31
|
this.iterator = yield visit(this.item.iterator);
|
|
32
32
|
return this;
|
|
@@ -31,7 +31,7 @@ class FunctionOperation extends operation_1.default {
|
|
|
31
31
|
build(visit) {
|
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
33
|
const stack = yield Promise.all(this.item.body.map((child) => visit(child)));
|
|
34
|
-
this.block = new block_1.default(stack);
|
|
34
|
+
this.block = new block_1.default(this.item, stack);
|
|
35
35
|
this.args = new Map();
|
|
36
36
|
const defers = this.item.parameters.map((child) => __awaiter(this, void 0, void 0, function* () {
|
|
37
37
|
switch (child.type) {
|
|
@@ -35,7 +35,7 @@ class IfStatement extends operation_1.default {
|
|
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
36
|
const condition = yield visit(node.condition);
|
|
37
37
|
const stack = yield Promise.all(node.body.map((child) => visit(child)));
|
|
38
|
-
const block = new block_1.default(stack);
|
|
38
|
+
const block = new block_1.default(this.item, stack);
|
|
39
39
|
this.clauses.push(new Clause(condition, block));
|
|
40
40
|
});
|
|
41
41
|
}
|
|
@@ -43,7 +43,7 @@ class IfStatement extends operation_1.default {
|
|
|
43
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
44
|
const condition = new reference_1.default(new boolean_1.default(true));
|
|
45
45
|
const stack = yield Promise.all(node.body.map((child) => visit(child)));
|
|
46
|
-
const block = new block_1.default(stack);
|
|
46
|
+
const block = new block_1.default(this.item, stack);
|
|
47
47
|
this.clauses.push(new Clause(condition, block));
|
|
48
48
|
});
|
|
49
49
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { ASTBase } from 'greyscript-core';
|
|
2
1
|
import context from '../context';
|
|
3
2
|
import CustomValue from '../types/base';
|
|
4
3
|
import Operation, { CPSVisit } from './operation';
|
|
5
4
|
export default class Noop extends Operation {
|
|
6
|
-
constructor(item?: ASTBase, target?: string);
|
|
7
5
|
build(_visit: CPSVisit): Promise<Operation>;
|
|
8
6
|
handle(_ctx: context): Promise<CustomValue>;
|
|
9
7
|
}
|
package/dist/operations/noop.js
CHANGED
|
@@ -6,9 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const default_1 = __importDefault(require("../types/default"));
|
|
7
7
|
const operation_1 = __importDefault(require("./operation"));
|
|
8
8
|
class Noop extends operation_1.default {
|
|
9
|
-
constructor(item, target) {
|
|
10
|
-
super(null, target);
|
|
11
|
-
}
|
|
12
9
|
build(_visit) {
|
|
13
10
|
return Promise.resolve(this);
|
|
14
11
|
}
|
package/dist/operations/while.js
CHANGED
|
@@ -24,7 +24,7 @@ class While extends operation_1.default {
|
|
|
24
24
|
build(visit) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
26
|
const stack = yield Promise.all(this.item.body.map((child) => visit(child)));
|
|
27
|
-
this.block = new block_1.default(stack);
|
|
27
|
+
this.block = new block_1.default(this.item, stack);
|
|
28
28
|
this.condition = yield visit(this.item.condition);
|
|
29
29
|
return this;
|
|
30
30
|
});
|