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.
Files changed (116) hide show
  1. package/dist/byte-compiler/instruction.d.ts +129 -0
  2. package/dist/byte-compiler/instruction.js +60 -0
  3. package/dist/bytecode-generator.d.ts +61 -0
  4. package/dist/bytecode-generator.js +1165 -0
  5. package/dist/context.d.ts +20 -88
  6. package/dist/context.js +44 -273
  7. package/dist/index.d.ts +5 -29
  8. package/dist/index.js +14 -87
  9. package/dist/interpreter.d.ts +9 -11
  10. package/dist/interpreter.js +75 -87
  11. package/dist/types/function.d.ts +11 -25
  12. package/dist/types/function.js +41 -105
  13. package/dist/types/list.d.ts +4 -5
  14. package/dist/types/list.js +10 -52
  15. package/dist/types/map.d.ts +5 -6
  16. package/dist/types/map.js +15 -74
  17. package/dist/types/number.d.ts +4 -5
  18. package/dist/types/number.js +5 -12
  19. package/dist/types/string.d.ts +4 -5
  20. package/dist/types/string.js +6 -18
  21. package/dist/types/with-intrinsics.d.ts +4 -5
  22. package/dist/utils/error.d.ts +5 -5
  23. package/dist/utils/error.js +4 -5
  24. package/dist/utils/stack.d.ts +10 -0
  25. package/dist/utils/stack.js +30 -0
  26. package/dist/vm/evaluation.d.ts +26 -0
  27. package/dist/vm/evaluation.js +341 -0
  28. package/dist/vm.d.ts +66 -0
  29. package/dist/vm.js +662 -0
  30. package/package.json +1 -1
  31. package/dist/cps.d.ts +0 -16
  32. package/dist/cps.js +0 -202
  33. package/dist/operations/assign-globals.d.ts +0 -11
  34. package/dist/operations/assign-globals.js +0 -31
  35. package/dist/operations/assign-locals.d.ts +0 -11
  36. package/dist/operations/assign-locals.js +0 -31
  37. package/dist/operations/assign-outer.d.ts +0 -11
  38. package/dist/operations/assign-outer.js +0 -31
  39. package/dist/operations/assign-self.d.ts +0 -11
  40. package/dist/operations/assign-self.js +0 -41
  41. package/dist/operations/assign.d.ts +0 -13
  42. package/dist/operations/assign.js +0 -60
  43. package/dist/operations/block.d.ts +0 -13
  44. package/dist/operations/block.js +0 -48
  45. package/dist/operations/break.d.ts +0 -10
  46. package/dist/operations/break.js +0 -21
  47. package/dist/operations/call.d.ts +0 -13
  48. package/dist/operations/call.js +0 -64
  49. package/dist/operations/chunk.d.ts +0 -12
  50. package/dist/operations/chunk.js +0 -31
  51. package/dist/operations/continue.d.ts +0 -10
  52. package/dist/operations/continue.js +0 -21
  53. package/dist/operations/debugger-statement.d.ts +0 -10
  54. package/dist/operations/debugger-statement.js +0 -19
  55. package/dist/operations/envar.d.ts +0 -10
  56. package/dist/operations/envar.js +0 -21
  57. package/dist/operations/evaluate.d.ts +0 -45
  58. package/dist/operations/evaluate.js +0 -369
  59. package/dist/operations/for.d.ts +0 -14
  60. package/dist/operations/for.js +0 -87
  61. package/dist/operations/function-reference.d.ts +0 -12
  62. package/dist/operations/function-reference.js +0 -48
  63. package/dist/operations/function.d.ts +0 -19
  64. package/dist/operations/function.js +0 -84
  65. package/dist/operations/if-statement.d.ts +0 -19
  66. package/dist/operations/if-statement.js +0 -87
  67. package/dist/operations/import.d.ts +0 -20
  68. package/dist/operations/import.js +0 -56
  69. package/dist/operations/include.d.ts +0 -14
  70. package/dist/operations/include.js +0 -40
  71. package/dist/operations/list.d.ts +0 -11
  72. package/dist/operations/list.js +0 -40
  73. package/dist/operations/literal.d.ts +0 -11
  74. package/dist/operations/literal.js +0 -38
  75. package/dist/operations/map.d.ts +0 -11
  76. package/dist/operations/map.js +0 -42
  77. package/dist/operations/negated-binary.d.ts +0 -11
  78. package/dist/operations/negated-binary.js +0 -40
  79. package/dist/operations/new-instance.d.ts +0 -11
  80. package/dist/operations/new-instance.js +0 -37
  81. package/dist/operations/noop.d.ts +0 -7
  82. package/dist/operations/noop.js +0 -14
  83. package/dist/operations/not.d.ts +0 -11
  84. package/dist/operations/not.js +0 -33
  85. package/dist/operations/operation.d.ts +0 -15
  86. package/dist/operations/operation.js +0 -13
  87. package/dist/operations/reference-globals.d.ts +0 -7
  88. package/dist/operations/reference-globals.js +0 -13
  89. package/dist/operations/reference-locals.d.ts +0 -7
  90. package/dist/operations/reference-locals.js +0 -13
  91. package/dist/operations/reference-outer.d.ts +0 -7
  92. package/dist/operations/reference-outer.js +0 -13
  93. package/dist/operations/reference-self.d.ts +0 -7
  94. package/dist/operations/reference-self.js +0 -13
  95. package/dist/operations/reference.d.ts +0 -9
  96. package/dist/operations/reference.js +0 -17
  97. package/dist/operations/resolve-globals.d.ts +0 -5
  98. package/dist/operations/resolve-globals.js +0 -24
  99. package/dist/operations/resolve-locals.d.ts +0 -5
  100. package/dist/operations/resolve-locals.js +0 -24
  101. package/dist/operations/resolve-outer.d.ts +0 -5
  102. package/dist/operations/resolve-outer.js +0 -24
  103. package/dist/operations/resolve-self.d.ts +0 -5
  104. package/dist/operations/resolve-self.js +0 -24
  105. package/dist/operations/resolve.d.ts +0 -55
  106. package/dist/operations/resolve.js +0 -269
  107. package/dist/operations/return.d.ts +0 -11
  108. package/dist/operations/return.js +0 -43
  109. package/dist/operations/while.d.ts +0 -13
  110. package/dist/operations/while.js +0 -70
  111. package/dist/utils/create-assign.d.ts +0 -3
  112. package/dist/utils/create-assign.js +0 -25
  113. package/dist/utils/create-resolve.d.ts +0 -5
  114. package/dist/utils/create-resolve.js +0 -51
  115. package/dist/utils/path.d.ts +0 -10
  116. package/dist/utils/path.js +0 -33
