greybel-interpreter 4.5.13 → 4.6.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/bytecode-generator/context.d.ts +22 -0
- package/dist/bytecode-generator/context.js +31 -0
- package/dist/bytecode-generator/expression.d.ts +24 -0
- package/dist/bytecode-generator/expression.js +640 -0
- package/dist/{byte-compiler → bytecode-generator}/instruction.d.ts +17 -19
- package/dist/{byte-compiler → bytecode-generator}/instruction.js +13 -12
- package/dist/bytecode-generator/line.d.ts +9 -0
- package/dist/bytecode-generator/line.js +2 -0
- package/dist/bytecode-generator/models.d.ts +42 -0
- package/dist/bytecode-generator/models.js +2 -0
- package/dist/bytecode-generator/module.d.ts +25 -0
- package/dist/bytecode-generator/module.js +72 -0
- package/dist/bytecode-generator/statement.d.ts +31 -0
- package/dist/bytecode-generator/statement.js +825 -0
- package/dist/bytecode-generator/utils.d.ts +5 -0
- package/dist/bytecode-generator/utils.js +30 -0
- package/dist/bytecode-generator.d.ts +3 -57
- package/dist/bytecode-generator.js +31 -1219
- package/dist/context.d.ts +5 -2
- package/dist/context.js +15 -13
- package/dist/index.d.ts +6 -2
- package/dist/index.js +10 -2
- package/dist/types/function.d.ts +1 -1
- package/dist/types/function.js +2 -2
- package/dist/types/map.js +10 -10
- package/dist/types/string.js +1 -1
- package/dist/utils/error.d.ts +1 -1
- package/dist/utils/hash.js +8 -14
- package/dist/utils/object-value.d.ts +1 -1
- package/dist/utils/object-value.js +9 -9
- package/dist/utils/stack.d.ts +1 -0
- package/dist/utils/stack.js +3 -0
- package/dist/utils/uuid.d.ts +2 -1
- package/dist/utils/uuid.js +5 -33
- package/dist/utils/value-hash.d.ts +2 -0
- package/dist/utils/value-hash.js +15 -0
- package/dist/vm/call.js +1 -1
- package/dist/vm.d.ts +1 -1
- package/dist/vm.js +36 -18
- package/package.json +4 -4
- /package/dist/{byte-compiler → bytecode-generator}/keywords.d.ts +0 -0
- /package/dist/{byte-compiler → bytecode-generator}/keywords.js +0 -0
package/dist/context.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { CustomValue } from './types/base';
|
|
|
2
2
|
import { CustomMap } from './types/map';
|
|
3
3
|
import { ObjectValue } from './utils/object-value';
|
|
4
4
|
import { ContextTypeIntrinsics } from './context/types';
|
|
5
|
-
import { Instruction } from './
|
|
5
|
+
import { Instruction } from './bytecode-generator/instruction';
|
|
6
6
|
import { CustomValueWithIntrinsicsResult } from './types/with-intrinsics';
|
|
7
7
|
import { Stack } from './utils/stack';
|
|
8
8
|
export declare enum ContextType {
|
|
@@ -24,6 +24,7 @@ export interface ContextOptions {
|
|
|
24
24
|
self?: CustomValue;
|
|
25
25
|
super?: CustomValue;
|
|
26
26
|
isProtected?: boolean;
|
|
27
|
+
isCalledByCommand?: boolean;
|
|
27
28
|
outer?: OperationContext;
|
|
28
29
|
}
|
|
29
30
|
export interface ContextForkOptions {
|
|
@@ -32,6 +33,7 @@ export interface ContextForkOptions {
|
|
|
32
33
|
self?: CustomValue;
|
|
33
34
|
super?: CustomValue;
|
|
34
35
|
target?: string;
|
|
36
|
+
isCalledByCommand?: boolean;
|
|
35
37
|
outer?: OperationContext;
|
|
36
38
|
}
|
|
37
39
|
export declare class OperationContext {
|
|
@@ -42,6 +44,7 @@ export declare class OperationContext {
|
|
|
42
44
|
readonly type: ContextType;
|
|
43
45
|
readonly scope: Scope;
|
|
44
46
|
isProtected: boolean;
|
|
47
|
+
isCalledByCommand: boolean;
|
|
45
48
|
injected: boolean;
|
|
46
49
|
cp: null | number;
|
|
47
50
|
ip: number;
|
|
@@ -57,7 +60,7 @@ export declare class OperationContext {
|
|
|
57
60
|
private static readonly lookupLocalsType;
|
|
58
61
|
constructor(options: ContextOptions);
|
|
59
62
|
lookupAllOfType(validate: (type: ContextType) => boolean): OperationContext[];
|
|
60
|
-
lookupType(allowedTypes:
|
|
63
|
+
lookupType(allowedTypes: Set<ContextType>): OperationContext;
|
|
61
64
|
lookupAllScopes(): OperationContext[];
|
|
62
65
|
lookupApi(): OperationContext;
|
|
63
66
|
lookupGlobals(): OperationContext;
|
package/dist/context.js
CHANGED
|
@@ -63,7 +63,7 @@ class Scope extends map_1.CustomMap {
|
|
|
63
63
|
exports.Scope = Scope;
|
|
64
64
|
class OperationContext {
|
|
65
65
|
constructor(options) {
|
|
66
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
66
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
67
67
|
this.iterators = new stack_1.Stack();
|
|
68
68
|
this.code = options.code;
|
|
69
69
|
this.cp = null;
|
|
@@ -74,10 +74,11 @@ class OperationContext {
|
|
|
74
74
|
this.self = (_c = options.self) !== null && _c !== void 0 ? _c : null;
|
|
75
75
|
this.super = (_d = options.super) !== null && _d !== void 0 ? _d : null;
|
|
76
76
|
this.isProtected = (_e = options.isProtected) !== null && _e !== void 0 ? _e : false;
|
|
77
|
-
this.
|
|
78
|
-
this.
|
|
79
|
-
this.
|
|
80
|
-
this.
|
|
77
|
+
this.isCalledByCommand = (_f = options.isCalledByCommand) !== null && _f !== void 0 ? _f : false;
|
|
78
|
+
this.api = (_h = (_g = this.previous) === null || _g === void 0 ? void 0 : _g.api) !== null && _h !== void 0 ? _h : this.lookupApi();
|
|
79
|
+
this.globals = (_k = (_j = this.previous) === null || _j === void 0 ? void 0 : _j.globals) !== null && _k !== void 0 ? _k : this.lookupGlobals();
|
|
80
|
+
this.locals = (_l = this.lookupLocals()) !== null && _l !== void 0 ? _l : this;
|
|
81
|
+
this.outer = (_m = options.outer) !== null && _m !== void 0 ? _m : this.lookupOuter();
|
|
81
82
|
}
|
|
82
83
|
lookupAllOfType(validate) {
|
|
83
84
|
const me = this;
|
|
@@ -95,12 +96,12 @@ class OperationContext {
|
|
|
95
96
|
return result;
|
|
96
97
|
}
|
|
97
98
|
lookupType(allowedTypes) {
|
|
98
|
-
if (allowedTypes.
|
|
99
|
+
if (allowedTypes.has(this.type)) {
|
|
99
100
|
return this;
|
|
100
101
|
}
|
|
101
102
|
let current = this.previous;
|
|
102
103
|
while (current !== null) {
|
|
103
|
-
if (allowedTypes.
|
|
104
|
+
if (allowedTypes.has(current.type)) {
|
|
104
105
|
return current;
|
|
105
106
|
}
|
|
106
107
|
current = current.previous;
|
|
@@ -152,16 +153,17 @@ class OperationContext {
|
|
|
152
153
|
code: options.code,
|
|
153
154
|
self: options.self,
|
|
154
155
|
super: options.super,
|
|
155
|
-
outer: options.outer
|
|
156
|
+
outer: options.outer,
|
|
157
|
+
isCalledByCommand: options.isCalledByCommand
|
|
156
158
|
});
|
|
157
159
|
}
|
|
158
160
|
}
|
|
159
|
-
OperationContext.lookupApiType = [ContextType.Api];
|
|
160
|
-
OperationContext.lookupGlobalsType = [
|
|
161
|
+
OperationContext.lookupApiType = new Set([ContextType.Api]);
|
|
162
|
+
OperationContext.lookupGlobalsType = new Set([
|
|
161
163
|
ContextType.Global
|
|
162
|
-
];
|
|
163
|
-
OperationContext.lookupLocalsType = [
|
|
164
|
+
]);
|
|
165
|
+
OperationContext.lookupLocalsType = new Set([
|
|
164
166
|
ContextType.Global,
|
|
165
167
|
ContextType.Function
|
|
166
|
-
];
|
|
168
|
+
]);
|
|
167
169
|
exports.OperationContext = OperationContext;
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export { ObjectValue } from './utils/object-value';
|
|
|
19
19
|
export { deepEqual } from './utils/deep-equal';
|
|
20
20
|
export { deepHash } from './utils/deep-hash';
|
|
21
21
|
export { Debugger, VM, VMOptions } from './vm';
|
|
22
|
-
export { Instruction, OpCode } from './
|
|
23
|
-
export {
|
|
22
|
+
export { Instruction, OpCode } from './bytecode-generator/instruction';
|
|
23
|
+
export { Module as BytecodeGeneratorModule } from './bytecode-generator/module';
|
|
24
|
+
export { Context as BytecodeGeneratorContext } from './bytecode-generator/context';
|
|
25
|
+
export { BytecodeStatementGenerator } from './bytecode-generator/statement';
|
|
26
|
+
export { BytecodeExpressionGenerator } from './bytecode-generator/expression';
|
|
27
|
+
export { BytecodeGenerator, BytecodeCompileResult, BytecodeConverterOptions } from './bytecode-generator';
|
|
24
28
|
export { Stack } from './utils/stack';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Stack = exports.BytecodeGenerator = exports.OpCode = 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;
|
|
3
|
+
exports.Stack = exports.BytecodeGenerator = exports.BytecodeExpressionGenerator = exports.BytecodeStatementGenerator = exports.BytecodeGeneratorContext = exports.BytecodeGeneratorModule = exports.OpCode = 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;
|
|
4
4
|
var context_1 = require("./context");
|
|
5
5
|
Object.defineProperty(exports, "ContextType", { enumerable: true, get: function () { return context_1.ContextType; } });
|
|
6
6
|
Object.defineProperty(exports, "OperationContext", { enumerable: true, get: function () { return context_1.OperationContext; } });
|
|
@@ -54,8 +54,16 @@ Object.defineProperty(exports, "deepHash", { enumerable: true, get: function ()
|
|
|
54
54
|
var vm_1 = require("./vm");
|
|
55
55
|
Object.defineProperty(exports, "Debugger", { enumerable: true, get: function () { return vm_1.Debugger; } });
|
|
56
56
|
Object.defineProperty(exports, "VM", { enumerable: true, get: function () { return vm_1.VM; } });
|
|
57
|
-
var instruction_1 = require("./
|
|
57
|
+
var instruction_1 = require("./bytecode-generator/instruction");
|
|
58
58
|
Object.defineProperty(exports, "OpCode", { enumerable: true, get: function () { return instruction_1.OpCode; } });
|
|
59
|
+
var module_1 = require("./bytecode-generator/module");
|
|
60
|
+
Object.defineProperty(exports, "BytecodeGeneratorModule", { enumerable: true, get: function () { return module_1.Module; } });
|
|
61
|
+
var context_2 = require("./bytecode-generator/context");
|
|
62
|
+
Object.defineProperty(exports, "BytecodeGeneratorContext", { enumerable: true, get: function () { return context_2.Context; } });
|
|
63
|
+
var statement_1 = require("./bytecode-generator/statement");
|
|
64
|
+
Object.defineProperty(exports, "BytecodeStatementGenerator", { enumerable: true, get: function () { return statement_1.BytecodeStatementGenerator; } });
|
|
65
|
+
var expression_1 = require("./bytecode-generator/expression");
|
|
66
|
+
Object.defineProperty(exports, "BytecodeExpressionGenerator", { enumerable: true, get: function () { return expression_1.BytecodeExpressionGenerator; } });
|
|
59
67
|
var bytecode_generator_1 = require("./bytecode-generator");
|
|
60
68
|
Object.defineProperty(exports, "BytecodeGenerator", { enumerable: true, get: function () { return bytecode_generator_1.BytecodeGenerator; } });
|
|
61
69
|
var stack_1 = require("./utils/stack");
|
package/dist/types/function.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FunctionDefinitionInstructionArgument, Instruction } from '../
|
|
1
|
+
import { FunctionDefinitionInstructionArgument, Instruction } from '../bytecode-generator/instruction';
|
|
2
2
|
import { OperationContext } from '../context';
|
|
3
3
|
import { ContextTypeIntrinsics } from '../context/types';
|
|
4
4
|
import { ObjectValue } from '../utils/object-value';
|
package/dist/types/function.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CustomFunction = void 0;
|
|
4
|
-
const instruction_1 = require("../
|
|
5
|
-
const keywords_1 = require("../
|
|
4
|
+
const instruction_1 = require("../bytecode-generator/instruction");
|
|
5
|
+
const keywords_1 = require("../bytecode-generator/keywords");
|
|
6
6
|
const hash_1 = require("../utils/hash");
|
|
7
7
|
const object_value_1 = require("../utils/object-value");
|
|
8
8
|
const uuid_1 = require("../utils/uuid");
|
package/dist/types/map.js
CHANGED
|
@@ -118,12 +118,12 @@ class CustomMap extends with_intrinsics_1.CustomObject {
|
|
|
118
118
|
}
|
|
119
119
|
get(current, typeIntrinsics) {
|
|
120
120
|
var _a;
|
|
121
|
-
const isa = this.getIsa();
|
|
122
121
|
if (current !== null) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
const item = this.value.get(current);
|
|
123
|
+
if (item)
|
|
124
|
+
return item;
|
|
125
|
+
const isa = this.getIsa();
|
|
126
|
+
if (isa === null || isa === void 0 ? void 0 : isa.has(current)) {
|
|
127
127
|
return isa.get(current, typeIntrinsics);
|
|
128
128
|
}
|
|
129
129
|
const intrinsics = (_a = typeIntrinsics.map) !== null && _a !== void 0 ? _a : CustomMap.getIntrinsics();
|
|
@@ -135,16 +135,16 @@ class CustomMap extends with_intrinsics_1.CustomObject {
|
|
|
135
135
|
}
|
|
136
136
|
getWithOrigin(current, typeIntrinsics) {
|
|
137
137
|
var _a;
|
|
138
|
-
const isa = this.getIsa();
|
|
139
138
|
if (current !== null) {
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
const item = this.value.get(current);
|
|
140
|
+
if (item) {
|
|
142
141
|
return {
|
|
143
|
-
value:
|
|
142
|
+
value: item,
|
|
144
143
|
origin: this
|
|
145
144
|
};
|
|
146
145
|
}
|
|
147
|
-
|
|
146
|
+
const isa = this.getIsa();
|
|
147
|
+
if (isa === null || isa === void 0 ? void 0 : isa.has(current)) {
|
|
148
148
|
return isa.getWithOrigin(current, typeIntrinsics);
|
|
149
149
|
}
|
|
150
150
|
const intrinsics = (_a = typeIntrinsics.map) !== null && _a !== void 0 ? _a : CustomMap.getIntrinsics();
|
package/dist/types/string.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Outer = exports.Locals = exports.Globals = exports.Super = exports.Isa = exports.Self = exports.CustomString = exports.CustomStringIterator = void 0;
|
|
4
|
-
const keywords_1 = require("../
|
|
4
|
+
const keywords_1 = require("../bytecode-generator/keywords");
|
|
5
5
|
const hash_1 = require("../utils/hash");
|
|
6
6
|
const object_value_1 = require("../utils/object-value");
|
|
7
7
|
const number_1 = require("./number");
|
package/dist/utils/error.d.ts
CHANGED
package/dist/utils/hash.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getStringHashCode = exports.getHashCode = exports.rotateBits = void 0;
|
|
4
|
-
const lru_cache_1 = require("lru-cache");
|
|
5
4
|
function rotateBits(n) {
|
|
6
5
|
return (n >> 1) | (n << 31);
|
|
7
6
|
}
|
|
@@ -15,24 +14,19 @@ function getHashCode(value, offset = 0) {
|
|
|
15
14
|
}
|
|
16
15
|
exports.getHashCode = getHashCode;
|
|
17
16
|
exports.getStringHashCode = (function () {
|
|
18
|
-
const cache = new
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
let hash = 0;
|
|
24
|
-
for (let i = 0; i < value.length; i++) {
|
|
25
|
-
const chr = value.charCodeAt(i);
|
|
26
|
-
hash = getHashCode(chr, hash);
|
|
27
|
-
}
|
|
28
|
-
return hash;
|
|
17
|
+
const cache = new Map();
|
|
18
|
+
const generateHash = (s) => {
|
|
19
|
+
for (var i = 0, h = 0; i < s.length; i++)
|
|
20
|
+
h = (Math.imul(31, h) + s.charCodeAt(i)) | 0;
|
|
21
|
+
return h;
|
|
29
22
|
};
|
|
30
23
|
return (value) => {
|
|
31
24
|
if (value.length === 0) {
|
|
32
25
|
return 0;
|
|
33
26
|
}
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
const cachedHash = cache.get(value);
|
|
28
|
+
if (cachedHash !== undefined) {
|
|
29
|
+
return cachedHash;
|
|
36
30
|
}
|
|
37
31
|
const hash = generateHash(value);
|
|
38
32
|
cache.set(value, hash);
|
|
@@ -3,7 +3,7 @@ export type ObjectValueKeyPair = [CustomValue, CustomValue];
|
|
|
3
3
|
export declare class ObjectValue {
|
|
4
4
|
private data;
|
|
5
5
|
constructor(entries?: ObjectValue | ObjectValueKeyPair[] | null);
|
|
6
|
-
get(mapKey: CustomValue): CustomValue;
|
|
6
|
+
get(mapKey: CustomValue): CustomValue | null;
|
|
7
7
|
has(mapKey: CustomValue): boolean;
|
|
8
8
|
set(mapKey: CustomValue, mapValue: CustomValue): this;
|
|
9
9
|
delete(mapKey: CustomValue): boolean;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObjectValue = void 0;
|
|
4
|
-
const
|
|
5
|
-
const deep_hash_1 = require("./deep-hash");
|
|
4
|
+
const value_hash_1 = require("./value-hash");
|
|
6
5
|
class ObjectValue {
|
|
7
6
|
constructor(entries) {
|
|
8
7
|
if (entries == null) {
|
|
@@ -22,22 +21,23 @@ class ObjectValue {
|
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
get(mapKey) {
|
|
25
|
-
const hash = (0,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
const hash = (0, value_hash_1.valueHash)(mapKey);
|
|
25
|
+
const keyPair = this.data.get(hash);
|
|
26
|
+
if (!keyPair)
|
|
27
|
+
return null;
|
|
28
|
+
return keyPair[1];
|
|
29
29
|
}
|
|
30
30
|
has(mapKey) {
|
|
31
|
-
const hash = (0,
|
|
31
|
+
const hash = (0, value_hash_1.valueHash)(mapKey);
|
|
32
32
|
return this.data.has(hash);
|
|
33
33
|
}
|
|
34
34
|
set(mapKey, mapValue) {
|
|
35
|
-
const hash = (0,
|
|
35
|
+
const hash = (0, value_hash_1.valueHash)(mapKey);
|
|
36
36
|
this.data.set(hash, [mapKey, mapValue]);
|
|
37
37
|
return this;
|
|
38
38
|
}
|
|
39
39
|
delete(mapKey) {
|
|
40
|
-
const hash = (0,
|
|
40
|
+
const hash = (0, value_hash_1.valueHash)(mapKey);
|
|
41
41
|
return this.data.delete(hash);
|
|
42
42
|
}
|
|
43
43
|
values() {
|
package/dist/utils/stack.d.ts
CHANGED
package/dist/utils/stack.js
CHANGED
package/dist/utils/uuid.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import hyperid from 'hyperid';
|
|
2
|
+
export declare const uuid: hyperid.Instance;
|
package/dist/utils/uuid.js
CHANGED
|
@@ -1,36 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.uuid = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const lut = [];
|
|
7
|
-
for (let i = 0; i < 256; i++)
|
|
8
|
-
lut[i] = (i < 16 ? '0' : '') + i.toString(16);
|
|
9
|
-
return function () {
|
|
10
|
-
const d0 = (Math.random() * 0xffffffff) | 0;
|
|
11
|
-
const d1 = (Math.random() * 0xffffffff) | 0;
|
|
12
|
-
const d2 = (Math.random() * 0xffffffff) | 0;
|
|
13
|
-
const d3 = (Math.random() * 0xffffffff) | 0;
|
|
14
|
-
return (lut[d0 & 0xff] +
|
|
15
|
-
lut[(d0 >> 8) & 0xff] +
|
|
16
|
-
lut[(d0 >> 16) & 0xff] +
|
|
17
|
-
lut[(d0 >> 24) & 0xff] +
|
|
18
|
-
'-' +
|
|
19
|
-
lut[d1 & 0xff] +
|
|
20
|
-
lut[(d1 >> 8) & 0xff] +
|
|
21
|
-
'-' +
|
|
22
|
-
lut[((d1 >> 16) & 0x0f) | 0x40] +
|
|
23
|
-
lut[(d1 >> 24) & 0xff] +
|
|
24
|
-
'-' +
|
|
25
|
-
lut[(d2 & 0x3f) | 0x80] +
|
|
26
|
-
lut[(d2 >> 8) & 0xff] +
|
|
27
|
-
'-' +
|
|
28
|
-
lut[(d2 >> 16) & 0xff] +
|
|
29
|
-
lut[(d2 >> 24) & 0xff] +
|
|
30
|
-
lut[d3 & 0xff] +
|
|
31
|
-
lut[(d3 >> 8) & 0xff] +
|
|
32
|
-
lut[(d3 >> 16) & 0xff] +
|
|
33
|
-
lut[(d3 >> 24) & 0xff]);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
exports.uuid = createUUIDFactory();
|
|
7
|
+
const hyperid_1 = __importDefault(require("hyperid"));
|
|
8
|
+
exports.uuid = (0, hyperid_1.default)();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.valueHash = void 0;
|
|
4
|
+
const deep_hash_1 = require("./deep-hash");
|
|
5
|
+
function valueHash(value) {
|
|
6
|
+
const valueType = typeof value.value;
|
|
7
|
+
switch (valueType) {
|
|
8
|
+
case 'string':
|
|
9
|
+
case 'number':
|
|
10
|
+
case 'boolean':
|
|
11
|
+
return value.hash();
|
|
12
|
+
}
|
|
13
|
+
return (0, deep_hash_1.deepHash)(value);
|
|
14
|
+
}
|
|
15
|
+
exports.valueHash = valueHash;
|
package/dist/vm/call.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.callWithContext = exports.call = void 0;
|
|
4
|
-
const keywords_1 = require("../
|
|
4
|
+
const keywords_1 = require("../bytecode-generator/keywords");
|
|
5
5
|
const map_1 = require("../types/map");
|
|
6
6
|
function call(frame, fn, args) {
|
|
7
7
|
var _a;
|
package/dist/vm.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { OperationContext } from "./context";
|
|
|
3
3
|
import { ContextTypeIntrinsics } from "./context/types";
|
|
4
4
|
import { HandlerContainer } from "./handler-container";
|
|
5
5
|
import { CustomValue } from "./types/base";
|
|
6
|
-
import { Instruction, SourceLocation } from "./
|
|
6
|
+
import { Instruction, SourceLocation } from "./bytecode-generator/instruction";
|
|
7
7
|
import { Stack } from "./utils/stack";
|
|
8
8
|
import EventEmitter from "events";
|
|
9
9
|
export declare class Debugger {
|
package/dist/vm.js
CHANGED
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.VM = exports.VMState = exports.Debugger = void 0;
|
|
16
16
|
const context_1 = require("./context");
|
|
17
|
-
const instruction_1 = require("./
|
|
17
|
+
const instruction_1 = require("./bytecode-generator/instruction");
|
|
18
18
|
const default_1 = require("./types/default");
|
|
19
19
|
const stack_1 = require("./utils/stack");
|
|
20
20
|
const error_1 = require("./utils/error");
|
|
@@ -270,7 +270,8 @@ class VM {
|
|
|
270
270
|
const newFrame = this.getFrame().fork({
|
|
271
271
|
code: fn.value,
|
|
272
272
|
type: context_1.ContextType.Function,
|
|
273
|
-
outer: fn.outer
|
|
273
|
+
outer: fn.outer,
|
|
274
|
+
isCalledByCommand: !!instruction.command
|
|
274
275
|
});
|
|
275
276
|
(0, call_1.call)(newFrame, fn, args);
|
|
276
277
|
this.frames.push(newFrame);
|
|
@@ -293,7 +294,8 @@ class VM {
|
|
|
293
294
|
code: fn.value,
|
|
294
295
|
self: context,
|
|
295
296
|
super: ret.origin instanceof map_1.CustomMap ? ((_b = ret.origin.getIsa()) !== null && _b !== void 0 ? _b : default_1.DefaultType.Void) : null,
|
|
296
|
-
outer: fn.outer
|
|
297
|
+
outer: fn.outer,
|
|
298
|
+
isCalledByCommand: !!instruction.command
|
|
297
299
|
});
|
|
298
300
|
(0, call_1.callWithContext)(newFrame, fn, args);
|
|
299
301
|
this.frames.push(newFrame);
|
|
@@ -316,7 +318,8 @@ class VM {
|
|
|
316
318
|
code: fn.value,
|
|
317
319
|
self: frame.self,
|
|
318
320
|
super: ret.origin instanceof map_1.CustomMap ? ((_c = ret.origin.getIsa()) !== null && _c !== void 0 ? _c : default_1.DefaultType.Void) : null,
|
|
319
|
-
outer: fn.outer
|
|
321
|
+
outer: fn.outer,
|
|
322
|
+
isCalledByCommand: !!instruction.command
|
|
320
323
|
});
|
|
321
324
|
(0, call_1.callWithContext)(newFrame, fn, args);
|
|
322
325
|
this.frames.push(newFrame);
|
|
@@ -331,7 +334,8 @@ class VM {
|
|
|
331
334
|
const key = this.popStack();
|
|
332
335
|
map.unshift([key, value]);
|
|
333
336
|
}
|
|
334
|
-
|
|
337
|
+
if (!instruction.command)
|
|
338
|
+
this.pushStack(new map_1.CustomMap(new object_value_1.ObjectValue(map)));
|
|
335
339
|
break;
|
|
336
340
|
}
|
|
337
341
|
case instruction_1.OpCode.CONSTRUCT_LIST: {
|
|
@@ -341,7 +345,8 @@ class VM {
|
|
|
341
345
|
const value = this.popStack();
|
|
342
346
|
list.unshift(value);
|
|
343
347
|
}
|
|
344
|
-
|
|
348
|
+
if (!instruction.command)
|
|
349
|
+
this.pushStack(new list_1.CustomList(list));
|
|
345
350
|
break;
|
|
346
351
|
}
|
|
347
352
|
case instruction_1.OpCode.GOTO_A_IF_FALSE: {
|
|
@@ -364,6 +369,15 @@ class VM {
|
|
|
364
369
|
frame.ip = gotoAInstruction.goto.ip;
|
|
365
370
|
break;
|
|
366
371
|
}
|
|
372
|
+
case instruction_1.OpCode.GOTO_A_IF_TRUE: {
|
|
373
|
+
const condition = this.popStack();
|
|
374
|
+
if (!condition.toTruthy()) {
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
const gotoAInstruction = instruction;
|
|
378
|
+
frame.ip = gotoAInstruction.goto.ip;
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
367
381
|
case instruction_1.OpCode.GOTO_A_IF_TRUE_AND_PUSH: {
|
|
368
382
|
const condition = this.popStack();
|
|
369
383
|
const value = condition instanceof number_1.CustomNumber ? (0, evaluation_1.absClamp01)(condition.value) : +condition.toTruthy();
|
|
@@ -419,7 +433,8 @@ class VM {
|
|
|
419
433
|
const newFrame = this.getFrame().fork({
|
|
420
434
|
code: ret.value,
|
|
421
435
|
type: context_1.ContextType.Function,
|
|
422
|
-
outer: ret.outer
|
|
436
|
+
outer: ret.outer,
|
|
437
|
+
isCalledByCommand: !!instruction.command
|
|
423
438
|
});
|
|
424
439
|
(0, call_1.call)(newFrame, ret, []);
|
|
425
440
|
this.frames.push(newFrame);
|
|
@@ -442,7 +457,8 @@ class VM {
|
|
|
442
457
|
code: ret.value.value,
|
|
443
458
|
self: context,
|
|
444
459
|
super: ret.origin instanceof map_1.CustomMap ? ((_d = ret.origin.getIsa()) !== null && _d !== void 0 ? _d : default_1.DefaultType.Void) : null,
|
|
445
|
-
outer: ret.value.outer
|
|
460
|
+
outer: ret.value.outer,
|
|
461
|
+
isCalledByCommand: !!instruction.command
|
|
446
462
|
});
|
|
447
463
|
(0, call_1.callWithContext)(newFrame, ret.value, []);
|
|
448
464
|
this.frames.push(newFrame);
|
|
@@ -462,7 +478,8 @@ class VM {
|
|
|
462
478
|
code: ret.value.value,
|
|
463
479
|
self: frame.self,
|
|
464
480
|
super: ret.origin instanceof map_1.CustomMap ? ((_e = ret.origin.getIsa()) !== null && _e !== void 0 ? _e : default_1.DefaultType.Void) : null,
|
|
465
|
-
outer: ret.value.outer
|
|
481
|
+
outer: ret.value.outer,
|
|
482
|
+
isCalledByCommand: !!instruction.command
|
|
466
483
|
});
|
|
467
484
|
(0, call_1.callWithContext)(newFrame, ret.value, []);
|
|
468
485
|
this.frames.push(newFrame);
|
|
@@ -504,23 +521,23 @@ class VM {
|
|
|
504
521
|
break;
|
|
505
522
|
}
|
|
506
523
|
case instruction_1.OpCode.NEW: {
|
|
507
|
-
|
|
508
|
-
if (value instanceof map_1.CustomMap)
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
else {
|
|
524
|
+
let value = this.popStack();
|
|
525
|
+
if (value instanceof map_1.CustomMap)
|
|
526
|
+
value = value.createInstance();
|
|
527
|
+
if (!instruction.command)
|
|
512
528
|
this.pushStack(value);
|
|
513
|
-
}
|
|
514
529
|
break;
|
|
515
530
|
}
|
|
516
531
|
case instruction_1.OpCode.NEGATE: {
|
|
517
532
|
const value = this.popStack();
|
|
518
|
-
|
|
533
|
+
if (!instruction.command)
|
|
534
|
+
this.pushStack(new number_1.CustomNumber(-value.toNumber()));
|
|
519
535
|
break;
|
|
520
536
|
}
|
|
521
537
|
case instruction_1.OpCode.FALSIFY: {
|
|
522
538
|
const value = this.popStack();
|
|
523
|
-
|
|
539
|
+
if (!instruction.command)
|
|
540
|
+
this.pushStack(new boolean_1.CustomBoolean(!value.toTruthy()));
|
|
524
541
|
break;
|
|
525
542
|
}
|
|
526
543
|
case instruction_1.OpCode.ISA: {
|
|
@@ -647,7 +664,8 @@ class VM {
|
|
|
647
664
|
const value = this.popStack();
|
|
648
665
|
frame.iterators.clear();
|
|
649
666
|
this.popFrame();
|
|
650
|
-
|
|
667
|
+
if (!frame.isCalledByCommand)
|
|
668
|
+
this.pushStack(value !== null && value !== void 0 ? value : default_1.DefaultType.Void);
|
|
651
669
|
break;
|
|
652
670
|
}
|
|
653
671
|
case instruction_1.OpCode.GET_ENVAR: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "greybel-interpreter",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "Interpreter",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"build": "npm run clean && tsc -p .",
|
|
10
10
|
"watch": "tsc -w -p .",
|
|
11
11
|
"clean": "rm -rf dist",
|
|
12
|
-
"test": "jest ./tests",
|
|
12
|
+
"test": "jest ./tests --testTimeout 10000",
|
|
13
13
|
"lint": "eslint ./src/**/*.ts",
|
|
14
14
|
"lint:fix": "eslint --fix ./src/**/*.ts"
|
|
15
15
|
},
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"typescript": "^5.0.4"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"
|
|
52
|
-
"
|
|
51
|
+
"greybel-core": "~1.5.13",
|
|
52
|
+
"hyperid": "^3.2.0"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|
|
55
55
|
"miniscript"
|
|
File without changes
|
|
File without changes
|