greybel-interpreter 3.5.0 → 4.0.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/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 +9 -11
- 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 +5 -6
- 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/types/function.js
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.CustomFunction =
|
|
13
|
-
const
|
|
14
|
-
const literal_1 = require("../operations/literal");
|
|
15
|
-
const operation_1 = require("../operations/operation");
|
|
16
|
-
const reference_1 = require("../operations/reference");
|
|
3
|
+
exports.CustomFunction = void 0;
|
|
4
|
+
const instruction_1 = require("../byte-compiler/instruction");
|
|
17
5
|
const hash_1 = require("../utils/hash");
|
|
18
6
|
const object_value_1 = require("../utils/object-value");
|
|
19
7
|
const uuid_1 = require("../utils/uuid");
|
|
@@ -21,56 +9,53 @@ const base_1 = require("./base");
|
|
|
21
9
|
const default_1 = require("./default");
|
|
22
10
|
const nil_1 = require("./nil");
|
|
23
11
|
const string_1 = require("./string");
|
|
24
|
-
exports.DEFAULT_FUNCTION_NAME = 'anonymous';
|
|
25
|
-
exports.SELF_NAMESPACE = 'self';
|
|
26
|
-
exports.SUPER_NAMESPACE = 'super';
|
|
27
|
-
class Argument {
|
|
28
|
-
static createWithCustomValue(name, defaultValue) {
|
|
29
|
-
return new Argument(name, new reference_1.Reference(defaultValue));
|
|
30
|
-
}
|
|
31
|
-
constructor(name, defaultValue = default_1.DefaultType.Void) {
|
|
32
|
-
this.name = name;
|
|
33
|
-
if (defaultValue instanceof base_1.CustomValue) {
|
|
34
|
-
this.defaultValue = new reference_1.Reference(defaultValue);
|
|
35
|
-
}
|
|
36
|
-
else if (defaultValue instanceof operation_1.Operation) {
|
|
37
|
-
this.defaultValue = defaultValue;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
throw new Error('Invalid defaultValue in argument.');
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.Argument = Argument;
|
|
45
12
|
class CustomFunction extends base_1.CustomValue {
|
|
46
|
-
static createExternalAnonymous(callback) {
|
|
47
|
-
return new CustomFunction(null, exports.DEFAULT_FUNCTION_NAME, callback);
|
|
48
|
-
}
|
|
49
13
|
static createExternal(name, callback) {
|
|
50
|
-
|
|
14
|
+
const args = [];
|
|
15
|
+
return new CustomFunction(name, [
|
|
16
|
+
{
|
|
17
|
+
op: instruction_1.OpCode.CALL_INTERNAL,
|
|
18
|
+
source: {
|
|
19
|
+
path: 'internal',
|
|
20
|
+
start: { line: 0, character: 0 },
|
|
21
|
+
end: { line: 0, character: 0 }
|
|
22
|
+
},
|
|
23
|
+
callback,
|
|
24
|
+
arguments: args
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
op: instruction_1.OpCode.RETURN,
|
|
28
|
+
source: {
|
|
29
|
+
path: 'internal',
|
|
30
|
+
start: { line: 0, character: 0 },
|
|
31
|
+
end: { line: 0, character: 0 }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
], args);
|
|
51
35
|
}
|
|
52
36
|
static createExternalWithSelf(name, callback) {
|
|
53
|
-
return
|
|
37
|
+
return this.createExternal(name, callback).addArgument('self');
|
|
54
38
|
}
|
|
55
|
-
constructor(
|
|
39
|
+
constructor(name, value, args = [], outer) {
|
|
56
40
|
super();
|
|
57
41
|
this.id = (0, uuid_1.uuid)();
|
|
58
|
-
this.scope = scope;
|
|
59
42
|
this.name = name;
|
|
60
|
-
this.value =
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
63
|
-
this._nextContext = null;
|
|
43
|
+
this.value = value;
|
|
44
|
+
this.arguments = args;
|
|
45
|
+
this.outer = outer;
|
|
64
46
|
}
|
|
65
47
|
addArgument(name, defaultValue = default_1.DefaultType.Void) {
|
|
66
|
-
this.
|
|
48
|
+
this.arguments.push({
|
|
49
|
+
name: new string_1.CustomString(name),
|
|
50
|
+
defaultValue
|
|
51
|
+
});
|
|
67
52
|
return this;
|
|
68
53
|
}
|
|
69
54
|
fork() {
|
|
70
|
-
return new CustomFunction(this.
|
|
55
|
+
return new CustomFunction(this.name, this.value, this.arguments, this.outer);
|
|
71
56
|
}
|
|
72
57
|
forkAs(name) {
|
|
73
|
-
return new CustomFunction(
|
|
58
|
+
return new CustomFunction(name, this.value, this.arguments, this.outer);
|
|
74
59
|
}
|
|
75
60
|
getCustomType() {
|
|
76
61
|
return 'function';
|
|
@@ -85,23 +70,15 @@ class CustomFunction extends base_1.CustomValue {
|
|
|
85
70
|
return this.toString();
|
|
86
71
|
}
|
|
87
72
|
toString() {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
item.
|
|
92
|
-
const value = item.defaultValue.value;
|
|
93
|
-
if (value instanceof nil_1.CustomNil) {
|
|
94
|
-
return item.name;
|
|
95
|
-
}
|
|
96
|
-
else if (value instanceof string_1.CustomString) {
|
|
97
|
-
return `${item.name}="${value.value}"`;
|
|
98
|
-
}
|
|
99
|
-
return `${item.name}=${value.value}`;
|
|
73
|
+
const args = this.arguments.map((item) => {
|
|
74
|
+
const value = item.defaultValue;
|
|
75
|
+
if (value instanceof nil_1.CustomNil) {
|
|
76
|
+
return item.name;
|
|
100
77
|
}
|
|
101
|
-
else if (
|
|
102
|
-
return `${item.name}=
|
|
78
|
+
else if (value instanceof string_1.CustomString) {
|
|
79
|
+
return `${item.name}="${value.value}"`;
|
|
103
80
|
}
|
|
104
|
-
return item.name
|
|
81
|
+
return `${item.name}=${value.value}`;
|
|
105
82
|
});
|
|
106
83
|
return `FUNCTION(${args.join(', ')})`;
|
|
107
84
|
}
|
|
@@ -112,47 +89,6 @@ class CustomFunction extends base_1.CustomValue {
|
|
|
112
89
|
var _a;
|
|
113
90
|
return v.value === ((_a = typeIntrinsics.function) !== null && _a !== void 0 ? _a : CustomFunction.intrinsics);
|
|
114
91
|
}
|
|
115
|
-
setNextContext(value) {
|
|
116
|
-
this._nextContext = value;
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
getNextContext() {
|
|
120
|
-
return this._nextContext;
|
|
121
|
-
}
|
|
122
|
-
run(self, args, callContext) {
|
|
123
|
-
var _a, _b, _c, _d;
|
|
124
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
if (args.length > this.argumentDefs.length) {
|
|
126
|
-
throw new Error('Too many arguments.');
|
|
127
|
-
}
|
|
128
|
-
const fnCtx = (_a = this.scope) === null || _a === void 0 ? void 0 : _a.fork({
|
|
129
|
-
type: context_1.ContextType.Function,
|
|
130
|
-
state: context_1.ContextState.Default,
|
|
131
|
-
ignoreOuter: !this.assignOuter,
|
|
132
|
-
processState: callContext.processState
|
|
133
|
-
});
|
|
134
|
-
const argMap = new Map();
|
|
135
|
-
const hasSelf = !(self instanceof nil_1.CustomNil);
|
|
136
|
-
let selfWithinArgs = default_1.DefaultType.Void;
|
|
137
|
-
let argIndex = this.argumentDefs.length - 1;
|
|
138
|
-
const selfParam = hasSelf && ((_b = this.argumentDefs[0]) === null || _b === void 0 ? void 0 : _b.name) === exports.SELF_NAMESPACE ? 1 : 0;
|
|
139
|
-
for (; argIndex >= selfParam; argIndex--) {
|
|
140
|
-
const item = this.argumentDefs[argIndex];
|
|
141
|
-
if (item.name === exports.SELF_NAMESPACE) {
|
|
142
|
-
selfWithinArgs = (_c = args[argIndex - selfParam]) !== null && _c !== void 0 ? _c : default_1.DefaultType.Void;
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
argMap.set(item.name, (_d = args[argIndex - selfParam]) !== null && _d !== void 0 ? _d : (yield item.defaultValue.handle(fnCtx)));
|
|
146
|
-
}
|
|
147
|
-
const selfValue = hasSelf ? self : selfWithinArgs;
|
|
148
|
-
if (selfValue) {
|
|
149
|
-
argMap.set(exports.SELF_NAMESPACE, selfValue);
|
|
150
|
-
}
|
|
151
|
-
const result = yield this.value(fnCtx !== null && fnCtx !== void 0 ? fnCtx : callContext, selfValue, argMap);
|
|
152
|
-
this._nextContext = null;
|
|
153
|
-
return result;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
92
|
hash() {
|
|
157
93
|
return (0, hash_1.getStringHashCode)(this.toString());
|
|
158
94
|
}
|
package/dist/types/list.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ContextTypeIntrinsics } from '../context/types';
|
|
2
2
|
import { ObjectValue } from '../utils/object-value';
|
|
3
|
-
import { Path } from '../utils/path';
|
|
4
3
|
import { CustomValue } from './base';
|
|
5
4
|
import { CustomObject, CustomValueWithIntrinsicsResult } from './with-intrinsics';
|
|
6
5
|
export declare class CustomListIterator implements Iterator<CustomValue> {
|
|
@@ -28,9 +27,9 @@ export declare class CustomList extends CustomObject {
|
|
|
28
27
|
extend(list: CustomList | Array<CustomValue>): CustomList;
|
|
29
28
|
[Symbol.iterator](): CustomListIterator;
|
|
30
29
|
getItemIndex(index: number): number;
|
|
31
|
-
has(
|
|
32
|
-
set(
|
|
33
|
-
get(
|
|
34
|
-
getWithOrigin(
|
|
30
|
+
has(current: CustomValue): boolean;
|
|
31
|
+
set(current: CustomValue, newValue: CustomValue): void;
|
|
32
|
+
get(current: CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValue;
|
|
33
|
+
getWithOrigin(current: CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValueWithIntrinsicsResult;
|
|
35
34
|
hash(recursionDepth?: number): number;
|
|
36
35
|
}
|
package/dist/types/list.js
CHANGED
|
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CustomList = exports.CustomListIterator = void 0;
|
|
4
4
|
const hash_1 = require("../utils/hash");
|
|
5
5
|
const object_value_1 = require("../utils/object-value");
|
|
6
|
-
const path_1 = require("../utils/path");
|
|
7
6
|
const uuid_1 = require("../utils/uuid");
|
|
8
|
-
const base_1 = require("./base");
|
|
9
7
|
const number_1 = require("./number");
|
|
10
8
|
const with_intrinsics_1 = require("./with-intrinsics");
|
|
11
9
|
class CustomListIterator {
|
|
@@ -89,46 +87,19 @@ class CustomList extends with_intrinsics_1.CustomObject {
|
|
|
89
87
|
getItemIndex(index) {
|
|
90
88
|
return CustomList.getItemIndex(this, index);
|
|
91
89
|
}
|
|
92
|
-
has(
|
|
93
|
-
if (path instanceof base_1.CustomValue) {
|
|
94
|
-
return this.has(new path_1.Path([path]));
|
|
95
|
-
}
|
|
96
|
-
const traversalPath = path.clone();
|
|
97
|
-
const current = traversalPath.next();
|
|
90
|
+
has(current) {
|
|
98
91
|
if (current instanceof number_1.CustomNumber) {
|
|
99
92
|
const currentIndex = this.getItemIndex(current.toInt());
|
|
100
93
|
const sub = this.value[currentIndex];
|
|
101
94
|
if (sub) {
|
|
102
|
-
|
|
103
|
-
sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
104
|
-
return sub.has(traversalPath);
|
|
105
|
-
}
|
|
106
|
-
return traversalPath.count() === 0;
|
|
95
|
+
return true;
|
|
107
96
|
}
|
|
108
97
|
}
|
|
109
98
|
return false;
|
|
110
99
|
}
|
|
111
|
-
set(
|
|
112
|
-
if (path instanceof base_1.CustomValue) {
|
|
113
|
-
return this.set(new path_1.Path([path]), newValue);
|
|
114
|
-
}
|
|
115
|
-
const traversalPath = path.clone();
|
|
116
|
-
const last = traversalPath.last();
|
|
117
|
-
const current = traversalPath.next();
|
|
100
|
+
set(current, newValue) {
|
|
118
101
|
if (current instanceof number_1.CustomNumber) {
|
|
119
|
-
const
|
|
120
|
-
const sub = this.value[currentIndex];
|
|
121
|
-
if (sub) {
|
|
122
|
-
if (traversalPath.count() > 0 &&
|
|
123
|
-
sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
124
|
-
sub.set(traversalPath, newValue);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
throw new Error(`Cannot set path ${path.toString()}.`);
|
|
129
|
-
}
|
|
130
|
-
if (last instanceof number_1.CustomNumber) {
|
|
131
|
-
const lastIndex = this.getItemIndex(last.toInt());
|
|
102
|
+
const lastIndex = this.getItemIndex(current.toInt());
|
|
132
103
|
if (lastIndex >= 0 && lastIndex < this.value.length) {
|
|
133
104
|
this.value[lastIndex] = newValue;
|
|
134
105
|
return;
|
|
@@ -137,37 +108,24 @@ class CustomList extends with_intrinsics_1.CustomObject {
|
|
|
137
108
|
}
|
|
138
109
|
throw new Error(`Index is not a number.`);
|
|
139
110
|
}
|
|
140
|
-
get(
|
|
111
|
+
get(current, typeIntrinsics) {
|
|
141
112
|
var _a;
|
|
142
|
-
if (path instanceof base_1.CustomValue) {
|
|
143
|
-
return this.get(new path_1.Path([path]), typeIntrinsics);
|
|
144
|
-
}
|
|
145
|
-
const traversalPath = path.clone();
|
|
146
|
-
const current = traversalPath.next();
|
|
147
113
|
if (current instanceof number_1.CustomNumber) {
|
|
148
114
|
const currentIndex = this.getItemIndex(current.toInt());
|
|
149
115
|
if (currentIndex >= 0 && currentIndex < this.value.length) {
|
|
150
|
-
|
|
151
|
-
if (traversalPath.count() > 0) {
|
|
152
|
-
if (sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
153
|
-
return sub.get(traversalPath, typeIntrinsics);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
else if (traversalPath.count() === 0) {
|
|
157
|
-
return sub;
|
|
158
|
-
}
|
|
116
|
+
return this.value[currentIndex];
|
|
159
117
|
}
|
|
160
118
|
throw new Error(`Index error (list index ${currentIndex} out of range).`);
|
|
161
119
|
}
|
|
162
120
|
const intrinsics = (_a = typeIntrinsics.list) !== null && _a !== void 0 ? _a : CustomList.getIntrinsics();
|
|
163
|
-
if (
|
|
121
|
+
if (intrinsics.has(current)) {
|
|
164
122
|
return intrinsics.get(current);
|
|
165
123
|
}
|
|
166
|
-
throw new Error(`Unknown path in list ${
|
|
124
|
+
throw new Error(`Unknown path in list ${current.toString()}.`);
|
|
167
125
|
}
|
|
168
|
-
getWithOrigin(
|
|
126
|
+
getWithOrigin(current, typeIntrinsics) {
|
|
169
127
|
return {
|
|
170
|
-
value: this.get(
|
|
128
|
+
value: this.get(current, typeIntrinsics),
|
|
171
129
|
origin: null
|
|
172
130
|
};
|
|
173
131
|
}
|
package/dist/types/map.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ContextTypeIntrinsics } from '../context/types';
|
|
2
2
|
import { ObjectValue } from '../utils/object-value';
|
|
3
|
-
import { Path } from '../utils/path';
|
|
4
3
|
import { CustomValue } from './base';
|
|
5
4
|
import { CustomString } from './string';
|
|
6
5
|
import { CustomObject, CustomValueWithIntrinsicsResult } from './with-intrinsics';
|
|
@@ -17,7 +16,7 @@ export declare class CustomMap extends CustomObject {
|
|
|
17
16
|
static readonly intrinsics: ObjectValue;
|
|
18
17
|
readonly id: string;
|
|
19
18
|
value: ObjectValue;
|
|
20
|
-
|
|
19
|
+
isInstance: boolean;
|
|
21
20
|
static createWithInitialValue(value: ObjectValue): CustomMap;
|
|
22
21
|
constructor(value?: ObjectValue);
|
|
23
22
|
getCustomType(): string;
|
|
@@ -31,10 +30,10 @@ export declare class CustomMap extends CustomObject {
|
|
|
31
30
|
instanceOf(v: CustomValue, typeIntrinsics: ContextTypeIntrinsics): boolean;
|
|
32
31
|
[Symbol.iterator](): CustomMapIterator;
|
|
33
32
|
extend(map: CustomMap | ObjectValue): CustomMap;
|
|
34
|
-
has(
|
|
35
|
-
set(
|
|
36
|
-
get(
|
|
37
|
-
getWithOrigin(
|
|
33
|
+
has(current: CustomValue): boolean;
|
|
34
|
+
set(current: CustomValue, newValue: CustomValue): void;
|
|
35
|
+
get(current: CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValue;
|
|
36
|
+
getWithOrigin(current: CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValueWithIntrinsicsResult;
|
|
38
37
|
createInstance(): CustomMap;
|
|
39
38
|
getIsa(): CustomMap | null;
|
|
40
39
|
hash(recursionDepth?: number): number;
|
package/dist/types/map.js
CHANGED
|
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CustomMap = exports.CustomMapIterator = exports.CUSTOM_MAP_MAX_DEPTH_VALUE = exports.CUSTOM_MAP_MAX_DEPTH = exports.ISA_PROPERTY = void 0;
|
|
4
4
|
const hash_1 = require("../utils/hash");
|
|
5
5
|
const object_value_1 = require("../utils/object-value");
|
|
6
|
-
const path_1 = require("../utils/path");
|
|
7
6
|
const uuid_1 = require("../utils/uuid");
|
|
8
|
-
const base_1 = require("./base");
|
|
9
7
|
const nil_1 = require("./nil");
|
|
10
8
|
const string_1 = require("./string");
|
|
11
9
|
const with_intrinsics_1 = require("./with-intrinsics");
|
|
@@ -106,116 +104,59 @@ class CustomMap extends with_intrinsics_1.CustomObject {
|
|
|
106
104
|
this.value.extend(map);
|
|
107
105
|
return this;
|
|
108
106
|
}
|
|
109
|
-
has(
|
|
110
|
-
if (path instanceof base_1.CustomValue) {
|
|
111
|
-
return this.has(new path_1.Path([path]));
|
|
112
|
-
}
|
|
113
|
-
const traversalPath = path.clone();
|
|
114
|
-
const current = traversalPath.next();
|
|
107
|
+
has(current) {
|
|
115
108
|
if (current !== null) {
|
|
116
109
|
if (this.value.has(current)) {
|
|
117
|
-
|
|
118
|
-
if (traversalPath.count() > 0 &&
|
|
119
|
-
sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
120
|
-
return sub.has(traversalPath);
|
|
121
|
-
}
|
|
122
|
-
return traversalPath.count() === 0;
|
|
110
|
+
return true;
|
|
123
111
|
}
|
|
124
112
|
const isa = this.getIsa();
|
|
125
113
|
return isa ? isa.has(current) : false;
|
|
126
114
|
}
|
|
127
115
|
return false;
|
|
128
116
|
}
|
|
129
|
-
set(
|
|
130
|
-
|
|
131
|
-
return this.set(new path_1.Path([path]), newValue);
|
|
132
|
-
}
|
|
133
|
-
const traversalPath = path.clone();
|
|
134
|
-
const last = traversalPath.last();
|
|
135
|
-
const current = traversalPath.next();
|
|
136
|
-
if (current !== null) {
|
|
137
|
-
if (this.value.has(current)) {
|
|
138
|
-
const sub = this.value.get(current);
|
|
139
|
-
if (sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
140
|
-
sub.set(traversalPath, newValue);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
throw new Error(`Cannot set path ${path.toString()}.`);
|
|
145
|
-
}
|
|
146
|
-
this.value.set(last, newValue);
|
|
117
|
+
set(current, newValue) {
|
|
118
|
+
this.value.set(current, newValue);
|
|
147
119
|
}
|
|
148
|
-
get(
|
|
120
|
+
get(current, typeIntrinsics) {
|
|
149
121
|
var _a;
|
|
150
|
-
if (path instanceof base_1.CustomValue) {
|
|
151
|
-
return this.get(new path_1.Path([path]), typeIntrinsics);
|
|
152
|
-
}
|
|
153
|
-
const traversalPath = path.clone();
|
|
154
|
-
const current = traversalPath.next();
|
|
155
122
|
const isa = this.getIsa();
|
|
156
123
|
if (current !== null) {
|
|
157
124
|
if (this.value.has(current)) {
|
|
158
|
-
|
|
159
|
-
if (traversalPath.count() > 0) {
|
|
160
|
-
if (sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
161
|
-
return sub.get(traversalPath, typeIntrinsics);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
else if (traversalPath.count() === 0) {
|
|
165
|
-
return sub;
|
|
166
|
-
}
|
|
125
|
+
return this.value.get(current);
|
|
167
126
|
}
|
|
168
127
|
else if (isa === null || isa === void 0 ? void 0 : isa.has(current)) {
|
|
169
128
|
return isa.get(current, typeIntrinsics);
|
|
170
129
|
}
|
|
171
130
|
const intrinsics = (_a = typeIntrinsics.map) !== null && _a !== void 0 ? _a : CustomMap.getIntrinsics();
|
|
172
|
-
if (
|
|
131
|
+
if (intrinsics.has(current)) {
|
|
173
132
|
return intrinsics.get(current);
|
|
174
133
|
}
|
|
175
134
|
}
|
|
176
|
-
throw new Error(`Unknown path in map ${
|
|
135
|
+
throw new Error(`Unknown path in map ${current.toString()}.`);
|
|
177
136
|
}
|
|
178
|
-
getWithOrigin(
|
|
137
|
+
getWithOrigin(current, typeIntrinsics) {
|
|
179
138
|
var _a;
|
|
180
|
-
if (path instanceof base_1.CustomValue) {
|
|
181
|
-
return this.getWithOrigin(new path_1.Path([path]), typeIntrinsics);
|
|
182
|
-
}
|
|
183
|
-
const traversalPath = path.clone();
|
|
184
|
-
const current = traversalPath.next();
|
|
185
139
|
const isa = this.getIsa();
|
|
186
140
|
if (current !== null) {
|
|
187
141
|
if (this.value.has(current)) {
|
|
188
142
|
const sub = this.value.get(current);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
194
|
-
return {
|
|
195
|
-
value: sub.get(traversalPath, typeIntrinsics),
|
|
196
|
-
origin: this
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
else if (traversalPath.count() === 0) {
|
|
201
|
-
return {
|
|
202
|
-
value: sub,
|
|
203
|
-
origin: this
|
|
204
|
-
};
|
|
205
|
-
}
|
|
143
|
+
return {
|
|
144
|
+
value: sub,
|
|
145
|
+
origin: this
|
|
146
|
+
};
|
|
206
147
|
}
|
|
207
148
|
else if (isa === null || isa === void 0 ? void 0 : isa.has(current)) {
|
|
208
149
|
return isa.getWithOrigin(current, typeIntrinsics);
|
|
209
150
|
}
|
|
210
151
|
const intrinsics = (_a = typeIntrinsics.map) !== null && _a !== void 0 ? _a : CustomMap.getIntrinsics();
|
|
211
|
-
if (
|
|
152
|
+
if (intrinsics.has(current)) {
|
|
212
153
|
return {
|
|
213
154
|
value: intrinsics.get(current),
|
|
214
155
|
origin: null
|
|
215
156
|
};
|
|
216
157
|
}
|
|
217
158
|
}
|
|
218
|
-
throw new Error(`Unknown path in map ${
|
|
159
|
+
throw new Error(`Unknown path in map ${current.toString()}.`);
|
|
219
160
|
}
|
|
220
161
|
createInstance() {
|
|
221
162
|
const newInstance = new CustomMap(new object_value_1.ObjectValue());
|
package/dist/types/number.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ContextTypeIntrinsics } from '../context/types';
|
|
2
2
|
import { ObjectValue } from '../utils/object-value';
|
|
3
|
-
import { Path } from '../utils/path';
|
|
4
3
|
import { CustomValue } from './base';
|
|
5
4
|
import { CustomValueWithIntrinsics, CustomValueWithIntrinsicsResult } from './with-intrinsics';
|
|
6
5
|
export declare class CustomNumberIterator implements Iterator<CustomValue> {
|
|
@@ -21,10 +20,10 @@ export declare class CustomNumber extends CustomValueWithIntrinsics {
|
|
|
21
20
|
toTruthy(): boolean;
|
|
22
21
|
instanceOf(v: CustomValue, typeIntrinsics: ContextTypeIntrinsics): boolean;
|
|
23
22
|
[Symbol.iterator](): CustomNumberIterator;
|
|
24
|
-
has(_path:
|
|
25
|
-
set(_path:
|
|
26
|
-
get(
|
|
27
|
-
getWithOrigin(
|
|
23
|
+
has(_path: CustomValue): boolean;
|
|
24
|
+
set(_path: CustomValue, _newValue: CustomValue): void;
|
|
25
|
+
get(current: CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValue;
|
|
26
|
+
getWithOrigin(current: CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValueWithIntrinsicsResult;
|
|
28
27
|
hash(): number;
|
|
29
28
|
}
|
|
30
29
|
export declare const NegativeOne: CustomNumber;
|
package/dist/types/number.js
CHANGED
|
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Zero = exports.PositiveOne = exports.NegativeOne = exports.CustomNumber = exports.CustomNumberIterator = void 0;
|
|
4
4
|
const hash_1 = require("../utils/hash");
|
|
5
5
|
const object_value_1 = require("../utils/object-value");
|
|
6
|
-
const path_1 = require("../utils/path");
|
|
7
|
-
const base_1 = require("./base");
|
|
8
6
|
const with_intrinsics_1 = require("./with-intrinsics");
|
|
9
7
|
class CustomNumberIterator {
|
|
10
8
|
constructor() {
|
|
@@ -58,22 +56,17 @@ class CustomNumber extends with_intrinsics_1.CustomValueWithIntrinsics {
|
|
|
58
56
|
set(_path, _newValue) {
|
|
59
57
|
throw new Error('Mutable operations are not allowed on a number.');
|
|
60
58
|
}
|
|
61
|
-
get(
|
|
59
|
+
get(current, typeIntrinsics) {
|
|
62
60
|
var _a;
|
|
63
|
-
if (path instanceof base_1.CustomValue) {
|
|
64
|
-
return this.get(new path_1.Path([path]), typeIntrinsics);
|
|
65
|
-
}
|
|
66
|
-
const traversalPath = path.clone();
|
|
67
|
-
const current = traversalPath.next();
|
|
68
61
|
const intrinsics = (_a = typeIntrinsics.number) !== null && _a !== void 0 ? _a : CustomNumber.getIntrinsics();
|
|
69
|
-
if (
|
|
62
|
+
if (intrinsics.has(current)) {
|
|
70
63
|
return intrinsics.get(current);
|
|
71
64
|
}
|
|
72
|
-
throw new Error(`Unknown path in number ${
|
|
65
|
+
throw new Error(`Unknown path in number ${current.toString()}.`);
|
|
73
66
|
}
|
|
74
|
-
getWithOrigin(
|
|
67
|
+
getWithOrigin(current, typeIntrinsics) {
|
|
75
68
|
return {
|
|
76
|
-
value: this.get(
|
|
69
|
+
value: this.get(current, typeIntrinsics),
|
|
77
70
|
origin: null
|
|
78
71
|
};
|
|
79
72
|
}
|
package/dist/types/string.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ContextTypeIntrinsics } from '../context/types';
|
|
2
2
|
import { ObjectValue } from '../utils/object-value';
|
|
3
|
-
import { Path } from '../utils/path';
|
|
4
3
|
import { CustomValue } from './base';
|
|
5
4
|
import { CustomValueWithIntrinsics, CustomValueWithIntrinsicsResult } from './with-intrinsics';
|
|
6
5
|
export declare class CustomStringIterator implements Iterator<CustomValue> {
|
|
@@ -29,9 +28,9 @@ export declare class CustomString extends CustomValueWithIntrinsics {
|
|
|
29
28
|
slice(a: CustomValue, b: CustomValue): CustomString;
|
|
30
29
|
[Symbol.iterator](): CustomStringIterator;
|
|
31
30
|
getCharIndex(index: number): number;
|
|
32
|
-
has(
|
|
33
|
-
set(_path:
|
|
34
|
-
get(
|
|
35
|
-
getWithOrigin(
|
|
31
|
+
has(current: CustomValue): boolean;
|
|
32
|
+
set(_path: CustomValue, _newValue: CustomValue): void;
|
|
33
|
+
get(current: CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValue;
|
|
34
|
+
getWithOrigin(current: CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValueWithIntrinsicsResult;
|
|
36
35
|
hash(): number;
|
|
37
36
|
}
|
package/dist/types/string.js
CHANGED
|
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CustomString = exports.CustomStringIterator = void 0;
|
|
4
4
|
const hash_1 = require("../utils/hash");
|
|
5
5
|
const object_value_1 = require("../utils/object-value");
|
|
6
|
-
const path_1 = require("../utils/path");
|
|
7
|
-
const base_1 = require("./base");
|
|
8
6
|
const number_1 = require("./number");
|
|
9
7
|
const with_intrinsics_1 = require("./with-intrinsics");
|
|
10
8
|
class CustomStringIterator {
|
|
@@ -86,12 +84,7 @@ class CustomString extends with_intrinsics_1.CustomValueWithIntrinsics {
|
|
|
86
84
|
getCharIndex(index) {
|
|
87
85
|
return CustomString.getCharIndex(this, index);
|
|
88
86
|
}
|
|
89
|
-
has(
|
|
90
|
-
if (path instanceof base_1.CustomValue) {
|
|
91
|
-
return this.has(new path_1.Path([path]));
|
|
92
|
-
}
|
|
93
|
-
const traversalPath = path.clone();
|
|
94
|
-
const current = traversalPath.next();
|
|
87
|
+
has(current) {
|
|
95
88
|
if (current instanceof number_1.CustomNumber) {
|
|
96
89
|
const index = current.toInt();
|
|
97
90
|
return !!this.value[index];
|
|
@@ -101,13 +94,8 @@ class CustomString extends with_intrinsics_1.CustomValueWithIntrinsics {
|
|
|
101
94
|
set(_path, _newValue) {
|
|
102
95
|
throw new Error('Mutable operations are not allowed on a string.');
|
|
103
96
|
}
|
|
104
|
-
get(
|
|
97
|
+
get(current, typeIntrinsics) {
|
|
105
98
|
var _a;
|
|
106
|
-
if (path instanceof base_1.CustomValue) {
|
|
107
|
-
return this.get(new path_1.Path([path]), typeIntrinsics);
|
|
108
|
-
}
|
|
109
|
-
const traversalPath = path.clone();
|
|
110
|
-
const current = traversalPath.next();
|
|
111
99
|
if (current instanceof number_1.CustomNumber) {
|
|
112
100
|
const currentIndex = this.getCharIndex(current.toInt());
|
|
113
101
|
const segment = this.value[currentIndex];
|
|
@@ -117,14 +105,14 @@ class CustomString extends with_intrinsics_1.CustomValueWithIntrinsics {
|
|
|
117
105
|
throw new Error(`Index error (string index ${currentIndex} out of range).`);
|
|
118
106
|
}
|
|
119
107
|
const intrinsics = (_a = typeIntrinsics.string) !== null && _a !== void 0 ? _a : CustomString.getIntrinsics();
|
|
120
|
-
if (
|
|
108
|
+
if (intrinsics.has(current)) {
|
|
121
109
|
return intrinsics.get(current);
|
|
122
110
|
}
|
|
123
|
-
throw new Error(`Unknown path in string ${
|
|
111
|
+
throw new Error(`Unknown path in string ${current.toString()}.`);
|
|
124
112
|
}
|
|
125
|
-
getWithOrigin(
|
|
113
|
+
getWithOrigin(current, typeIntrinsics) {
|
|
126
114
|
return {
|
|
127
|
-
value: this.get(
|
|
115
|
+
value: this.get(current, typeIntrinsics),
|
|
128
116
|
origin: null
|
|
129
117
|
};
|
|
130
118
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ContextTypeIntrinsics } from '../context/types';
|
|
2
2
|
import { ObjectValue } from '../utils/object-value';
|
|
3
|
-
import { Path } from '../utils/path';
|
|
4
3
|
import { CustomValue } from './base';
|
|
5
4
|
import { CustomFunction } from './function';
|
|
6
5
|
export type CustomValueWithIntrinsicsResult = {
|
|
@@ -8,10 +7,10 @@ export type CustomValueWithIntrinsicsResult = {
|
|
|
8
7
|
origin: CustomValueWithIntrinsics;
|
|
9
8
|
};
|
|
10
9
|
export declare abstract class CustomValueWithIntrinsics extends CustomValue {
|
|
11
|
-
abstract has(path:
|
|
12
|
-
abstract set(path:
|
|
13
|
-
abstract get(path:
|
|
14
|
-
abstract getWithOrigin(path:
|
|
10
|
+
abstract has(path: CustomValue): boolean;
|
|
11
|
+
abstract set(path: CustomValue, value: CustomValue): void;
|
|
12
|
+
abstract get(path: CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValue;
|
|
13
|
+
abstract getWithOrigin(path: CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValueWithIntrinsicsResult;
|
|
15
14
|
abstract [Symbol.iterator](): Iterator<CustomValue> & {
|
|
16
15
|
index: number;
|
|
17
16
|
};
|