greybel-interpreter 1.4.6 → 1.4.7

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 (101) hide show
  1. package/.editorconfig +14 -14
  2. package/.eslintrc +47 -47
  3. package/LICENSE +21 -21
  4. package/README.md +2 -2
  5. package/dist/context.d.ts +110 -110
  6. package/dist/context.js +306 -306
  7. package/dist/cps.d.ts +14 -14
  8. package/dist/cps.js +160 -160
  9. package/dist/handler/error.d.ts +6 -6
  10. package/dist/handler/error.js +12 -12
  11. package/dist/handler/output.d.ts +18 -18
  12. package/dist/handler/output.js +29 -29
  13. package/dist/handler/resource.d.ts +12 -12
  14. package/dist/handler/resource.js +28 -28
  15. package/dist/handler-container.d.ts +14 -14
  16. package/dist/handler-container.js +14 -14
  17. package/dist/index.d.ts +46 -46
  18. package/dist/index.js +132 -132
  19. package/dist/interpreter.d.ts +42 -42
  20. package/dist/interpreter.js +218 -218
  21. package/dist/operations/assign.d.ts +13 -13
  22. package/dist/operations/assign.js +46 -46
  23. package/dist/operations/block.d.ts +12 -12
  24. package/dist/operations/block.js +52 -52
  25. package/dist/operations/break.d.ts +10 -10
  26. package/dist/operations/break.js +23 -23
  27. package/dist/operations/call.d.ts +13 -13
  28. package/dist/operations/call.js +49 -49
  29. package/dist/operations/chunk.d.ts +12 -12
  30. package/dist/operations/chunk.js +33 -33
  31. package/dist/operations/continue.d.ts +10 -10
  32. package/dist/operations/continue.js +23 -23
  33. package/dist/operations/debugger-statement.d.ts +10 -10
  34. package/dist/operations/debugger-statement.js +21 -21
  35. package/dist/operations/evaluate.d.ts +40 -40
  36. package/dist/operations/evaluate.js +334 -334
  37. package/dist/operations/for.d.ts +14 -14
  38. package/dist/operations/for.js +81 -81
  39. package/dist/operations/function-reference.d.ts +12 -12
  40. package/dist/operations/function-reference.js +44 -44
  41. package/dist/operations/function.d.ts +14 -14
  42. package/dist/operations/function.js +72 -72
  43. package/dist/operations/if-statement.d.ts +19 -19
  44. package/dist/operations/if-statement.js +85 -85
  45. package/dist/operations/import.d.ts +17 -17
  46. package/dist/operations/import.js +57 -57
  47. package/dist/operations/include.d.ts +13 -13
  48. package/dist/operations/include.js +41 -41
  49. package/dist/operations/list.d.ts +11 -11
  50. package/dist/operations/list.js +42 -42
  51. package/dist/operations/literal.d.ts +11 -11
  52. package/dist/operations/literal.js +40 -40
  53. package/dist/operations/map.d.ts +11 -11
  54. package/dist/operations/map.js +44 -44
  55. package/dist/operations/negated-binary.d.ts +11 -11
  56. package/dist/operations/negated-binary.js +42 -42
  57. package/dist/operations/new-instance.d.ts +11 -11
  58. package/dist/operations/new-instance.js +39 -39
  59. package/dist/operations/noop.d.ts +9 -9
  60. package/dist/operations/noop.js +19 -19
  61. package/dist/operations/not.d.ts +11 -11
  62. package/dist/operations/not.js +35 -35
  63. package/dist/operations/operation.d.ts +13 -13
  64. package/dist/operations/operation.js +9 -9
  65. package/dist/operations/reference.d.ts +9 -9
  66. package/dist/operations/reference.js +19 -19
  67. package/dist/operations/resolve.d.ts +38 -38
  68. package/dist/operations/resolve.js +210 -210
  69. package/dist/operations/return.d.ts +11 -11
  70. package/dist/operations/return.js +45 -45
  71. package/dist/operations/while.d.ts +13 -13
  72. package/dist/operations/while.js +65 -65
  73. package/dist/types/base.d.ts +9 -9
  74. package/dist/types/base.js +5 -5
  75. package/dist/types/boolean.d.ts +13 -13
  76. package/dist/types/boolean.js +34 -34
  77. package/dist/types/default.d.ts +8 -8
  78. package/dist/types/default.js +14 -14
  79. package/dist/types/function.d.ts +32 -32
  80. package/dist/types/function.js +104 -104
  81. package/dist/types/interface.d.ts +24 -24
  82. package/dist/types/interface.js +83 -83
  83. package/dist/types/list.d.ts +29 -29
  84. package/dist/types/list.js +158 -158
  85. package/dist/types/map.d.ts +33 -33
  86. package/dist/types/map.js +200 -200
  87. package/dist/types/nil.d.ts +11 -11
  88. package/dist/types/nil.js +33 -33
  89. package/dist/types/number.d.ts +25 -25
  90. package/dist/types/number.js +69 -69
  91. package/dist/types/string.d.ts +31 -31
  92. package/dist/types/string.js +121 -121
  93. package/dist/types/with-intrinsics.d.ts +15 -15
  94. package/dist/types/with-intrinsics.js +19 -19
  95. package/dist/utils/deep-equal.d.ts +1 -1
  96. package/dist/utils/deep-equal.js +37 -37
  97. package/dist/utils/object-value.d.ts +7 -7
  98. package/dist/utils/object-value.js +42 -42
  99. package/dist/utils/path.d.ts +10 -10
  100. package/dist/utils/path.js +32 -32
  101. package/package.json +58 -58
