greybel-interpreter 3.5.1 → 4.0.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.
- package/dist/byte-compiler/instruction.d.ts +129 -0
- package/dist/byte-compiler/instruction.js +60 -0
- package/dist/bytecode-generator.d.ts +61 -0
- package/dist/bytecode-generator.js +1165 -0
- package/dist/context.d.ts +20 -88
- package/dist/context.js +44 -273
- package/dist/index.d.ts +5 -29
- package/dist/index.js +14 -87
- package/dist/interpreter.d.ts +11 -12
- package/dist/interpreter.js +75 -87
- package/dist/types/function.d.ts +11 -25
- package/dist/types/function.js +41 -105
- package/dist/types/list.d.ts +4 -5
- package/dist/types/list.js +10 -52
- package/dist/types/map.d.ts +4 -5
- package/dist/types/map.js +15 -74
- package/dist/types/number.d.ts +4 -5
- package/dist/types/number.js +5 -12
- package/dist/types/string.d.ts +4 -5
- package/dist/types/string.js +6 -18
- package/dist/types/with-intrinsics.d.ts +4 -5
- package/dist/utils/error.d.ts +5 -5
- package/dist/utils/error.js +4 -5
- package/dist/utils/stack.d.ts +10 -0
- package/dist/utils/stack.js +30 -0
- package/dist/vm/evaluation.d.ts +26 -0
- package/dist/vm/evaluation.js +341 -0
- package/dist/vm.d.ts +66 -0
- package/dist/vm.js +662 -0
- package/package.json +1 -1
- package/dist/cps.d.ts +0 -16
- package/dist/cps.js +0 -202
- package/dist/operations/assign-globals.d.ts +0 -11
- package/dist/operations/assign-globals.js +0 -31
- package/dist/operations/assign-locals.d.ts +0 -11
- package/dist/operations/assign-locals.js +0 -31
- package/dist/operations/assign-outer.d.ts +0 -11
- package/dist/operations/assign-outer.js +0 -31
- package/dist/operations/assign-self.d.ts +0 -11
- package/dist/operations/assign-self.js +0 -41
- package/dist/operations/assign.d.ts +0 -13
- package/dist/operations/assign.js +0 -60
- package/dist/operations/block.d.ts +0 -13
- package/dist/operations/block.js +0 -48
- package/dist/operations/break.d.ts +0 -10
- package/dist/operations/break.js +0 -21
- package/dist/operations/call.d.ts +0 -13
- package/dist/operations/call.js +0 -64
- package/dist/operations/chunk.d.ts +0 -12
- package/dist/operations/chunk.js +0 -31
- package/dist/operations/continue.d.ts +0 -10
- package/dist/operations/continue.js +0 -21
- package/dist/operations/debugger-statement.d.ts +0 -10
- package/dist/operations/debugger-statement.js +0 -19
- package/dist/operations/envar.d.ts +0 -10
- package/dist/operations/envar.js +0 -21
- package/dist/operations/evaluate.d.ts +0 -45
- package/dist/operations/evaluate.js +0 -369
- package/dist/operations/for.d.ts +0 -14
- package/dist/operations/for.js +0 -87
- package/dist/operations/function-reference.d.ts +0 -12
- package/dist/operations/function-reference.js +0 -48
- package/dist/operations/function.d.ts +0 -19
- package/dist/operations/function.js +0 -84
- package/dist/operations/if-statement.d.ts +0 -19
- package/dist/operations/if-statement.js +0 -87
- package/dist/operations/import.d.ts +0 -20
- package/dist/operations/import.js +0 -56
- package/dist/operations/include.d.ts +0 -14
- package/dist/operations/include.js +0 -40
- package/dist/operations/list.d.ts +0 -11
- package/dist/operations/list.js +0 -40
- package/dist/operations/literal.d.ts +0 -11
- package/dist/operations/literal.js +0 -38
- package/dist/operations/map.d.ts +0 -11
- package/dist/operations/map.js +0 -42
- package/dist/operations/negated-binary.d.ts +0 -11
- package/dist/operations/negated-binary.js +0 -40
- package/dist/operations/new-instance.d.ts +0 -11
- package/dist/operations/new-instance.js +0 -37
- package/dist/operations/noop.d.ts +0 -7
- package/dist/operations/noop.js +0 -14
- package/dist/operations/not.d.ts +0 -11
- package/dist/operations/not.js +0 -33
- package/dist/operations/operation.d.ts +0 -15
- package/dist/operations/operation.js +0 -13
- package/dist/operations/reference-globals.d.ts +0 -7
- package/dist/operations/reference-globals.js +0 -13
- package/dist/operations/reference-locals.d.ts +0 -7
- package/dist/operations/reference-locals.js +0 -13
- package/dist/operations/reference-outer.d.ts +0 -7
- package/dist/operations/reference-outer.js +0 -13
- package/dist/operations/reference-self.d.ts +0 -7
- package/dist/operations/reference-self.js +0 -13
- package/dist/operations/reference.d.ts +0 -9
- package/dist/operations/reference.js +0 -17
- package/dist/operations/resolve-globals.d.ts +0 -5
- package/dist/operations/resolve-globals.js +0 -24
- package/dist/operations/resolve-locals.d.ts +0 -5
- package/dist/operations/resolve-locals.js +0 -24
- package/dist/operations/resolve-outer.d.ts +0 -5
- package/dist/operations/resolve-outer.js +0 -24
- package/dist/operations/resolve-self.d.ts +0 -5
- package/dist/operations/resolve-self.js +0 -24
- package/dist/operations/resolve.d.ts +0 -55
- package/dist/operations/resolve.js +0 -269
- package/dist/operations/return.d.ts +0 -11
- package/dist/operations/return.js +0 -43
- package/dist/operations/while.d.ts +0 -13
- package/dist/operations/while.js +0 -70
- package/dist/utils/create-assign.d.ts +0 -3
- package/dist/utils/create-assign.js +0 -25
- package/dist/utils/create-resolve.d.ts +0 -5
- package/dist/utils/create-resolve.js +0 -51
- package/dist/utils/path.d.ts +0 -10
- package/dist/utils/path.js +0 -33
package/dist/index.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.deepHash = exports.deepEqual = exports.Path = exports.ObjectValue = exports.RuntimeError = exports.PrepareError = exports.CustomValueWithIntrinsics = exports.CustomObject = exports.CustomStringIterator = exports.CustomString = exports.CustomNumber = exports.CustomNil = exports.CustomMapIterator = exports.CustomMap = exports.CustomListIterator = exports.CustomList = exports.CustomFunction = exports.Argument = exports.DefaultType = exports.CustomBoolean = exports.CustomValue = exports.While = exports.Return = exports.ResolveResult = exports.Resolve = exports.OperationSegment = exports.IndexSegment = exports.IdentifierSegment = exports.Reference = exports.Operation = void 0;
|
|
3
|
+
exports.BytecodeGenerator = exports.VM = exports.Debugger = exports.deepHash = exports.deepEqual = exports.ObjectValue = exports.RuntimeError = exports.PrepareError = exports.CustomValueWithIntrinsics = exports.CustomObject = exports.CustomStringIterator = exports.CustomString = exports.CustomNumber = exports.CustomNil = exports.CustomMapIterator = exports.CustomMap = exports.CustomListIterator = exports.CustomList = exports.CustomFunction = exports.DefaultType = exports.CustomBoolean = exports.CustomValue = exports.Interpreter = exports.HandlerContainer = exports.ResourceHandler = exports.DefaultResourceHandler = exports.OutputHandler = exports.DefaultOutputHandler = exports.ErrorHandler = exports.DefaultErrorHandler = exports.Scope = exports.OperationContext = exports.ContextType = void 0;
|
|
5
4
|
var context_1 = require("./context");
|
|
6
|
-
Object.defineProperty(exports, "ContextState", { enumerable: true, get: function () { return context_1.ContextState; } });
|
|
7
5
|
Object.defineProperty(exports, "ContextType", { enumerable: true, get: function () { return context_1.ContextType; } });
|
|
8
|
-
Object.defineProperty(exports, "Debugger", { enumerable: true, get: function () { return context_1.Debugger; } });
|
|
9
|
-
Object.defineProperty(exports, "FunctionState", { enumerable: true, get: function () { return context_1.FunctionState; } });
|
|
10
|
-
Object.defineProperty(exports, "LoopState", { enumerable: true, get: function () { return context_1.LoopState; } });
|
|
11
6
|
Object.defineProperty(exports, "OperationContext", { enumerable: true, get: function () { return context_1.OperationContext; } });
|
|
12
|
-
Object.defineProperty(exports, "ProcessState", { enumerable: true, get: function () { return context_1.ProcessState; } });
|
|
13
7
|
Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return context_1.Scope; } });
|
|
14
|
-
var cps_1 = require("./cps");
|
|
15
|
-
Object.defineProperty(exports, "CPS", { enumerable: true, get: function () { return cps_1.CPS; } });
|
|
16
|
-
Object.defineProperty(exports, "CPSContext", { enumerable: true, get: function () { return cps_1.CPSContext; } });
|
|
17
|
-
Object.defineProperty(exports, "defaultCPSVisit", { enumerable: true, get: function () { return cps_1.defaultCPSVisit; } });
|
|
18
8
|
var error_1 = require("./handler/error");
|
|
19
9
|
Object.defineProperty(exports, "DefaultErrorHandler", { enumerable: true, get: function () { return error_1.DefaultErrorHandler; } });
|
|
20
10
|
Object.defineProperty(exports, "ErrorHandler", { enumerable: true, get: function () { return error_1.ErrorHandler; } });
|
|
@@ -28,86 +18,20 @@ var handler_container_1 = require("./handler-container");
|
|
|
28
18
|
Object.defineProperty(exports, "HandlerContainer", { enumerable: true, get: function () { return handler_container_1.HandlerContainer; } });
|
|
29
19
|
var interpreter_1 = require("./interpreter");
|
|
30
20
|
Object.defineProperty(exports, "Interpreter", { enumerable: true, get: function () { return interpreter_1.Interpreter; } });
|
|
31
|
-
var assign_1 = require("./operations/assign");
|
|
32
|
-
Object.defineProperty(exports, "Assign", { enumerable: true, get: function () { return assign_1.Assign; } });
|
|
33
|
-
var block_1 = require("./operations/block");
|
|
34
|
-
Object.defineProperty(exports, "Block", { enumerable: true, get: function () { return block_1.Block; } });
|
|
35
|
-
var break_1 = require("./operations/break");
|
|
36
|
-
Object.defineProperty(exports, "Break", { enumerable: true, get: function () { return break_1.Break; } });
|
|
37
|
-
var call_1 = require("./operations/call");
|
|
38
|
-
Object.defineProperty(exports, "Call", { enumerable: true, get: function () { return call_1.Call; } });
|
|
39
|
-
var chunk_1 = require("./operations/chunk");
|
|
40
|
-
Object.defineProperty(exports, "Chunk", { enumerable: true, get: function () { return chunk_1.Chunk; } });
|
|
41
|
-
var continue_1 = require("./operations/continue");
|
|
42
|
-
Object.defineProperty(exports, "Continue", { enumerable: true, get: function () { return continue_1.Continue; } });
|
|
43
|
-
var debugger_statement_1 = require("./operations/debugger-statement");
|
|
44
|
-
Object.defineProperty(exports, "DebuggerStatement", { enumerable: true, get: function () { return debugger_statement_1.DebuggerStatement; } });
|
|
45
|
-
var evaluate_1 = require("./operations/evaluate");
|
|
46
|
-
Object.defineProperty(exports, "Evaluate", { enumerable: true, get: function () { return evaluate_1.Evaluate; } });
|
|
47
|
-
Object.defineProperty(exports, "GenericProcessorHandler", { enumerable: true, get: function () { return evaluate_1.GenericProcessorHandler; } });
|
|
48
|
-
Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return evaluate_1.handle; } });
|
|
49
|
-
Object.defineProperty(exports, "handleList", { enumerable: true, get: function () { return evaluate_1.handleList; } });
|
|
50
|
-
Object.defineProperty(exports, "handleMap", { enumerable: true, get: function () { return evaluate_1.handleMap; } });
|
|
51
|
-
Object.defineProperty(exports, "handleNumber", { enumerable: true, get: function () { return evaluate_1.handleNumber; } });
|
|
52
|
-
Object.defineProperty(exports, "handleString", { enumerable: true, get: function () { return evaluate_1.handleString; } });
|
|
53
|
-
Object.defineProperty(exports, "ListProcessorHandler", { enumerable: true, get: function () { return evaluate_1.ListProcessorHandler; } });
|
|
54
|
-
Object.defineProperty(exports, "MapProcessorHandler", { enumerable: true, get: function () { return evaluate_1.MapProcessorHandler; } });
|
|
55
|
-
Object.defineProperty(exports, "NumberProcessorHandler", { enumerable: true, get: function () { return evaluate_1.NumberProcessorHandler; } });
|
|
56
|
-
Object.defineProperty(exports, "StringProcessorHandler", { enumerable: true, get: function () { return evaluate_1.StringProcessorHandler; } });
|
|
57
|
-
var for_1 = require("./operations/for");
|
|
58
|
-
Object.defineProperty(exports, "For", { enumerable: true, get: function () { return for_1.For; } });
|
|
59
|
-
var function_1 = require("./operations/function");
|
|
60
|
-
Object.defineProperty(exports, "FunctionOperation", { enumerable: true, get: function () { return function_1.FunctionOperation; } });
|
|
61
|
-
var if_statement_1 = require("./operations/if-statement");
|
|
62
|
-
Object.defineProperty(exports, "Clause", { enumerable: true, get: function () { return if_statement_1.Clause; } });
|
|
63
|
-
Object.defineProperty(exports, "IfStatement", { enumerable: true, get: function () { return if_statement_1.IfStatement; } });
|
|
64
|
-
var import_1 = require("./operations/import");
|
|
65
|
-
Object.defineProperty(exports, "Import", { enumerable: true, get: function () { return import_1.Import; } });
|
|
66
|
-
var include_1 = require("./operations/include");
|
|
67
|
-
Object.defineProperty(exports, "Include", { enumerable: true, get: function () { return include_1.Include; } });
|
|
68
|
-
var list_1 = require("./operations/list");
|
|
69
|
-
Object.defineProperty(exports, "List", { enumerable: true, get: function () { return list_1.List; } });
|
|
70
|
-
var literal_1 = require("./operations/literal");
|
|
71
|
-
Object.defineProperty(exports, "Literal", { enumerable: true, get: function () { return literal_1.Literal; } });
|
|
72
|
-
var map_1 = require("./operations/map");
|
|
73
|
-
Object.defineProperty(exports, "MapOperation", { enumerable: true, get: function () { return map_1.MapOperation; } });
|
|
74
|
-
var negated_binary_1 = require("./operations/negated-binary");
|
|
75
|
-
Object.defineProperty(exports, "NegatedBinary", { enumerable: true, get: function () { return negated_binary_1.NegatedBinary; } });
|
|
76
|
-
var new_instance_1 = require("./operations/new-instance");
|
|
77
|
-
Object.defineProperty(exports, "NewInstance", { enumerable: true, get: function () { return new_instance_1.NewInstance; } });
|
|
78
|
-
var noop_1 = require("./operations/noop");
|
|
79
|
-
Object.defineProperty(exports, "Noop", { enumerable: true, get: function () { return noop_1.Noop; } });
|
|
80
|
-
var not_1 = require("./operations/not");
|
|
81
|
-
Object.defineProperty(exports, "Not", { enumerable: true, get: function () { return not_1.Not; } });
|
|
82
|
-
var operation_1 = require("./operations/operation");
|
|
83
|
-
Object.defineProperty(exports, "Operation", { enumerable: true, get: function () { return operation_1.Operation; } });
|
|
84
|
-
var reference_1 = require("./operations/reference");
|
|
85
|
-
Object.defineProperty(exports, "Reference", { enumerable: true, get: function () { return reference_1.Reference; } });
|
|
86
|
-
var resolve_1 = require("./operations/resolve");
|
|
87
|
-
Object.defineProperty(exports, "IdentifierSegment", { enumerable: true, get: function () { return resolve_1.IdentifierSegment; } });
|
|
88
|
-
Object.defineProperty(exports, "IndexSegment", { enumerable: true, get: function () { return resolve_1.IndexSegment; } });
|
|
89
|
-
Object.defineProperty(exports, "OperationSegment", { enumerable: true, get: function () { return resolve_1.OperationSegment; } });
|
|
90
|
-
Object.defineProperty(exports, "Resolve", { enumerable: true, get: function () { return resolve_1.Resolve; } });
|
|
91
|
-
Object.defineProperty(exports, "ResolveResult", { enumerable: true, get: function () { return resolve_1.ResolveResult; } });
|
|
92
|
-
var return_1 = require("./operations/return");
|
|
93
|
-
Object.defineProperty(exports, "Return", { enumerable: true, get: function () { return return_1.Return; } });
|
|
94
|
-
var while_1 = require("./operations/while");
|
|
95
|
-
Object.defineProperty(exports, "While", { enumerable: true, get: function () { return while_1.While; } });
|
|
96
21
|
var base_1 = require("./types/base");
|
|
97
22
|
Object.defineProperty(exports, "CustomValue", { enumerable: true, get: function () { return base_1.CustomValue; } });
|
|
98
23
|
var boolean_1 = require("./types/boolean");
|
|
99
24
|
Object.defineProperty(exports, "CustomBoolean", { enumerable: true, get: function () { return boolean_1.CustomBoolean; } });
|
|
100
25
|
var default_1 = require("./types/default");
|
|
101
26
|
Object.defineProperty(exports, "DefaultType", { enumerable: true, get: function () { return default_1.DefaultType; } });
|
|
102
|
-
var
|
|
103
|
-
Object.defineProperty(exports, "
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
Object.defineProperty(exports, "
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
Object.defineProperty(exports, "
|
|
110
|
-
Object.defineProperty(exports, "CustomMapIterator", { enumerable: true, get: function () { return map_2.CustomMapIterator; } });
|
|
27
|
+
var function_1 = require("./types/function");
|
|
28
|
+
Object.defineProperty(exports, "CustomFunction", { enumerable: true, get: function () { return function_1.CustomFunction; } });
|
|
29
|
+
var list_1 = require("./types/list");
|
|
30
|
+
Object.defineProperty(exports, "CustomList", { enumerable: true, get: function () { return list_1.CustomList; } });
|
|
31
|
+
Object.defineProperty(exports, "CustomListIterator", { enumerable: true, get: function () { return list_1.CustomListIterator; } });
|
|
32
|
+
var map_1 = require("./types/map");
|
|
33
|
+
Object.defineProperty(exports, "CustomMap", { enumerable: true, get: function () { return map_1.CustomMap; } });
|
|
34
|
+
Object.defineProperty(exports, "CustomMapIterator", { enumerable: true, get: function () { return map_1.CustomMapIterator; } });
|
|
111
35
|
var nil_1 = require("./types/nil");
|
|
112
36
|
Object.defineProperty(exports, "CustomNil", { enumerable: true, get: function () { return nil_1.CustomNil; } });
|
|
113
37
|
var number_1 = require("./types/number");
|
|
@@ -123,9 +47,12 @@ Object.defineProperty(exports, "PrepareError", { enumerable: true, get: function
|
|
|
123
47
|
Object.defineProperty(exports, "RuntimeError", { enumerable: true, get: function () { return error_2.RuntimeError; } });
|
|
124
48
|
var object_value_1 = require("./utils/object-value");
|
|
125
49
|
Object.defineProperty(exports, "ObjectValue", { enumerable: true, get: function () { return object_value_1.ObjectValue; } });
|
|
126
|
-
var path_1 = require("./utils/path");
|
|
127
|
-
Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return path_1.Path; } });
|
|
128
50
|
var deep_equal_1 = require("./utils/deep-equal");
|
|
129
51
|
Object.defineProperty(exports, "deepEqual", { enumerable: true, get: function () { return deep_equal_1.deepEqual; } });
|
|
130
52
|
var deep_hash_1 = require("./utils/deep-hash");
|
|
131
53
|
Object.defineProperty(exports, "deepHash", { enumerable: true, get: function () { return deep_hash_1.deepHash; } });
|
|
54
|
+
var vm_1 = require("./vm");
|
|
55
|
+
Object.defineProperty(exports, "Debugger", { enumerable: true, get: function () { return vm_1.Debugger; } });
|
|
56
|
+
Object.defineProperty(exports, "VM", { enumerable: true, get: function () { return vm_1.VM; } });
|
|
57
|
+
var bytecode_generator_1 = require("./bytecode-generator");
|
|
58
|
+
Object.defineProperty(exports, "BytecodeGenerator", { enumerable: true, get: function () { return bytecode_generator_1.BytecodeGenerator; } });
|
package/dist/interpreter.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import { ContextOptions,
|
|
4
|
-
import { CPS } from './cps';
|
|
3
|
+
import { ContextOptions, OperationContext } from './context';
|
|
5
4
|
import { HandlerContainer } from './handler-container';
|
|
6
|
-
import { Operation } from './operations/operation';
|
|
7
5
|
import { CustomValue } from './types/base';
|
|
8
6
|
import { CustomString } from './types/string';
|
|
9
7
|
import { ObjectValue } from './utils/object-value';
|
|
8
|
+
import { Debugger, VM } from './vm';
|
|
9
|
+
import { BytecodeCompileResult } from './bytecode-generator';
|
|
10
10
|
export declare const PARAMS_PROPERTY: CustomString;
|
|
11
11
|
export declare const IS_GREYBEL_PROPERTY: CustomString;
|
|
12
12
|
export interface InterpreterOptions {
|
|
@@ -15,6 +15,7 @@ export interface InterpreterOptions {
|
|
|
15
15
|
params?: Array<string>;
|
|
16
16
|
handler?: HandlerContainer;
|
|
17
17
|
debugger?: Debugger;
|
|
18
|
+
debugMode?: boolean;
|
|
18
19
|
environmentVariables?: Map<string, string>;
|
|
19
20
|
}
|
|
20
21
|
export interface InterpreterRunOptions {
|
|
@@ -28,25 +29,23 @@ export declare class Interpreter extends EventEmitter {
|
|
|
28
29
|
environmentVariables: Map<string, string>;
|
|
29
30
|
handler: HandlerContainer;
|
|
30
31
|
debugger: Debugger;
|
|
32
|
+
debugMode: boolean;
|
|
31
33
|
apiContext: OperationContext;
|
|
32
34
|
globalContext: OperationContext;
|
|
33
|
-
|
|
34
|
-
constructor(options
|
|
35
|
+
vm: VM;
|
|
36
|
+
constructor(options?: InterpreterOptions);
|
|
35
37
|
setTarget(target: string): Interpreter;
|
|
36
38
|
setDebugger(dbgr: Debugger): Interpreter;
|
|
37
39
|
setApi(newApi: ObjectValue): Interpreter;
|
|
38
40
|
setHandler(handler: HandlerContainer): Interpreter;
|
|
39
|
-
parse(code: string): import("miniscript-core").ASTBase | import("greybel-core").ASTChunkAdvanced;
|
|
40
|
-
prepare(code: string): Promise<Operation>;
|
|
41
41
|
inject(code: string, context?: OperationContext): Promise<Interpreter>;
|
|
42
42
|
injectInLastContext(code: string): Promise<Interpreter>;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
run({ customCode, ctxOptions }?: InterpreterRunOptions): Promise<Interpreter>;
|
|
43
|
+
protected initVM(result: BytecodeCompileResult): void;
|
|
44
|
+
protected start(): Promise<Interpreter>;
|
|
45
|
+
run({ customCode }?: InterpreterRunOptions): Promise<Interpreter>;
|
|
47
46
|
resume(): Interpreter;
|
|
48
47
|
pause(): Interpreter;
|
|
49
|
-
exit():
|
|
48
|
+
exit(): void;
|
|
50
49
|
setGlobalVariable(path: string, value: CustomValue): Interpreter;
|
|
51
50
|
getGlobalVariable(path: string): CustomValue;
|
|
52
51
|
}
|
package/dist/interpreter.js
CHANGED
|
@@ -11,11 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Interpreter = exports.IS_GREYBEL_PROPERTY = exports.PARAMS_PROPERTY = void 0;
|
|
13
13
|
const events_1 = require("events");
|
|
14
|
-
const greybel_core_1 = require("greybel-core");
|
|
15
14
|
const context_1 = require("./context");
|
|
16
|
-
const cps_1 = require("./cps");
|
|
17
15
|
const handler_container_1 = require("./handler-container");
|
|
18
|
-
const noop_1 = require("./operations/noop");
|
|
19
16
|
const default_1 = require("./types/default");
|
|
20
17
|
const function_1 = require("./types/function");
|
|
21
18
|
const list_1 = require("./types/list");
|
|
@@ -25,88 +22,81 @@ const string_1 = require("./types/string");
|
|
|
25
22
|
const error_1 = require("./utils/error");
|
|
26
23
|
const object_value_1 = require("./utils/object-value");
|
|
27
24
|
const boolean_1 = require("./types/boolean");
|
|
25
|
+
const vm_1 = require("./vm");
|
|
26
|
+
const bytecode_generator_1 = require("./bytecode-generator");
|
|
28
27
|
exports.PARAMS_PROPERTY = new string_1.CustomString('params');
|
|
29
28
|
exports.IS_GREYBEL_PROPERTY = new string_1.CustomString('IS_GREYBEL');
|
|
30
29
|
class Interpreter extends events_1.EventEmitter {
|
|
31
|
-
constructor(options) {
|
|
32
|
-
var _a, _b, _c, _d, _e, _f;
|
|
30
|
+
constructor(options = {}) {
|
|
31
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
33
32
|
super();
|
|
34
33
|
this.handler = (_a = options.handler) !== null && _a !== void 0 ? _a : new handler_container_1.HandlerContainer();
|
|
35
|
-
this.debugger = (_b = options.debugger) !== null && _b !== void 0 ? _b : new
|
|
34
|
+
this.debugger = (_b = options.debugger) !== null && _b !== void 0 ? _b : new vm_1.Debugger();
|
|
35
|
+
this.vm = null;
|
|
36
36
|
this.api = (_c = options.api) !== null && _c !== void 0 ? _c : new object_value_1.ObjectValue();
|
|
37
37
|
this.params = (_d = options.params) !== null && _d !== void 0 ? _d : [];
|
|
38
38
|
this.environmentVariables = (_e = options.environmentVariables) !== null && _e !== void 0 ? _e : new Map();
|
|
39
|
+
this.debugMode = (_f = options.debugMode) !== null && _f !== void 0 ? _f : false;
|
|
39
40
|
this.apiContext = null;
|
|
40
41
|
this.globalContext = null;
|
|
41
|
-
this.setTarget((
|
|
42
|
+
this.setTarget((_g = options.target) !== null && _g !== void 0 ? _g : 'unknown');
|
|
42
43
|
}
|
|
43
44
|
setTarget(target) {
|
|
44
|
-
if (this.
|
|
45
|
+
if (this.vm !== null && this.vm.isPending()) {
|
|
45
46
|
throw new Error('You cannot set a target while a process is running.');
|
|
46
47
|
}
|
|
47
48
|
this.target = target;
|
|
48
49
|
return this;
|
|
49
50
|
}
|
|
50
51
|
setDebugger(dbgr) {
|
|
51
|
-
if (this.
|
|
52
|
+
if (this.vm !== null && this.vm.isPending()) {
|
|
52
53
|
throw new Error('You cannot set a debugger while a process is running.');
|
|
53
54
|
}
|
|
54
55
|
this.debugger = dbgr;
|
|
55
56
|
return this;
|
|
56
57
|
}
|
|
57
58
|
setApi(newApi) {
|
|
58
|
-
if (this.
|
|
59
|
-
throw new Error('You cannot set
|
|
59
|
+
if (this.vm !== null && this.vm.isPending()) {
|
|
60
|
+
throw new Error('You cannot set a api while a process is running.');
|
|
60
61
|
}
|
|
61
62
|
this.api = newApi;
|
|
62
63
|
return this;
|
|
63
64
|
}
|
|
64
65
|
setHandler(handler) {
|
|
65
|
-
if (this.
|
|
66
|
+
if (this.vm !== null && this.vm.isPending()) {
|
|
66
67
|
throw new Error('You cannot set a handler while a process is running.');
|
|
67
68
|
}
|
|
68
69
|
this.handler = handler;
|
|
69
70
|
return this;
|
|
70
71
|
}
|
|
71
|
-
parse(code) {
|
|
72
|
-
const parser = new greybel_core_1.Parser(code);
|
|
73
|
-
return parser.parseChunk();
|
|
74
|
-
}
|
|
75
|
-
prepare(code) {
|
|
76
|
-
try {
|
|
77
|
-
const chunk = this.parse(code);
|
|
78
|
-
return this.cps.visit(chunk);
|
|
79
|
-
}
|
|
80
|
-
catch (err) {
|
|
81
|
-
if (err instanceof error_1.PrepareError) {
|
|
82
|
-
this.handler.errorHandler.raise(err);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
this.handler.errorHandler.raise(new error_1.PrepareError(err.message, {
|
|
86
|
-
range: err.range,
|
|
87
|
-
target: this.target
|
|
88
|
-
}));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return Promise.resolve(new noop_1.Noop(null));
|
|
92
|
-
}
|
|
93
72
|
inject(code, context) {
|
|
94
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const bytecodeGenerator = new bytecode_generator_1.BytecodeGenerator({
|
|
75
|
+
target: 'injected',
|
|
76
|
+
handler: this.handler
|
|
77
|
+
});
|
|
78
|
+
const result = yield bytecodeGenerator.compile(code);
|
|
79
|
+
const vm = new vm_1.VM({
|
|
80
|
+
target: this.target,
|
|
81
|
+
debugger: this.debugger,
|
|
82
|
+
handler: this.handler,
|
|
83
|
+
environmentVariables: this.environmentVariables,
|
|
84
|
+
contextTypeIntrinsics: this.vm.contextTypeIntrinsics,
|
|
85
|
+
globals: (context !== null && context !== void 0 ? context : this.globalContext).fork({
|
|
86
|
+
code: result.code,
|
|
87
|
+
type: context_1.ContextType.Injected
|
|
88
|
+
}),
|
|
89
|
+
imports: result.imports
|
|
90
|
+
});
|
|
95
91
|
try {
|
|
96
|
-
|
|
97
|
-
const injectionCtx = (context !== null && context !== void 0 ? context : this.globalContext).fork({
|
|
98
|
-
type: context_1.ContextType.Call,
|
|
99
|
-
state: context_1.ContextState.Temporary,
|
|
100
|
-
injected: true
|
|
101
|
-
});
|
|
102
|
-
yield top.handle(injectionCtx);
|
|
92
|
+
yield vm.exec();
|
|
103
93
|
}
|
|
104
94
|
catch (err) {
|
|
105
95
|
if (err instanceof error_1.PrepareError || err instanceof error_1.RuntimeError) {
|
|
106
96
|
this.handler.errorHandler.raise(err);
|
|
107
97
|
}
|
|
108
98
|
else {
|
|
109
|
-
this.handler.errorHandler.raise(new error_1.RuntimeError(err.message,
|
|
99
|
+
this.handler.errorHandler.raise(new error_1.RuntimeError(err.message, vm, err));
|
|
110
100
|
}
|
|
111
101
|
}
|
|
112
102
|
return this;
|
|
@@ -114,52 +104,59 @@ class Interpreter extends events_1.EventEmitter {
|
|
|
114
104
|
}
|
|
115
105
|
injectInLastContext(code) {
|
|
116
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
|
|
118
|
-
|
|
107
|
+
if (this.vm !== null && this.vm.isPending()) {
|
|
108
|
+
const last = this.vm.getFrame();
|
|
119
109
|
return this.inject(code, last);
|
|
120
110
|
}
|
|
121
111
|
throw new Error('Unable to inject into last context.');
|
|
122
112
|
});
|
|
123
113
|
}
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
114
|
+
initVM(result) {
|
|
115
|
+
const apiContext = new context_1.OperationContext({
|
|
116
|
+
isProtected: true,
|
|
117
|
+
code: [],
|
|
118
|
+
});
|
|
119
|
+
const globalContext = apiContext.fork({
|
|
120
|
+
type: context_1.ContextType.Global,
|
|
121
|
+
code: result.code
|
|
122
|
+
});
|
|
123
|
+
const vm = new vm_1.VM({
|
|
124
|
+
target: this.target,
|
|
125
|
+
debugger: this.debugger,
|
|
126
|
+
handler: this.handler,
|
|
127
|
+
environmentVariables: this.environmentVariables,
|
|
128
|
+
contextTypeIntrinsics: {
|
|
131
129
|
string: string_1.CustomString.getIntrinsics().fork(),
|
|
132
130
|
number: number_1.CustomNumber.getIntrinsics().fork(),
|
|
133
131
|
list: list_1.CustomList.getIntrinsics().fork(),
|
|
134
132
|
map: map_1.CustomMap.getIntrinsics().fork(),
|
|
135
133
|
function: function_1.CustomFunction.intrinsics.fork()
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
const
|
|
134
|
+
},
|
|
135
|
+
globals: globalContext,
|
|
136
|
+
imports: result.imports
|
|
137
|
+
});
|
|
138
|
+
const stringIntrinsics = map_1.CustomMap.createWithInitialValue(vm.contextTypeIntrinsics.string);
|
|
139
|
+
const numberIntrinsics = map_1.CustomMap.createWithInitialValue(vm.contextTypeIntrinsics.number);
|
|
140
|
+
const listIntrinsics = map_1.CustomMap.createWithInitialValue(vm.contextTypeIntrinsics.list);
|
|
141
|
+
const mapIntrinsics = map_1.CustomMap.createWithInitialValue(vm.contextTypeIntrinsics.map);
|
|
142
|
+
const funcRefIntrinsics = map_1.CustomMap.createWithInitialValue(vm.contextTypeIntrinsics.function);
|
|
142
143
|
apiContext.scope.set(new string_1.CustomString('string'), stringIntrinsics);
|
|
143
144
|
apiContext.scope.set(new string_1.CustomString('number'), numberIntrinsics);
|
|
144
145
|
apiContext.scope.set(new string_1.CustomString('list'), listIntrinsics);
|
|
145
146
|
apiContext.scope.set(new string_1.CustomString('map'), mapIntrinsics);
|
|
146
147
|
apiContext.scope.set(new string_1.CustomString('funcRef'), funcRefIntrinsics);
|
|
147
148
|
apiContext.scope.extend(this.api);
|
|
148
|
-
const globalContext = apiContext.fork({
|
|
149
|
-
type: context_1.ContextType.Global,
|
|
150
|
-
state: context_1.ContextState.Default
|
|
151
|
-
});
|
|
152
149
|
const newParams = new list_1.CustomList(this.params.map((item) => new string_1.CustomString(item)));
|
|
153
150
|
globalContext.scope.set(exports.IS_GREYBEL_PROPERTY, new boolean_1.CustomBoolean(true));
|
|
154
151
|
globalContext.scope.set(exports.PARAMS_PROPERTY, newParams);
|
|
152
|
+
this.vm = vm;
|
|
155
153
|
this.apiContext = apiContext;
|
|
156
154
|
this.globalContext = globalContext;
|
|
157
155
|
}
|
|
158
|
-
start(
|
|
156
|
+
start() {
|
|
159
157
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
158
|
try {
|
|
161
|
-
this.
|
|
162
|
-
const process = top.handle(this.globalContext);
|
|
159
|
+
const process = this.vm.exec();
|
|
163
160
|
this.emit('start', this);
|
|
164
161
|
yield process;
|
|
165
162
|
}
|
|
@@ -168,51 +165,42 @@ class Interpreter extends events_1.EventEmitter {
|
|
|
168
165
|
this.handler.errorHandler.raise(err);
|
|
169
166
|
}
|
|
170
167
|
else {
|
|
171
|
-
this.handler.errorHandler.raise(new error_1.RuntimeError(err.message, this.
|
|
168
|
+
this.handler.errorHandler.raise(new error_1.RuntimeError(err.message, this.vm, err));
|
|
172
169
|
}
|
|
173
170
|
}
|
|
174
171
|
finally {
|
|
175
|
-
this.apiContext.setPending(false);
|
|
176
172
|
this.emit('exit', this);
|
|
177
173
|
}
|
|
178
174
|
return this;
|
|
179
175
|
});
|
|
180
176
|
}
|
|
181
|
-
run({ customCode
|
|
177
|
+
run({ customCode } = {}) {
|
|
182
178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
-
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
184
|
-
throw new Error('Process already running.');
|
|
185
|
-
}
|
|
186
|
-
this.initScopes(ctxOptions);
|
|
187
179
|
const code = customCode !== null && customCode !== void 0 ? customCode : (yield this.handler.resourceHandler.get(this.target));
|
|
188
|
-
const
|
|
189
|
-
|
|
180
|
+
const bytecodeConverter = new bytecode_generator_1.BytecodeGenerator({
|
|
181
|
+
target: this.target,
|
|
182
|
+
handler: this.handler,
|
|
183
|
+
debugMode: this.debugMode
|
|
184
|
+
});
|
|
185
|
+
const bytecode = yield bytecodeConverter.compile(code);
|
|
186
|
+
this.initVM(bytecode);
|
|
187
|
+
return this.start();
|
|
190
188
|
});
|
|
191
189
|
}
|
|
192
190
|
resume() {
|
|
193
|
-
if (this.
|
|
191
|
+
if (this.vm !== null && this.vm.isPending()) {
|
|
194
192
|
this.debugger.setBreakpoint(false);
|
|
195
193
|
}
|
|
196
194
|
return this;
|
|
197
195
|
}
|
|
198
196
|
pause() {
|
|
199
|
-
if (this.
|
|
197
|
+
if (this.vm !== null && this.vm.isPending()) {
|
|
200
198
|
this.debugger.setBreakpoint(true);
|
|
201
199
|
}
|
|
202
200
|
return this;
|
|
203
201
|
}
|
|
204
202
|
exit() {
|
|
205
|
-
|
|
206
|
-
return this.apiContext.exit();
|
|
207
|
-
}
|
|
208
|
-
catch (err) {
|
|
209
|
-
if (err instanceof error_1.PrepareError || err instanceof error_1.RuntimeError) {
|
|
210
|
-
this.handler.errorHandler.raise(err);
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
this.handler.errorHandler.raise(new error_1.RuntimeError(err.message, this.apiContext.getLastActive(), err));
|
|
214
|
-
}
|
|
215
|
-
}
|
|
203
|
+
this.vm.exit();
|
|
216
204
|
}
|
|
217
205
|
setGlobalVariable(path, value) {
|
|
218
206
|
if (this.globalContext != null) {
|
|
@@ -222,7 +210,7 @@ class Interpreter extends events_1.EventEmitter {
|
|
|
222
210
|
}
|
|
223
211
|
getGlobalVariable(path) {
|
|
224
212
|
if (this.globalContext != null) {
|
|
225
|
-
this.globalContext.get(new string_1.CustomString(path));
|
|
213
|
+
return this.globalContext.get(new string_1.CustomString(path), this.vm.contextTypeIntrinsics);
|
|
226
214
|
}
|
|
227
215
|
return default_1.DefaultType.Void;
|
|
228
216
|
}
|
package/dist/types/function.d.ts
CHANGED
|
@@ -1,34 +1,23 @@
|
|
|
1
|
+
import { FunctionDefinitionInstructionArgument, Instruction } from '../byte-compiler/instruction';
|
|
1
2
|
import { OperationContext } from '../context';
|
|
2
3
|
import { ContextTypeIntrinsics } from '../context/types';
|
|
3
|
-
import { Operation } from '../operations/operation';
|
|
4
4
|
import { ObjectValue } from '../utils/object-value';
|
|
5
|
+
import type { VM } from '../vm';
|
|
5
6
|
import { CustomValue } from './base';
|
|
6
|
-
export interface
|
|
7
|
-
(
|
|
8
|
-
}
|
|
9
|
-
export declare const DEFAULT_FUNCTION_NAME = "anonymous";
|
|
10
|
-
export declare const SELF_NAMESPACE = "self";
|
|
11
|
-
export declare const SUPER_NAMESPACE = "super";
|
|
12
|
-
export declare class Argument {
|
|
13
|
-
readonly name: string;
|
|
14
|
-
readonly defaultValue: Operation;
|
|
15
|
-
static createWithCustomValue(name: string, defaultValue: CustomValue): Argument;
|
|
16
|
-
constructor(name: string, defaultValue?: Operation | CustomValue);
|
|
7
|
+
export interface CustomFunctionCallback {
|
|
8
|
+
(vm: VM, self: CustomValue, args: Map<string, CustomValue>): Promise<NonNullable<CustomValue>>;
|
|
17
9
|
}
|
|
18
10
|
export declare class CustomFunction extends CustomValue {
|
|
19
11
|
static readonly intrinsics: ObjectValue;
|
|
20
|
-
|
|
12
|
+
static createExternal(name: string, callback: CustomFunctionCallback): CustomFunction;
|
|
13
|
+
static createExternalWithSelf(name: string, callback: CustomFunctionCallback): CustomFunction;
|
|
14
|
+
readonly outer?: OperationContext;
|
|
21
15
|
readonly name: string;
|
|
22
|
-
readonly value: Callback;
|
|
23
|
-
readonly argumentDefs: Array<Argument>;
|
|
24
|
-
readonly assignOuter: boolean;
|
|
25
16
|
readonly id: string;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
constructor(scope: OperationContext, name: string, callback: Callback, argumentDefs?: Array<Argument>, assignOuter?: boolean);
|
|
31
|
-
addArgument(name: string, defaultValue?: Operation | CustomValue): CustomFunction;
|
|
17
|
+
readonly arguments: FunctionDefinitionInstructionArgument[];
|
|
18
|
+
readonly value: Instruction[];
|
|
19
|
+
constructor(name: string, value: Instruction[], args?: FunctionDefinitionInstructionArgument[], outer?: OperationContext);
|
|
20
|
+
addArgument(name: string, defaultValue?: CustomValue): CustomFunction;
|
|
32
21
|
fork(): CustomFunction;
|
|
33
22
|
forkAs(name: string): CustomFunction;
|
|
34
23
|
getCustomType(): string;
|
|
@@ -38,8 +27,5 @@ export declare class CustomFunction extends CustomValue {
|
|
|
38
27
|
toString(): string;
|
|
39
28
|
toTruthy(): boolean;
|
|
40
29
|
instanceOf(v: CustomValue, typeIntrinsics: ContextTypeIntrinsics): boolean;
|
|
41
|
-
setNextContext(value: CustomValue): this;
|
|
42
|
-
getNextContext(): CustomValue;
|
|
43
|
-
run(self: CustomValue, args: Array<CustomValue>, callContext: OperationContext): Promise<CustomValue>;
|
|
44
30
|
hash(): number;
|
|
45
31
|
}
|