@@ -0,0 +1,1165 @@
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.BytecodeGenerator = void 0;
13
+ const greybel_core_1 = require("greybel-core");
14
+ const miniscript_core_1 = require("miniscript-core");
15
+ const error_1 = require("./utils/error");
16
+ const instruction_1 = require("./byte-compiler/instruction");
17
+ const number_1 = require("./types/number");
18
+ const boolean_1 = require("./types/boolean");
19
+ const string_1 = require("./types/string");
20
+ const default_1 = require("./types/default");
21
+ const stack_1 = require("./utils/stack");
22
+ function generateCustomValueFromASTLiteral(node) {
23
+ switch (node.type) {
24
+ case miniscript_core_1.ASTType.BooleanLiteral:
25
+ return new boolean_1.CustomBoolean(node.value);
26
+ case miniscript_core_1.ASTType.StringLiteral:
27
+ return new string_1.CustomString(node.value);
28
+ case miniscript_core_1.ASTType.NumericLiteral:
29
+ return new number_1.CustomNumber(node.value);
30
+ case miniscript_core_1.ASTType.NilLiteral:
31
+ return default_1.DefaultType.Void;
32
+ default:
33
+ throw new Error('Unexpected literal type.');
34
+ }
35
+ }
36
+ class BytecodeGenerator {
37
+ constructor(options) {
38
+ var _a;
39
+ this.target = new stack_1.Stack(options.target);
40
+ this.handler = options.handler;
41
+ this.context = new stack_1.Stack({
42
+ code: [],
43
+ jumpPoints: []
44
+ });
45
+ this.imports = new Map();
46
+ this.debugMode = (_a = options.debugMode) !== null && _a !== void 0 ? _a : false;
47
+ }
48
+ parse(code) {
49
+ const parser = new greybel_core_1.Parser(code);
50
+ return parser.parseChunk();
51
+ }
52
+ compile(code) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const node = this.parse(code);
55
+ yield this.processNode(node);
56
+ this.push({
57
+ op: instruction_1.OpCode.HALT,
58
+ source: this.getSourceLocation(node)
59
+ });
60
+ return {
61
+ code: this.context.peek().code,
62
+ imports: this.imports
63
+ };
64
+ });
65
+ }
66
+ getCurrentPointer() {
67
+ return this.context.peek().code.length - 1;
68
+ }
69
+ getSourceLocation(node) {
70
+ const target = this.target.peek();
71
+ return {
72
+ path: target,
73
+ start: node.start,
74
+ end: node.end
75
+ };
76
+ }
77
+ getInternalLocation() {
78
+ return {
79
+ path: 'internal',
80
+ start: { line: 0, character: 0 },
81
+ end: { line: 0, character: 0 }
82
+ };
83
+ }
84
+ pushContext() {
85
+ this.context.push({
86
+ code: [],
87
+ jumpPoints: []
88
+ });
89
+ }
90
+ popContext() {
91
+ return this.context.pop();
92
+ }
93
+ getLastJumpoint() {
94
+ const jumpPoints = this.context.peek().jumpPoints;
95
+ return jumpPoints[jumpPoints.length - 1];
96
+ }
97
+ pushJumppoint(start, end) {
98
+ this.context.peek().jumpPoints.push([start, end]);
99
+ }
100
+ popJumppoint() {
101
+ return this.context.peek().jumpPoints.pop();
102
+ }
103
+ push(item) {
104
+ item.ip = this.getCurrentPointer() + 1;
105
+ this.context.peek().code.push(item);
106
+ }
107
+ processNode(node) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ if (this.debugMode) {
110
+ this.push({
111
+ op: instruction_1.OpCode.BREAKPOINT,
112
+ source: this.getSourceLocation(node)
113
+ });
114
+ }
115
+ switch (node.type) {
116
+ case miniscript_core_1.ASTType.MemberExpression:
117
+ yield this.processMemberExpression(node);
118
+ this.push({
119
+ op: instruction_1.OpCode.POP,
120
+ source: this.getSourceLocation(node)
121
+ });
122
+ return;
123
+ case miniscript_core_1.ASTType.IndexExpression:
124
+ yield this.processIndexExpression(node);
125
+ this.push({
126
+ op: instruction_1.OpCode.POP,
127
+ source: this.getSourceLocation(node)
128
+ });
129
+ return;
130
+ case miniscript_core_1.ASTType.SliceExpression:
131
+ yield this.processSliceExpression(node);
132
+ this.push({
133
+ op: instruction_1.OpCode.POP,
134
+ source: this.getSourceLocation(node)
135
+ });
136
+ return;
137
+ case miniscript_core_1.ASTType.Identifier:
138
+ yield this.processIdentifier(node);
139
+ this.push({
140
+ op: instruction_1.OpCode.POP,
141
+ source: this.getSourceLocation(node)
142
+ });
143
+ return;
144
+ case miniscript_core_1.ASTType.AssignmentStatement:
145
+ yield this.processAssignmentStatement(node);
146
+ return;
147
+ case miniscript_core_1.ASTType.Chunk:
148
+ const chunk = node;
149
+ for (const item of chunk.body) {
150
+ yield this.processNode(item);
151
+ }
152
+ return;
153
+ case miniscript_core_1.ASTType.BooleanLiteral:
154
+ case miniscript_core_1.ASTType.StringLiteral:
155
+ case miniscript_core_1.ASTType.NumericLiteral:
156
+ case miniscript_core_1.ASTType.NilLiteral:
157
+ yield this.processLiteral(node);
158
+ this.push({
159
+ op: instruction_1.OpCode.POP,
160
+ source: this.getSourceLocation(node)
161
+ });
162
+ return;
163
+ case miniscript_core_1.ASTType.IsaExpression:
164
+ case miniscript_core_1.ASTType.BinaryExpression:
165
+ case miniscript_core_1.ASTType.LogicalExpression:
166
+ yield this.processEvaluationExpression(node);
167
+ this.push({
168
+ op: instruction_1.OpCode.POP,
169
+ source: this.getSourceLocation(node)
170
+ });
171
+ return;
172
+ case miniscript_core_1.ASTType.ReturnStatement:
173
+ yield this.processReturn(node);
174
+ return;
175
+ case miniscript_core_1.ASTType.BreakStatement:
176
+ yield this.processBreak(node);
177
+ return;
178
+ case miniscript_core_1.ASTType.ContinueStatement:
179
+ yield this.processContinue(node);
180
+ return;
181
+ case miniscript_core_1.ASTType.MapConstructorExpression:
182
+ yield this.processMapConstructorExpression(node);
183
+ this.push({
184
+ op: instruction_1.OpCode.POP,
185
+ source: this.getSourceLocation(node)
186
+ });
187
+ return;
188
+ case miniscript_core_1.ASTType.ListConstructorExpression:
189
+ yield this.processListConstructorExpression(node);
190
+ this.push({
191
+ op: instruction_1.OpCode.POP,
192
+ source: this.getSourceLocation(node)
193
+ });
194
+ return;
195
+ case miniscript_core_1.ASTType.FunctionDeclaration:
196
+ yield this.processFunctionDeclaration(node);
197
+ this.push({
198
+ op: instruction_1.OpCode.POP,
199
+ source: this.getSourceLocation(node)
200
+ });
201
+ return;
202
+ case miniscript_core_1.ASTType.WhileStatement:
203
+ yield this.processWhileStatement(node);
204
+ return;
205
+ case miniscript_core_1.ASTType.ParenthesisExpression:
206
+ yield this.processNode(node.expression);
207
+ return;
208
+ case miniscript_core_1.ASTType.BinaryNegatedExpression:
209
+ case miniscript_core_1.ASTType.UnaryExpression:
210
+ case miniscript_core_1.ASTType.NegationExpression:
211
+ yield this.processUnaryExpression(node);
212
+ this.push({
213
+ op: instruction_1.OpCode.POP,
214
+ source: this.getSourceLocation(node)
215
+ });
216
+ return;
217
+ case miniscript_core_1.ASTType.CallStatement:
218
+ yield this.processNode(node.expression);
219
+ return;
220
+ case miniscript_core_1.ASTType.CallExpression:
221
+ yield this.processCallExpression(node);
222
+ this.push({
223
+ op: instruction_1.OpCode.POP,
224
+ source: this.getSourceLocation(node)
225
+ });
226
+ return;
227
+ case miniscript_core_1.ASTType.IfStatement:
228
+ case miniscript_core_1.ASTType.IfShortcutStatement:
229
+ yield this.processIfStatement(node);
230
+ return;
231
+ case miniscript_core_1.ASTType.ForGenericStatement:
232
+ yield this.processForGenericStatement(node);
233
+ return;
234
+ case miniscript_core_1.ASTType.EmptyExpression:
235
+ case miniscript_core_1.ASTType.Comment:
236
+ return;
237
+ case greybel_core_1.ASTType.FeatureEnvarExpression:
238
+ yield this.processEnvarExpression(node);
239
+ this.push({
240
+ op: instruction_1.OpCode.POP,
241
+ source: this.getSourceLocation(node)
242
+ });
243
+ return;
244
+ case greybel_core_1.ASTType.FeatureImportExpression:
245
+ yield this.processImportExpression(node);
246
+ return;
247
+ case greybel_core_1.ASTType.FeatureIncludeExpression:
248
+ yield this.processIncludeExpression(node);
249
+ return;
250
+ case greybel_core_1.ASTType.FeatureDebuggerExpression:
251
+ yield this.processDebuggerExpression(node);
252
+ return;
253
+ default: {
254
+ const range = new miniscript_core_1.ASTRange(node.start, node.end);
255
+ throw new error_1.PrepareError(`Unexpected AST type ${node.type}`, {
256
+ target: this.target.peek(),
257
+ range
258
+ });
259
+ }
260
+ }
261
+ });
262
+ }
263
+ processSubNode(node, ignoreOuter = true) {
264
+ return __awaiter(this, void 0, void 0, function* () {
265
+ switch (node.type) {
266
+ case miniscript_core_1.ASTType.MemberExpression:
267
+ yield this.processMemberExpression(node);
268
+ return;
269
+ case miniscript_core_1.ASTType.IndexExpression:
270
+ yield this.processIndexExpression(node);
271
+ return;
272
+ case miniscript_core_1.ASTType.SliceExpression:
273
+ yield this.processSliceExpression(node);
274
+ return;
275
+ case miniscript_core_1.ASTType.Identifier:
276
+ yield this.processIdentifier(node);
277
+ return;
278
+ case miniscript_core_1.ASTType.BooleanLiteral:
279
+ case miniscript_core_1.ASTType.StringLiteral:
280
+ case miniscript_core_1.ASTType.NumericLiteral:
281
+ case miniscript_core_1.ASTType.NilLiteral:
282
+ yield this.processLiteral(node);
283
+ return;
284
+ case miniscript_core_1.ASTType.IsaExpression:
285
+ case miniscript_core_1.ASTType.BinaryExpression:
286
+ case miniscript_core_1.ASTType.LogicalExpression:
287
+ yield this.processEvaluationExpression(node);
288
+ return;
289
+ case miniscript_core_1.ASTType.MapConstructorExpression:
290
+ yield this.processMapConstructorExpression(node);
291
+ return;
292
+ case miniscript_core_1.ASTType.ListConstructorExpression:
293
+ yield this.processListConstructorExpression(node);
294
+ return;
295
+ case miniscript_core_1.ASTType.FunctionDeclaration:
296
+ yield this.processFunctionDeclaration(node, ignoreOuter);
297
+ return;
298
+ case miniscript_core_1.ASTType.ParenthesisExpression:
299
+ yield this.processSubNode(node.expression);
300
+ return;
301
+ case miniscript_core_1.ASTType.BinaryNegatedExpression:
302
+ case miniscript_core_1.ASTType.UnaryExpression:
303
+ case miniscript_core_1.ASTType.NegationExpression:
304
+ yield this.processUnaryExpression(node);
305
+ return;
306
+ case miniscript_core_1.ASTType.CallStatement:
307
+ yield this.processNode(node.expression);
308
+ return;
309
+ case miniscript_core_1.ASTType.CallExpression:
310
+ yield this.processCallExpression(node);
311
+ return;
312
+ case miniscript_core_1.ASTType.EmptyExpression:
313
+ this.push({
314
+ op: instruction_1.OpCode.PUSH,
315
+ source: this.getSourceLocation(node),
316
+ value: default_1.DefaultType.Void
317
+ });
318
+ return;
319
+ case greybel_core_1.ASTType.FeatureEnvarExpression:
320
+ yield this.processEnvarExpression(node);
321
+ return;
322
+ case miniscript_core_1.ASTType.Comment:
323
+ return;
324
+ default: {
325
+ const range = new miniscript_core_1.ASTRange(node.start, node.end);
326
+ throw new error_1.PrepareError(`Unexpected AST type ${node.type}`, {
327
+ target: this.target.peek(),
328
+ range
329
+ });
330
+ }
331
+ }
332
+ });
333
+ }
334
+ processMemberExpression(node, isInvoke = true) {
335
+ return __awaiter(this, void 0, void 0, function* () {
336
+ if (node.base instanceof miniscript_core_1.ASTIdentifier && node.base.name === 'super') {
337
+ this.push({
338
+ op: instruction_1.OpCode.PUSH,
339
+ source: this.getSourceLocation(node.identifier),
340
+ value: new string_1.CustomString(node.identifier.name)
341
+ });
342
+ this.push({
343
+ op: instruction_1.OpCode.GET_SUPER_PROPERTY,
344
+ source: this.getSourceLocation(node.identifier),
345
+ invoke: isInvoke
346
+ });
347
+ }
348
+ else {
349
+ yield this.processSubNode(node.base);
350
+ if (node.identifier instanceof miniscript_core_1.ASTIdentifier) {
351
+ yield this.processIdentifier(node.identifier, false, isInvoke);
352
+ }
353
+ else {
354
+ yield this.processSubNode(node.identifier);
355
+ }
356
+ }
357
+ });
358
+ }
359
+ processIndexExpression(node, isInvoke = true) {
360
+ return __awaiter(this, void 0, void 0, function* () {
361
+ if (node.base instanceof miniscript_core_1.ASTIdentifier && node.base.name === 'super') {
362
+ yield this.processSubNode(node.index);
363
+ this.push({
364
+ op: instruction_1.OpCode.GET_SUPER_PROPERTY,
365
+ source: this.getSourceLocation(node),
366
+ invoke: isInvoke
367
+ });
368
+ }
369
+ else {
370
+ yield this.processSubNode(node.base);
371
+ yield this.processSubNode(node.index);
372
+ this.push({
373
+ op: instruction_1.OpCode.GET_PROPERTY,
374
+ source: this.getSourceLocation(node.index),
375
+ invoke: isInvoke
376
+ });
377
+ }
378
+ });
379
+ }
380
+ processSliceExpression(node) {
381
+ return __awaiter(this, void 0, void 0, function* () {
382
+ yield this.processSubNode(node.base);
383
+ yield this.processSubNode(node.left);
384
+ yield this.processSubNode(node.right);
385
+ this.push({
386
+ op: instruction_1.OpCode.SLICE,
387
+ source: this.getSourceLocation(node)
388
+ });
389
+ });
390
+ }
391
+ processIdentifier(node, isFirst = true, isInvoke = true) {
392
+ return __awaiter(this, void 0, void 0, function* () {
393
+ if (isFirst) {
394
+ switch (node.name) {
395
+ case 'self': {
396
+ this.push({
397
+ op: instruction_1.OpCode.GET_SELF,
398
+ source: this.getSourceLocation(node)
399
+ });
400
+ return;
401
+ }
402
+ case 'super': {
403
+ this.push({
404
+ op: instruction_1.OpCode.GET_SUPER,
405
+ source: this.getSourceLocation(node)
406
+ });
407
+ return;
408
+ }
409
+ case 'outer': {
410
+ this.push({
411
+ op: instruction_1.OpCode.GET_OUTER,
412
+ source: this.getSourceLocation(node)
413
+ });
414
+ return;
415
+ }
416
+ case 'locals': {
417
+ this.push({
418
+ op: instruction_1.OpCode.GET_LOCALS,
419
+ source: this.getSourceLocation(node)
420
+ });
421
+ return;
422
+ }
423
+ case 'globals': {
424
+ this.push({
425
+ op: instruction_1.OpCode.GET_GLOBALS,
426
+ source: this.getSourceLocation(node)
427
+ });
428
+ return;
429
+ }
430
+ default: {
431
+ this.push({
432
+ op: instruction_1.OpCode.GET_VARIABLE,
433
+ source: this.getSourceLocation(node),
434
+ property: new string_1.CustomString(node.name),
435
+ invoke: isInvoke
436
+ });
437
+ }
438
+ }
439
+ }
440
+ else {
441
+ this.push({
442
+ op: instruction_1.OpCode.PUSH,
443
+ source: this.getSourceLocation(node),
444
+ value: new string_1.CustomString(node.name)
445
+ });
446
+ this.push({
447
+ op: instruction_1.OpCode.GET_PROPERTY,
448
+ source: this.getSourceLocation(node),
449
+ invoke: isInvoke
450
+ });
451
+ }
452
+ });
453
+ }
454
+ processAssignmentStatement(node) {
455
+ return __awaiter(this, void 0, void 0, function* () {
456
+ let variable = node.variable;
457
+ if (variable instanceof miniscript_core_1.ASTUnaryExpression) {
458
+ variable = variable.argument;
459
+ }
460
+ if (variable instanceof miniscript_core_1.ASTMemberExpression) {
461
+ yield this.processSubNode(variable.base);
462
+ this.push({
463
+ op: instruction_1.OpCode.PUSH,
464
+ source: this.getSourceLocation(variable.identifier),
465
+ value: new string_1.CustomString(variable.identifier.name)
466
+ });
467
+ }
468
+ else if (variable instanceof miniscript_core_1.ASTIndexExpression) {
469
+ yield this.processSubNode(variable.base);
470
+ yield this.processSubNode(variable.index);
471
+ }
472
+ else if (variable instanceof miniscript_core_1.ASTIdentifier) {
473
+ this.push({
474
+ op: instruction_1.OpCode.GET_LOCALS,
475
+ source: this.getSourceLocation(variable)
476
+ });
477
+ this.push({
478
+ op: instruction_1.OpCode.PUSH,
479
+ source: this.getSourceLocation(variable),
480
+ value: new string_1.CustomString(variable.name)
481
+ });
482
+ }
483
+ else {
484
+ yield this.processSubNode(variable);
485
+ this.push({
486
+ op: instruction_1.OpCode.PUSH,
487
+ source: this.getSourceLocation(variable),
488
+ value: default_1.DefaultType.Void
489
+ });
490
+ }
491
+ yield this.processSubNode(node.init, false);
492
+ this.push({
493
+ op: instruction_1.OpCode.ASSIGN,
494
+ source: this.getSourceLocation(node)
495
+ });
496
+ });
497
+ }
498
+ processLiteral(node) {
499
+ return __awaiter(this, void 0, void 0, function* () {
500
+ const value = generateCustomValueFromASTLiteral(node);
501
+ this.push({
502
+ op: instruction_1.OpCode.PUSH,
503
+ source: this.getSourceLocation(node),
504
+ value
505
+ });
506
+ });
507
+ }
508
+ processEvaluationExpression(node) {
509
+ return __awaiter(this, void 0, void 0, function* () {
510
+ yield this.processSubNode(node.left);
511
+ yield this.processSubNode(node.right);
512
+ switch (node.operator) {
513
+ case miniscript_core_1.Operator.Isa: {
514
+ this.push({
515
+ op: instruction_1.OpCode.ISA,
516
+ source: this.getSourceLocation(node)
517
+ });
518
+ break;
519
+ }
520
+ case miniscript_core_1.Operator.Equal: {
521
+ this.push({
522
+ op: instruction_1.OpCode.EQUAL,
523
+ source: this.getSourceLocation(node)
524
+ });
525
+ break;
526
+ }
527
+ case miniscript_core_1.Operator.NotEqual: {
528
+ this.push({
529
+ op: instruction_1.OpCode.NOT_EQUAL,
530
+ source: this.getSourceLocation(node)
531
+ });
532
+ break;
533
+ }
534
+ case miniscript_core_1.Operator.LessThan: {
535
+ this.push({
536
+ op: instruction_1.OpCode.LESS_THAN,
537
+ source: this.getSourceLocation(node)
538
+ });
539
+ break;
540
+ }
541
+ case miniscript_core_1.Operator.LessThanOrEqual: {
542
+ this.push({
543
+ op: instruction_1.OpCode.LESS_THAN_OR_EQUAL,
544
+ source: this.getSourceLocation(node)
545
+ });
546
+ break;
547
+ }
548
+ case miniscript_core_1.Operator.GreaterThan: {
549
+ this.push({
550
+ op: instruction_1.OpCode.GREATER_THAN,
551
+ source: this.getSourceLocation(node)
552
+ });
553
+ break;
554
+ }
555
+ case miniscript_core_1.Operator.GreaterThanOrEqual: {
556
+ this.push({
557
+ op: instruction_1.OpCode.GREATER_THAN_OR_EQUAL,
558
+ source: this.getSourceLocation(node)
559
+ });
560
+ break;
561
+ }
562
+ case miniscript_core_1.Operator.And: {
563
+ this.push({
564
+ op: instruction_1.OpCode.AND,
565
+ source: this.getSourceLocation(node)
566
+ });
567
+ break;
568
+ }
569
+ case miniscript_core_1.Operator.Or: {
570
+ this.push({
571
+ op: instruction_1.OpCode.OR,
572
+ source: this.getSourceLocation(node)
573
+ });
574
+ break;
575
+ }
576
+ case miniscript_core_1.Operator.Plus: {
577
+ this.push({
578
+ op: instruction_1.OpCode.ADD,
579
+ source: this.getSourceLocation(node)
580
+ });
581
+ break;
582
+ }
583
+ case miniscript_core_1.Operator.Minus: {
584
+ this.push({
585
+ op: instruction_1.OpCode.SUB,
586
+ source: this.getSourceLocation(node)
587
+ });
588
+ break;
589
+ }
590
+ case miniscript_core_1.Operator.Asterik: {
591
+ this.push({
592
+ op: instruction_1.OpCode.MUL,
593
+ source: this.getSourceLocation(node)
594
+ });
595
+ break;
596
+ }
597
+ case miniscript_core_1.Operator.Slash: {
598
+ this.push({
599
+ op: instruction_1.OpCode.DIV,
600
+ source: this.getSourceLocation(node)
601
+ });
602
+ break;
603
+ }
604
+ case miniscript_core_1.Operator.Modulo: {
605
+ this.push({
606
+ op: instruction_1.OpCode.MOD,
607
+ source: this.getSourceLocation(node)
608
+ });
609
+ break;
610
+ }
611
+ case miniscript_core_1.Operator.Power: {
612
+ this.push({
613
+ op: instruction_1.OpCode.POW,
614
+ source: this.getSourceLocation(node)
615
+ });
616
+ break;
617
+ }
618
+ case greybel_core_1.Operator.BitwiseAnd: {
619
+ this.push({
620
+ op: instruction_1.OpCode.BITWISE_AND,
621
+ source: this.getSourceLocation(node)
622
+ });
623
+ break;
624
+ }
625
+ case greybel_core_1.Operator.BitwiseOr: {
626
+ this.push({
627
+ op: instruction_1.OpCode.BITWISE_OR,
628
+ source: this.getSourceLocation(node)
629
+ });
630
+ break;
631
+ }
632
+ case greybel_core_1.Operator.LeftShift: {
633
+ this.push({
634
+ op: instruction_1.OpCode.BITWISE_LEFT_SHIFT,
635
+ source: this.getSourceLocation(node)
636
+ });
637
+ break;
638
+ }
639
+ case greybel_core_1.Operator.RightShift: {
640
+ this.push({
641
+ op: instruction_1.OpCode.BITWISE_RIGHT_SHIFT,
642
+ source: this.getSourceLocation(node)
643
+ });
644
+ break;
645
+ }
646
+ case greybel_core_1.Operator.UnsignedRightShift: {
647
+ this.push({
648
+ op: instruction_1.OpCode.BITWISE_UNSIGNED_RIGHT_SHIFT,
649
+ source: this.getSourceLocation(node)
650
+ });
651
+ break;
652
+ }
653
+ default:
654
+ throw new Error(`Unexpected evaluation expression operator. ("${node.operator}")`);
655
+ }
656
+ });
657
+ }
658
+ processReturn(node) {
659
+ return __awaiter(this, void 0, void 0, function* () {
660
+ if (node.argument) {
661
+ yield this.processSubNode(node.argument);
662
+ }
663
+ else {
664
+ this.push({
665
+ op: instruction_1.OpCode.PUSH,
666
+ source: this.getSourceLocation(node),
667
+ value: default_1.DefaultType.Void
668
+ });
669
+ }
670
+ this.push({
671
+ op: instruction_1.OpCode.RETURN,
672
+ source: this.getSourceLocation(node)
673
+ });
674
+ });
675
+ }
676
+ processBreak(node) {
677
+ return __awaiter(this, void 0, void 0, function* () {
678
+ const [_, end] = this.getLastJumpoint();
679
+ this.push({
680
+ op: instruction_1.OpCode.GOTO_A,
681
+ source: this.getSourceLocation(node),
682
+ goto: end
683
+ });
684
+ });
685
+ }
686
+ processContinue(node) {
687
+ return __awaiter(this, void 0, void 0, function* () {
688
+ const [start] = this.getLastJumpoint();
689
+ this.push({
690
+ op: instruction_1.OpCode.GOTO_A,
691
+ source: this.getSourceLocation(node),
692
+ goto: start
693
+ });
694
+ });
695
+ }
696
+ processMapConstructorExpression(node) {
697
+ return __awaiter(this, void 0, void 0, function* () {
698
+ for (const field of node.fields) {
699
+ yield this.processSubNode(field.key);
700
+ yield this.processSubNode(field.value);
701
+ }
702
+ this.push({
703
+ op: instruction_1.OpCode.CONSTRUCT_MAP,
704
+ source: this.getSourceLocation(node),
705
+ length: node.fields.length
706
+ });
707
+ });
708
+ }
709
+ processListConstructorExpression(node) {
710
+ return __awaiter(this, void 0, void 0, function* () {
711
+ for (const field of node.fields) {
712
+ yield this.processSubNode(field.value);
713
+ }
714
+ this.push({
715
+ op: instruction_1.OpCode.CONSTRUCT_LIST,
716
+ source: this.getSourceLocation(node),
717
+ length: node.fields.length
718
+ });
719
+ });
720
+ }
721
+ processFunctionDeclaration(node, ignoreOuter = false) {
722
+ return __awaiter(this, void 0, void 0, function* () {
723
+ const args = [];
724
+ for (const item of node.parameters) {
725
+ if (item instanceof miniscript_core_1.ASTIdentifier) {
726
+ args.push({
727
+ name: new string_1.CustomString(item.name),
728
+ defaultValue: default_1.DefaultType.Void
729
+ });
730
+ }
731
+ else if (item instanceof miniscript_core_1.ASTAssignmentStatement) {
732
+ let defaultValue = default_1.DefaultType.Void;
733
+ if (item.init instanceof miniscript_core_1.ASTLiteral) {
734
+ defaultValue = generateCustomValueFromASTLiteral(item.init);
735
+ }
736
+ args.push({
737
+ name: new string_1.CustomString(item.variable.name),
738
+ defaultValue
739
+ });
740
+ }
741
+ }
742
+ this.pushContext();
743
+ for (const item of node.body) {
744
+ yield this.processNode(item);
745
+ }
746
+ const fnCode = this.popContext().code;
747
+ this.push({
748
+ op: instruction_1.OpCode.FUNCTION_DEFINITION,
749
+ source: this.getSourceLocation(node),
750
+ arguments: args,
751
+ code: fnCode,
752
+ /*
753
+ Can be removed after MiniScript fixed outer context bug.
754
+ */
755
+ ignoreOuter
756
+ });
757
+ });
758
+ }
759
+ processWhileStatement(node) {
760
+ return __awaiter(this, void 0, void 0, function* () {
761
+ const start = {
762
+ op: instruction_1.OpCode.NOOP,
763
+ source: this.getSourceLocation(node.condition)
764
+ };
765
+ const end = {
766
+ op: instruction_1.OpCode.NOOP,
767
+ source: this.getSourceLocation(node)
768
+ };
769
+ this.push(start);
770
+ yield this.processSubNode(node.condition);
771
+ this.push({
772
+ op: instruction_1.OpCode.GOTO_A_IF_FALSE,
773
+ source: this.getSourceLocation(node.condition),
774
+ goto: end
775
+ });
776
+ this.pushJumppoint(start, end);
777
+ for (const item of node.body) {
778
+ yield this.processNode(item);
779
+ }
780
+ this.popJumppoint();
781
+ this.push({
782
+ op: instruction_1.OpCode.GOTO_A,
783
+ source: this.getSourceLocation(node.condition),
784
+ goto: start
785
+ });
786
+ this.push(end);
787
+ });
788
+ }
789
+ processUnaryExpression(node) {
790
+ return __awaiter(this, void 0, void 0, function* () {
791
+ const arg = node.argument;
792
+ switch (node.operator) {
793
+ case miniscript_core_1.Operator.Reference:
794
+ if (arg instanceof miniscript_core_1.ASTMemberExpression) {
795
+ yield this.processMemberExpression(arg, false);
796
+ }
797
+ else if (arg instanceof miniscript_core_1.ASTIndexExpression) {
798
+ yield this.processIndexExpression(arg, false);
799
+ }
800
+ else if (arg instanceof miniscript_core_1.ASTIdentifier) {
801
+ yield this.processIdentifier(arg, true, false);
802
+ }
803
+ else {
804
+ yield this.processSubNode(arg);
805
+ }
806
+ return;
807
+ case miniscript_core_1.Operator.Not: {
808
+ yield this.processSubNode(arg);
809
+ this.push({
810
+ op: instruction_1.OpCode.FALSIFY,
811
+ source: this.getSourceLocation(node)
812
+ });
813
+ return;
814
+ }
815
+ case miniscript_core_1.Operator.Minus: {
816
+ yield this.processSubNode(arg);
817
+ this.push({
818
+ op: instruction_1.OpCode.NEGATE,
819
+ source: this.getSourceLocation(node)
820
+ });
821
+ return;
822
+ }
823
+ case miniscript_core_1.Operator.New: {
824
+ yield this.processSubNode(arg);
825
+ this.push({
826
+ op: instruction_1.OpCode.NEW,
827
+ source: this.getSourceLocation(node)
828
+ });
829
+ return;
830
+ }
831
+ }
832
+ });
833
+ }
834
+ processCallExpression(node) {
835
+ return __awaiter(this, void 0, void 0, function* () {
836
+ const pushArgs = () => __awaiter(this, void 0, void 0, function* () {
837
+ for (const arg of node.arguments) {
838
+ yield this.processSubNode(arg);
839
+ }
840
+ });
841
+ const left = node.base;
842
+ if (left instanceof miniscript_core_1.ASTMemberExpression) {
843
+ if (left.base instanceof miniscript_core_1.ASTIdentifier && left.base.name === 'super') {
844
+ this.push({
845
+ op: instruction_1.OpCode.PUSH,
846
+ source: this.getSourceLocation(left.identifier),
847
+ value: new string_1.CustomString(left.identifier.name)
848
+ });
849
+ yield pushArgs();
850
+ this.push({
851
+ op: instruction_1.OpCode.CALL_SUPER_PROPERTY,
852
+ source: this.getSourceLocation(node),
853
+ length: node.arguments.length
854
+ });
855
+ }
856
+ else {
857
+ yield this.processSubNode(left.base);
858
+ this.push({
859
+ op: instruction_1.OpCode.PUSH,
860
+ source: this.getSourceLocation(left.identifier),
861
+ value: new string_1.CustomString(left.identifier.name)
862
+ });
863
+ yield pushArgs();
864
+ this.push({
865
+ op: instruction_1.OpCode.CALL_WITH_CONTEXT,
866
+ source: this.getSourceLocation(node),
867
+ length: node.arguments.length
868
+ });
869
+ }
870
+ }
871
+ else if (left instanceof miniscript_core_1.ASTIndexExpression) {
872
+ if (left.base instanceof miniscript_core_1.ASTIdentifier && left.base.name === 'super') {
873
+ yield this.processSubNode(left.index);
874
+ yield pushArgs();
875
+ this.push({
876
+ op: instruction_1.OpCode.CALL_SUPER_PROPERTY,
877
+ source: this.getSourceLocation(node),
878
+ length: node.arguments.length
879
+ });
880
+ }
881
+ else {
882
+ yield this.processSubNode(left.base);
883
+ yield this.processSubNode(left.index);
884
+ yield pushArgs();
885
+ this.push({
886
+ op: instruction_1.OpCode.CALL_WITH_CONTEXT,
887
+ source: this.getSourceLocation(node),
888
+ length: node.arguments.length
889
+ });
890
+ }
891
+ }
892
+ else if (left instanceof miniscript_core_1.ASTIdentifier) {
893
+ yield this.processIdentifier(left, true, false);
894
+ yield pushArgs();
895
+ this.push({
896
+ op: instruction_1.OpCode.CALL,
897
+ source: this.getSourceLocation(node),
898
+ length: node.arguments.length
899
+ });
900
+ }
901
+ else {
902
+ yield this.processSubNode(left);
903
+ yield pushArgs();
904
+ this.push({
905
+ op: instruction_1.OpCode.CALL,
906
+ source: this.getSourceLocation(node),
907
+ length: node.arguments.length
908
+ });
909
+ }
910
+ });
911
+ }
912
+ processIfStatement(node) {
913
+ return __awaiter(this, void 0, void 0, function* () {
914
+ const end = {
915
+ op: instruction_1.OpCode.NOOP,
916
+ source: this.getSourceLocation(node)
917
+ };
918
+ for (const clause of node.clauses) {
919
+ if (clause instanceof miniscript_core_1.ASTIfClause) {
920
+ const next = {
921
+ op: instruction_1.OpCode.NOOP,
922
+ source: this.getSourceLocation(clause)
923
+ };
924
+ yield this.processSubNode(clause.condition);
925
+ this.push({
926
+ op: instruction_1.OpCode.GOTO_A_IF_FALSE,
927
+ source: this.getSourceLocation(node),
928
+ goto: next
929
+ });
930
+ for (const item of clause.body) {
931
+ yield this.processNode(item);
932
+ }
933
+ this.push({
934
+ op: instruction_1.OpCode.GOTO_A,
935
+ source: this.getSourceLocation(node),
936
+ goto: end
937
+ });
938
+ this.push(next);
939
+ }
940
+ else if (clause instanceof miniscript_core_1.ASTElseClause) {
941
+ for (const item of clause.body) {
942
+ yield this.processNode(item);
943
+ }
944
+ }
945
+ }
946
+ this.push(end);
947
+ });
948
+ }
949
+ processForGenericStatement(node) {
950
+ return __awaiter(this, void 0, void 0, function* () {
951
+ const variable = node.variable;
952
+ const idxVariable = new string_1.CustomString(`__${variable.name}_idx`);
953
+ const start = {
954
+ op: instruction_1.OpCode.NEXT,
955
+ source: this.getSourceLocation(node.iterator),
956
+ idxVariable,
957
+ variable: new string_1.CustomString(variable.name)
958
+ };
959
+ const end = {
960
+ op: instruction_1.OpCode.POP_ITERATOR,
961
+ source: this.getSourceLocation(node.iterator)
962
+ };
963
+ this.push({
964
+ op: instruction_1.OpCode.GET_LOCALS,
965
+ source: this.getSourceLocation(node)
966
+ });
967
+ this.push({
968
+ op: instruction_1.OpCode.PUSH,
969
+ source: this.getSourceLocation(node),
970
+ value: idxVariable
971
+ });
972
+ this.push({
973
+ op: instruction_1.OpCode.PUSH,
974
+ source: this.getSourceLocation(node),
975
+ value: new number_1.CustomNumber(-1)
976
+ });
977
+ this.push({
978
+ op: instruction_1.OpCode.ASSIGN,
979
+ source: this.getSourceLocation(node)
980
+ });
981
+ yield this.processSubNode(node.iterator);
982
+ this.push({
983
+ op: instruction_1.OpCode.PUSH_ITERATOR,
984
+ source: this.getSourceLocation(node.iterator)
985
+ });
986
+ this.push(start);
987
+ this.push({
988
+ op: instruction_1.OpCode.GOTO_A_IF_FALSE,
989
+ source: this.getSourceLocation(node.iterator),
990
+ goto: end
991
+ });
992
+ for (const item of node.body) {
993
+ yield this.processNode(item);
994
+ }
995
+ this.push({
996
+ op: instruction_1.OpCode.GOTO_A,
997
+ source: this.getSourceLocation(node.iterator),
998
+ goto: start
999
+ });
1000
+ this.push(end);
1001
+ });
1002
+ }
1003
+ processEnvarExpression(node) {
1004
+ return __awaiter(this, void 0, void 0, function* () {
1005
+ this.push({
1006
+ op: instruction_1.OpCode.PUSH,
1007
+ source: this.getSourceLocation(node),
1008
+ value: new string_1.CustomString(node.name)
1009
+ });
1010
+ this.push({
1011
+ op: instruction_1.OpCode.GET_ENVAR,
1012
+ source: this.getSourceLocation(node)
1013
+ });
1014
+ });
1015
+ }
1016
+ createImport(node, path, code) {
1017
+ return __awaiter(this, void 0, void 0, function* () {
1018
+ try {
1019
+ this.target.push(path);
1020
+ this.pushContext();
1021
+ const childNodes = this.parse(code);
1022
+ this.push({
1023
+ op: instruction_1.OpCode.GET_LOCALS,
1024
+ source: this.getInternalLocation()
1025
+ });
1026
+ this.push({
1027
+ op: instruction_1.OpCode.PUSH,
1028
+ source: this.getInternalLocation(),
1029
+ value: new string_1.CustomString('module')
1030
+ });
1031
+ this.push({
1032
+ op: instruction_1.OpCode.PUSH,
1033
+ source: this.getInternalLocation(),
1034
+ value: new string_1.CustomString('exports')
1035
+ });
1036
+ this.push({
1037
+ op: instruction_1.OpCode.CONSTRUCT_MAP,
1038
+ source: this.getInternalLocation(),
1039
+ length: 0
1040
+ });
1041
+ this.push({
1042
+ op: instruction_1.OpCode.CONSTRUCT_MAP,
1043
+ source: this.getInternalLocation(),
1044
+ length: 1
1045
+ });
1046
+ this.push({
1047
+ op: instruction_1.OpCode.ASSIGN,
1048
+ source: this.getInternalLocation(),
1049
+ });
1050
+ yield this.processNode(childNodes);
1051
+ this.push({
1052
+ op: instruction_1.OpCode.GET_VARIABLE,
1053
+ source: this.getInternalLocation(),
1054
+ property: new string_1.CustomString('module')
1055
+ });
1056
+ this.push({
1057
+ op: instruction_1.OpCode.PUSH,
1058
+ source: this.getInternalLocation(),
1059
+ value: new string_1.CustomString('exports')
1060
+ });
1061
+ this.push({
1062
+ op: instruction_1.OpCode.GET_PROPERTY,
1063
+ source: this.getInternalLocation(),
1064
+ });
1065
+ const context = this.popContext();
1066
+ this.target.pop();
1067
+ this.imports.set(path, context.code);
1068
+ }
1069
+ catch (err) {
1070
+ if (err instanceof error_1.PrepareError) {
1071
+ throw err;
1072
+ }
1073
+ throw new error_1.PrepareError(err.message, {
1074
+ target: path,
1075
+ range: new miniscript_core_1.ASTRange(node.start, node.end)
1076
+ }, err);
1077
+ }
1078
+ });
1079
+ }
1080
+ processImportExpression(node) {
1081
+ return __awaiter(this, void 0, void 0, function* () {
1082
+ const currentTarget = this.target.peek();
1083
+ const importTarget = yield this.handler.resourceHandler.getTargetRelativeTo(currentTarget, node.path);
1084
+ if (this.target.includes(importTarget)) {
1085
+ console.warn(`Found circular dependency between "${currentTarget}" and "${importTarget}" at line ${node.start.line}. Using noop instead to prevent overflow.`);
1086
+ return;
1087
+ }
1088
+ if (!this.imports.has(importTarget)) {
1089
+ const code = yield this.handler.resourceHandler.get(importTarget);
1090
+ if (code == null) {
1091
+ const range = new miniscript_core_1.ASTRange(node.start, node.end);
1092
+ throw new error_1.PrepareError(`Cannot find import "${currentTarget}"`, {
1093
+ target: currentTarget,
1094
+ range
1095
+ });
1096
+ }
1097
+ yield this.createImport(node, importTarget, code);
1098
+ }
1099
+ this.push({
1100
+ op: instruction_1.OpCode.GET_LOCALS,
1101
+ source: this.getSourceLocation(node)
1102
+ });
1103
+ this.push({
1104
+ op: instruction_1.OpCode.PUSH,
1105
+ source: this.getSourceLocation(node),
1106
+ value: new string_1.CustomString(node.name.name),
1107
+ });
1108
+ this.push({
1109
+ op: instruction_1.OpCode.IMPORT,
1110
+ source: this.getSourceLocation(node),
1111
+ path: importTarget
1112
+ });
1113
+ this.push({
1114
+ op: instruction_1.OpCode.ASSIGN,
1115
+ source: this.getSourceLocation(node)
1116
+ });
1117
+ });
1118
+ }
1119
+ processIncludeExpression(node) {
1120
+ return __awaiter(this, void 0, void 0, function* () {
1121
+ const currentTarget = this.target.peek();
1122
+ const importTarget = yield this.handler.resourceHandler.getTargetRelativeTo(currentTarget, node.path);
1123
+ if (this.target.includes(importTarget)) {
1124
+ console.warn(`Found circular dependency between "${currentTarget}" and "${importTarget}" at line ${node.start.line}. Using noop instead to prevent overflow.`);
1125
+ return;
1126
+ }
1127
+ const code = yield this.handler.resourceHandler.get(importTarget);
1128
+ if (code == null) {
1129
+ const range = new miniscript_core_1.ASTRange(node.start, node.end);
1130
+ throw new error_1.PrepareError(`Cannot find import "${currentTarget}"`, {
1131
+ target: currentTarget,
1132
+ range
1133
+ });
1134
+ }
1135
+ try {
1136
+ this.target.push(importTarget);
1137
+ const childNodes = this.parse(code);
1138
+ yield this.processNode(childNodes);
1139
+ this.target.pop();
1140
+ }
1141
+ catch (err) {
1142
+ if (err instanceof error_1.PrepareError) {
1143
+ throw err;
1144
+ }
1145
+ throw new error_1.PrepareError(err.message, {
1146
+ target: importTarget,
1147
+ range: new miniscript_core_1.ASTRange(node.start, node.end)
1148
+ }, err);
1149
+ }
1150
+ });
1151
+ }
1152
+ processDebuggerExpression(node) {
1153
+ return __awaiter(this, void 0, void 0, function* () {
1154
+ this.push({
1155
+ op: instruction_1.OpCode.BREAKPOINT_ENABLE,
1156
+ source: this.getSourceLocation(node)
1157
+ });
1158
+ this.push({
1159
+ op: instruction_1.OpCode.BREAKPOINT,
1160
+ source: this.getSourceLocation(node)
1161
+ });
1162
+ });
1163
+ }
1164
+ }
1165
+ exports.BytecodeGenerator = BytecodeGenerator;