@elaraai/east 0.0.1-beta.28 → 0.0.1-beta.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/analyze.d.ts.map +1 -1
- package/dist/src/analyze.js +12 -4
- package/dist/src/analyze.js.map +1 -1
- package/dist/src/ast.d.ts +33 -33
- package/dist/src/ast.d.ts.map +1 -1
- package/dist/src/ast_to_ir.d.ts +2 -2
- package/dist/src/ast_to_ir.d.ts.map +1 -1
- package/dist/src/ast_to_ir.js +100 -100
- package/dist/src/ast_to_ir.js.map +1 -1
- package/dist/src/compile.d.ts +20 -1
- package/dist/src/compile.d.ts.map +1 -1
- package/dist/src/compile.js +103 -84
- package/dist/src/compile.js.map +1 -1
- package/dist/src/error.d.ts +8 -1
- package/dist/src/error.d.ts.map +1 -1
- package/dist/src/error.js +11 -1
- package/dist/src/error.js.map +1 -1
- package/dist/src/expr/array.js +48 -48
- package/dist/src/expr/array.js.map +1 -1
- package/dist/src/expr/ast.d.ts +1 -1
- package/dist/src/expr/ast.d.ts.map +1 -1
- package/dist/src/expr/ast.js +14 -14
- package/dist/src/expr/ast.js.map +1 -1
- package/dist/src/expr/asyncfunction.js +1 -1
- package/dist/src/expr/asyncfunction.js.map +1 -1
- package/dist/src/expr/blob.js +7 -7
- package/dist/src/expr/blob.js.map +1 -1
- package/dist/src/expr/block.d.ts +2 -2
- package/dist/src/expr/block.d.ts.map +1 -1
- package/dist/src/expr/block.js +131 -131
- package/dist/src/expr/block.js.map +1 -1
- package/dist/src/expr/boolean.js +5 -5
- package/dist/src/expr/boolean.js.map +1 -1
- package/dist/src/expr/datetime.js +33 -33
- package/dist/src/expr/datetime.js.map +1 -1
- package/dist/src/expr/dict.js +55 -55
- package/dist/src/expr/dict.js.map +1 -1
- package/dist/src/expr/expr.d.ts +1 -1
- package/dist/src/expr/expr.d.ts.map +1 -1
- package/dist/src/expr/expr.js.map +1 -1
- package/dist/src/expr/float.js +16 -16
- package/dist/src/expr/float.js.map +1 -1
- package/dist/src/expr/function.js +1 -1
- package/dist/src/expr/function.js.map +1 -1
- package/dist/src/expr/integer.js +17 -17
- package/dist/src/expr/integer.js.map +1 -1
- package/dist/src/expr/libs/blob.js +2 -2
- package/dist/src/expr/libs/blob.js.map +1 -1
- package/dist/src/expr/libs/string.js +1 -1
- package/dist/src/expr/libs/string.js.map +1 -1
- package/dist/src/expr/recursive.js +2 -2
- package/dist/src/expr/recursive.js.map +1 -1
- package/dist/src/expr/ref.js +3 -3
- package/dist/src/expr/ref.js.map +1 -1
- package/dist/src/expr/set.js +45 -45
- package/dist/src/expr/set.js.map +1 -1
- package/dist/src/expr/string.js +22 -22
- package/dist/src/expr/string.js.map +1 -1
- package/dist/src/expr/struct.d.ts +1 -1
- package/dist/src/expr/struct.d.ts.map +1 -1
- package/dist/src/expr/struct.js +1 -1
- package/dist/src/expr/struct.js.map +1 -1
- package/dist/src/expr/variant.js +2 -2
- package/dist/src/expr/variant.js.map +1 -1
- package/dist/src/ir.d.ts +121 -114
- package/dist/src/ir.d.ts.map +1 -1
- package/dist/src/ir.js +49 -34
- package/dist/src/ir.js.map +1 -1
- package/dist/src/location.d.ts +30 -10
- package/dist/src/location.d.ts.map +1 -1
- package/dist/src/location.js +70 -28
- package/dist/src/location.js.map +1 -1
- package/dist/src/serialization/beast2.d.ts +1 -1
- package/dist/src/serialization/beast2.d.ts.map +1 -1
- package/dist/src/serialization/beast2.js +131 -22
- package/dist/src/serialization/beast2.js.map +1 -1
- package/dist/src/serialization/index.d.ts +1 -1
- package/dist/src/serialization/index.d.ts.map +1 -1
- package/dist/src/serialization/index.js +1 -1
- package/dist/src/serialization/index.js.map +1 -1
- package/package.json +1 -1
package/dist/src/expr/block.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
5
|
import {} from "../ast.js";
|
|
6
|
-
import { get_location,
|
|
6
|
+
import { get_location, printLocations } from "../location.js";
|
|
7
7
|
import { FunctionType, isSubtype, NullType, printType, isTypeEqual, StringType, NeverType, VariantType, BooleanType, TypeUnion, IntegerType, StructType, ArrayType, AsyncFunctionType } from "../types.js";
|
|
8
8
|
import { AstSymbol, Expr, TypeSymbol } from "./expr.js";
|
|
9
9
|
import { NeverExpr } from "./never.js";
|
|
@@ -85,7 +85,7 @@ export function fromAst(ast) {
|
|
|
85
85
|
return createAsyncFunctionExpr(ast.type.inputs, ast.type.output, ast, fromAst);
|
|
86
86
|
}
|
|
87
87
|
else {
|
|
88
|
-
throw new Error(`fromAst not implemented for type ${printType(ast.type)} at ${
|
|
88
|
+
throw new Error(`fromAst not implemented for type ${printType(ast.type)} at ${printLocations(ast.location)}`);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
@@ -127,7 +127,7 @@ export function from(value, type) {
|
|
|
127
127
|
const input_variables = inputs.map(i => ({
|
|
128
128
|
ast_type: "Variable",
|
|
129
129
|
type: i,
|
|
130
|
-
location: get_location(
|
|
130
|
+
location: get_location(),
|
|
131
131
|
mutable: false,
|
|
132
132
|
}));
|
|
133
133
|
const $ = BlockBuilder(output);
|
|
@@ -151,19 +151,19 @@ export function from(value, type) {
|
|
|
151
151
|
let body_ast;
|
|
152
152
|
if (isTypeEqual(output, NullType)) {
|
|
153
153
|
if (statements.length === 0) {
|
|
154
|
-
body_ast = { ast_type: "Value", type: NullType, location: get_location(
|
|
154
|
+
body_ast = { ast_type: "Value", type: NullType, location: get_location(), value: null };
|
|
155
155
|
}
|
|
156
156
|
else if (statements.length === 1 && isSubtype(statements[0].type, NullType)) {
|
|
157
157
|
body_ast = statements[0];
|
|
158
158
|
}
|
|
159
159
|
else {
|
|
160
160
|
if (!isSubtype(statements[statements.length - 1].type, NullType)) {
|
|
161
|
-
statements.push({ ast_type: "Value", type: NullType, location: get_location(
|
|
161
|
+
statements.push({ ast_type: "Value", type: NullType, location: get_location(), value: null });
|
|
162
162
|
}
|
|
163
163
|
body_ast = {
|
|
164
164
|
ast_type: "Block",
|
|
165
165
|
type: statements[statements.length - 1].type,
|
|
166
|
-
location: get_location(
|
|
166
|
+
location: get_location(),
|
|
167
167
|
statements: statements,
|
|
168
168
|
};
|
|
169
169
|
}
|
|
@@ -185,7 +185,7 @@ export function from(value, type) {
|
|
|
185
185
|
body_ast = {
|
|
186
186
|
ast_type: "Block",
|
|
187
187
|
type: statements[statements.length - 1].type,
|
|
188
|
-
location: get_location(
|
|
188
|
+
location: get_location(),
|
|
189
189
|
statements: statements,
|
|
190
190
|
};
|
|
191
191
|
}
|
|
@@ -196,7 +196,7 @@ export function from(value, type) {
|
|
|
196
196
|
const ast = {
|
|
197
197
|
ast_type: "Function",
|
|
198
198
|
type: FunctionType(inputs, output),
|
|
199
|
-
location: get_location(
|
|
199
|
+
location: get_location(),
|
|
200
200
|
parameters: input_variables,
|
|
201
201
|
body: body_ast,
|
|
202
202
|
};
|
|
@@ -210,7 +210,7 @@ export function from(value, type) {
|
|
|
210
210
|
const input_variables = inputs.map(i => ({
|
|
211
211
|
ast_type: "Variable",
|
|
212
212
|
type: i,
|
|
213
|
-
location: get_location(
|
|
213
|
+
location: get_location(),
|
|
214
214
|
mutable: false,
|
|
215
215
|
}));
|
|
216
216
|
const $ = BlockBuilder(output);
|
|
@@ -234,19 +234,19 @@ export function from(value, type) {
|
|
|
234
234
|
let body_ast;
|
|
235
235
|
if (isTypeEqual(output, NullType)) {
|
|
236
236
|
if (statements.length === 0) {
|
|
237
|
-
body_ast = { ast_type: "Value", type: NullType, location: get_location(
|
|
237
|
+
body_ast = { ast_type: "Value", type: NullType, location: get_location(), value: null };
|
|
238
238
|
}
|
|
239
239
|
else if (statements.length === 1 && isSubtype(statements[0].type, NullType)) {
|
|
240
240
|
body_ast = statements[0];
|
|
241
241
|
}
|
|
242
242
|
else {
|
|
243
243
|
if (!isSubtype(statements[statements.length - 1].type, NullType)) {
|
|
244
|
-
statements.push({ ast_type: "Value", type: NullType, location: get_location(
|
|
244
|
+
statements.push({ ast_type: "Value", type: NullType, location: get_location(), value: null });
|
|
245
245
|
}
|
|
246
246
|
body_ast = {
|
|
247
247
|
ast_type: "Block",
|
|
248
248
|
type: statements[statements.length - 1].type,
|
|
249
|
-
location: get_location(
|
|
249
|
+
location: get_location(),
|
|
250
250
|
statements: statements,
|
|
251
251
|
};
|
|
252
252
|
}
|
|
@@ -268,7 +268,7 @@ export function from(value, type) {
|
|
|
268
268
|
body_ast = {
|
|
269
269
|
ast_type: "Block",
|
|
270
270
|
type: statements[statements.length - 1].type,
|
|
271
|
-
location: get_location(
|
|
271
|
+
location: get_location(),
|
|
272
272
|
statements: statements,
|
|
273
273
|
};
|
|
274
274
|
}
|
|
@@ -279,7 +279,7 @@ export function from(value, type) {
|
|
|
279
279
|
const ast = {
|
|
280
280
|
ast_type: "AsyncFunction",
|
|
281
281
|
type: FunctionType(inputs, output),
|
|
282
|
-
location: get_location(
|
|
282
|
+
location: get_location(),
|
|
283
283
|
parameters: input_variables,
|
|
284
284
|
body: body_ast,
|
|
285
285
|
};
|
|
@@ -292,7 +292,7 @@ export function func(input_types, output_type, body) {
|
|
|
292
292
|
const parameters = input_types.map(i => ({
|
|
293
293
|
ast_type: "Variable",
|
|
294
294
|
type: i,
|
|
295
|
-
location: get_location(
|
|
295
|
+
location: get_location(),
|
|
296
296
|
mutable: false,
|
|
297
297
|
}));
|
|
298
298
|
const $ = BlockBuilder(output_type ?? NeverType);
|
|
@@ -309,7 +309,7 @@ export function func(input_types, output_type, body) {
|
|
|
309
309
|
const ret_type = ret_ast.type;
|
|
310
310
|
let body_ast;
|
|
311
311
|
if (statements.length === 0) {
|
|
312
|
-
body_ast = { ast_type: "Value", type: NullType, location: get_location(
|
|
312
|
+
body_ast = { ast_type: "Value", type: NullType, location: get_location(), value: null };
|
|
313
313
|
}
|
|
314
314
|
else if (statements.length === 1) {
|
|
315
315
|
body_ast = statements[0];
|
|
@@ -318,7 +318,7 @@ export function func(input_types, output_type, body) {
|
|
|
318
318
|
body_ast = {
|
|
319
319
|
ast_type: "Block",
|
|
320
320
|
type: statements[statements.length - 1].type,
|
|
321
|
-
location: get_location(
|
|
321
|
+
location: get_location(),
|
|
322
322
|
statements: statements,
|
|
323
323
|
};
|
|
324
324
|
}
|
|
@@ -328,7 +328,7 @@ export function func(input_types, output_type, body) {
|
|
|
328
328
|
const ast = {
|
|
329
329
|
ast_type: "Function",
|
|
330
330
|
type: FunctionType(input_types, ret_type),
|
|
331
|
-
location: get_location(
|
|
331
|
+
location: get_location(),
|
|
332
332
|
parameters: parameters,
|
|
333
333
|
body: body_ast,
|
|
334
334
|
};
|
|
@@ -343,7 +343,7 @@ export function func(input_types, output_type, body) {
|
|
|
343
343
|
}
|
|
344
344
|
let body_ast;
|
|
345
345
|
if (statements.length === 0) {
|
|
346
|
-
body_ast = { ast_type: "Value", type: NullType, location: get_location(
|
|
346
|
+
body_ast = { ast_type: "Value", type: NullType, location: get_location(), value: null };
|
|
347
347
|
}
|
|
348
348
|
else if (statements.length === 1) {
|
|
349
349
|
body_ast = statements[0];
|
|
@@ -352,7 +352,7 @@ export function func(input_types, output_type, body) {
|
|
|
352
352
|
body_ast = {
|
|
353
353
|
ast_type: "Block",
|
|
354
354
|
type: statements[statements.length - 1].type,
|
|
355
|
-
location: get_location(
|
|
355
|
+
location: get_location(),
|
|
356
356
|
statements: statements,
|
|
357
357
|
};
|
|
358
358
|
}
|
|
@@ -363,7 +363,7 @@ export function func(input_types, output_type, body) {
|
|
|
363
363
|
const ast = {
|
|
364
364
|
ast_type: "Function",
|
|
365
365
|
type: FunctionType(input_types, output_type),
|
|
366
|
-
location: get_location(
|
|
366
|
+
location: get_location(),
|
|
367
367
|
parameters: parameters,
|
|
368
368
|
body: body_ast,
|
|
369
369
|
};
|
|
@@ -374,7 +374,7 @@ export function asyncFunction(input_types, output_type, body) {
|
|
|
374
374
|
const parameters = input_types.map(i => ({
|
|
375
375
|
ast_type: "Variable",
|
|
376
376
|
type: i,
|
|
377
|
-
location: get_location(
|
|
377
|
+
location: get_location(),
|
|
378
378
|
mutable: false,
|
|
379
379
|
}));
|
|
380
380
|
const $ = BlockBuilder(output_type ?? NeverType);
|
|
@@ -391,7 +391,7 @@ export function asyncFunction(input_types, output_type, body) {
|
|
|
391
391
|
const ret_type = ret_ast.type;
|
|
392
392
|
let body_ast;
|
|
393
393
|
if (statements.length === 0) {
|
|
394
|
-
body_ast = { ast_type: "Value", type: NullType, location: get_location(
|
|
394
|
+
body_ast = { ast_type: "Value", type: NullType, location: get_location(), value: null };
|
|
395
395
|
}
|
|
396
396
|
else if (statements.length === 1) {
|
|
397
397
|
body_ast = statements[0];
|
|
@@ -400,7 +400,7 @@ export function asyncFunction(input_types, output_type, body) {
|
|
|
400
400
|
body_ast = {
|
|
401
401
|
ast_type: "Block",
|
|
402
402
|
type: statements[statements.length - 1].type,
|
|
403
|
-
location: get_location(
|
|
403
|
+
location: get_location(),
|
|
404
404
|
statements: statements,
|
|
405
405
|
};
|
|
406
406
|
}
|
|
@@ -410,7 +410,7 @@ export function asyncFunction(input_types, output_type, body) {
|
|
|
410
410
|
const ast = {
|
|
411
411
|
ast_type: "AsyncFunction",
|
|
412
412
|
type: AsyncFunctionType(input_types, ret_type),
|
|
413
|
-
location: get_location(
|
|
413
|
+
location: get_location(),
|
|
414
414
|
parameters: parameters,
|
|
415
415
|
body: body_ast,
|
|
416
416
|
};
|
|
@@ -425,7 +425,7 @@ export function asyncFunction(input_types, output_type, body) {
|
|
|
425
425
|
}
|
|
426
426
|
let body_ast;
|
|
427
427
|
if (statements.length === 0) {
|
|
428
|
-
body_ast = { ast_type: "Value", type: NullType, location: get_location(
|
|
428
|
+
body_ast = { ast_type: "Value", type: NullType, location: get_location(), value: null };
|
|
429
429
|
}
|
|
430
430
|
else if (statements.length === 1) {
|
|
431
431
|
body_ast = statements[0];
|
|
@@ -434,7 +434,7 @@ export function asyncFunction(input_types, output_type, body) {
|
|
|
434
434
|
body_ast = {
|
|
435
435
|
ast_type: "Block",
|
|
436
436
|
type: statements[statements.length - 1].type,
|
|
437
|
-
location: get_location(
|
|
437
|
+
location: get_location(),
|
|
438
438
|
statements: statements,
|
|
439
439
|
};
|
|
440
440
|
}
|
|
@@ -445,7 +445,7 @@ export function asyncFunction(input_types, output_type, body) {
|
|
|
445
445
|
const ast = {
|
|
446
446
|
ast_type: "AsyncFunction",
|
|
447
447
|
type: AsyncFunctionType(input_types, output_type),
|
|
448
|
-
location: get_location(
|
|
448
|
+
location: get_location(),
|
|
449
449
|
parameters: parameters,
|
|
450
450
|
body: body_ast,
|
|
451
451
|
};
|
|
@@ -460,7 +460,7 @@ export function asyncFunction(input_types, output_type, body) {
|
|
|
460
460
|
* ```
|
|
461
461
|
*/
|
|
462
462
|
export function str(strings, ...expressions) {
|
|
463
|
-
const location = get_location(
|
|
463
|
+
const location = get_location();
|
|
464
464
|
// For simple strings, e.g: str`abc`
|
|
465
465
|
if (strings.length === 1) {
|
|
466
466
|
return fromAst({
|
|
@@ -576,7 +576,7 @@ export function str(strings, ...expressions) {
|
|
|
576
576
|
let ret = {
|
|
577
577
|
ast_type: "Value",
|
|
578
578
|
type: StringType,
|
|
579
|
-
location: get_location(
|
|
579
|
+
location: get_location(),
|
|
580
580
|
value: strings[0],
|
|
581
581
|
};
|
|
582
582
|
for (let i = 1; i < strings.length; i++) {
|
|
@@ -671,7 +671,7 @@ export function block(body) {
|
|
|
671
671
|
if (statements.length === 0) {
|
|
672
672
|
return fromAst({
|
|
673
673
|
ast_type: "Value",
|
|
674
|
-
location: get_location(
|
|
674
|
+
location: get_location(),
|
|
675
675
|
type: ret_type,
|
|
676
676
|
value: null,
|
|
677
677
|
});
|
|
@@ -682,7 +682,7 @@ export function block(body) {
|
|
|
682
682
|
else {
|
|
683
683
|
return fromAst({
|
|
684
684
|
ast_type: "Block",
|
|
685
|
-
location: get_location(
|
|
685
|
+
location: get_location(),
|
|
686
686
|
type: ret_type,
|
|
687
687
|
statements: statements,
|
|
688
688
|
});
|
|
@@ -691,7 +691,7 @@ export function block(body) {
|
|
|
691
691
|
/**
|
|
692
692
|
* Create an East error expression
|
|
693
693
|
*/
|
|
694
|
-
export function error(message, location = get_location(
|
|
694
|
+
export function error(message, location = get_location()) {
|
|
695
695
|
const messageAst = message instanceof Expr ? Expr.ast(message) : valueOrExprToAstTyped(message, StringType);
|
|
696
696
|
return fromAst({
|
|
697
697
|
ast_type: "Error",
|
|
@@ -712,7 +712,7 @@ export function matchExpr(variant, handlers) {
|
|
|
712
712
|
const data_variable = {
|
|
713
713
|
ast_type: "Variable",
|
|
714
714
|
type: t,
|
|
715
|
-
location: get_location(
|
|
715
|
+
location: get_location(),
|
|
716
716
|
mutable: false,
|
|
717
717
|
};
|
|
718
718
|
const ast = handler === undefined ? valueOrExprToAstTyped(null, NullType) : block($ => handler($, fromAst(data_variable)))[AstSymbol];
|
|
@@ -723,7 +723,7 @@ export function matchExpr(variant, handlers) {
|
|
|
723
723
|
return fromAst({
|
|
724
724
|
ast_type: "Match",
|
|
725
725
|
type: out_type,
|
|
726
|
-
location: get_location(
|
|
726
|
+
location: get_location(),
|
|
727
727
|
variant: Expr.ast(variant),
|
|
728
728
|
cases: cases_out,
|
|
729
729
|
});
|
|
@@ -737,13 +737,13 @@ export function tryCatch(try_body, catch_body) {
|
|
|
737
737
|
const message_variable = {
|
|
738
738
|
ast_type: "Variable",
|
|
739
739
|
type: StringType,
|
|
740
|
-
location: get_location(
|
|
740
|
+
location: get_location(),
|
|
741
741
|
mutable: false,
|
|
742
742
|
};
|
|
743
743
|
const stack_variable = {
|
|
744
744
|
ast_type: "Variable",
|
|
745
745
|
type: ArrayType(StructType({ filename: StringType, line: IntegerType, column: IntegerType })),
|
|
746
|
-
location: get_location(
|
|
746
|
+
location: get_location(),
|
|
747
747
|
mutable: false,
|
|
748
748
|
};
|
|
749
749
|
if (typeof catch_body !== "function") {
|
|
@@ -756,7 +756,7 @@ export function tryCatch(try_body, catch_body) {
|
|
|
756
756
|
return fromAst({
|
|
757
757
|
ast_type: "TryCatch",
|
|
758
758
|
type: ret_type,
|
|
759
|
-
location: get_location(
|
|
759
|
+
location: get_location(),
|
|
760
760
|
try_body: Expr.ast(try_body),
|
|
761
761
|
catch_body: catch_body_ast,
|
|
762
762
|
message: message_variable,
|
|
@@ -769,7 +769,7 @@ export function equal(left, right) {
|
|
|
769
769
|
return fromAst({
|
|
770
770
|
ast_type: "Builtin",
|
|
771
771
|
type: BooleanType,
|
|
772
|
-
location: get_location(
|
|
772
|
+
location: get_location(),
|
|
773
773
|
builtin: "Equal",
|
|
774
774
|
type_parameters: [Expr.type(left)],
|
|
775
775
|
arguments: [Expr.ast(left), rightAst],
|
|
@@ -781,7 +781,7 @@ export function notEqual(left, right) {
|
|
|
781
781
|
return fromAst({
|
|
782
782
|
ast_type: "Builtin",
|
|
783
783
|
type: BooleanType,
|
|
784
|
-
location: get_location(
|
|
784
|
+
location: get_location(),
|
|
785
785
|
builtin: "NotEqual",
|
|
786
786
|
type_parameters: [Expr.type(left)],
|
|
787
787
|
arguments: [Expr.ast(left), rightAst],
|
|
@@ -793,7 +793,7 @@ export function less(left, right) {
|
|
|
793
793
|
return fromAst({
|
|
794
794
|
ast_type: "Builtin",
|
|
795
795
|
type: BooleanType,
|
|
796
|
-
location: get_location(
|
|
796
|
+
location: get_location(),
|
|
797
797
|
builtin: "Less",
|
|
798
798
|
type_parameters: [Expr.type(left)],
|
|
799
799
|
arguments: [Expr.ast(left), rightAst],
|
|
@@ -805,7 +805,7 @@ export function lessEqual(left, right) {
|
|
|
805
805
|
return fromAst({
|
|
806
806
|
ast_type: "Builtin",
|
|
807
807
|
type: BooleanType,
|
|
808
|
-
location: get_location(
|
|
808
|
+
location: get_location(),
|
|
809
809
|
builtin: "LessEqual",
|
|
810
810
|
type_parameters: [Expr.type(left)],
|
|
811
811
|
arguments: [Expr.ast(left), rightAst],
|
|
@@ -817,7 +817,7 @@ export function greater(left, right) {
|
|
|
817
817
|
return fromAst({
|
|
818
818
|
ast_type: "Builtin",
|
|
819
819
|
type: BooleanType,
|
|
820
|
-
location: get_location(
|
|
820
|
+
location: get_location(),
|
|
821
821
|
builtin: "Greater",
|
|
822
822
|
type_parameters: [Expr.type(left)],
|
|
823
823
|
arguments: [Expr.ast(left), rightAst],
|
|
@@ -829,7 +829,7 @@ export function greaterEqual(left, right) {
|
|
|
829
829
|
return fromAst({
|
|
830
830
|
ast_type: "Builtin",
|
|
831
831
|
type: BooleanType,
|
|
832
|
-
location: get_location(
|
|
832
|
+
location: get_location(),
|
|
833
833
|
builtin: "GreaterEqual",
|
|
834
834
|
type_parameters: [Expr.type(left)],
|
|
835
835
|
arguments: [Expr.ast(left), rightAst],
|
|
@@ -875,7 +875,7 @@ export function is(left, right) {
|
|
|
875
875
|
return fromAst({
|
|
876
876
|
ast_type: "Builtin",
|
|
877
877
|
type: BooleanType,
|
|
878
|
-
location: get_location(
|
|
878
|
+
location: get_location(),
|
|
879
879
|
builtin: "Is",
|
|
880
880
|
type_parameters: [Expr.type(left)],
|
|
881
881
|
arguments: [Expr.ast(left), rightAst],
|
|
@@ -887,7 +887,7 @@ export function print(value) {
|
|
|
887
887
|
return fromAst({
|
|
888
888
|
ast_type: "Builtin",
|
|
889
889
|
type: StringType,
|
|
890
|
-
location: get_location(
|
|
890
|
+
location: get_location(),
|
|
891
891
|
builtin: "Print",
|
|
892
892
|
type_parameters: [valueAst.type],
|
|
893
893
|
arguments: [valueAst],
|
|
@@ -907,7 +907,7 @@ export function diff(before, after) {
|
|
|
907
907
|
return fromAst({
|
|
908
908
|
ast_type: "Builtin",
|
|
909
909
|
type: patchType,
|
|
910
|
-
location: get_location(
|
|
910
|
+
location: get_location(),
|
|
911
911
|
builtin: "Diff",
|
|
912
912
|
type_parameters: [valueType, patchType],
|
|
913
913
|
arguments: [beforeAst, afterAst],
|
|
@@ -924,7 +924,7 @@ export function applyPatch(value, patch) {
|
|
|
924
924
|
return fromAst({
|
|
925
925
|
ast_type: "Builtin",
|
|
926
926
|
type: valueType,
|
|
927
|
-
location: get_location(
|
|
927
|
+
location: get_location(),
|
|
928
928
|
builtin: "ApplyPatch",
|
|
929
929
|
type_parameters: [valueType, patchType],
|
|
930
930
|
arguments: [valueAst, patchAst],
|
|
@@ -942,7 +942,7 @@ export function composePatch(first, second, type) {
|
|
|
942
942
|
return fromAst({
|
|
943
943
|
ast_type: "Builtin",
|
|
944
944
|
type: patchType,
|
|
945
|
-
location: get_location(
|
|
945
|
+
location: get_location(),
|
|
946
946
|
builtin: "ComposePatch",
|
|
947
947
|
type_parameters: [valueType, patchType],
|
|
948
948
|
arguments: [firstAst, secondAst],
|
|
@@ -958,7 +958,7 @@ export function invertPatch(patch, type) {
|
|
|
958
958
|
return fromAst({
|
|
959
959
|
ast_type: "Builtin",
|
|
960
960
|
type: patchType,
|
|
961
|
-
location: get_location(
|
|
961
|
+
location: get_location(),
|
|
962
962
|
builtin: "InvertPatch",
|
|
963
963
|
type_parameters: [valueType, patchType],
|
|
964
964
|
arguments: [patchAst],
|
|
@@ -1014,7 +1014,7 @@ export function platform(name, input_types, output_type) {
|
|
|
1014
1014
|
ast = {
|
|
1015
1015
|
ast_type: "As",
|
|
1016
1016
|
type: expectedType,
|
|
1017
|
-
location: get_location(
|
|
1017
|
+
location: get_location(),
|
|
1018
1018
|
value: ast,
|
|
1019
1019
|
};
|
|
1020
1020
|
}
|
|
@@ -1023,7 +1023,7 @@ export function platform(name, input_types, output_type) {
|
|
|
1023
1023
|
return fromAst({
|
|
1024
1024
|
ast_type: "Platform",
|
|
1025
1025
|
type: output_type,
|
|
1026
|
-
location: get_location(
|
|
1026
|
+
location: get_location(),
|
|
1027
1027
|
name: name,
|
|
1028
1028
|
type_parameters: [],
|
|
1029
1029
|
arguments: argAsts,
|
|
@@ -1104,7 +1104,7 @@ export function asyncPlatform(name, input_types, output_type) {
|
|
|
1104
1104
|
ast = {
|
|
1105
1105
|
ast_type: "As",
|
|
1106
1106
|
type: expectedType,
|
|
1107
|
-
location: get_location(
|
|
1107
|
+
location: get_location(),
|
|
1108
1108
|
value: ast,
|
|
1109
1109
|
};
|
|
1110
1110
|
}
|
|
@@ -1113,7 +1113,7 @@ export function asyncPlatform(name, input_types, output_type) {
|
|
|
1113
1113
|
return fromAst({
|
|
1114
1114
|
ast_type: "Platform",
|
|
1115
1115
|
type: output_type,
|
|
1116
|
-
location: get_location(
|
|
1116
|
+
location: get_location(),
|
|
1117
1117
|
name: name,
|
|
1118
1118
|
type_parameters: [],
|
|
1119
1119
|
arguments: argAsts,
|
|
@@ -1295,7 +1295,7 @@ export function genericPlatform(name, typeParams, inputs, output) {
|
|
|
1295
1295
|
ast = {
|
|
1296
1296
|
ast_type: "As",
|
|
1297
1297
|
type: expectedType,
|
|
1298
|
-
location: get_location(
|
|
1298
|
+
location: get_location(),
|
|
1299
1299
|
value: ast,
|
|
1300
1300
|
};
|
|
1301
1301
|
}
|
|
@@ -1305,7 +1305,7 @@ export function genericPlatform(name, typeParams, inputs, output) {
|
|
|
1305
1305
|
return fromAst({
|
|
1306
1306
|
ast_type: "Platform",
|
|
1307
1307
|
type: outputType,
|
|
1308
|
-
location: get_location(
|
|
1308
|
+
location: get_location(),
|
|
1309
1309
|
name: name,
|
|
1310
1310
|
type_parameters: type_args,
|
|
1311
1311
|
arguments: argAsts,
|
|
@@ -1431,7 +1431,7 @@ export function asyncGenericPlatform(name, typeParams, inputs, output) {
|
|
|
1431
1431
|
ast = {
|
|
1432
1432
|
ast_type: "As",
|
|
1433
1433
|
type: expectedType,
|
|
1434
|
-
location: get_location(
|
|
1434
|
+
location: get_location(),
|
|
1435
1435
|
value: ast,
|
|
1436
1436
|
};
|
|
1437
1437
|
}
|
|
@@ -1441,7 +1441,7 @@ export function asyncGenericPlatform(name, typeParams, inputs, output) {
|
|
|
1441
1441
|
return fromAst({
|
|
1442
1442
|
ast_type: "Platform",
|
|
1443
1443
|
type: outputType,
|
|
1444
|
-
location: get_location(
|
|
1444
|
+
location: get_location(),
|
|
1445
1445
|
name: name,
|
|
1446
1446
|
type_parameters: type_args,
|
|
1447
1447
|
arguments: argAsts,
|
|
@@ -1503,7 +1503,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1503
1503
|
};
|
|
1504
1504
|
$.const = ((value, type) => {
|
|
1505
1505
|
if (isTypeEqual($.type(), NeverType)) {
|
|
1506
|
-
throw new Error(`Unreachable statement detected at ${
|
|
1506
|
+
throw new Error(`Unreachable statement detected at ${printLocations(get_location())}`);
|
|
1507
1507
|
}
|
|
1508
1508
|
let ast;
|
|
1509
1509
|
if (value instanceof Expr) {
|
|
@@ -1518,13 +1518,13 @@ export const BlockBuilder = (return_type) => {
|
|
|
1518
1518
|
const variable = {
|
|
1519
1519
|
ast_type: "Variable",
|
|
1520
1520
|
type: type ?? ast.type,
|
|
1521
|
-
location: get_location(
|
|
1521
|
+
location: get_location(),
|
|
1522
1522
|
mutable: false,
|
|
1523
1523
|
};
|
|
1524
1524
|
statements.push({
|
|
1525
1525
|
ast_type: "Let",
|
|
1526
1526
|
type: NullType,
|
|
1527
|
-
location: get_location(
|
|
1527
|
+
location: get_location(),
|
|
1528
1528
|
variable,
|
|
1529
1529
|
value: ast,
|
|
1530
1530
|
});
|
|
@@ -1532,7 +1532,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1532
1532
|
});
|
|
1533
1533
|
$.let = ((value, type) => {
|
|
1534
1534
|
if (isTypeEqual($.type(), NeverType)) {
|
|
1535
|
-
throw new Error(`Unreachable statement detected at ${
|
|
1535
|
+
throw new Error(`Unreachable statement detected at ${printLocations(get_location())}`);
|
|
1536
1536
|
}
|
|
1537
1537
|
let ast;
|
|
1538
1538
|
if (value instanceof Expr) {
|
|
@@ -1547,13 +1547,13 @@ export const BlockBuilder = (return_type) => {
|
|
|
1547
1547
|
const variable = {
|
|
1548
1548
|
ast_type: "Variable",
|
|
1549
1549
|
type: type ?? ast.type,
|
|
1550
|
-
location: get_location(
|
|
1550
|
+
location: get_location(),
|
|
1551
1551
|
mutable: true,
|
|
1552
1552
|
};
|
|
1553
1553
|
statements.push({
|
|
1554
1554
|
ast_type: "Let",
|
|
1555
1555
|
type: NullType,
|
|
1556
|
-
location: get_location(
|
|
1556
|
+
location: get_location(),
|
|
1557
1557
|
variable,
|
|
1558
1558
|
value: ast,
|
|
1559
1559
|
});
|
|
@@ -1561,7 +1561,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1561
1561
|
});
|
|
1562
1562
|
$.assign = ((variable, value) => {
|
|
1563
1563
|
if (isTypeEqual($.type(), NeverType)) {
|
|
1564
|
-
throw new Error(`Unreachable statement detected at ${
|
|
1564
|
+
throw new Error(`Unreachable statement detected at ${printLocations(get_location())}`);
|
|
1565
1565
|
}
|
|
1566
1566
|
let v = Expr.ast(variable);
|
|
1567
1567
|
// Handle RecursiveType variables which are auto-unwrapped by fromAst
|
|
@@ -1572,13 +1572,13 @@ export const BlockBuilder = (return_type) => {
|
|
|
1572
1572
|
throw new Error("Can only assign to a variable");
|
|
1573
1573
|
}
|
|
1574
1574
|
if (!v.mutable) {
|
|
1575
|
-
throw new Error(`Cannot assign to variable defined at ${
|
|
1575
|
+
throw new Error(`Cannot assign to variable defined at ${printLocations(v.location)} defined as const`);
|
|
1576
1576
|
}
|
|
1577
1577
|
const ast_value = value instanceof Expr ? Expr.ast(value) : valueOrExprToAstTyped(value, v.type);
|
|
1578
1578
|
const ast = {
|
|
1579
1579
|
ast_type: "Assign",
|
|
1580
1580
|
type: NullType,
|
|
1581
|
-
location: get_location(
|
|
1581
|
+
location: get_location(),
|
|
1582
1582
|
variable: v,
|
|
1583
1583
|
value: ast_value,
|
|
1584
1584
|
};
|
|
@@ -1588,7 +1588,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1588
1588
|
// TODO if/when we introduce recursion, can we somehow get benefit from the typing?
|
|
1589
1589
|
$.return = (expr) => {
|
|
1590
1590
|
if (isTypeEqual($.type(), NeverType)) {
|
|
1591
|
-
throw new Error(`Unreachable statement detected at ${
|
|
1591
|
+
throw new Error(`Unreachable statement detected at ${printLocations(get_location())}`);
|
|
1592
1592
|
}
|
|
1593
1593
|
const expAst = expr instanceof Expr ? Expr.ast(expr) : valueOrExprToAst(expr);
|
|
1594
1594
|
if (!isSubtype(expAst.type, return_type)) {
|
|
@@ -1603,7 +1603,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1603
1603
|
const ast = {
|
|
1604
1604
|
ast_type: "Return",
|
|
1605
1605
|
type: NeverType,
|
|
1606
|
-
location: get_location(
|
|
1606
|
+
location: get_location(),
|
|
1607
1607
|
value: expAst
|
|
1608
1608
|
};
|
|
1609
1609
|
statements.push(ast);
|
|
@@ -1611,12 +1611,12 @@ export const BlockBuilder = (return_type) => {
|
|
|
1611
1611
|
};
|
|
1612
1612
|
$.break = (label) => {
|
|
1613
1613
|
if (isTypeEqual($.type(), NeverType)) {
|
|
1614
|
-
throw new Error(`Unreachable statement detected at ${
|
|
1614
|
+
throw new Error(`Unreachable statement detected at ${printLocations(get_location())}`);
|
|
1615
1615
|
}
|
|
1616
1616
|
const ast = {
|
|
1617
1617
|
ast_type: "Break",
|
|
1618
1618
|
type: NeverType,
|
|
1619
|
-
location: get_location(
|
|
1619
|
+
location: get_location(),
|
|
1620
1620
|
label,
|
|
1621
1621
|
};
|
|
1622
1622
|
statements.push(ast);
|
|
@@ -1624,12 +1624,12 @@ export const BlockBuilder = (return_type) => {
|
|
|
1624
1624
|
};
|
|
1625
1625
|
$.continue = (label) => {
|
|
1626
1626
|
if (isTypeEqual($.type(), NeverType)) {
|
|
1627
|
-
throw new Error(`Unreachable statement detected at ${
|
|
1627
|
+
throw new Error(`Unreachable statement detected at ${printLocations(get_location())}`);
|
|
1628
1628
|
}
|
|
1629
1629
|
const ast = {
|
|
1630
1630
|
ast_type: "Continue",
|
|
1631
1631
|
type: NeverType,
|
|
1632
|
-
location: get_location(
|
|
1632
|
+
location: get_location(),
|
|
1633
1633
|
label,
|
|
1634
1634
|
};
|
|
1635
1635
|
statements.push(ast);
|
|
@@ -1637,7 +1637,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1637
1637
|
};
|
|
1638
1638
|
$.if = (predicate, true_branch) => {
|
|
1639
1639
|
if (isTypeEqual($.type(), NeverType)) {
|
|
1640
|
-
throw new Error(`Unreachable statement detected at ${
|
|
1640
|
+
throw new Error(`Unreachable statement detected at ${printLocations(get_location())}`);
|
|
1641
1641
|
}
|
|
1642
1642
|
const predicateAst = predicate instanceof Expr ? Expr.ast(predicate) : valueOrExprToAstTyped(predicate, BooleanType);
|
|
1643
1643
|
if (predicateAst.type.type !== "Boolean") {
|
|
@@ -1655,38 +1655,38 @@ export const BlockBuilder = (return_type) => {
|
|
|
1655
1655
|
}
|
|
1656
1656
|
let true_ast;
|
|
1657
1657
|
if (true_stmts.length === 0) {
|
|
1658
|
-
true_ast = { ast_type: "Value", type: NullType, location: get_location(
|
|
1658
|
+
true_ast = { ast_type: "Value", type: NullType, location: get_location(), value: null };
|
|
1659
1659
|
}
|
|
1660
1660
|
else if (true_stmts.length === 1 && isSubtype(true_stmts[0].type, NullType)) {
|
|
1661
1661
|
true_ast = true_stmts[0];
|
|
1662
1662
|
}
|
|
1663
1663
|
else {
|
|
1664
1664
|
if (!isSubtype(true_stmts[true_stmts.length - 1].type, NullType)) {
|
|
1665
|
-
true_stmts.push({ ast_type: "Value", type: NullType, location: get_location(
|
|
1665
|
+
true_stmts.push({ ast_type: "Value", type: NullType, location: get_location(), value: null });
|
|
1666
1666
|
}
|
|
1667
1667
|
true_ast = {
|
|
1668
1668
|
ast_type: "Block",
|
|
1669
1669
|
type: true_stmts[true_stmts.length - 1].type,
|
|
1670
|
-
location: get_location(
|
|
1670
|
+
location: get_location(),
|
|
1671
1671
|
statements: true_stmts,
|
|
1672
1672
|
};
|
|
1673
1673
|
}
|
|
1674
1674
|
const if_else_ast = {
|
|
1675
1675
|
ast_type: "IfElse",
|
|
1676
1676
|
type: NullType,
|
|
1677
|
-
location: get_location(
|
|
1677
|
+
location: get_location(),
|
|
1678
1678
|
ifs: [{
|
|
1679
1679
|
predicate: Expr.ast(predicate),
|
|
1680
1680
|
body: true_ast,
|
|
1681
1681
|
}],
|
|
1682
|
-
else_body: { ast_type: "Value", type: NullType, location: get_location(
|
|
1682
|
+
else_body: { ast_type: "Value", type: NullType, location: get_location(), value: null },
|
|
1683
1683
|
};
|
|
1684
1684
|
statements.push(if_else_ast);
|
|
1685
1685
|
return new IfElseExpr(if_else_ast, return_type);
|
|
1686
1686
|
};
|
|
1687
1687
|
$.match = (variant, cases) => {
|
|
1688
1688
|
if (isTypeEqual($.type(), NeverType)) {
|
|
1689
|
-
throw new Error(`Unreachable statement detected at ${
|
|
1689
|
+
throw new Error(`Unreachable statement detected at ${printLocations(get_location())}`);
|
|
1690
1690
|
}
|
|
1691
1691
|
if (Expr.type(variant).type !== "Variant") {
|
|
1692
1692
|
throw new Error(`match not defined over ${printType(Expr.type(variant))}`);
|
|
@@ -1698,11 +1698,11 @@ export const BlockBuilder = (return_type) => {
|
|
|
1698
1698
|
const data_variable = {
|
|
1699
1699
|
ast_type: "Variable",
|
|
1700
1700
|
type: t,
|
|
1701
|
-
location: get_location(
|
|
1701
|
+
location: get_location(),
|
|
1702
1702
|
mutable: false,
|
|
1703
1703
|
};
|
|
1704
1704
|
if (f === undefined) {
|
|
1705
|
-
cases_out[k] = { variable: data_variable, body: { ast_type: "Value", type: NullType, location: get_location(
|
|
1705
|
+
cases_out[k] = { variable: data_variable, body: { ast_type: "Value", type: NullType, location: get_location(), value: null } };
|
|
1706
1706
|
}
|
|
1707
1707
|
else {
|
|
1708
1708
|
const data = fromAst(data_variable);
|
|
@@ -1717,19 +1717,19 @@ export const BlockBuilder = (return_type) => {
|
|
|
1717
1717
|
}
|
|
1718
1718
|
let expr;
|
|
1719
1719
|
if (stmts.length === 0) {
|
|
1720
|
-
expr = { ast_type: "Value", type: NullType, location: get_location(
|
|
1720
|
+
expr = { ast_type: "Value", type: NullType, location: get_location(), value: null };
|
|
1721
1721
|
}
|
|
1722
1722
|
else if (stmts.length === 1 && isSubtype(stmts[0].type, NullType)) {
|
|
1723
1723
|
expr = stmts[0];
|
|
1724
1724
|
}
|
|
1725
1725
|
else {
|
|
1726
1726
|
if (!isSubtype(stmts[stmts.length - 1].type, NullType)) {
|
|
1727
|
-
stmts.push({ ast_type: "Value", type: NullType, location: get_location(
|
|
1727
|
+
stmts.push({ ast_type: "Value", type: NullType, location: get_location(), value: null });
|
|
1728
1728
|
}
|
|
1729
1729
|
expr = {
|
|
1730
1730
|
ast_type: "Block",
|
|
1731
1731
|
type: stmts[stmts.length - 1].type,
|
|
1732
|
-
location: get_location(
|
|
1732
|
+
location: get_location(),
|
|
1733
1733
|
statements: stmts,
|
|
1734
1734
|
};
|
|
1735
1735
|
}
|
|
@@ -1740,7 +1740,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1740
1740
|
const ast = {
|
|
1741
1741
|
ast_type: "Match",
|
|
1742
1742
|
type: out_type,
|
|
1743
|
-
location: get_location(
|
|
1743
|
+
location: get_location(),
|
|
1744
1744
|
variant: Expr.ast(variant),
|
|
1745
1745
|
cases: cases_out,
|
|
1746
1746
|
};
|
|
@@ -1749,13 +1749,13 @@ export const BlockBuilder = (return_type) => {
|
|
|
1749
1749
|
};
|
|
1750
1750
|
$.while = (predicate, body) => {
|
|
1751
1751
|
if (isTypeEqual($.type(), NeverType)) {
|
|
1752
|
-
throw new Error(`Unreachable statement detected at ${
|
|
1752
|
+
throw new Error(`Unreachable statement detected at ${printLocations(get_location())}`);
|
|
1753
1753
|
}
|
|
1754
1754
|
const predicateAst = predicate instanceof Expr ? Expr.ast(predicate) : valueOrExprToAstTyped(predicate, BooleanType);
|
|
1755
1755
|
if (predicateAst.type.type !== "Boolean") {
|
|
1756
1756
|
throw new Error(`while predicate expected to have type Boolean, got ${printType(predicateAst.type)}`);
|
|
1757
1757
|
}
|
|
1758
|
-
const label = { location: get_location(
|
|
1758
|
+
const label = { location: get_location() };
|
|
1759
1759
|
const $_body = BlockBuilder(return_type);
|
|
1760
1760
|
const ret = body($_body, label);
|
|
1761
1761
|
const stmts = $_body.statements;
|
|
@@ -1767,19 +1767,19 @@ export const BlockBuilder = (return_type) => {
|
|
|
1767
1767
|
}
|
|
1768
1768
|
let expr;
|
|
1769
1769
|
if (stmts.length === 0) {
|
|
1770
|
-
expr = { ast_type: "Value", type: NullType, location: get_location(
|
|
1770
|
+
expr = { ast_type: "Value", type: NullType, location: get_location(), value: null };
|
|
1771
1771
|
}
|
|
1772
1772
|
else if (stmts.length === 1 && isSubtype(stmts[0].type, NullType)) {
|
|
1773
1773
|
expr = stmts[0];
|
|
1774
1774
|
}
|
|
1775
1775
|
else {
|
|
1776
1776
|
if (!isSubtype(stmts[stmts.length - 1].type, NullType)) {
|
|
1777
|
-
stmts.push({ ast_type: "Value", type: NullType, location: get_location(
|
|
1777
|
+
stmts.push({ ast_type: "Value", type: NullType, location: get_location(), value: null });
|
|
1778
1778
|
}
|
|
1779
1779
|
expr = {
|
|
1780
1780
|
ast_type: "Block",
|
|
1781
1781
|
type: stmts[stmts.length - 1].type,
|
|
1782
|
-
location: get_location(
|
|
1782
|
+
location: get_location(),
|
|
1783
1783
|
statements: stmts,
|
|
1784
1784
|
};
|
|
1785
1785
|
}
|
|
@@ -1789,7 +1789,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1789
1789
|
const ast = {
|
|
1790
1790
|
ast_type: "While",
|
|
1791
1791
|
type: NullType,
|
|
1792
|
-
location: get_location(
|
|
1792
|
+
location: get_location(),
|
|
1793
1793
|
predicate: predicateAst,
|
|
1794
1794
|
label,
|
|
1795
1795
|
body: expr,
|
|
@@ -1799,24 +1799,24 @@ export const BlockBuilder = (return_type) => {
|
|
|
1799
1799
|
};
|
|
1800
1800
|
$.for = ((collection, body) => {
|
|
1801
1801
|
if (isTypeEqual($.type(), NeverType)) {
|
|
1802
|
-
throw new Error(`Unreachable statement detected at ${
|
|
1802
|
+
throw new Error(`Unreachable statement detected at ${printLocations(get_location())}`);
|
|
1803
1803
|
}
|
|
1804
1804
|
if (collection instanceof ArrayExpr) {
|
|
1805
1805
|
const value_variable = {
|
|
1806
1806
|
ast_type: "Variable",
|
|
1807
1807
|
type: Expr.type(collection).value,
|
|
1808
|
-
location: get_location(
|
|
1808
|
+
location: get_location(),
|
|
1809
1809
|
mutable: false,
|
|
1810
1810
|
};
|
|
1811
1811
|
const value = fromAst(value_variable);
|
|
1812
1812
|
const key_variable = {
|
|
1813
1813
|
ast_type: "Variable",
|
|
1814
1814
|
type: IntegerType,
|
|
1815
|
-
location: get_location(
|
|
1815
|
+
location: get_location(),
|
|
1816
1816
|
mutable: false,
|
|
1817
1817
|
};
|
|
1818
1818
|
const key = fromAst(key_variable);
|
|
1819
|
-
const label = { location: get_location(
|
|
1819
|
+
const label = { location: get_location() };
|
|
1820
1820
|
const $ = BlockBuilder(return_type);
|
|
1821
1821
|
const ret = body($, value, key, label);
|
|
1822
1822
|
const stmts = $.statements;
|
|
@@ -1828,26 +1828,26 @@ export const BlockBuilder = (return_type) => {
|
|
|
1828
1828
|
}
|
|
1829
1829
|
let expr;
|
|
1830
1830
|
if (stmts.length === 0) {
|
|
1831
|
-
expr = { ast_type: "Value", type: NullType, location: get_location(
|
|
1831
|
+
expr = { ast_type: "Value", type: NullType, location: get_location(), value: null };
|
|
1832
1832
|
}
|
|
1833
1833
|
else if (stmts.length === 1 && isSubtype(stmts[0].type, NullType)) {
|
|
1834
1834
|
expr = stmts[0];
|
|
1835
1835
|
}
|
|
1836
1836
|
else {
|
|
1837
1837
|
if (!isSubtype(stmts[stmts.length - 1].type, NullType)) {
|
|
1838
|
-
stmts.push({ ast_type: "Value", type: NullType, location: get_location(
|
|
1838
|
+
stmts.push({ ast_type: "Value", type: NullType, location: get_location(), value: null });
|
|
1839
1839
|
}
|
|
1840
1840
|
expr = {
|
|
1841
1841
|
ast_type: "Block",
|
|
1842
1842
|
type: stmts[stmts.length - 1].type,
|
|
1843
|
-
location: get_location(
|
|
1843
|
+
location: get_location(),
|
|
1844
1844
|
statements: stmts,
|
|
1845
1845
|
};
|
|
1846
1846
|
}
|
|
1847
1847
|
const ast = {
|
|
1848
1848
|
ast_type: "ForArray",
|
|
1849
1849
|
type: NullType,
|
|
1850
|
-
location: get_location(
|
|
1850
|
+
location: get_location(),
|
|
1851
1851
|
label,
|
|
1852
1852
|
array: Expr.ast(collection),
|
|
1853
1853
|
key: key_variable,
|
|
@@ -1861,11 +1861,11 @@ export const BlockBuilder = (return_type) => {
|
|
|
1861
1861
|
const key_variable = {
|
|
1862
1862
|
ast_type: "Variable",
|
|
1863
1863
|
type: Expr.type(collection).key,
|
|
1864
|
-
location: get_location(
|
|
1864
|
+
location: get_location(),
|
|
1865
1865
|
mutable: false,
|
|
1866
1866
|
};
|
|
1867
1867
|
const key = fromAst(key_variable);
|
|
1868
|
-
const label = { location: get_location(
|
|
1868
|
+
const label = { location: get_location() };
|
|
1869
1869
|
const $ = BlockBuilder(return_type);
|
|
1870
1870
|
const ret = body($, key, label);
|
|
1871
1871
|
const stmts = $.statements;
|
|
@@ -1877,26 +1877,26 @@ export const BlockBuilder = (return_type) => {
|
|
|
1877
1877
|
}
|
|
1878
1878
|
let expr;
|
|
1879
1879
|
if (stmts.length === 0) {
|
|
1880
|
-
expr = { ast_type: "Value", type: NullType, location: get_location(
|
|
1880
|
+
expr = { ast_type: "Value", type: NullType, location: get_location(), value: null };
|
|
1881
1881
|
}
|
|
1882
1882
|
else if (stmts.length === 1 && isSubtype(stmts[0].type, NullType)) {
|
|
1883
1883
|
expr = stmts[0];
|
|
1884
1884
|
}
|
|
1885
1885
|
else {
|
|
1886
1886
|
if (!isSubtype(stmts[stmts.length - 1].type, NullType)) {
|
|
1887
|
-
stmts.push({ ast_type: "Value", type: NullType, location: get_location(
|
|
1887
|
+
stmts.push({ ast_type: "Value", type: NullType, location: get_location(), value: null });
|
|
1888
1888
|
}
|
|
1889
1889
|
expr = {
|
|
1890
1890
|
ast_type: "Block",
|
|
1891
1891
|
type: stmts[stmts.length - 1].type,
|
|
1892
|
-
location: get_location(
|
|
1892
|
+
location: get_location(),
|
|
1893
1893
|
statements: stmts,
|
|
1894
1894
|
};
|
|
1895
1895
|
}
|
|
1896
1896
|
const ast = {
|
|
1897
1897
|
ast_type: "ForSet",
|
|
1898
1898
|
type: NullType,
|
|
1899
|
-
location: get_location(
|
|
1899
|
+
location: get_location(),
|
|
1900
1900
|
label,
|
|
1901
1901
|
set: Expr.ast(collection),
|
|
1902
1902
|
key: key_variable,
|
|
@@ -1909,18 +1909,18 @@ export const BlockBuilder = (return_type) => {
|
|
|
1909
1909
|
const value_variable = {
|
|
1910
1910
|
ast_type: "Variable",
|
|
1911
1911
|
type: Expr.type(collection).value,
|
|
1912
|
-
location: get_location(
|
|
1912
|
+
location: get_location(),
|
|
1913
1913
|
mutable: false,
|
|
1914
1914
|
};
|
|
1915
1915
|
const value = fromAst(value_variable);
|
|
1916
1916
|
const key_variable = {
|
|
1917
1917
|
ast_type: "Variable",
|
|
1918
1918
|
type: Expr.type(collection).key,
|
|
1919
|
-
location: get_location(
|
|
1919
|
+
location: get_location(),
|
|
1920
1920
|
mutable: false,
|
|
1921
1921
|
};
|
|
1922
1922
|
const key = fromAst(key_variable);
|
|
1923
|
-
const label = { location: get_location(
|
|
1923
|
+
const label = { location: get_location() };
|
|
1924
1924
|
const $ = BlockBuilder(return_type);
|
|
1925
1925
|
const ret = body($, value, key, label);
|
|
1926
1926
|
const stmts = $.statements;
|
|
@@ -1932,26 +1932,26 @@ export const BlockBuilder = (return_type) => {
|
|
|
1932
1932
|
}
|
|
1933
1933
|
let expr;
|
|
1934
1934
|
if (stmts.length === 0) {
|
|
1935
|
-
expr = { ast_type: "Value", type: NullType, location: get_location(
|
|
1935
|
+
expr = { ast_type: "Value", type: NullType, location: get_location(), value: null };
|
|
1936
1936
|
}
|
|
1937
1937
|
else if (stmts.length === 1 && isSubtype(stmts[0].type, NullType)) {
|
|
1938
1938
|
expr = stmts[0];
|
|
1939
1939
|
}
|
|
1940
1940
|
else {
|
|
1941
1941
|
if (!isSubtype(stmts[stmts.length - 1].type, NullType)) {
|
|
1942
|
-
stmts.push({ ast_type: "Value", type: NullType, location: get_location(
|
|
1942
|
+
stmts.push({ ast_type: "Value", type: NullType, location: get_location(), value: null });
|
|
1943
1943
|
}
|
|
1944
1944
|
expr = {
|
|
1945
1945
|
ast_type: "Block",
|
|
1946
1946
|
type: stmts[stmts.length - 1].type,
|
|
1947
|
-
location: get_location(
|
|
1947
|
+
location: get_location(),
|
|
1948
1948
|
statements: stmts,
|
|
1949
1949
|
};
|
|
1950
1950
|
}
|
|
1951
1951
|
const ast = {
|
|
1952
1952
|
ast_type: "ForDict",
|
|
1953
1953
|
type: NullType,
|
|
1954
|
-
location: get_location(
|
|
1954
|
+
location: get_location(),
|
|
1955
1955
|
label,
|
|
1956
1956
|
dict: Expr.ast(collection),
|
|
1957
1957
|
key: key_variable,
|
|
@@ -1967,10 +1967,10 @@ export const BlockBuilder = (return_type) => {
|
|
|
1967
1967
|
});
|
|
1968
1968
|
$.error = (message, location) => {
|
|
1969
1969
|
if (isTypeEqual($.type(), NeverType)) {
|
|
1970
|
-
throw new Error(`Unreachable statement detected at ${
|
|
1970
|
+
throw new Error(`Unreachable statement detected at ${printLocations(get_location())}`);
|
|
1971
1971
|
}
|
|
1972
1972
|
if (location === undefined) {
|
|
1973
|
-
location = get_location(
|
|
1973
|
+
location = get_location();
|
|
1974
1974
|
}
|
|
1975
1975
|
const ast = {
|
|
1976
1976
|
ast_type: "Error",
|
|
@@ -1983,7 +1983,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1983
1983
|
};
|
|
1984
1984
|
$.try = (body) => {
|
|
1985
1985
|
if (isTypeEqual($.type(), NeverType)) {
|
|
1986
|
-
throw new Error(`Unreachable statement detected at ${
|
|
1986
|
+
throw new Error(`Unreachable statement detected at ${printLocations(get_location())}`);
|
|
1987
1987
|
}
|
|
1988
1988
|
const $try = BlockBuilder(return_type);
|
|
1989
1989
|
const ret = body($try);
|
|
@@ -1995,7 +1995,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1995
1995
|
}
|
|
1996
1996
|
}
|
|
1997
1997
|
if (try_stmts.length === 0 || !isSubtype(try_stmts[try_stmts.length - 1].type, NullType)) {
|
|
1998
|
-
try_stmts.push({ ast_type: "Value", type: NullType, location: get_location(
|
|
1998
|
+
try_stmts.push({ ast_type: "Value", type: NullType, location: get_location(), value: null });
|
|
1999
1999
|
}
|
|
2000
2000
|
let try_expr;
|
|
2001
2001
|
if (try_stmts.length === 1) {
|
|
@@ -2005,7 +2005,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
2005
2005
|
try_expr = {
|
|
2006
2006
|
ast_type: "Block",
|
|
2007
2007
|
type: try_stmts[try_stmts.length - 1].type,
|
|
2008
|
-
location: get_location(
|
|
2008
|
+
location: get_location(),
|
|
2009
2009
|
statements: try_stmts,
|
|
2010
2010
|
};
|
|
2011
2011
|
}
|
|
@@ -2013,21 +2013,21 @@ export const BlockBuilder = (return_type) => {
|
|
|
2013
2013
|
const message_variable = {
|
|
2014
2014
|
ast_type: "Variable",
|
|
2015
2015
|
type: StringType,
|
|
2016
|
-
location: get_location(
|
|
2016
|
+
location: get_location(),
|
|
2017
2017
|
mutable: false,
|
|
2018
2018
|
};
|
|
2019
2019
|
const stack_variable = {
|
|
2020
2020
|
ast_type: "Variable",
|
|
2021
2021
|
type: ArrayType(StructType({ filename: StringType, line: IntegerType, column: IntegerType })),
|
|
2022
|
-
location: get_location(
|
|
2022
|
+
location: get_location(),
|
|
2023
2023
|
mutable: false,
|
|
2024
2024
|
};
|
|
2025
2025
|
const try_catch_ast = {
|
|
2026
2026
|
ast_type: "TryCatch",
|
|
2027
2027
|
type: NullType,
|
|
2028
|
-
location: get_location(
|
|
2028
|
+
location: get_location(),
|
|
2029
2029
|
try_body: try_expr,
|
|
2030
|
-
catch_body: { ast_type: "Value", type: NullType, location: get_location(
|
|
2030
|
+
catch_body: { ast_type: "Value", type: NullType, location: get_location(), value: null }, // will be updated later
|
|
2031
2031
|
message: message_variable,
|
|
2032
2032
|
stack: stack_variable,
|
|
2033
2033
|
};
|
|
@@ -2058,12 +2058,12 @@ class IfElseExpr extends NullExpr {
|
|
|
2058
2058
|
}
|
|
2059
2059
|
}
|
|
2060
2060
|
if (stmts.length === 0 || !isSubtype(stmts[stmts.length - 1].type, NullType)) {
|
|
2061
|
-
stmts.push({ ast_type: "Value", type: NullType, location: get_location(
|
|
2061
|
+
stmts.push({ ast_type: "Value", type: NullType, location: get_location(), value: null });
|
|
2062
2062
|
}
|
|
2063
2063
|
this[AstSymbol].else_body = stmts.length === 1 ? stmts[0] : {
|
|
2064
2064
|
ast_type: "Block",
|
|
2065
2065
|
type: stmts[stmts.length - 1].type,
|
|
2066
|
-
location: get_location(
|
|
2066
|
+
location: get_location(),
|
|
2067
2067
|
statements: stmts,
|
|
2068
2068
|
};
|
|
2069
2069
|
// propagate unreachable information
|
|
@@ -2104,14 +2104,14 @@ class IfElseExpr extends NullExpr {
|
|
|
2104
2104
|
}
|
|
2105
2105
|
}
|
|
2106
2106
|
if (stmts.length === 0 || !isSubtype(stmts[stmts.length - 1].type, NullType)) {
|
|
2107
|
-
stmts.push({ ast_type: "Value", type: NullType, location: get_location(
|
|
2107
|
+
stmts.push({ ast_type: "Value", type: NullType, location: get_location(), value: null });
|
|
2108
2108
|
}
|
|
2109
2109
|
this[AstSymbol].ifs.push({
|
|
2110
2110
|
predicate: Expr.ast(predicate),
|
|
2111
2111
|
body: stmts.length === 1 ? stmts[0] : {
|
|
2112
2112
|
ast_type: "Block",
|
|
2113
2113
|
type: stmts[stmts.length - 1].type,
|
|
2114
|
-
location: get_location(
|
|
2114
|
+
location: get_location(),
|
|
2115
2115
|
statements: stmts,
|
|
2116
2116
|
},
|
|
2117
2117
|
});
|
|
@@ -2136,7 +2136,7 @@ class TryCatchExpr extends NullExpr {
|
|
|
2136
2136
|
/** Define the logic to follow when an error is caught. The error message and stack trace is provided. */
|
|
2137
2137
|
catch(body) {
|
|
2138
2138
|
if (this.catchCalled) {
|
|
2139
|
-
throw new Error(`Cannot call .catch() more than once on the same try block at ${
|
|
2139
|
+
throw new Error(`Cannot call .catch() more than once on the same try block at ${printLocations(get_location())}`);
|
|
2140
2140
|
}
|
|
2141
2141
|
this.catchCalled = true;
|
|
2142
2142
|
const $ = BlockBuilder(this.return_type);
|
|
@@ -2149,12 +2149,12 @@ class TryCatchExpr extends NullExpr {
|
|
|
2149
2149
|
}
|
|
2150
2150
|
}
|
|
2151
2151
|
if (stmts.length === 0 || !isSubtype(stmts[stmts.length - 1].type, NullType)) {
|
|
2152
|
-
stmts.push({ ast_type: "Value", type: NullType, location: get_location(
|
|
2152
|
+
stmts.push({ ast_type: "Value", type: NullType, location: get_location(), value: null });
|
|
2153
2153
|
}
|
|
2154
2154
|
this[AstSymbol].catch_body = stmts.length === 1 ? stmts[0] : {
|
|
2155
2155
|
ast_type: "Block",
|
|
2156
2156
|
type: stmts[stmts.length - 1].type,
|
|
2157
|
-
location: get_location(
|
|
2157
|
+
location: get_location(),
|
|
2158
2158
|
statements: stmts,
|
|
2159
2159
|
};
|
|
2160
2160
|
// Propagate unreachable information
|
|
@@ -2175,12 +2175,12 @@ class TryCatchExpr extends NullExpr {
|
|
|
2175
2175
|
}
|
|
2176
2176
|
}
|
|
2177
2177
|
if (stmts.length === 0 || !isSubtype(stmts[stmts.length - 1].type, NullType)) {
|
|
2178
|
-
stmts.push({ ast_type: "Value", type: NullType, location: get_location(
|
|
2178
|
+
stmts.push({ ast_type: "Value", type: NullType, location: get_location(), value: null });
|
|
2179
2179
|
}
|
|
2180
2180
|
this[AstSymbol].finally_body = stmts.length === 1 ? stmts[0] : {
|
|
2181
2181
|
ast_type: "Block",
|
|
2182
2182
|
type: stmts[stmts.length - 1].type,
|
|
2183
|
-
location: get_location(
|
|
2183
|
+
location: get_location(),
|
|
2184
2184
|
statements: stmts,
|
|
2185
2185
|
};
|
|
2186
2186
|
}
|