@@ -1,38 +1,38 @@
1
- import { ASTBase } from 'greyscript-core';
2
- import OperationContext from '../context';
3
- import CustomValue from '../types/base';
4
- import Path from '../utils/path';
5
- import Operation, { CPSVisit } from './operation';
6
- export declare class SliceSegment {
7
- readonly left: Operation;
8
- readonly right: Operation;
9
- constructor(left: Operation, right: Operation);
10
- }
11
- export declare class IdentifierSegment {
12
- readonly value: string;
13
- constructor(value: string);
14
- }
15
- export declare class IndexSegment {
16
- readonly op: Operation;
17
- constructor(op: Operation);
18
- }
19
- export declare class OperationSegment {
20
- readonly op: Operation;
21
- constructor(op: Operation);
22
- }
23
- export declare type Segment = SliceSegment | IdentifierSegment | IndexSegment | OperationSegment;
24
- export declare class ResolveResult {
25
- readonly path: Path<CustomValue>;
26
- readonly handle: CustomValue;
27
- constructor(path: Path<CustomValue>, handle: CustomValue);
28
- }
29
- export default class Resolve extends Operation {
30
- readonly item: ASTBase;
31
- path: Array<Segment>;
32
- last: Segment;
33
- constructor(item: ASTBase, target?: string);
34
- buildProcessor(node: ASTBase, visit: CPSVisit): Promise<void>;
35
- build(visit: CPSVisit): Promise<Resolve>;
36
- getResult(ctx: OperationContext): Promise<ResolveResult>;
37
- handle(ctx: OperationContext, result?: ResolveResult, autoCall?: boolean): Promise<CustomValue>;
38
- }
1
+ import { ASTBase } from 'greyscript-core';
2
+ import OperationContext from '../context';
3
+ import CustomValue from '../types/base';
4
+ import Path from '../utils/path';
5
+ import Operation, { CPSVisit } from './operation';
6
+ export declare class SliceSegment {
7
+ readonly left: Operation;
8
+ readonly right: Operation;
9
+ constructor(left: Operation, right: Operation);
10
+ }
11
+ export declare class IdentifierSegment {
12
+ readonly value: string;
13
+ constructor(value: string);
14
+ }
15
+ export declare class IndexSegment {
16
+ readonly op: Operation;
17
+ constructor(op: Operation);
18
+ }
19
+ export declare class OperationSegment {
20
+ readonly op: Operation;
21
+ constructor(op: Operation);
22
+ }
23
+ export declare type Segment = SliceSegment | IdentifierSegment | IndexSegment | OperationSegment;
24
+ export declare class ResolveResult {
25
+ readonly path: Path<CustomValue>;
26
+ readonly handle: CustomValue;
27
+ constructor(path: Path<CustomValue>, handle: CustomValue);
28
+ }
29
+ export default class Resolve extends Operation {
30
+ readonly item: ASTBase;
31
+ path: Array<Segment>;
32
+ last: Segment;
33
+ constructor(item: ASTBase, target?: string);
34
+ buildProcessor(node: ASTBase, visit: CPSVisit): Promise<void>;
35
+ build(visit: CPSVisit): Promise<Resolve>;
36
+ getResult(ctx: OperationContext): Promise<ResolveResult>;
37
+ handle(ctx: OperationContext, result?: ResolveResult, autoCall?: boolean): Promise<CustomValue>;
38
+ }
@@ -1,210 +1,210 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.ResolveResult = exports.OperationSegment = exports.IndexSegment = exports.IdentifierSegment = exports.SliceSegment = void 0;
16
- const greyscript_core_1 = require("greyscript-core");
17
- const default_1 = __importDefault(require("../types/default"));
18
- const function_1 = __importDefault(require("../types/function"));
19
- const list_1 = __importDefault(require("../types/list"));
20
- const string_1 = __importDefault(require("../types/string"));
21
- const with_intrinsics_1 = require("../types/with-intrinsics");
22
- const path_1 = __importDefault(require("../utils/path"));
23
- const operation_1 = __importDefault(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 IdentifierSegment {
32
- constructor(value) {
33
- this.value = value;
34
- }
35
- }
36
- exports.IdentifierSegment = IdentifierSegment;
37
- class IndexSegment {
38
- constructor(op) {
39
- this.op = op;
40
- }
41
- }
42
- exports.IndexSegment = IndexSegment;
43
- class OperationSegment {
44
- constructor(op) {
45
- this.op = op;
46
- }
47
- }
48
- exports.OperationSegment = OperationSegment;
49
- class ResolveResult {
50
- constructor(path, handle) {
51
- this.path = path;
52
- this.handle = handle;
53
- }
54
- }
55
- exports.ResolveResult = ResolveResult;
56
- class Resolve extends operation_1.default {
57
- constructor(item, target) {
58
- super(null, target);
59
- this.item = item;
60
- }
61
- buildProcessor(node, visit) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- switch (node.type) {
64
- case greyscript_core_1.ASTType.MemberExpression: {
65
- const memberExpr = node;
66
- yield this.buildProcessor(memberExpr.base, visit);
67
- yield this.buildProcessor(memberExpr.identifier, visit);
68
- break;
69
- }
70
- case greyscript_core_1.ASTType.IndexExpression: {
71
- const indexExpr = node;
72
- yield this.buildProcessor(indexExpr.base, visit);
73
- if (indexExpr.index.type === greyscript_core_1.ASTType.SliceExpression) {
74
- const sliceExpr = indexExpr.index;
75
- const left = yield visit(sliceExpr.left);
76
- const right = yield visit(sliceExpr.right);
77
- const sliceSegment = new SliceSegment(left, right);
78
- this.path.push(sliceSegment);
79
- }
80
- else {
81
- const indexSegment = new IndexSegment(yield visit(indexExpr.index));
82
- this.path.push(indexSegment);
83
- }
84
- break;
85
- }
86
- case greyscript_core_1.ASTType.Identifier: {
87
- const identifier = node;
88
- const identifierSegment = new IdentifierSegment(identifier.name);
89
- this.path.push(identifierSegment);
90
- break;
91
- }
92
- default: {
93
- const opSegment = new OperationSegment(yield visit(node));
94
- this.path.push(opSegment);
95
- break;
96
- }
97
- }
98
- });
99
- }
100
- build(visit) {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- this.path = [];
103
- yield this.buildProcessor(this.item, visit);
104
- this.last = this.path[this.path.length - 1];
105
- return this;
106
- });
107
- }
108
- getResult(ctx) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- let traversedPath = new path_1.default();
111
- let handle = default_1.default.Void;
112
- const maxIndex = this.path.length;
113
- const lastIndex = maxIndex - 1;
114
- for (let index = 0; index < maxIndex; index++) {
115
- const current = this.path[index];
116
- if (current instanceof OperationSegment) {
117
- const opSegment = current;
118
- handle = yield opSegment.op.handle(ctx);
119
- }
120
- else if (current instanceof IdentifierSegment) {
121
- const identifierSegment = current;
122
- traversedPath.add(new string_1.default(identifierSegment.value));
123
- if (index === lastIndex) {
124
- break;
125
- }
126
- const previous = handle;
127
- if (handle !== default_1.default.Void) {
128
- if (handle instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
129
- const customValueCtx = handle;
130
- handle = customValueCtx.get(traversedPath);
131
- }
132
- else {
133
- throw new Error('Handle has no properties.');
134
- }
135
- }
136
- else {
137
- handle = ctx.get(traversedPath);
138
- }
139
- if (handle instanceof function_1.default) {
140
- handle = yield handle.run(previous || default_1.default.Void, [], ctx);
141
- }
142
- traversedPath = new path_1.default();
143
- }
144
- else if (current instanceof IndexSegment) {
145
- const indexSegment = current;
146
- const indexValue = yield indexSegment.op.handle(ctx);
147
- traversedPath.add(indexValue);
148
- if (index === lastIndex) {
149
- break;
150
- }
151
- if (handle !== default_1.default.Void) {
152
- if (handle instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
153
- const customValueCtx = handle;
154
- handle = customValueCtx.get(traversedPath);
155
- }
156
- else {
157
- throw new Error('Handle has no properties.');
158
- }
159
- }
160
- else {
161
- handle = ctx.get(traversedPath);
162
- }
163
- traversedPath = new path_1.default();
164
- }
165
- else if (current instanceof SliceSegment) {
166
- const sliceSegment = current;
167
- const left = yield sliceSegment.left.handle(ctx);
168
- const right = yield sliceSegment.right.handle(ctx);
169
- if (handle instanceof list_1.default || handle instanceof string_1.default) {
170
- handle = handle.slice(left, right);
171
- }
172
- else {
173
- throw new Error(`Unexpected slice attempt. ${handle.getCustomType()} does not seem to support slicing.`);
174
- }
175
- }
176
- }
177
- return new ResolveResult(traversedPath, handle);
178
- });
179
- }
180
- handle(ctx, result = null, autoCall = true) {
181
- return __awaiter(this, void 0, void 0, function* () {
182
- if (result === null) {
183
- result = yield this.getResult(ctx);
184
- }
185
- if (result.handle !== default_1.default.Void) {
186
- if (result.path.count() === 0) {
187
- if (autoCall && result.handle instanceof function_1.default) {
188
- return result.handle.run(default_1.default.Void, [], ctx);
189
- }
190
- return result.handle;
191
- }
192
- const customValueCtx = result.handle;
193
- const child = customValueCtx.get(result.path);
194
- if (autoCall &&
195
- child instanceof function_1.default &&
196
- // support index bug in greyscript
197
- !(this.last instanceof IndexSegment)) {
198
- return child.run(customValueCtx, [], ctx);
199
- }
200
- return child;
201
- }
202
- const handle = ctx.get(result.path);
203
- if (autoCall && handle instanceof function_1.default) {
204
- return handle.run(default_1.default.Void, [], ctx);
205
- }
206
- return handle;
207
- });
208
- }
209
- }
210
- exports.default = Resolve;
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ResolveResult = exports.OperationSegment = exports.IndexSegment = exports.IdentifierSegment = exports.SliceSegment = void 0;
16
+ const greyscript_core_1 = require("greyscript-core");
17
+ const default_1 = __importDefault(require("../types/default"));
18
+ const function_1 = __importDefault(require("../types/function"));
19
+ const list_1 = __importDefault(require("../types/list"));
20
+ const string_1 = __importDefault(require("../types/string"));
21
+ const with_intrinsics_1 = require("../types/with-intrinsics");
22
+ const path_1 = __importDefault(require("../utils/path"));
23
+ const operation_1 = __importDefault(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 IdentifierSegment {
32
+ constructor(value) {
33
+ this.value = value;
34
+ }
35
+ }
36
+ exports.IdentifierSegment = IdentifierSegment;
37
+ class IndexSegment {
38
+ constructor(op) {
39
+ this.op = op;
40
+ }
41
+ }
42
+ exports.IndexSegment = IndexSegment;
43
+ class OperationSegment {
44
+ constructor(op) {
45
+ this.op = op;
46
+ }
47
+ }
48
+ exports.OperationSegment = OperationSegment;
49
+ class ResolveResult {
50
+ constructor(path, handle) {
51
+ this.path = path;
52
+ this.handle = handle;
53
+ }
54
+ }
55
+ exports.ResolveResult = ResolveResult;
56
+ class Resolve extends operation_1.default {
57
+ constructor(item, target) {
58
+ super(null, target);
59
+ this.item = item;
60
+ }
61
+ buildProcessor(node, visit) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ switch (node.type) {
64
+ case greyscript_core_1.ASTType.MemberExpression: {
65
+ const memberExpr = node;
66
+ yield this.buildProcessor(memberExpr.base, visit);
67
+ yield this.buildProcessor(memberExpr.identifier, visit);
68
+ break;
69
+ }
70
+ case greyscript_core_1.ASTType.IndexExpression: {
71
+ const indexExpr = node;
72
+ yield this.buildProcessor(indexExpr.base, visit);
73
+ if (indexExpr.index.type === greyscript_core_1.ASTType.SliceExpression) {
74
+ const sliceExpr = indexExpr.index;
75
+ const left = yield visit(sliceExpr.left);
76
+ const right = yield visit(sliceExpr.right);
77
+ const sliceSegment = new SliceSegment(left, right);
78
+ this.path.push(sliceSegment);
79
+ }
80
+ else {
81
+ const indexSegment = new IndexSegment(yield visit(indexExpr.index));
82
+ this.path.push(indexSegment);
83
+ }
84
+ break;
85
+ }
86
+ case greyscript_core_1.ASTType.Identifier: {
87
+ const identifier = node;
88
+ const identifierSegment = new IdentifierSegment(identifier.name);
89
+ this.path.push(identifierSegment);
90
+ break;
91
+ }
92
+ default: {
93
+ const opSegment = new OperationSegment(yield visit(node));
94
+ this.path.push(opSegment);
95
+ break;
96
+ }
97
+ }
98
+ });
99
+ }
100
+ build(visit) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ this.path = [];
103
+ yield this.buildProcessor(this.item, visit);
104
+ this.last = this.path[this.path.length - 1];
105
+ return this;
106
+ });
107
+ }
108
+ getResult(ctx) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ let traversedPath = new path_1.default();
111
+ let handle = default_1.default.Void;
112
+ const maxIndex = this.path.length;
113
+ const lastIndex = maxIndex - 1;
114
+ for (let index = 0; index < maxIndex; index++) {
115
+ const current = this.path[index];
116
+ if (current instanceof OperationSegment) {
117
+ const opSegment = current;
118
+ handle = yield opSegment.op.handle(ctx);
119
+ }
120
+ else if (current instanceof IdentifierSegment) {
121
+ const identifierSegment = current;
122
+ traversedPath.add(new string_1.default(identifierSegment.value));
123
+ if (index === lastIndex) {
124
+ break;
125
+ }
126
+ const previous = handle;
127
+ if (handle !== default_1.default.Void) {
128
+ if (handle instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
129
+ const customValueCtx = handle;
130
+ handle = customValueCtx.get(traversedPath);
131
+ }
132
+ else {
133
+ throw new Error('Handle has no properties.');
134
+ }
135
+ }
136
+ else {
137
+ handle = ctx.get(traversedPath);
138
+ }
139
+ if (handle instanceof function_1.default) {
140
+ handle = yield handle.run(previous || default_1.default.Void, [], ctx);
141
+ }
142
+ traversedPath = new path_1.default();
143
+ }
144
+ else if (current instanceof IndexSegment) {
145
+ const indexSegment = current;
146
+ const indexValue = yield indexSegment.op.handle(ctx);
147
+ traversedPath.add(indexValue);
148
+ if (index === lastIndex) {
149
+ break;
150
+ }
151
+ if (handle !== default_1.default.Void) {
152
+ if (handle instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
153
+ const customValueCtx = handle;
154
+ handle = customValueCtx.get(traversedPath);
155
+ }
156
+ else {
157
+ throw new Error('Handle has no properties.');
158
+ }
159
+ }
160
+ else {
161
+ handle = ctx.get(traversedPath);
162
+ }
163
+ traversedPath = new path_1.default();
164
+ }
165
+ else if (current instanceof SliceSegment) {
166
+ const sliceSegment = current;
167
+ const left = yield sliceSegment.left.handle(ctx);
168
+ const right = yield sliceSegment.right.handle(ctx);
169
+ if (handle instanceof list_1.default || handle instanceof string_1.default) {
170
+ handle = handle.slice(left, right);
171
+ }
172
+ else {
173
+ throw new Error(`Unexpected slice attempt. ${handle.getCustomType()} does not seem to support slicing.`);
174
+ }
175
+ }
176
+ }
177
+ return new ResolveResult(traversedPath, handle);
178
+ });
179
+ }
180
+ handle(ctx, result = null, autoCall = true) {
181
+ return __awaiter(this, void 0, void 0, function* () {
182
+ if (result === null) {
183
+ result = yield this.getResult(ctx);
184
+ }
185
+ if (result.handle !== default_1.default.Void) {
186
+ if (result.path.count() === 0) {
187
+ if (autoCall && result.handle instanceof function_1.default) {
188
+ return result.handle.run(default_1.default.Void, [], ctx);
189
+ }
190
+ return result.handle;
191
+ }
192
+ const customValueCtx = result.handle;
193
+ const child = customValueCtx.get(result.path);
194
+ if (autoCall &&
195
+ child instanceof function_1.default &&
196
+ // support index bug in greyscript
197
+ !(this.last instanceof IndexSegment)) {
198
+ return child.run(customValueCtx, [], ctx);
199
+ }
200
+ return child;
201
+ }
202
+ const handle = ctx.get(result.path);
203
+ if (autoCall && handle instanceof function_1.default) {
204
+ return handle.run(default_1.default.Void, [], ctx);
205
+ }
206
+ return handle;
207
+ });
208
+ }
209
+ }
210
+ exports.default = Resolve;
@@ -1,11 +1,11 @@
1
- import { ASTReturnStatement } from 'greyscript-core';
2
- import context from '../context';
3
- import CustomValue from '../types/base';
4
- import Operation, { CPSVisit } from './operation';
5
- export default 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: context): Promise<CustomValue>;
11
- }
1
+ import { ASTReturnStatement } from 'greyscript-core';
2
+ import context from '../context';
3
+ import CustomValue from '../types/base';
4
+ import Operation, { CPSVisit } from './operation';
5
+ export default 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: context): Promise<CustomValue>;
11
+ }
@@ -1,45 +1,45 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const default_1 = __importDefault(require("../types/default"));
16
- const operation_1 = __importDefault(require("./operation"));
17
- const reference_1 = __importDefault(require("./reference"));
18
- class Return extends operation_1.default {
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
- if (this.item.argument) {
26
- this.arg = yield visit(this.item.argument);
27
- }
28
- else {
29
- this.arg = new reference_1.default(default_1.default.Void);
30
- }
31
- return this;
32
- });
33
- }
34
- handle(ctx) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- // no typesafe equal
37
- if (ctx.functionState != null) {
38
- ctx.functionState.value = yield this.arg.handle(ctx);
39
- ctx.functionState.isReturn = true;
40
- }
41
- return default_1.default.Void;
42
- });
43
- }
44
- }
45
- exports.default = Return;
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const default_1 = __importDefault(require("../types/default"));
16
+ const operation_1 = __importDefault(require("./operation"));
17
+ const reference_1 = __importDefault(require("./reference"));
18
+ class Return extends operation_1.default {
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
+ if (this.item.argument) {
26
+ this.arg = yield visit(this.item.argument);
27
+ }
28
+ else {
29
+ this.arg = new reference_1.default(default_1.default.Void);
30
+ }
31
+ return this;
32
+ });
33
+ }
34
+ handle(ctx) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ // no typesafe equal
37
+ if (ctx.functionState != null) {
38
+ ctx.functionState.value = yield this.arg.handle(ctx);
39
+ ctx.functionState.isReturn = true;
40
+ }
41
+ return default_1.default.Void;
42
+ });
43
+ }
44
+ }
45
+ exports.default = Return;
@@ -1,13 +1,13 @@
1
- import { ASTWhileStatement } from 'greyscript-core';
2
- import context from '../context';
3
- import CustomValue from '../types/base';
4
- import Block from './block';
5
- import Operation, { CPSVisit } from './operation';
6
- export default class While extends Operation {
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: context): Promise<CustomValue>;
13
- }
1
+ import { ASTWhileStatement } from 'greyscript-core';
2
+ import context from '../context';
3
+ import CustomValue from '../types/base';
4
+ import Block from './block';
5
+ import Operation, { CPSVisit } from './operation';
6
+ export default class While extends Operation {
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: context): Promise<CustomValue>;
13
+ }