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
package/dist/cps.js DELETED
@@ -1,202 +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.CPS = exports.defaultCPSVisit = exports.CPSContext = void 0;
13
- const greybel_core_1 = require("greybel-core");
14
- const miniscript_core_1 = require("miniscript-core");
15
- const break_1 = require("./operations/break");
16
- const call_1 = require("./operations/call");
17
- const chunk_1 = require("./operations/chunk");
18
- const continue_1 = require("./operations/continue");
19
- const debugger_statement_1 = require("./operations/debugger-statement");
20
- const envar_1 = require("./operations/envar");
21
- const evaluate_1 = require("./operations/evaluate");
22
- const for_1 = require("./operations/for");
23
- const function_1 = require("./operations/function");
24
- const function_reference_1 = require("./operations/function-reference");
25
- const if_statement_1 = require("./operations/if-statement");
26
- const import_1 = require("./operations/import");
27
- const include_1 = require("./operations/include");
28
- const list_1 = require("./operations/list");
29
- const literal_1 = require("./operations/literal");
30
- const map_1 = require("./operations/map");
31
- const negated_binary_1 = require("./operations/negated-binary");
32
- const new_instance_1 = require("./operations/new-instance");
33
- const noop_1 = require("./operations/noop");
34
- const not_1 = require("./operations/not");
35
- const return_1 = require("./operations/return");
36
- const while_1 = require("./operations/while");
37
- const error_1 = require("./utils/error");
38
- const create_resolve_1 = require("./utils/create-resolve");
39
- const create_assign_1 = require("./utils/create-assign");
40
- class CPSContext {
41
- constructor(target, handler) {
42
- this.target = target;
43
- this.handler = handler;
44
- }
45
- }
46
- exports.CPSContext = CPSContext;
47
- const defaultCPSVisit = (cpsVisit, context, stack, item) => __awaiter(void 0, void 0, void 0, function* () {
48
- const currentTarget = stack[stack.length - 1];
49
- const defaultVisit = cpsVisit.bind(null, cpsVisit, context, stack);
50
- switch (item.type) {
51
- case miniscript_core_1.ASTType.MapConstructorExpression:
52
- return new map_1.MapOperation(item, currentTarget).build(defaultVisit);
53
- case miniscript_core_1.ASTType.ListConstructorExpression:
54
- return new list_1.List(item, currentTarget).build(defaultVisit);
55
- case miniscript_core_1.ASTType.AssignmentStatement:
56
- return (0, create_assign_1.createAssign)(item, currentTarget).build(defaultVisit);
57
- case miniscript_core_1.ASTType.MemberExpression:
58
- case miniscript_core_1.ASTType.IndexExpression:
59
- case miniscript_core_1.ASTType.SliceExpression:
60
- return (0, create_resolve_1.createResolve)(item, currentTarget).build(defaultVisit);
61
- case miniscript_core_1.ASTType.Identifier:
62
- return (0, create_resolve_1.createIdentifierResolve)(item, currentTarget).build(defaultVisit);
63
- case miniscript_core_1.ASTType.FunctionDeclaration:
64
- return new function_1.FunctionOperation(item, currentTarget).build(defaultVisit);
65
- case miniscript_core_1.ASTType.InvalidCodeExpression:
66
- return new noop_1.Noop(item, currentTarget).build(defaultVisit);
67
- case miniscript_core_1.ASTType.WhileStatement:
68
- return new while_1.While(item, currentTarget).build(defaultVisit);
69
- case miniscript_core_1.ASTType.ForGenericStatement:
70
- return new for_1.For(item, currentTarget).build(defaultVisit);
71
- case miniscript_core_1.ASTType.IfStatement:
72
- case miniscript_core_1.ASTType.IfShortcutStatement:
73
- return new if_statement_1.IfStatement(item, currentTarget).build(defaultVisit);
74
- case miniscript_core_1.ASTType.ReturnStatement:
75
- return new return_1.Return(item, currentTarget).build(defaultVisit);
76
- case miniscript_core_1.ASTType.BreakStatement:
77
- return new break_1.Break(item, currentTarget).build(defaultVisit);
78
- case miniscript_core_1.ASTType.ContinueStatement:
79
- return new continue_1.Continue(item, currentTarget).build(defaultVisit);
80
- case miniscript_core_1.ASTType.CallExpression:
81
- return new call_1.Call(item, currentTarget).build(defaultVisit);
82
- case miniscript_core_1.ASTType.CallStatement:
83
- return defaultVisit(item.expression);
84
- case greybel_core_1.ASTType.FeatureImportExpression: {
85
- const importExpr = item;
86
- const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, importExpr.path);
87
- if (stack.includes(target)) {
88
- console.warn(`Found circular dependency between "${currentTarget}" and "${target}" at line ${item.start.line}. Using noop instead to prevent overflow.`);
89
- return new noop_1.Noop(item, target);
90
- }
91
- const code = yield context.handler.resourceHandler.get(target);
92
- if (code == null) {
93
- const range = new miniscript_core_1.ASTRange(item.start, item.end);
94
- throw new error_1.PrepareError(`Cannot find import "${currentTarget}"`, {
95
- target: currentTarget,
96
- range
97
- });
98
- }
99
- try {
100
- const subVisit = cpsVisit.bind(null, cpsVisit, context, [...stack, target]);
101
- const importStatement = yield new import_1.Import(importExpr, currentTarget, target, code).build(subVisit);
102
- return importStatement;
103
- }
104
- catch (err) {
105
- if (err instanceof error_1.PrepareError) {
106
- throw err;
107
- }
108
- throw new error_1.PrepareError(err.message, {
109
- target,
110
- range: new miniscript_core_1.ASTRange(item.start, item.end)
111
- }, err);
112
- }
113
- }
114
- case greybel_core_1.ASTType.FeatureIncludeExpression: {
115
- const includeExpr = item;
116
- const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, includeExpr.path);
117
- if (stack.includes(target)) {
118
- console.warn(`Found circular dependency between "${currentTarget}" and "${target}" at line ${item.start.line}. Using noop instead to prevent overflow.`);
119
- return new noop_1.Noop(item, target);
120
- }
121
- const code = yield context.handler.resourceHandler.get(target);
122
- if (code == null) {
123
- const range = new miniscript_core_1.ASTRange(item.start, item.end);
124
- throw new error_1.PrepareError(`Cannot find include "${currentTarget}"`, {
125
- target: currentTarget,
126
- range
127
- });
128
- }
129
- try {
130
- const subVisit = cpsVisit.bind(null, cpsVisit, context, [...stack, target]);
131
- const importStatement = yield new include_1.Include(includeExpr, currentTarget, target, code).build(subVisit);
132
- return importStatement;
133
- }
134
- catch (err) {
135
- if (err instanceof error_1.PrepareError) {
136
- throw err;
137
- }
138
- throw new error_1.PrepareError(err.message, {
139
- target,
140
- range: new miniscript_core_1.ASTRange(item.start, item.end)
141
- }, err);
142
- }
143
- }
144
- case greybel_core_1.ASTType.FeatureDebuggerExpression:
145
- return new debugger_statement_1.DebuggerStatement(item, currentTarget);
146
- case greybel_core_1.ASTType.FeatureEnvarExpression:
147
- return new envar_1.EnvarExpression(item, currentTarget);
148
- case miniscript_core_1.ASTType.BooleanLiteral:
149
- case miniscript_core_1.ASTType.StringLiteral:
150
- case miniscript_core_1.ASTType.NumericLiteral:
151
- case miniscript_core_1.ASTType.NilLiteral:
152
- return new literal_1.Literal(item, currentTarget).build(defaultVisit);
153
- case miniscript_core_1.ASTType.EmptyExpression:
154
- return new noop_1.Noop(item, currentTarget).build(defaultVisit);
155
- case miniscript_core_1.ASTType.IsaExpression:
156
- case miniscript_core_1.ASTType.BinaryExpression:
157
- case miniscript_core_1.ASTType.LogicalExpression:
158
- return new evaluate_1.Evaluate(item, currentTarget).build(defaultVisit);
159
- case miniscript_core_1.ASTType.NegationExpression:
160
- return new not_1.Not(item, currentTarget).build(defaultVisit);
161
- case miniscript_core_1.ASTType.BinaryNegatedExpression:
162
- return new negated_binary_1.NegatedBinary(item, currentTarget).build(defaultVisit);
163
- case miniscript_core_1.ASTType.UnaryExpression: {
164
- const unaryExpr = item;
165
- if (unaryExpr.operator === 'new') {
166
- return new new_instance_1.NewInstance(unaryExpr).build(defaultVisit);
167
- }
168
- else if (unaryExpr.operator === '@') {
169
- return new function_reference_1.FunctionReference(unaryExpr).build(defaultVisit);
170
- }
171
- const range = new miniscript_core_1.ASTRange(item.start, item.end);
172
- throw new error_1.PrepareError(`Unknown unary expression`, {
173
- target: currentTarget,
174
- range
175
- });
176
- }
177
- case miniscript_core_1.ASTType.Chunk:
178
- return new chunk_1.Chunk(item, currentTarget).build(defaultVisit);
179
- case miniscript_core_1.ASTType.Comment:
180
- return new noop_1.Noop(item, currentTarget);
181
- case miniscript_core_1.ASTType.ParenthesisExpression:
182
- return defaultVisit(item.expression);
183
- default: {
184
- const range = new miniscript_core_1.ASTRange(item.start, item.end);
185
- throw new error_1.PrepareError(`Unexpected AST type ${item.type}`, {
186
- target: currentTarget,
187
- range
188
- });
189
- }
190
- }
191
- });
192
- exports.defaultCPSVisit = defaultCPSVisit;
193
- class CPS {
194
- constructor(context, cpsVisit = exports.defaultCPSVisit) {
195
- this.context = context;
196
- this.__visit = cpsVisit.bind(null, cpsVisit, context, [context.target]);
197
- }
198
- visit(item) {
199
- return this.__visit(item);
200
- }
201
- }
202
- exports.CPS = CPS;
@@ -1,11 +0,0 @@
1
- import { ASTAssignmentStatement } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- export declare class AssignGlobals extends Operation {
6
- readonly item: ASTAssignmentStatement;
7
- right: Operation;
8
- constructor(item: ASTAssignmentStatement, target?: string);
9
- build(visit: CPSVisit): Promise<Operation>;
10
- handle(_ctx: OperationContext): Promise<CustomValue>;
11
- }
@@ -1,31 +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.AssignGlobals = void 0;
13
- const operation_1 = require("./operation");
14
- class AssignGlobals extends operation_1.Operation {
15
- constructor(item, target) {
16
- super(null, target);
17
- this.item = item;
18
- }
19
- build(visit) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- this.right = yield visit(this.item.init);
22
- return this;
23
- });
24
- }
25
- handle(_ctx) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- throw new Error('Cannot assign to globals.');
28
- });
29
- }
30
- }
31
- exports.AssignGlobals = AssignGlobals;
@@ -1,11 +0,0 @@
1
- import { ASTAssignmentStatement } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- export declare class AssignLocals extends Operation {
6
- readonly item: ASTAssignmentStatement;
7
- right: Operation;
8
- constructor(item: ASTAssignmentStatement, target?: string);
9
- build(visit: CPSVisit): Promise<Operation>;
10
- handle(_ctx: OperationContext): Promise<CustomValue>;
11
- }
@@ -1,31 +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.AssignLocals = void 0;
13
- const operation_1 = require("./operation");
14
- class AssignLocals extends operation_1.Operation {
15
- constructor(item, target) {
16
- super(null, target);
17
- this.item = item;
18
- }
19
- build(visit) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- this.right = yield visit(this.item.init);
22
- return this;
23
- });
24
- }
25
- handle(_ctx) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- throw new Error('Cannot assign to locals.');
28
- });
29
- }
30
- }
31
- exports.AssignLocals = AssignLocals;
@@ -1,11 +0,0 @@
1
- import { ASTAssignmentStatement } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- export declare class AssignOuter extends Operation {
6
- readonly item: ASTAssignmentStatement;
7
- right: Operation;
8
- constructor(item: ASTAssignmentStatement, target?: string);
9
- build(visit: CPSVisit): Promise<Operation>;
10
- handle(_ctx: OperationContext): Promise<CustomValue>;
11
- }
@@ -1,31 +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.AssignOuter = void 0;
13
- const operation_1 = require("./operation");
14
- class AssignOuter extends operation_1.Operation {
15
- constructor(item, target) {
16
- super(null, target);
17
- this.item = item;
18
- }
19
- build(visit) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- this.right = yield visit(this.item.init);
22
- return this;
23
- });
24
- }
25
- handle(_ctx) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- throw new Error('Cannot assign to outer.');
28
- });
29
- }
30
- }
31
- exports.AssignOuter = AssignOuter;
@@ -1,11 +0,0 @@
1
- import { ASTAssignmentStatement } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- export declare class AssignSelf extends Operation {
6
- readonly item: ASTAssignmentStatement;
7
- right: Operation;
8
- constructor(item: ASTAssignmentStatement, target?: string);
9
- build(visit: CPSVisit): Promise<Operation>;
10
- handle(ctx: OperationContext): Promise<CustomValue>;
11
- }
@@ -1,41 +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.AssignSelf = void 0;
13
- const default_1 = require("../types/default");
14
- const function_1 = require("./function");
15
- const operation_1 = require("./operation");
16
- class AssignSelf 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
- this.right = yield visit(this.item.init);
24
- return this;
25
- });
26
- }
27
- handle(ctx) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- let rightValue;
30
- if (this.right instanceof function_1.FunctionOperation) {
31
- rightValue = yield this.right.handle(ctx, true);
32
- }
33
- else {
34
- rightValue = yield this.right.handle(ctx);
35
- }
36
- ctx.functionState.context = rightValue;
37
- return default_1.DefaultType.Void;
38
- });
39
- }
40
- }
41
- exports.AssignSelf = AssignSelf;
@@ -1,13 +0,0 @@
1
- import { ASTAssignmentStatement } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- import { Resolve } from './resolve';
6
- export declare class Assign extends Operation {
7
- readonly item: ASTAssignmentStatement;
8
- left: Resolve;
9
- right: Operation;
10
- constructor(item: ASTAssignmentStatement, target?: string);
11
- build(visit: CPSVisit): Promise<Operation>;
12
- handle(ctx: OperationContext): Promise<CustomValue>;
13
- }
@@ -1,60 +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.Assign = void 0;
13
- const default_1 = require("../types/default");
14
- const create_resolve_1 = require("../utils/create-resolve");
15
- const function_1 = require("./function");
16
- const operation_1 = require("./operation");
17
- const resolve_1 = require("./resolve");
18
- class Assign extends operation_1.Operation {
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
- this.left = (0, create_resolve_1.createResolve)(this.item.variable, this.target);
26
- yield this.left.build(visit);
27
- this.right = yield visit(this.item.init);
28
- return this;
29
- });
30
- }
31
- handle(ctx) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const exitObserver = ctx.processState.createExitObserver();
34
- const resolveResult = yield this.left.getResult(ctx);
35
- exitObserver.close();
36
- if (exitObserver.occured()) {
37
- return default_1.DefaultType.Void;
38
- }
39
- if (resolveResult.path.count() === 0) {
40
- throw new Error('Resolve path cannot be empty.');
41
- }
42
- let rightValue;
43
- if (this.right instanceof function_1.FunctionOperation) {
44
- rightValue = yield this.right.handle(ctx, true);
45
- }
46
- else {
47
- rightValue = yield this.right.handle(ctx);
48
- }
49
- if (!(resolveResult.handle instanceof resolve_1.ResolveNil)) {
50
- const resultValueCtx = resolveResult.handle;
51
- resultValueCtx.set(resolveResult.path, rightValue);
52
- }
53
- else {
54
- ctx.set(resolveResult.path, rightValue);
55
- }
56
- return default_1.DefaultType.Void;
57
- });
58
- }
59
- }
60
- exports.Assign = Assign;
@@ -1,13 +0,0 @@
1
- import { ASTBase } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- export interface IsEOL {
6
- (): boolean;
7
- }
8
- export declare class Block extends Operation {
9
- readonly stack: Array<Operation>;
10
- constructor(item: ASTBase, stack: Array<Operation>);
11
- build(_visit: CPSVisit): Promise<Block>;
12
- handle(ctx: OperationContext): Promise<CustomValue>;
13
- }
@@ -1,48 +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.Block = void 0;
13
- const context_1 = require("../context");
14
- const default_1 = require("../types/default");
15
- const operation_1 = require("./operation");
16
- class Block extends operation_1.Operation {
17
- constructor(item, stack) {
18
- super(item, 'block');
19
- this.stack = stack;
20
- }
21
- build(_visit) {
22
- return Promise.resolve(this);
23
- }
24
- handle(ctx) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- let isEOL = () => false;
27
- if (ctx.type === context_1.ContextType.Loop) {
28
- isEOL = () => ctx.functionState.isReturn ||
29
- ctx.loopState.isBreak ||
30
- ctx.loopState.isContinue;
31
- }
32
- else if (ctx.type === context_1.ContextType.Function) {
33
- isEOL = () => ctx.functionState.isReturn;
34
- }
35
- const exitObserver = ctx.processState.createExitObserver();
36
- for (let index = 0; index < this.stack.length; index++) {
37
- if (isEOL() || exitObserver.occured()) {
38
- break;
39
- }
40
- const op = this.stack[index];
41
- yield ctx.step(op);
42
- }
43
- exitObserver.close();
44
- return default_1.DefaultType.Void;
45
- });
46
- }
47
- }
48
- exports.Block = Block;
@@ -1,10 +0,0 @@
1
- import { ASTBase } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- export declare class Break extends Operation {
6
- readonly item: ASTBase;
7
- constructor(item: ASTBase, target?: string);
8
- build(_visit: CPSVisit): Promise<Break>;
9
- handle(ctx: OperationContext): Promise<CustomValue>;
10
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Break = void 0;
4
- const default_1 = require("../types/default");
5
- const operation_1 = require("./operation");
6
- class Break extends operation_1.Operation {
7
- constructor(item, target) {
8
- super(null, target);
9
- this.item = item;
10
- }
11
- build(_visit) {
12
- return Promise.resolve(this);
13
- }
14
- handle(ctx) {
15
- if (ctx.loopState !== null) {
16
- ctx.loopState.isBreak = true;
17
- }
18
- return Promise.resolve(default_1.DefaultType.Void);
19
- }
20
- }
21
- exports.Break = Break;
@@ -1,13 +0,0 @@
1
- import { ASTCallExpression } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- import { Resolve } from './resolve';
6
- export declare class Call extends Operation {
7
- readonly item: ASTCallExpression;
8
- fnRef: Resolve;
9
- args: Array<Operation>;
10
- constructor(item: ASTCallExpression, target?: string);
11
- build(visit: CPSVisit): Promise<Call>;
12
- handle(ctx: OperationContext): Promise<CustomValue>;
13
- }
@@ -1,64 +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.Call = void 0;
13
- const default_1 = require("../types/default");
14
- const function_1 = require("../types/function");
15
- const create_resolve_1 = require("../utils/create-resolve");
16
- const operation_1 = require("./operation");
17
- class Call extends operation_1.Operation {
18
- constructor(item, target) {
19
- super(null, target);
20
- this.item = item;
21
- }
22
- build(visit) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- this.fnRef = (0, create_resolve_1.createResolve)(this.item.base, this.target);
25
- yield this.fnRef.build(visit);
26
- const args = this.item.arguments.map((arg) => visit(arg));
27
- this.args = yield Promise.all(args);
28
- return this;
29
- });
30
- }
31
- handle(ctx) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const exitObserver = ctx.processState.createExitObserver();
34
- const resolveResult = yield this.fnRef.getResult(ctx);
35
- if (exitObserver.occured()) {
36
- exitObserver.close();
37
- return default_1.DefaultType.Void;
38
- }
39
- const valueRef = yield this.fnRef.handle(ctx, resolveResult, false);
40
- const fnArgs = [];
41
- for (let index = 0; index < this.args.length; index++) {
42
- if (exitObserver.occured()) {
43
- exitObserver.close();
44
- return default_1.DefaultType.Void;
45
- }
46
- fnArgs.push(yield this.args[index].handle(ctx));
47
- }
48
- if (exitObserver.occured()) {
49
- exitObserver.close();
50
- return default_1.DefaultType.Void;
51
- }
52
- exitObserver.close();
53
- if (valueRef instanceof function_1.CustomFunction) {
54
- const func = valueRef;
55
- if (this.fnRef.path.isSuper() && ctx.functionState.context) {
56
- return func.run(ctx.functionState.context, fnArgs, ctx);
57
- }
58
- return func.run(resolveResult.handle, fnArgs, ctx);
59
- }
60
- return default_1.DefaultType.Void;
61
- });
62
- }
63
- }
64
- exports.Call = Call;
@@ -1,12 +0,0 @@
1
- import { ASTChunk } 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 Chunk extends OperationBlock {
7
- readonly item: ASTChunk;
8
- block: Block;
9
- constructor(item: ASTChunk, target?: string);
10
- build(visit: CPSVisit): Promise<Operation>;
11
- handle(ctx: OperationContext): Promise<CustomValue>;
12
- }