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
|
@@ -1,269 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Resolve = exports.ResolveResult = exports.ResolveNil = exports.SegmentContainer = exports.OperationSegment = exports.IndexSegment = exports.IdentifierSegment = exports.PathSegment = exports.SliceSegment = void 0;
|
|
13
|
-
const miniscript_core_1 = require("miniscript-core");
|
|
14
|
-
const default_1 = require("../types/default");
|
|
15
|
-
const function_1 = require("../types/function");
|
|
16
|
-
const list_1 = require("../types/list");
|
|
17
|
-
const map_1 = require("../types/map");
|
|
18
|
-
const nil_1 = require("../types/nil");
|
|
19
|
-
const string_1 = require("../types/string");
|
|
20
|
-
const with_intrinsics_1 = require("../types/with-intrinsics");
|
|
21
|
-
const get_super_1 = require("../utils/get-super");
|
|
22
|
-
const path_1 = require("../utils/path");
|
|
23
|
-
const operation_1 = require("./operation");
|
|
24
|
-
class SliceSegment {
|
|
25
|
-
constructor(left, right) {
|
|
26
|
-
this.left = left;
|
|
27
|
-
this.right = right;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.SliceSegment = SliceSegment;
|
|
31
|
-
class PathSegment {
|
|
32
|
-
toPath(_ctx) {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
return Promise.resolve(default_1.DefaultType.Void);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.PathSegment = PathSegment;
|
|
39
|
-
class IdentifierSegment extends PathSegment {
|
|
40
|
-
constructor(value) {
|
|
41
|
-
super();
|
|
42
|
-
this.value = value;
|
|
43
|
-
}
|
|
44
|
-
toPath(_ctx) {
|
|
45
|
-
return Promise.resolve(new string_1.CustomString(this.value));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.IdentifierSegment = IdentifierSegment;
|
|
49
|
-
class IndexSegment extends PathSegment {
|
|
50
|
-
constructor(op) {
|
|
51
|
-
super();
|
|
52
|
-
this.op = op;
|
|
53
|
-
}
|
|
54
|
-
toPath(ctx) {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
return this.op.handle(ctx);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.IndexSegment = IndexSegment;
|
|
61
|
-
class OperationSegment {
|
|
62
|
-
constructor(op) {
|
|
63
|
-
this.op = op;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.OperationSegment = OperationSegment;
|
|
67
|
-
class SegmentContainer {
|
|
68
|
-
constructor() {
|
|
69
|
-
this.path = [];
|
|
70
|
-
}
|
|
71
|
-
push(item) {
|
|
72
|
-
this.path.push(item);
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
count() {
|
|
76
|
-
return this.path.length;
|
|
77
|
-
}
|
|
78
|
-
at(index) {
|
|
79
|
-
return this.path[index];
|
|
80
|
-
}
|
|
81
|
-
isSuper() {
|
|
82
|
-
return (this.path.length === 2 &&
|
|
83
|
-
this.path[0] instanceof IdentifierSegment &&
|
|
84
|
-
this.path[0].value === function_1.SUPER_NAMESPACE);
|
|
85
|
-
}
|
|
86
|
-
getLast() {
|
|
87
|
-
return this.path[this.path.length - 1];
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
exports.SegmentContainer = SegmentContainer;
|
|
91
|
-
class ResolveNil extends nil_1.CustomNil {
|
|
92
|
-
}
|
|
93
|
-
exports.ResolveNil = ResolveNil;
|
|
94
|
-
class ResolveResult {
|
|
95
|
-
constructor(path, handle) {
|
|
96
|
-
this.path = path;
|
|
97
|
-
this.handle = handle;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
exports.ResolveResult = ResolveResult;
|
|
101
|
-
class Resolve extends operation_1.Operation {
|
|
102
|
-
constructor(item, target) {
|
|
103
|
-
super(null, target);
|
|
104
|
-
this.item = item;
|
|
105
|
-
}
|
|
106
|
-
buildProcessor(node, visit) {
|
|
107
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
switch (node.type) {
|
|
109
|
-
case miniscript_core_1.ASTType.MemberExpression: {
|
|
110
|
-
const memberExpr = node;
|
|
111
|
-
if (memberExpr.base != null)
|
|
112
|
-
yield this.buildProcessor(memberExpr.base, visit);
|
|
113
|
-
yield this.buildProcessor(memberExpr.identifier, visit);
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
case miniscript_core_1.ASTType.IndexExpression: {
|
|
117
|
-
const indexExpr = node;
|
|
118
|
-
if (indexExpr.base != null)
|
|
119
|
-
yield this.buildProcessor(indexExpr.base, visit);
|
|
120
|
-
const indexSegment = new IndexSegment(yield visit(indexExpr.index));
|
|
121
|
-
this.path.push(indexSegment);
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
case miniscript_core_1.ASTType.SliceExpression: {
|
|
125
|
-
const sliceExpr = node;
|
|
126
|
-
if (sliceExpr.base != null)
|
|
127
|
-
yield this.buildProcessor(sliceExpr.base, visit);
|
|
128
|
-
const left = yield visit(sliceExpr.left);
|
|
129
|
-
const right = yield visit(sliceExpr.right);
|
|
130
|
-
const sliceSegment = new SliceSegment(left, right);
|
|
131
|
-
this.path.push(sliceSegment);
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
case miniscript_core_1.ASTType.Identifier: {
|
|
135
|
-
const identifier = node;
|
|
136
|
-
const identifierSegment = new IdentifierSegment(identifier.name);
|
|
137
|
-
this.path.push(identifierSegment);
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
default: {
|
|
141
|
-
const opSegment = new OperationSegment(yield visit(node));
|
|
142
|
-
this.path.push(opSegment);
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
build(visit) {
|
|
149
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
this.path = new SegmentContainer();
|
|
151
|
-
yield this.buildProcessor(this.item, visit);
|
|
152
|
-
this.last = this.path.getLast();
|
|
153
|
-
return this;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
getResult(ctx, handle = new ResolveNil()) {
|
|
157
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
let traversedPath = new path_1.Path();
|
|
159
|
-
let index = 0;
|
|
160
|
-
const exitObserver = ctx.processState.createExitObserver();
|
|
161
|
-
const maxIndex = this.path.count();
|
|
162
|
-
const lastIndex = maxIndex - 1;
|
|
163
|
-
for (; index < maxIndex; index++) {
|
|
164
|
-
if (exitObserver.occured()) {
|
|
165
|
-
exitObserver.close();
|
|
166
|
-
return new ResolveResult(null, new ResolveNil());
|
|
167
|
-
}
|
|
168
|
-
const current = this.path.at(index);
|
|
169
|
-
if (current instanceof OperationSegment) {
|
|
170
|
-
const opSegment = current;
|
|
171
|
-
handle = yield opSegment.op.handle(ctx);
|
|
172
|
-
}
|
|
173
|
-
else if (current instanceof PathSegment) {
|
|
174
|
-
traversedPath.add(yield current.toPath(ctx));
|
|
175
|
-
if (index === lastIndex) {
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
const previous = handle;
|
|
179
|
-
if (!(handle instanceof ResolveNil)) {
|
|
180
|
-
if (handle instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
181
|
-
const customValueCtx = handle;
|
|
182
|
-
handle = customValueCtx.get(traversedPath, ctx.contextTypeIntrinsics);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
throw new Error(`Unknown path ${traversedPath.toString()}.`);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
handle = ctx.get(traversedPath);
|
|
190
|
-
}
|
|
191
|
-
if (handle instanceof function_1.CustomFunction) {
|
|
192
|
-
if (index === 1 &&
|
|
193
|
-
traversedPath.toString() === function_1.SUPER_NAMESPACE &&
|
|
194
|
-
ctx.functionState.context &&
|
|
195
|
-
previous instanceof map_1.CustomMap) {
|
|
196
|
-
handle.setNextContext(previous.getIsa());
|
|
197
|
-
handle = yield handle.run(ctx.functionState.context, [], ctx);
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
handle = yield handle.run(previous || default_1.DefaultType.Void, [], ctx);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
traversedPath = new path_1.Path();
|
|
204
|
-
}
|
|
205
|
-
else if (current instanceof SliceSegment) {
|
|
206
|
-
const sliceSegment = current;
|
|
207
|
-
const left = yield sliceSegment.left.handle(ctx);
|
|
208
|
-
const right = yield sliceSegment.right.handle(ctx);
|
|
209
|
-
if (handle instanceof list_1.CustomList || handle instanceof string_1.CustomString) {
|
|
210
|
-
handle = handle.slice(left, right);
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
throw new Error(`Unexpected slice attempt. ${handle.getCustomType()} does not seem to support slicing.`);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
exitObserver.close();
|
|
218
|
-
return new ResolveResult(traversedPath, handle);
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
handle(ctx, result = null, autoCall = true) {
|
|
222
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
-
if (result === null) {
|
|
224
|
-
const exitObserver = ctx.processState.createExitObserver();
|
|
225
|
-
result = yield this.getResult(ctx);
|
|
226
|
-
exitObserver.close();
|
|
227
|
-
if (exitObserver.occured()) {
|
|
228
|
-
return default_1.DefaultType.Void;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
if (!(result.handle instanceof ResolveNil)) {
|
|
232
|
-
if (result.path.count() === 0) {
|
|
233
|
-
if (autoCall && result.handle instanceof function_1.CustomFunction) {
|
|
234
|
-
return result.handle.run(default_1.DefaultType.Void, [], ctx);
|
|
235
|
-
}
|
|
236
|
-
return result.handle;
|
|
237
|
-
}
|
|
238
|
-
if (result.handle instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
239
|
-
const customValueCtx = result.handle;
|
|
240
|
-
const { value: child, origin } = customValueCtx.getWithOrigin(result.path, ctx.contextTypeIntrinsics);
|
|
241
|
-
const next = (0, get_super_1.getSuper)(origin);
|
|
242
|
-
if (child instanceof function_1.CustomFunction) {
|
|
243
|
-
child.setNextContext(next);
|
|
244
|
-
}
|
|
245
|
-
if (this.path.isSuper() && customValueCtx instanceof map_1.CustomMap) {
|
|
246
|
-
if (autoCall && child instanceof function_1.CustomFunction) {
|
|
247
|
-
if (ctx.functionState.context) {
|
|
248
|
-
return child.run(ctx.functionState.context, [], ctx);
|
|
249
|
-
}
|
|
250
|
-
return child.run(customValueCtx, [], ctx);
|
|
251
|
-
}
|
|
252
|
-
return child;
|
|
253
|
-
}
|
|
254
|
-
if (autoCall && child instanceof function_1.CustomFunction) {
|
|
255
|
-
return child.run(customValueCtx, [], ctx);
|
|
256
|
-
}
|
|
257
|
-
return child;
|
|
258
|
-
}
|
|
259
|
-
throw new Error(`Unknown path ${result.path.toString()}.`);
|
|
260
|
-
}
|
|
261
|
-
const handle = ctx.get(result.path);
|
|
262
|
-
if (autoCall && handle instanceof function_1.CustomFunction) {
|
|
263
|
-
return handle.run(default_1.DefaultType.Void, [], ctx);
|
|
264
|
-
}
|
|
265
|
-
return handle;
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
exports.Resolve = Resolve;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ASTReturnStatement } from 'miniscript-core';
|
|
2
|
-
import { OperationContext } from '../context';
|
|
3
|
-
import { CustomValue } from '../types/base';
|
|
4
|
-
import { CPSVisit, Operation } from './operation';
|
|
5
|
-
export declare class Return extends Operation {
|
|
6
|
-
readonly item: ASTReturnStatement;
|
|
7
|
-
arg: Operation;
|
|
8
|
-
constructor(item: ASTReturnStatement, target?: string);
|
|
9
|
-
build(visit: CPSVisit): Promise<Operation>;
|
|
10
|
-
handle(ctx: OperationContext): Promise<CustomValue>;
|
|
11
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Return = void 0;
|
|
13
|
-
const default_1 = require("../types/default");
|
|
14
|
-
const operation_1 = require("./operation");
|
|
15
|
-
const reference_1 = require("./reference");
|
|
16
|
-
class Return extends operation_1.Operation {
|
|
17
|
-
constructor(item, target) {
|
|
18
|
-
super(null, target);
|
|
19
|
-
this.item = item;
|
|
20
|
-
}
|
|
21
|
-
build(visit) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
if (this.item.argument) {
|
|
24
|
-
this.arg = yield visit(this.item.argument);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
this.arg = new reference_1.Reference(default_1.DefaultType.Void);
|
|
28
|
-
}
|
|
29
|
-
return this;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
handle(ctx) {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
// no typesafe equal
|
|
35
|
-
if (ctx.functionState != null) {
|
|
36
|
-
ctx.functionState.value = yield this.arg.handle(ctx);
|
|
37
|
-
ctx.functionState.isReturn = true;
|
|
38
|
-
}
|
|
39
|
-
return default_1.DefaultType.Void;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.Return = Return;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ASTWhileStatement } from 'miniscript-core';
|
|
2
|
-
import { OperationContext } from '../context';
|
|
3
|
-
import { CustomValue } from '../types/base';
|
|
4
|
-
import { Block } from './block';
|
|
5
|
-
import { CPSVisit, Operation, OperationBlock } from './operation';
|
|
6
|
-
export declare class While extends OperationBlock {
|
|
7
|
-
readonly item: ASTWhileStatement;
|
|
8
|
-
block: Block;
|
|
9
|
-
condition: Operation;
|
|
10
|
-
constructor(item: ASTWhileStatement, target?: string);
|
|
11
|
-
build(visit: CPSVisit): Promise<Operation>;
|
|
12
|
-
handle(ctx: OperationContext): Promise<CustomValue>;
|
|
13
|
-
}
|
package/dist/operations/while.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.While = void 0;
|
|
13
|
-
const context_1 = require("../context");
|
|
14
|
-
const default_1 = require("../types/default");
|
|
15
|
-
const set_immediate_1 = require("../utils/set-immediate");
|
|
16
|
-
const block_1 = require("./block");
|
|
17
|
-
const operation_1 = require("./operation");
|
|
18
|
-
class While extends operation_1.OperationBlock {
|
|
19
|
-
constructor(item, target) {
|
|
20
|
-
super(null, target);
|
|
21
|
-
this.item = item;
|
|
22
|
-
}
|
|
23
|
-
build(visit) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
const stack = yield Promise.all(this.item.body.map((child) => visit(child)));
|
|
26
|
-
this.block = new block_1.Block(this.item, stack);
|
|
27
|
-
this.condition = yield visit(this.item.condition);
|
|
28
|
-
return this;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
handle(ctx) {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const whileCtx = ctx.fork({
|
|
34
|
-
type: context_1.ContextType.Loop,
|
|
35
|
-
state: context_1.ContextState.Temporary
|
|
36
|
-
});
|
|
37
|
-
const loopState = new context_1.LoopState();
|
|
38
|
-
const exitObserver = ctx.processState.createExitObserver();
|
|
39
|
-
whileCtx.loopState = loopState;
|
|
40
|
-
return new Promise((resolve, reject) => {
|
|
41
|
-
const iteration = () => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
try {
|
|
43
|
-
const conditionResult = yield whileCtx.step(this.condition);
|
|
44
|
-
if (!conditionResult.toTruthy()) {
|
|
45
|
-
exitObserver.close();
|
|
46
|
-
resolve(default_1.DefaultType.Void);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
loopState.isContinue = false;
|
|
50
|
-
yield this.block.handle(whileCtx);
|
|
51
|
-
if (loopState.isBreak ||
|
|
52
|
-
whileCtx.functionState.isReturn ||
|
|
53
|
-
exitObserver.occured()) {
|
|
54
|
-
exitObserver.close();
|
|
55
|
-
resolve(default_1.DefaultType.Void);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
(0, set_immediate_1.setImmediate)(iteration);
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
exitObserver.close();
|
|
62
|
-
reject(err);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
iteration();
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.While = While;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAssign = void 0;
|
|
4
|
-
const miniscript_core_1 = require("miniscript-core");
|
|
5
|
-
const assign_1 = require("../operations/assign");
|
|
6
|
-
const assign_globals_1 = require("../operations/assign-globals");
|
|
7
|
-
const assign_locals_1 = require("../operations/assign-locals");
|
|
8
|
-
const assign_outer_1 = require("../operations/assign-outer");
|
|
9
|
-
const assign_self_1 = require("../operations/assign-self");
|
|
10
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
11
|
-
const optAssignMap = {
|
|
12
|
-
self: assign_self_1.AssignSelf,
|
|
13
|
-
globals: assign_globals_1.AssignGlobals,
|
|
14
|
-
locals: assign_locals_1.AssignLocals,
|
|
15
|
-
outer: assign_outer_1.AssignOuter
|
|
16
|
-
};
|
|
17
|
-
function createAssign(item, target) {
|
|
18
|
-
if (item.variable instanceof miniscript_core_1.ASTIdentifier &&
|
|
19
|
-
hasOwnProperty.call(optAssignMap, item.variable.name)) {
|
|
20
|
-
const OptAssign = optAssignMap[item.variable.name];
|
|
21
|
-
return new OptAssign(item, target);
|
|
22
|
-
}
|
|
23
|
-
return new assign_1.Assign(item, target);
|
|
24
|
-
}
|
|
25
|
-
exports.createAssign = createAssign;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ASTBase, ASTIdentifier } from 'miniscript-core';
|
|
2
|
-
import { Operation } from '../operations/operation';
|
|
3
|
-
import { Resolve } from '../operations/resolve';
|
|
4
|
-
export declare function createIdentifierResolve(item: ASTIdentifier, target?: string): Operation;
|
|
5
|
-
export declare function createResolve(item: ASTBase, target?: string): Resolve;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createResolve = exports.createIdentifierResolve = void 0;
|
|
4
|
-
const miniscript_core_1 = require("miniscript-core");
|
|
5
|
-
const reference_globals_1 = require("../operations/reference-globals");
|
|
6
|
-
const reference_locals_1 = require("../operations/reference-locals");
|
|
7
|
-
const reference_outer_1 = require("../operations/reference-outer");
|
|
8
|
-
const reference_self_1 = require("../operations/reference-self");
|
|
9
|
-
const resolve_1 = require("../operations/resolve");
|
|
10
|
-
const resolve_globals_1 = require("../operations/resolve-globals");
|
|
11
|
-
const resolve_locals_1 = require("../operations/resolve-locals");
|
|
12
|
-
const resolve_outer_1 = require("../operations/resolve-outer");
|
|
13
|
-
const resolve_self_1 = require("../operations/resolve-self");
|
|
14
|
-
const lookup_path_1 = require("./lookup-path");
|
|
15
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
16
|
-
const optIdentifierResolveMap = {
|
|
17
|
-
self: reference_self_1.ReferenceSelf,
|
|
18
|
-
globals: reference_globals_1.ReferenceGlobals,
|
|
19
|
-
locals: reference_locals_1.ReferenceLocals,
|
|
20
|
-
outer: reference_outer_1.ReferenceOuter
|
|
21
|
-
};
|
|
22
|
-
function createIdentifierResolve(item, target) {
|
|
23
|
-
if (hasOwnProperty.call(optIdentifierResolveMap, item.name)) {
|
|
24
|
-
const OptResolve = optIdentifierResolveMap[item.name];
|
|
25
|
-
return new OptResolve(item, target);
|
|
26
|
-
}
|
|
27
|
-
return new resolve_1.Resolve(item, target);
|
|
28
|
-
}
|
|
29
|
-
exports.createIdentifierResolve = createIdentifierResolve;
|
|
30
|
-
const optResolveMap = {
|
|
31
|
-
self: resolve_self_1.ResolveSelf,
|
|
32
|
-
globals: resolve_globals_1.ResolveGlobals,
|
|
33
|
-
locals: resolve_locals_1.ResolveLocals,
|
|
34
|
-
outer: resolve_outer_1.ResolveOuter
|
|
35
|
-
};
|
|
36
|
-
function createResolve(item, target) {
|
|
37
|
-
if (item instanceof miniscript_core_1.ASTMemberExpression ||
|
|
38
|
-
item instanceof miniscript_core_1.ASTIndexExpression ||
|
|
39
|
-
item instanceof miniscript_core_1.ASTSliceExpression) {
|
|
40
|
-
const path = (0, lookup_path_1.lookupPath)(item);
|
|
41
|
-
if (path.length > 0 &&
|
|
42
|
-
path[0].base instanceof miniscript_core_1.ASTIdentifier &&
|
|
43
|
-
hasOwnProperty.call(optResolveMap, path[0].base.name)) {
|
|
44
|
-
const OptResolve = optResolveMap[path[0].base.name];
|
|
45
|
-
path[0].base = null;
|
|
46
|
-
return new OptResolve(item, target);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return new resolve_1.Resolve(item, target);
|
|
50
|
-
}
|
|
51
|
-
exports.createResolve = createResolve;
|
package/dist/utils/path.d.ts
DELETED
package/dist/utils/path.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Path = void 0;
|
|
4
|
-
class Path {
|
|
5
|
-
constructor(path = []) {
|
|
6
|
-
this.path = [...path];
|
|
7
|
-
}
|
|
8
|
-
next() {
|
|
9
|
-
if (this.path.length === 0) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
return this.path.shift();
|
|
13
|
-
}
|
|
14
|
-
last() {
|
|
15
|
-
if (this.path.length === 0) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return this.path.pop();
|
|
19
|
-
}
|
|
20
|
-
add(value) {
|
|
21
|
-
this.path.push(value);
|
|
22
|
-
}
|
|
23
|
-
toString() {
|
|
24
|
-
return this.path.join('.');
|
|
25
|
-
}
|
|
26
|
-
count() {
|
|
27
|
-
return this.path.length;
|
|
28
|
-
}
|
|
29
|
-
clone() {
|
|
30
|
-
return new Path(this.path);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.Path = Path;
|