@magnusopera/fscript 0.77.1 → 0.79.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 (85) hide show
  1. package/dist/FScript.Language/Ast.js +2 -2
  2. package/dist/FScript.Language/BuiltinFunctions.js +68 -67
  3. package/dist/FScript.Language/BuiltinSignatures.js +7 -7
  4. package/dist/FScript.Language/BuiltinTypes.js +3 -3
  5. package/dist/FScript.Language/Error.js +2 -2
  6. package/dist/FScript.Language/Eval.js +305 -213
  7. package/dist/FScript.Language/IncludeResolver.js +97 -79
  8. package/dist/FScript.Language/Interactive.js +149 -0
  9. package/dist/FScript.Language/Lexer.js +77 -77
  10. package/dist/FScript.Language/Parser.js +274 -272
  11. package/dist/FScript.Language/Pretty.js +4 -4
  12. package/dist/FScript.Language/Span.js +2 -2
  13. package/dist/FScript.Language/Token.js +59 -2
  14. package/dist/FScript.Language/TypeInfer.js +704 -379
  15. package/dist/FScript.Language/Types.js +98 -27
  16. package/dist/FScript.Language/Value.js +3 -2
  17. package/dist/Library.js +91 -79
  18. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Array.js +36 -35
  19. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Async.js +52 -23
  20. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/AsyncBuilder.js +23 -2
  21. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/BigInt.js +33 -32
  22. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/BitConverter.js +2 -2
  23. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/CHANGELOG.md +80 -1
  24. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Date.js +8 -15
  25. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/DateOffset.js +8 -17
  26. package/dist/fable_modules/fable-library-js.5.13.0/Directory.js +11 -0
  27. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Double.js +8 -2
  28. package/dist/fable_modules/fable-library-js.5.13.0/Environment.js +3 -0
  29. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Event.js +10 -1
  30. package/dist/fable_modules/fable-library-js.5.13.0/File.js +27 -0
  31. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/List.js +35 -21
  32. package/dist/fable_modules/fable-library-js.5.13.0/Long.js +38 -0
  33. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/MailboxProcessor.js +11 -5
  34. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Map.js +8 -4
  35. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/MutableMap.js +2 -2
  36. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/MutableSet.js +1 -1
  37. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Observable.js +5 -3
  38. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Option.js +1 -18
  39. package/dist/fable_modules/fable-library-js.5.13.0/Path.js +31 -0
  40. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Reflection.js +13 -3
  41. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/RegExp.js +53 -24
  42. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Seq.js +109 -22
  43. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Set.js +16 -3
  44. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/String.js +28 -1
  45. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/System.js +15 -9
  46. package/dist/fable_modules/fable-library-js.5.13.0/Task.js +27 -0
  47. package/dist/fable_modules/fable-library-js.5.13.0/TaskBuilder.js +72 -0
  48. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Types.js +12 -12
  49. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Util.js +15 -3
  50. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/package.json +1 -1
  51. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/quotation.js +25 -8
  52. package/dist/fable_modules/project_cracked.json +1 -1
  53. package/package.json +2 -2
  54. package/dist/fable_modules/fable-library-js.5.2.0/Long.js +0 -47
  55. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Boolean.js +0 -0
  56. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Char.js +0 -0
  57. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Choice.js +0 -0
  58. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/CollectionUtil.js +0 -0
  59. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/ConditionalWeakTable.js +0 -0
  60. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/DateOnly.js +0 -0
  61. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Decimal.js +0 -0
  62. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Encoding.js +0 -0
  63. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/FSharp.Collections.js +0 -0
  64. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/FSharp.Core.CompilerServices.js +0 -0
  65. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/FSharp.Core.js +0 -0
  66. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Global.js +0 -0
  67. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Guid.js +0 -0
  68. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Int32.js +0 -0
  69. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/MapUtil.js +0 -0
  70. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Native.js +0 -0
  71. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Numeric.js +0 -0
  72. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/README.md +0 -0
  73. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Random.js +0 -0
  74. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Range.js +0 -0
  75. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Result.js +0 -0
  76. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Seq2.js +0 -0
  77. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/System.Collections.Generic.js +0 -0
  78. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/System.Text.js +0 -0
  79. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/TimeOnly.js +0 -0
  80. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/TimeSpan.js +0 -0
  81. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Timer.js +0 -0
  82. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Unicode.13.0.0.js +0 -0
  83. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Uri.js +0 -0
  84. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/big.d.ts +0 -0
  85. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/lib/big.js +0 -0
@@ -1,20 +1,20 @@
1
1
 
2
- import { toString, FSharpRef, Record } from "../fable_modules/fable-library-js.5.2.0/Types.js";
3
- import { option_type, array_type, obj_type, record_type, class_type, string_type } from "../fable_modules/fable-library-js.5.2.0/Reflection.js";
2
+ import { toString, FSharpRef, Record } from "../fable_modules/fable-library-js.5.13.0/Types.js";
3
+ import { option_type, array_type, obj_type, record_type, class_type, string_type } from "../fable_modules/fable-library-js.5.13.0/Reflection.js";
4
4
  import { Type, Types_typeToString, Type_$reflection } from "./Types.js";
5
5
  import { ExternalCallContext, MapKey, Value, TaskHandle_$reflection, Value_$reflection } from "./Value.js";
6
6
  import { EvalException, EvalError$, EvalError$_$reflection } from "./Error.js";
7
7
  import { Span, Position } from "./Span.js";
8
- import { printf, toText, join, concat } from "../fable_modules/fable-library-js.5.2.0/String.js";
9
- import { curry2, disposeSafe, getEnumerator, equals as equals_1, compare, comparePrimitives, int64ToString } from "../fable_modules/fable-library-js.5.2.0/Util.js";
10
- import { ofArray, collect, tryFindIndex, choose, tryPick as tryPick_1, tryFind as tryFind_1, append, reverse, zip, fold as fold_1, singleton, forAll as forAll_1, empty, cons, tail as tail_2, head as head_2, isEmpty, forAll2, length, map } from "../fable_modules/fable-library-js.5.2.0/List.js";
11
- import { map as map_2, containsKey, FSharpMap__Add, fold, empty as empty_1, FSharpMap__Remove, FSharpMap__get_IsEmpty, FSharpMap__ContainsKey, add, FSharpMap__TryFind, tryFind, toSeq, ofList, FSharpMap__get_Item, forAll, FSharpMap__get_Keys, FSharpMap__get_Count, toList } from "../fable_modules/fable-library-js.5.2.0/Map.js";
12
- import { op_Modulus, op_Division, op_Multiply, op_Subtraction, op_Addition, toInt64_unchecked, compare as compare_1, equals } from "../fable_modules/fable-library-js.5.2.0/BigInt.js";
13
- import { contains, ofSeq } from "../fable_modules/fable-library-js.5.2.0/Set.js";
14
- import { toArray, some, bind, map as map_1 } from "../fable_modules/fable-library-js.5.2.0/Option.js";
15
- import { filter, length as length_1, iterate, foldBack, head as head_3, tryPick } from "../fable_modules/fable-library-js.5.2.0/Seq.js";
8
+ import { printf, toText, join, concat } from "../fable_modules/fable-library-js.5.13.0/String.js";
9
+ import { curry2, disposeSafe, getEnumerator, equals as equals_1, compare, comparePrimitives, int64ToString } from "../fable_modules/fable-library-js.5.13.0/Util.js";
10
+ import { ofArray, collect, tryFindIndex, choose, tryFind as tryFind_1, tryPick as tryPick_1, append, reverse, zip, fold as fold_1, singleton, forAll as forAll_1, empty, cons, tail as tail_2, head as head_2, isEmpty, forAll2, length, map } from "../fable_modules/fable-library-js.5.13.0/List.js";
11
+ import { map as map_1, containsKey, FSharpMap__Add, fold, empty as empty_1, FSharpMap__Remove, FSharpMap__get_IsEmpty, FSharpMap__ContainsKey, add, FSharpMap__TryFind, tryFind, toSeq, ofList, FSharpMap__get_Item, forAll, FSharpMap__get_Keys, FSharpMap__get_Count, toList } from "../fable_modules/fable-library-js.5.13.0/Map.js";
12
+ import { op_Modulus, op_Division, op_Multiply, op_Subtraction, op_Addition, toInt64_unchecked, compare as compare_1, equals } from "../fable_modules/fable-library-js.5.13.0/BigInt.js";
13
+ import { contains, ofSeq } from "../fable_modules/fable-library-js.5.13.0/Set.js";
14
+ import { filter, length as length_1, foldBack, head as head_3, tryPick } from "../fable_modules/fable-library-js.5.13.0/Seq.js";
16
15
  import { Ast_spanOfExpr, Expr, Ast_spanOfPattern, TypeRef } from "./Ast.js";
17
- import { StringBuilder__Append_Z721C83C5, StringBuilder_$ctor } from "../fable_modules/fable-library-js.5.2.0/System.Text.js";
16
+ import { some } from "../fable_modules/fable-library-js.5.13.0/Option.js";
17
+ import { StringBuilder__Append_Z721C83C5, StringBuilder_$ctor } from "../fable_modules/fable-library-js.5.13.0/System.Text.js";
18
18
  import { builtinReservedNames } from "./BuiltinSignatures.js";
19
19
  import { typeDefs as typeDefs_3 } from "./BuiltinTypes.js";
20
20
  import { builtinExterns } from "./BuiltinFunctions.js";
@@ -73,13 +73,13 @@ function raiseIfBackgroundFailed(runtime) {
73
73
  function literalToValue(lit) {
74
74
  switch (lit.tag) {
75
75
  case 1:
76
- return new Value(2, [lit.fields[0]]);
76
+ return new Value(/* VFloat */ 2, [lit.fields[0]]);
77
77
  case 2:
78
- return new Value(3, [lit.fields[0]]);
78
+ return new Value(/* VBool */ 3, [lit.fields[0]]);
79
79
  case 3:
80
- return new Value(4, [lit.fields[0]]);
80
+ return new Value(/* VString */ 4, [lit.fields[0]]);
81
81
  default:
82
- return new Value(1, [lit.fields[0]]);
82
+ return new Value(/* VInt */ 1, [lit.fields[0]]);
83
83
  }
84
84
  }
85
85
 
@@ -431,19 +431,19 @@ function valueEquals(a_mut, b_mut) {
431
431
 
432
432
  function mapKeyToValue(key) {
433
433
  if (key.tag === 1) {
434
- return new Value(1, [key.fields[0]]);
434
+ return new Value(/* VInt */ 1, [key.fields[0]]);
435
435
  }
436
436
  else {
437
- return new Value(4, [key.fields[0]]);
437
+ return new Value(/* VString */ 4, [key.fields[0]]);
438
438
  }
439
439
  }
440
440
 
441
441
  function valueToMapKey(span, value) {
442
442
  switch (value.tag) {
443
443
  case 4:
444
- return new MapKey(0, [value.fields[0]]);
444
+ return new MapKey(/* MKString */ 0, [value.fields[0]]);
445
445
  case 1:
446
- return new MapKey(1, [value.fields[0]]);
446
+ return new MapKey(/* MKInt */ 1, [value.fields[0]]);
447
447
  default:
448
448
  throw new EvalException(new EvalError$("Map key must be string or int", span));
449
449
  }
@@ -452,27 +452,64 @@ function valueToMapKey(span, value) {
452
452
  function valueMatchesTypeRef(typeDefs, tref, value) {
453
453
  const resolve = (tref_1) => {
454
454
  switch (tref_1.tag) {
455
- case 1:
456
- return map_1((Item) => (new Type(7, [Item])), resolveTypeList(tref_1.fields[0]));
455
+ case 1: {
456
+ const option_1 = resolveTypeList(tref_1.fields[0]);
457
+ if (option_1 != null) {
458
+ return new Type(/* TTuple */ 7, [option_1]);
459
+ }
460
+ else {
461
+ return undefined;
462
+ }
463
+ }
457
464
  case 2:
458
465
  return undefined;
459
466
  case 3:
460
467
  switch (tref_1.fields[1]) {
461
- case "list":
462
- return map_1((Item_1) => (new Type(5, [Item_1])), resolve(tref_1.fields[0]));
463
- case "task":
464
- return map_1((Item_2) => (new Type(6, [Item_2])), resolve(tref_1.fields[0]));
465
- case "option":
466
- return map_1((Item_3) => (new Type(10, [Item_3])), resolve(tref_1.fields[0]));
467
- case "map":
468
- return map_1((t) => (new Type(9, [new Type(4, []), t])), resolve(tref_1.fields[0]));
468
+ case "list": {
469
+ const option_3 = resolve(tref_1.fields[0]);
470
+ if (option_3 != null) {
471
+ return new Type(/* TList */ 5, [option_3]);
472
+ }
473
+ else {
474
+ return undefined;
475
+ }
476
+ }
477
+ case "task": {
478
+ const option_5 = resolve(tref_1.fields[0]);
479
+ if (option_5 != null) {
480
+ return new Type(/* TTask */ 6, [option_5]);
481
+ }
482
+ else {
483
+ return undefined;
484
+ }
485
+ }
486
+ case "option": {
487
+ const option_7 = resolve(tref_1.fields[0]);
488
+ if (option_7 != null) {
489
+ return new Type(/* TOption */ 10, [option_7]);
490
+ }
491
+ else {
492
+ return undefined;
493
+ }
494
+ }
495
+ case "map": {
496
+ const option_9 = resolve(tref_1.fields[0]);
497
+ if (option_9 != null) {
498
+ return new Type(/* TMap */ 9, [Type.TString, option_9]);
499
+ }
500
+ else {
501
+ return undefined;
502
+ }
503
+ }
469
504
  default:
470
505
  return undefined;
471
506
  }
472
507
  case 4: {
473
- const shape = map_1((elements) => ofList(elements, {
508
+ let shape;
509
+ const option_11 = resolveFieldList(tref_1.fields[0]);
510
+ shape = ((option_11 != null) ? ofList(option_11, {
474
511
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
475
- }), resolveFieldList(tref_1.fields[0]));
512
+ }) : undefined);
476
513
  if (shape != null) {
477
514
  const s = shape;
478
515
  return tryPick((tupledArg) => {
@@ -492,7 +529,7 @@ function valueMatchesTypeRef(typeDefs, tref, value) {
492
529
  }
493
530
  switch (matchResult) {
494
531
  case 0:
495
- return new Type(12, [tupledArg[0]]);
532
+ return new Type(/* TNamed */ 12, [tupledArg[0]]);
496
533
  default:
497
534
  return undefined;
498
535
  }
@@ -502,22 +539,29 @@ function valueMatchesTypeRef(typeDefs, tref, value) {
502
539
  return undefined;
503
540
  }
504
541
  }
505
- case 5:
506
- return map_1((arg) => (new Type(8, [ofList(arg, {
507
- Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
508
- })])), resolveFieldList(tref_1.fields[0]));
542
+ case 5: {
543
+ const option_13 = resolveFieldList(tref_1.fields[0]);
544
+ if (option_13 != null) {
545
+ return new Type(/* TRecord */ 8, [ofList(option_13, {
546
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
547
+ })]);
548
+ }
549
+ else {
550
+ return undefined;
551
+ }
552
+ }
509
553
  default:
510
554
  switch (tref_1.fields[0]) {
511
555
  case "unit":
512
- return new Type(0, []);
556
+ return Type.TUnit;
513
557
  case "int":
514
- return new Type(1, []);
558
+ return Type.TInt;
515
559
  case "float":
516
- return new Type(2, []);
560
+ return Type.TFloat;
517
561
  case "bool":
518
- return new Type(3, []);
562
+ return Type.TBool;
519
563
  case "string":
520
- return new Type(4, []);
564
+ return Type.TString;
521
565
  default:
522
566
  return tryFind(tref_1.fields[0], typeDefs);
523
567
  }
@@ -778,7 +822,7 @@ function valueMatchesTypeRef(typeDefs, tref, value) {
778
822
  }
779
823
  }
780
824
  case 5: {
781
- const matchValue_10 = resolve(new TypeRef(5, [tref.fields[0]]));
825
+ const matchValue_10 = resolve(new TypeRef(/* TRStructuralRecord */ 5, [tref.fields[0]]));
782
826
  if (matchValue_10 == null) {
783
827
  return false;
784
828
  }
@@ -897,11 +941,11 @@ function patternMatch(typeDefs_mut, pat_mut, value_mut) {
897
941
  let targetKey;
898
942
  switch (targetKeyValue.tag) {
899
943
  case 4: {
900
- targetKey = (new MapKey(0, [targetKeyValue.fields[0]]));
944
+ targetKey = (new MapKey(/* MKString */ 0, [targetKeyValue.fields[0]]));
901
945
  break;
902
946
  }
903
947
  case 1: {
904
- targetKey = (new MapKey(1, [targetKeyValue.fields[0]]));
948
+ targetKey = (new MapKey(/* MKInt */ 1, [targetKeyValue.fields[0]]));
905
949
  break;
906
950
  }
907
951
  default:
@@ -938,7 +982,7 @@ function patternMatch(typeDefs_mut, pat_mut, value_mut) {
938
982
  }
939
983
  }
940
984
  else {
941
- return bind((tupledArg) => matchMapClauses(hasExplicitClauses, rest, tailPattern, FSharpMap__Remove(remaining, tupledArg[0]), tupledArg[1]), tryPick((kv) => {
985
+ const option_1 = tryPick((kv) => {
942
986
  const matchValue_10 = patternMatch(typeDefs, keyPattern, mapKeyToValue(kv[0]));
943
987
  if (matchValue_10 == null) {
944
988
  return undefined;
@@ -965,7 +1009,19 @@ function patternMatch(typeDefs_mut, pat_mut, value_mut) {
965
1009
  }
966
1010
  }
967
1011
  }
968
- }, remaining));
1012
+ }, remaining);
1013
+ if (option_1 != null) {
1014
+ const tupledArg = option_1;
1015
+ hasExplicitClauses_mut = hasExplicitClauses;
1016
+ clauses_mut = rest;
1017
+ tailPattern_mut = tailPattern;
1018
+ remaining_mut = FSharpMap__Remove(remaining, tupledArg[0]);
1019
+ envAcc_mut = tupledArg[1];
1020
+ continue matchMapClauses;
1021
+ }
1022
+ else {
1023
+ return undefined;
1024
+ }
969
1025
  }
970
1026
  }
971
1027
  else if (tailPattern == null) {
@@ -977,7 +1033,7 @@ function patternMatch(typeDefs_mut, pat_mut, value_mut) {
977
1033
  }
978
1034
  }
979
1035
  else {
980
- const matchValue_1 = patternMatch(typeDefs, tailPattern, new Value(8, [remaining]));
1036
+ const matchValue_1 = patternMatch(typeDefs, tailPattern, new Value(/* VMap */ 8, [remaining]));
981
1037
  if (matchValue_1 == null) {
982
1038
  return undefined;
983
1039
  }
@@ -1151,7 +1207,7 @@ function patternMatch(typeDefs_mut, pat_mut, value_mut) {
1151
1207
  });
1152
1208
  case 4: {
1153
1209
  const matchValue_15 = patternMatch(typeDefs, p1, h);
1154
- const matchValue_16 = patternMatch(typeDefs, p2, new Value(5, [t]));
1210
+ const matchValue_16 = patternMatch(typeDefs, p2, new Value(/* VList */ 5, [t]));
1155
1211
  let matchResult_2, env1, env2;
1156
1212
  if (matchValue_15 != null) {
1157
1213
  if (matchValue_16 != null) {
@@ -1246,8 +1302,10 @@ function patternMatch(typeDefs_mut, pat_mut, value_mut) {
1246
1302
  return empty_1({
1247
1303
  Compare: (x_7, y_7) => (comparePrimitives(x_7, y_7) | 0),
1248
1304
  });
1249
- case 10:
1250
- if ((caseName === valueCaseName) && ((qualifier == null) ? true : (qualifier === valueTypeName))) {
1305
+ case 10: {
1306
+ const caseMatches = caseName === valueCaseName;
1307
+ const qualifierMatches = (qualifier == null) ? true : (qualifier === valueTypeName);
1308
+ if (caseMatches && qualifierMatches) {
1251
1309
  let matchResult_5, p_3, v_7;
1252
1310
  if (payload != null) {
1253
1311
  if (valuePayload != null) {
@@ -1283,6 +1341,7 @@ function patternMatch(typeDefs_mut, pat_mut, value_mut) {
1283
1341
  else {
1284
1342
  return undefined;
1285
1343
  }
1344
+ }
1286
1345
  case 11:
1287
1346
  if (valueMatchesTypeRef(typeDefs, tref, v_8)) {
1288
1347
  return empty_1({
@@ -1321,7 +1380,7 @@ function applyFunctionValue(runtime, eval$, typeDefs, span, fnValue, argValue) {
1321
1380
  case 14:
1322
1381
  return eval$(runtime, typeDefs, add(fnValue.fields[0], argValue, fnValue.fields[2].contents), fnValue.fields[1]);
1323
1382
  case 11:
1324
- return new Value(10, [fnValue.fields[0], fnValue.fields[1], argValue]);
1383
+ return new Value(/* VUnionCase */ 10, [fnValue.fields[0], fnValue.fields[1], argValue]);
1325
1384
  case 15: {
1326
1385
  const ext = fnValue.fields[0];
1327
1386
  const args$0027 = cons(argValue, fnValue.fields[1]);
@@ -1329,7 +1388,7 @@ function applyFunctionValue(runtime, eval$, typeDefs, span, fnValue, argValue) {
1329
1388
  return ext.Impl(createExternContext(runtime, typeDefs, span), reverse(args$0027));
1330
1389
  }
1331
1390
  else if (length(args$0027) < ext.Arity) {
1332
- return new Value(15, [ext, args$0027]);
1391
+ return new Value(/* VExternal */ 15, [ext, args$0027]);
1333
1392
  }
1334
1393
  else {
1335
1394
  throw new EvalException(new EvalError$(toText(printf("External function \'%s\' received too many arguments"))(ext.Name), span));
@@ -1366,7 +1425,7 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1366
1425
  continue evalExpr;
1367
1426
  }
1368
1427
  case 4:
1369
- return new Value(14, [expr.fields[0].Name, expr.fields[1], new FSharpRef(env)]);
1428
+ return new Value(/* VClosure */ 14, [expr.fields[0].Name, expr.fields[1], new FSharpRef(env)]);
1370
1429
  case 5:
1371
1430
  return applyFunctionValue(runtime, evalExpr, typeDefs, expr.fields[2], evalExpr(runtime, typeDefs, env, expr.fields[0]), evalExpr(runtime, typeDefs, env, expr.fields[1]));
1372
1431
  case 6: {
@@ -1413,7 +1472,7 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1413
1472
  finally {
1414
1473
  disposeSafe(enumerator);
1415
1474
  }
1416
- return new Value(0, []);
1475
+ return Value.VUnit;
1417
1476
  }
1418
1477
  else {
1419
1478
  throw new EvalException(new EvalError$("For loop source must be list", expr.fields[3]));
@@ -1426,7 +1485,7 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1426
1485
  if (expr.fields[3]) {
1427
1486
  if (value_1.tag === 4) {
1428
1487
  const recEnv = new FSharpRef(env);
1429
- recEnv.contents = add(name_2, new Value(14, [value_1.fields[0].Name, value_1.fields[1], recEnv]), env);
1488
+ recEnv.contents = add(name_2, new Value(/* VClosure */ 14, [value_1.fields[0].Name, value_1.fields[1], recEnv]), env);
1430
1489
  runtime_mut = runtime;
1431
1490
  typeDefs_mut = typeDefs;
1432
1491
  env_mut = recEnv.contents;
@@ -1476,9 +1535,9 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1476
1535
  if (isEmpty(args)) {
1477
1536
  throw new EvalException(new EvalError$("\'let rec ... and ...\' requires function arguments for each binding", bindingSpan));
1478
1537
  }
1479
- const folded = foldBack((arg_2, accExpr) => (new Expr(4, [arg_2, accExpr, bindingSpan])), args, tupledArg[3]);
1538
+ const folded = foldBack((arg_2, accExpr) => (new Expr(/* ELambda */ 4, [arg_2, accExpr, bindingSpan])), args, tupledArg[3]);
1480
1539
  if (folded.tag === 4) {
1481
- return [tupledArg[0], new Value(14, [folded.fields[0].Name, folded.fields[1], recEnv_1])];
1540
+ return [tupledArg[0], new Value(/* VClosure */ 14, [folded.fields[0].Name, folded.fields[1], recEnv_1])];
1482
1541
  }
1483
1542
  else {
1484
1543
  throw new EvalException(new EvalError$("let rec requires a function binding", expr.fields[2]));
@@ -1539,7 +1598,7 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1539
1598
  return tryCases(expr.fields[1]);
1540
1599
  }
1541
1600
  case 13:
1542
- return new Value(5, [map((expr_2) => evalExpr(runtime, typeDefs, env, expr_2), expr.fields[0])]);
1601
+ return new Value(/* VList */ 5, [map((expr_2) => evalExpr(runtime, typeDefs, env, expr_2), expr.fields[0])]);
1543
1602
  case 14: {
1544
1603
  const startValue = evalExpr(runtime, typeDefs, env, expr.fields[0]);
1545
1604
  const endValue = evalExpr(runtime, typeDefs, env, expr.fields[1]);
@@ -1568,31 +1627,31 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1568
1627
  return reverse(acc_3);
1569
1628
  }
1570
1629
  else {
1571
- acc_3_mut = cons(new Value(1, [current]), acc_3);
1630
+ acc_3_mut = cons(new Value(/* VInt */ 1, [current]), acc_3);
1572
1631
  current_mut = toInt64_unchecked(op_Addition(current, step));
1573
1632
  continue build;
1574
1633
  }
1575
1634
  break;
1576
1635
  }
1577
1636
  };
1578
- return new Value(5, [build(empty(), s)]);
1637
+ return new Value(/* VList */ 5, [build(empty(), s)]);
1579
1638
  }
1580
1639
  default:
1581
1640
  throw new EvalException(new EvalError$("Range endpoints must be int", expr.fields[2]));
1582
1641
  }
1583
1642
  }
1584
1643
  case 15:
1585
- return new Value(6, [map((expr_3) => evalExpr(runtime, typeDefs, env, expr_3), expr.fields[0])]);
1644
+ return new Value(/* VTuple */ 6, [map((expr_3) => evalExpr(runtime, typeDefs, env, expr_3), expr.fields[0])]);
1586
1645
  case 16:
1587
- return new Value(7, [ofList(map((tupledArg_2) => [tupledArg_2[0], evalExpr(runtime, typeDefs, env, tupledArg_2[1])], expr.fields[0]), {
1646
+ return new Value(/* VRecord */ 7, [ofList(map((tupledArg_2) => [tupledArg_2[0], evalExpr(runtime, typeDefs, env, tupledArg_2[1])], expr.fields[0]), {
1588
1647
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
1589
1648
  })]);
1590
1649
  case 17:
1591
- return new Value(7, [ofList(map((tupledArg_3) => [tupledArg_3[0], evalExpr(runtime, typeDefs, env, tupledArg_3[1])], expr.fields[0]), {
1650
+ return new Value(/* VRecord */ 7, [ofList(map((tupledArg_3) => [tupledArg_3[0], evalExpr(runtime, typeDefs, env, tupledArg_3[1])], expr.fields[0]), {
1592
1651
  Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
1593
1652
  })]);
1594
1653
  case 18:
1595
- return new Value(8, [fold_1((acc_4, entry) => {
1654
+ return new Value(/* VMap */ 8, [fold_1((acc_4, entry) => {
1596
1655
  if (entry.tag === 1) {
1597
1656
  const spreadExpr = entry.fields[0];
1598
1657
  const matchValue_8 = evalExpr(runtime, typeDefs, env, spreadExpr);
@@ -1628,7 +1687,7 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1628
1687
  const span_10 = expr.fields[2];
1629
1688
  const matchValue_9 = evalExpr(runtime, typeDefs, env, expr.fields[0]);
1630
1689
  if (matchValue_9.tag === 7) {
1631
- return new Value(7, [fold_1((acc_5, tupledArg_4) => {
1690
+ return new Value(/* VRecord */ 7, [fold_1((acc_5, tupledArg_4) => {
1632
1691
  const name_7 = tupledArg_4[0];
1633
1692
  if (containsKey(name_7, acc_5)) {
1634
1693
  return add(name_7, evalExpr(runtime, typeDefs, env, tupledArg_4[1]), acc_5);
@@ -1645,7 +1704,7 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1645
1704
  case 20: {
1646
1705
  const matchValue_10 = evalExpr(runtime, typeDefs, env, expr.fields[0]);
1647
1706
  if (matchValue_10.tag === 7) {
1648
- return new Value(7, [fold_1((acc_6, tupledArg_5) => add(tupledArg_5[0], evalExpr(runtime, typeDefs, env, tupledArg_5[1]), acc_6), matchValue_10.fields[0], expr.fields[1])]);
1707
+ return new Value(/* VRecord */ 7, [fold_1((acc_6, tupledArg_5) => add(tupledArg_5[0], evalExpr(runtime, typeDefs, env, tupledArg_5[1]), acc_6), matchValue_10.fields[0], expr.fields[1])]);
1649
1708
  }
1650
1709
  else {
1651
1710
  throw new EvalException(new EvalError$("Structural record update requires a record value", expr.fields[2]));
@@ -1767,14 +1826,14 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1767
1826
  }
1768
1827
  };
1769
1828
  if (compare_1(index, 0n) < 0) {
1770
- return new Value(9, [undefined]);
1829
+ return new Value(/* VOption */ 9, [undefined]);
1771
1830
  }
1772
1831
  else {
1773
- return new Value(9, [loop(values, 0n)]);
1832
+ return new Value(/* VOption */ 9, [loop(values, 0n)]);
1774
1833
  }
1775
1834
  }
1776
1835
  case 1:
1777
- return new Value(9, [FSharpMap__TryFind(mapValue, valueToMapKey(span_13, keyValue_1))]);
1836
+ return new Value(/* VOption */ 9, [FSharpMap__TryFind(mapValue, valueToMapKey(span_13, keyValue_1))]);
1778
1837
  case 2:
1779
1838
  throw new EvalException(new EvalError$("Map index key must be string or int", span_13));
1780
1839
  case 3:
@@ -1787,7 +1846,7 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1787
1846
  const h = evalExpr(runtime, typeDefs, env, expr.fields[0]);
1788
1847
  const t = evalExpr(runtime, typeDefs, env, expr.fields[1]);
1789
1848
  if (t.tag === 5) {
1790
- return new Value(5, [cons(h, t.fields[0])]);
1849
+ return new Value(/* VList */ 5, [cons(h, t.fields[0])]);
1791
1850
  }
1792
1851
  else {
1793
1852
  throw new EvalException(new EvalError$("Right side of \'::\' must be list", expr.fields[2]));
@@ -1812,7 +1871,7 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1812
1871
  }
1813
1872
  switch (matchResult_3) {
1814
1873
  case 0:
1815
- return new Value(5, [append(xs_1, ys)]);
1874
+ return new Value(/* VList */ 5, [append(xs_1, ys)]);
1816
1875
  default:
1817
1876
  throw new EvalException(new EvalError$("Both sides of \'@\' must be lists", expr.fields[2]));
1818
1877
  }
@@ -1852,9 +1911,9 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1852
1911
  }
1853
1912
  switch (matchResult_4) {
1854
1913
  case 0:
1855
- return new Value(1, [fInt(x_3)(y_3)]);
1914
+ return new Value(/* VInt */ 1, [fInt(x_3)(y_3)]);
1856
1915
  case 1:
1857
- return new Value(2, [fFloat(x_4)(y_4)]);
1916
+ return new Value(/* VFloat */ 2, [fFloat(x_4)(y_4)]);
1858
1917
  default:
1859
1918
  throw new EvalException(new EvalError$("Numeric operands required", span_16));
1860
1919
  }
@@ -1898,9 +1957,9 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1898
1957
  }
1899
1958
  switch (matchResult_5) {
1900
1959
  case 0:
1901
- return new Value(1, [toInt64_unchecked(op_Division(x_11, y_11))]);
1960
+ return new Value(/* VInt */ 1, [toInt64_unchecked(op_Division(x_11, y_11))]);
1902
1961
  case 1:
1903
- return new Value(2, [x_12 / y_12]);
1962
+ return new Value(/* VFloat */ 2, [x_12 / y_12]);
1904
1963
  default:
1905
1964
  throw new EvalException(new EvalError$("Numeric operands required", span_16));
1906
1965
  }
@@ -1922,13 +1981,13 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1922
1981
  }
1923
1982
  switch (matchResult_6) {
1924
1983
  case 0:
1925
- return new Value(1, [toInt64_unchecked(op_Modulus(x_13, y_13))]);
1984
+ return new Value(/* VInt */ 1, [toInt64_unchecked(op_Modulus(x_13, y_13))]);
1926
1985
  default:
1927
1986
  throw new EvalException(new EvalError$("Integer operands required", span_16));
1928
1987
  }
1929
1988
  }
1930
1989
  case "=":
1931
- return new Value(3, [valueEquals(av_1, bv_1)]);
1990
+ return new Value(/* VBool */ 3, [valueEquals(av_1, bv_1)]);
1932
1991
  case "<":
1933
1992
  case ">":
1934
1993
  case "<=":
@@ -1962,9 +2021,9 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1962
2021
  }
1963
2022
  switch (matchResult_7) {
1964
2023
  case 0:
1965
- return new Value(3, [(op === "<") ? (compare_1(x_14, y_14) < 0) : ((op === ">") ? (compare_1(x_14, y_14) > 0) : ((op === "<=") ? (compare_1(x_14, y_14) <= 0) : ((op === ">=") && (compare_1(x_14, y_14) >= 0))))]);
2024
+ return new Value(/* VBool */ 3, [(op === "<") ? (compare_1(x_14, y_14) < 0) : ((op === ">") ? (compare_1(x_14, y_14) > 0) : ((op === "<=") ? (compare_1(x_14, y_14) <= 0) : ((op === ">=") && (compare_1(x_14, y_14) >= 0))))]);
1966
2025
  case 1:
1967
- return new Value(3, [(op === "<") ? (x_15 < y_15) : ((op === ">") ? (x_15 > y_15) : ((op === "<=") ? (x_15 <= y_15) : ((op === ">=") && (x_15 >= y_15))))]);
2026
+ return new Value(/* VBool */ 3, [(op === "<") ? (x_15 < y_15) : ((op === ">") ? (x_15 > y_15) : ((op === "<=") ? (x_15 <= y_15) : ((op === ">=") && (x_15 >= y_15))))]);
1968
2027
  default:
1969
2028
  throw new EvalException(new EvalError$("Numeric operands required", span_16));
1970
2029
  }
@@ -1987,14 +2046,14 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
1987
2046
  }
1988
2047
  switch (matchResult_8) {
1989
2048
  case 0:
1990
- return new Value(3, [(op === "&&") ? (x_16 && y_16) : (x_16 ? true : y_16)]);
2049
+ return new Value(/* VBool */ 3, [(op === "&&") ? (x_16 && y_16) : (x_16 ? true : y_16)]);
1991
2050
  default:
1992
2051
  throw new EvalException(new EvalError$("Boolean operands required", span_16));
1993
2052
  }
1994
2053
  }
1995
2054
  case "::":
1996
2055
  if (bv_1.tag === 5) {
1997
- return new Value(5, [cons(av_1, bv_1.fields[0])]);
2056
+ return new Value(/* VList */ 5, [cons(av_1, bv_1.fields[0])]);
1998
2057
  }
1999
2058
  else {
2000
2059
  throw new EvalException(new EvalError$("Right side of \'::\' must be list", span_16));
@@ -2016,7 +2075,7 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
2016
2075
  }
2017
2076
  switch (matchResult_9) {
2018
2077
  case 0:
2019
- return new Value(5, [append(xs_3, ys_1)]);
2078
+ return new Value(/* VList */ 5, [append(xs_3, ys_1)]);
2020
2079
  default:
2021
2080
  throw new EvalException(new EvalError$("Both sides of \'@\' must be lists", span_16));
2022
2081
  }
@@ -2026,9 +2085,9 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
2026
2085
  }
2027
2086
  }
2028
2087
  case 26:
2029
- return new Value(9, [evalExpr(runtime, typeDefs, env, expr.fields[0])]);
2088
+ return new Value(/* VOption */ 9, [evalExpr(runtime, typeDefs, env, expr.fields[0])]);
2030
2089
  case 27:
2031
- return new Value(9, [undefined]);
2090
+ return new Value(/* VOption */ 9, [undefined]);
2032
2091
  case 28: {
2033
2092
  const name_9 = expr.fields[0];
2034
2093
  const matchValue_24 = FSharpMap__TryFind(typeDefs, name_9);
@@ -2036,13 +2095,13 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
2036
2095
  throw new EvalException(new EvalError$(concat("Unknown type \'", name_9, "\'"), expr.fields[1]));
2037
2096
  }
2038
2097
  else {
2039
- return new Value(12, [matchValue_24]);
2098
+ return new Value(/* VTypeToken */ 12, [matchValue_24]);
2040
2099
  }
2041
2100
  }
2042
2101
  case 29: {
2043
2102
  const name_10 = expr.fields[0];
2044
2103
  if (FSharpMap__ContainsKey(env, name_10)) {
2045
- return new Value(4, [name_10]);
2104
+ return new Value(/* VString */ 4, [name_10]);
2046
2105
  }
2047
2106
  else {
2048
2107
  throw new EvalException(new EvalError$(concat("Unbound variable \'", name_10, "\'"), expr.fields[1]));
@@ -2065,10 +2124,10 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
2065
2124
  finally {
2066
2125
  disposeSafe(enumerator_1);
2067
2126
  }
2068
- return new Value(4, [toString(sb)]);
2127
+ return new Value(/* VString */ 4, [toString(sb)]);
2069
2128
  }
2070
2129
  default:
2071
- return new Value(0, []);
2130
+ return Value.VUnit;
2072
2131
  }
2073
2132
  break;
2074
2133
  }
@@ -2089,7 +2148,7 @@ export function invokeValue(typeDefs, fnValue, args) {
2089
2148
  return ext.Impl(createExternContext(runtime, typeDefs, unknownSpan), allArgs);
2090
2149
  }
2091
2150
  else if (length(allArgs) < ext.Arity) {
2092
- return new Value(15, [ext, reverse(allArgs)]);
2151
+ return new Value(/* VExternal */ 15, [ext, reverse(allArgs)]);
2093
2152
  }
2094
2153
  else {
2095
2154
  throw new EvalException(new EvalError$(toText(printf("External function \'%s\' received too many arguments"))(ext.Name), unknownSpan));
@@ -2150,14 +2209,8 @@ export function invokeValue(typeDefs, fnValue, args) {
2150
2209
  return applyMany(fnValue, args);
2151
2210
  }
2152
2211
 
2153
- export function evalProgramWithExternsState(externs, program) {
2154
- const runtime = new RuntimeState({}, [], undefined);
2155
- iterate((ext_1) => {
2156
- throw new EvalException(new EvalError$(concat("Host extern \'", ext_1.Name, "\' collides with reserved stdlib symbol"), unknownSpan));
2157
- }, toArray(tryFind_1((ext) => contains(ext.Name, builtinReservedNames), externs)));
2158
- iterate((name_5) => {
2159
- throw new EvalException(new EvalError$(concat("Top-level binding \'", name_5, "\' collides with reserved stdlib symbol"), unknownSpan));
2160
- }, toArray(tryPick_1((_arg) => {
2212
+ function validateTopLevelBindings(program) {
2213
+ const option_5 = tryPick_1((_arg) => {
2161
2214
  let matchResult, name_1, bindings, bindings_1;
2162
2215
  switch (_arg.tag) {
2163
2216
  case 1: {
@@ -2186,17 +2239,127 @@ export function evalProgramWithExternsState(externs, program) {
2186
2239
  switch (matchResult) {
2187
2240
  case 0:
2188
2241
  return name_1;
2189
- case 1:
2190
- return map_1((tuple) => tuple[0], tryFind_1((tupledArg) => contains(tupledArg[0], builtinReservedNames), toList(bindings)));
2191
- case 2:
2192
- return map_1((tupledArg_2) => tupledArg_2[0], tryFind_1((tupledArg_1) => contains(tupledArg_1[0], builtinReservedNames), bindings_1));
2242
+ case 1: {
2243
+ const option_1 = tryFind_1((tupledArg) => contains(tupledArg[0], builtinReservedNames), toList(bindings));
2244
+ if (option_1 != null) {
2245
+ return option_1[0];
2246
+ }
2247
+ else {
2248
+ return undefined;
2249
+ }
2250
+ }
2251
+ case 2: {
2252
+ const option_3 = tryFind_1((tupledArg_1) => contains(tupledArg_1[0], builtinReservedNames), bindings_1);
2253
+ if (option_3 != null) {
2254
+ return option_3[0];
2255
+ }
2256
+ else {
2257
+ return undefined;
2258
+ }
2259
+ }
2193
2260
  default:
2194
2261
  return undefined;
2195
2262
  }
2196
- }, program)));
2197
- const decls = ofList(append(map((def) => [def.Name, def], typeDefs_3), choose((_arg_8) => {
2198
- if (_arg_8.tag === 0) {
2199
- const def_1 = _arg_8.fields[0];
2263
+ }, program);
2264
+ if (option_5 != null) {
2265
+ throw new EvalException(new EvalError$(concat("Top-level binding \'", option_5, "\' collides with reserved stdlib symbol"), unknownSpan));
2266
+ }
2267
+ }
2268
+
2269
+ function evaluateStatements(runtime, typeDefs, initialEnv, program) {
2270
+ validateTopLevelBindings(program);
2271
+ let env = initialEnv;
2272
+ let lastValue = Value.VUnit;
2273
+ const enumerator = getEnumerator(program);
2274
+ try {
2275
+ while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
2276
+ const stmt = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
2277
+ raiseIfBackgroundFailed(runtime);
2278
+ switch (stmt.tag) {
2279
+ case 1: {
2280
+ const name = stmt.fields[0];
2281
+ const expr = stmt.fields[1];
2282
+ if (stmt.fields[3]) {
2283
+ if (expr.tag === 4) {
2284
+ const recEnv = new FSharpRef(env);
2285
+ const finalEnv = add(name, new Value(/* VClosure */ 14, [expr.fields[0].Name, expr.fields[1], recEnv]), env);
2286
+ recEnv.contents = finalEnv;
2287
+ env = finalEnv;
2288
+ }
2289
+ else {
2290
+ throw new EvalException(new EvalError$("let rec requires a function binding", stmt.fields[5]));
2291
+ }
2292
+ }
2293
+ else {
2294
+ const v = evalExpr(runtime, typeDefs, env, expr);
2295
+ env = add(name, v, env);
2296
+ }
2297
+ break;
2298
+ }
2299
+ case 2: {
2300
+ const matchValue = patternMatch(typeDefs, stmt.fields[0], evalExpr(runtime, typeDefs, env, stmt.fields[1]));
2301
+ if (matchValue == null) {
2302
+ throw new EvalException(new EvalError$("Let pattern did not match value", stmt.fields[4]));
2303
+ }
2304
+ else {
2305
+ const bindings = matchValue;
2306
+ env = fold((acc, k, value) => add(k, value, acc), env, bindings);
2307
+ }
2308
+ break;
2309
+ }
2310
+ case 3: {
2311
+ const bindings_1 = stmt.fields[0];
2312
+ if (!isEmpty(bindings_1)) {
2313
+ const recEnv_1 = new FSharpRef(env);
2314
+ let finalEnv_1;
2315
+ const list_1 = map((tupledArg) => {
2316
+ const expr_2 = tupledArg[1];
2317
+ if (expr_2.tag === 4) {
2318
+ return [tupledArg[0], new Value(/* VClosure */ 14, [expr_2.fields[0].Name, expr_2.fields[1], recEnv_1])];
2319
+ }
2320
+ else {
2321
+ throw new EvalException(new EvalError$("let rec requires a function binding", tupledArg[3]));
2322
+ }
2323
+ }, bindings_1);
2324
+ finalEnv_1 = fold_1((acc_1, tupledArg_1) => add(tupledArg_1[0], tupledArg_1[1], acc_1), env, list_1);
2325
+ recEnv_1.contents = finalEnv_1;
2326
+ env = finalEnv_1;
2327
+ }
2328
+ break;
2329
+ }
2330
+ case 4: {
2331
+ lastValue = evalExpr(runtime, typeDefs, env, stmt.fields[0].Expr);
2332
+ break;
2333
+ }
2334
+ default:
2335
+ undefined;
2336
+ }
2337
+ }
2338
+ }
2339
+ finally {
2340
+ disposeSafe(enumerator);
2341
+ }
2342
+ raiseIfBackgroundFailed(runtime);
2343
+ const unawaitedCount = length_1(filter((handle) => !handle.Awaited, runtime.PendingTasks)) | 0;
2344
+ if (unawaitedCount > 0) {
2345
+ throw new EvalException(new EvalError$(`Program completed with ${unawaitedCount} unawaited ${(unawaitedCount === 1) ? "task" : "tasks"}`, unknownSpan));
2346
+ }
2347
+ return new ProgramState(typeDefs, env, lastValue);
2348
+ }
2349
+
2350
+ export function evalProgramFromState(state, program) {
2351
+ return evaluateStatements(new RuntimeState({}, [], undefined), state.TypeDefs, state.Env, program);
2352
+ }
2353
+
2354
+ export function evalProgramWithExternsState(externs, program) {
2355
+ const runtime = new RuntimeState({}, [], undefined);
2356
+ const option_1 = tryFind_1((ext) => contains(ext.Name, builtinReservedNames), externs);
2357
+ if (option_1 != null) {
2358
+ throw new EvalException(new EvalError$(concat("Host extern \'", option_1.Name, "\' collides with reserved stdlib symbol"), unknownSpan));
2359
+ }
2360
+ const decls = ofList(append(map((def) => [def.Name, def], typeDefs_3), choose((_arg) => {
2361
+ if (_arg.tag === 0) {
2362
+ const def_1 = _arg.fields[0];
2200
2363
  return [def_1.Name, def_1];
2201
2364
  }
2202
2365
  else {
@@ -2208,65 +2371,68 @@ export function evalProgramWithExternsState(externs, program) {
2208
2371
  const fromRef = (stack, tref) => {
2209
2372
  switch (tref.tag) {
2210
2373
  case 1:
2211
- return new Type(7, [map(curry2(fromRef)(stack), tref.fields[0])]);
2374
+ return new Type(/* TTuple */ 7, [map(curry2(fromRef)(stack), tref.fields[0])]);
2212
2375
  case 2:
2213
- return new Type(11, [fromRef(stack, tref.fields[0]), fromRef(stack, tref.fields[1])]);
2376
+ return new Type(/* TFun */ 11, [fromRef(stack, tref.fields[0]), fromRef(stack, tref.fields[1])]);
2214
2377
  case 3:
2215
2378
  switch (tref.fields[1]) {
2216
2379
  case "list":
2217
- return new Type(5, [fromRef(stack, tref.fields[0])]);
2380
+ return new Type(/* TList */ 5, [fromRef(stack, tref.fields[0])]);
2218
2381
  case "task":
2219
- return new Type(6, [fromRef(stack, tref.fields[0])]);
2382
+ return new Type(/* TTask */ 6, [fromRef(stack, tref.fields[0])]);
2220
2383
  case "option":
2221
- return new Type(10, [fromRef(stack, tref.fields[0])]);
2384
+ return new Type(/* TOption */ 10, [fromRef(stack, tref.fields[0])]);
2222
2385
  case "map":
2223
- return new Type(9, [new Type(4, []), fromRef(stack, tref.fields[0])]);
2386
+ return new Type(/* TMap */ 9, [Type.TString, fromRef(stack, tref.fields[0])]);
2224
2387
  default:
2225
2388
  throw new EvalException(new EvalError$(concat("Unsupported type suffix ", tref.fields[1]), unknownSpan));
2226
2389
  }
2227
2390
  case 4:
2228
- return new Type(8, [ofList(map((tupledArg_5) => [tupledArg_5[0], fromRef(stack, tupledArg_5[1])], tref.fields[0]), {
2391
+ return new Type(/* TRecord */ 8, [ofList(map((tupledArg_2) => [tupledArg_2[0], fromRef(stack, tupledArg_2[1])], tref.fields[0]), {
2229
2392
  Compare: (x_3, y_4) => (comparePrimitives(x_3, y_4) | 0),
2230
2393
  })]);
2231
2394
  case 5:
2232
- return new Type(8, [ofList(map((tupledArg_6) => [tupledArg_6[0], fromRef(stack, tupledArg_6[1])], tref.fields[0]), {
2395
+ return new Type(/* TRecord */ 8, [ofList(map((tupledArg_3) => [tupledArg_3[0], fromRef(stack, tupledArg_3[1])], tref.fields[0]), {
2233
2396
  Compare: (x_4, y_5) => (comparePrimitives(x_4, y_5) | 0),
2234
2397
  })]);
2235
2398
  default:
2236
2399
  switch (tref.fields[0]) {
2237
2400
  case "unit":
2238
- return new Type(0, []);
2401
+ return Type.TUnit;
2239
2402
  case "int":
2240
- return new Type(1, []);
2403
+ return Type.TInt;
2241
2404
  case "float":
2242
- return new Type(2, []);
2405
+ return Type.TFloat;
2243
2406
  case "bool":
2244
- return new Type(3, []);
2407
+ return Type.TBool;
2245
2408
  case "string":
2246
- return new Type(4, []);
2409
+ return Type.TString;
2247
2410
  default: {
2248
2411
  const matchValue = FSharpMap__TryFind(decls, tref.fields[0]);
2249
2412
  if (matchValue == null) {
2250
- return new Type(12, [tref.fields[0]]);
2413
+ return new Type(/* TNamed */ 12, [tref.fields[0]]);
2251
2414
  }
2252
2415
  else {
2253
2416
  const d = matchValue;
2254
2417
  const matchValue_1 = tryFindIndex((y_1) => (tref.fields[0] === y_1), stack);
2255
2418
  if (matchValue_1 == null) {
2256
2419
  if (!isEmpty(d.Cases)) {
2257
- return new Type(13, [tref.fields[0], ofList(map((tupledArg_3) => [tupledArg_3[0], map_1(curry2(fromRef)(cons(tref.fields[0], stack)), tupledArg_3[1])], d.Cases), {
2420
+ return new Type(/* TUnion */ 13, [tref.fields[0], ofList(map((tupledArg) => {
2421
+ let mapping_1, option_3;
2422
+ return [tupledArg[0], (mapping_1 = curry2(fromRef)(cons(tref.fields[0], stack)), (option_3 = tupledArg[1], (option_3 != null) ? mapping_1(option_3) : undefined))];
2423
+ }, d.Cases), {
2258
2424
  Compare: (x_1, y_2) => (comparePrimitives(x_1, y_2) | 0),
2259
2425
  })]);
2260
2426
  }
2261
2427
  else {
2262
- return new Type(8, [ofList(map((tupledArg_4) => [tupledArg_4[0], fromRef(cons(tref.fields[0], stack), tupledArg_4[1])], d.Fields), {
2428
+ return new Type(/* TRecord */ 8, [ofList(map((tupledArg_1) => [tupledArg_1[0], fromRef(cons(tref.fields[0], stack), tupledArg_1[1])], d.Fields), {
2263
2429
  Compare: (x_2, y_3) => (comparePrimitives(x_2, y_3) | 0),
2264
2430
  })]);
2265
2431
  }
2266
2432
  }
2267
2433
  else if (matchValue_1 === 0) {
2268
2434
  if (d.IsRecursive) {
2269
- return new Type(12, [tref.fields[0]]);
2435
+ return new Type(/* TNamed */ 12, [tref.fields[0]]);
2270
2436
  }
2271
2437
  else {
2272
2438
  throw new EvalException(new EvalError$(concat("Recursive type \'", tref.fields[0], "\' requires \'type rec\'"), unknownSpan));
@@ -2280,118 +2446,44 @@ export function evalProgramWithExternsState(externs, program) {
2280
2446
  }
2281
2447
  }
2282
2448
  };
2283
- const typeDefs = map_2((name_8, def_2) => {
2449
+ const typeDefs = map_1((name_2, def_2) => {
2284
2450
  if (!isEmpty(def_2.Cases)) {
2285
- return new Type(13, [name_8, ofList(map((tupledArg_7) => [tupledArg_7[0], map_1(curry2(fromRef)(singleton(name_8)), tupledArg_7[1])], def_2.Cases), {
2451
+ return new Type(/* TUnion */ 13, [name_2, ofList(map((tupledArg_4) => {
2452
+ let mapping_8, option_5;
2453
+ return [tupledArg_4[0], (mapping_8 = curry2(fromRef)(singleton(name_2)), (option_5 = tupledArg_4[1], (option_5 != null) ? mapping_8(option_5) : undefined))];
2454
+ }, def_2.Cases), {
2286
2455
  Compare: (x_5, y_6) => (comparePrimitives(x_5, y_6) | 0),
2287
2456
  })]);
2288
2457
  }
2289
2458
  else {
2290
- return new Type(8, [ofList(map((tupledArg_8) => [tupledArg_8[0], fromRef(singleton(name_8), tupledArg_8[1])], def_2.Fields), {
2459
+ return new Type(/* TRecord */ 8, [ofList(map((tupledArg_5) => [tupledArg_5[0], fromRef(singleton(name_2), tupledArg_5[1])], def_2.Fields), {
2291
2460
  Compare: (x_6, y_7) => (comparePrimitives(x_6, y_7) | 0),
2292
2461
  })]);
2293
2462
  }
2294
2463
  }, decls);
2295
- const constructorValues = collect((tupledArg_9) => {
2296
- const typeName = tupledArg_9[0];
2297
- return collect((tupledArg_10) => {
2298
- const caseName_2 = tupledArg_10[0];
2299
- const value = (tupledArg_10[1] != null) ? (new Value(11, [typeName, caseName_2])) : (new Value(10, [typeName, caseName_2, undefined]));
2464
+ const constructorValues = collect((tupledArg_6) => {
2465
+ const typeName = tupledArg_6[0];
2466
+ return collect((tupledArg_7) => {
2467
+ const caseName_2 = tupledArg_7[0];
2468
+ const value = (tupledArg_7[1] != null) ? (new Value(/* VUnionCtor */ 11, [typeName, caseName_2])) : (new Value(/* VUnionCase */ 10, [typeName, caseName_2, undefined]));
2300
2469
  return ofArray([[caseName_2, value], [concat(typeName, ".", caseName_2), value]]);
2301
- }, tupledArg_9[1].Cases);
2470
+ }, tupledArg_6[1].Cases);
2302
2471
  }, toList(decls));
2303
2472
  const externContext = createExternContext(runtime, typeDefs, unknownSpan);
2304
2473
  let env;
2305
- const list_16 = append(builtinExterns, externs);
2474
+ const list_13 = append(builtinExterns, externs);
2306
2475
  env = fold_1((acc, ext_2) => {
2307
2476
  if (ext_2.Arity === 0) {
2308
2477
  return FSharpMap__Add(acc, ext_2.Name, ext_2.Impl(externContext, empty()));
2309
2478
  }
2310
2479
  else {
2311
- return FSharpMap__Add(acc, ext_2.Name, new Value(15, [ext_2, empty()]));
2480
+ return FSharpMap__Add(acc, ext_2.Name, new Value(/* VExternal */ 15, [ext_2, empty()]));
2312
2481
  }
2313
2482
  }, empty_1({
2314
2483
  Compare: (x_7, y_8) => (comparePrimitives(x_7, y_8) | 0),
2315
- }), list_16);
2316
- env = fold_1((acc_1, tupledArg_11) => FSharpMap__Add(acc_1, tupledArg_11[0], tupledArg_11[1]), env, constructorValues);
2317
- let lastValue = new Value(0, []);
2318
- const enumerator = getEnumerator(program);
2319
- try {
2320
- while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
2321
- const stmt = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
2322
- raiseIfBackgroundFailed(runtime);
2323
- switch (stmt.tag) {
2324
- case 1: {
2325
- const name_10 = stmt.fields[0];
2326
- const expr = stmt.fields[1];
2327
- if (stmt.fields[3]) {
2328
- if (expr.tag === 4) {
2329
- const recEnv = new FSharpRef(env);
2330
- const finalEnv = add(name_10, new Value(14, [expr.fields[0].Name, expr.fields[1], recEnv]), env);
2331
- recEnv.contents = finalEnv;
2332
- env = finalEnv;
2333
- }
2334
- else {
2335
- throw new EvalException(new EvalError$("let rec requires a function binding", stmt.fields[5]));
2336
- }
2337
- }
2338
- else {
2339
- const v = evalExpr(runtime, typeDefs, env, expr);
2340
- env = add(name_10, v, env);
2341
- }
2342
- break;
2343
- }
2344
- case 2: {
2345
- const matchValue_2 = patternMatch(typeDefs, stmt.fields[0], evalExpr(runtime, typeDefs, env, stmt.fields[1]));
2346
- if (matchValue_2 == null) {
2347
- throw new EvalException(new EvalError$("Let pattern did not match value", stmt.fields[4]));
2348
- }
2349
- else {
2350
- const bindings_2 = matchValue_2;
2351
- env = fold((acc_2, k, value_3) => add(k, value_3, acc_2), env, bindings_2);
2352
- }
2353
- break;
2354
- }
2355
- case 3: {
2356
- const bindings_3 = stmt.fields[0];
2357
- if (isEmpty(bindings_3)) {
2358
- }
2359
- else {
2360
- const recEnv_1 = new FSharpRef(env);
2361
- let finalEnv_1;
2362
- const list_19 = map((tupledArg_12) => {
2363
- const expr_2 = tupledArg_12[1];
2364
- if (expr_2.tag === 4) {
2365
- return [tupledArg_12[0], new Value(14, [expr_2.fields[0].Name, expr_2.fields[1], recEnv_1])];
2366
- }
2367
- else {
2368
- throw new EvalException(new EvalError$("let rec requires a function binding", tupledArg_12[3]));
2369
- }
2370
- }, bindings_3);
2371
- finalEnv_1 = fold_1((acc_3, tupledArg_13) => add(tupledArg_13[0], tupledArg_13[1], acc_3), env, list_19);
2372
- recEnv_1.contents = finalEnv_1;
2373
- env = finalEnv_1;
2374
- }
2375
- break;
2376
- }
2377
- case 4: {
2378
- lastValue = evalExpr(runtime, typeDefs, env, stmt.fields[0].Expr);
2379
- break;
2380
- }
2381
- default:
2382
- undefined;
2383
- }
2384
- }
2385
- }
2386
- finally {
2387
- disposeSafe(enumerator);
2388
- }
2389
- raiseIfBackgroundFailed(runtime);
2390
- const unawaitedCount = length_1(filter((handle) => !handle.Awaited, runtime.PendingTasks)) | 0;
2391
- if (unawaitedCount > 0) {
2392
- throw new EvalException(new EvalError$(`Program completed with ${unawaitedCount} unawaited ${(unawaitedCount === 1) ? "task" : "tasks"}`, unknownSpan));
2393
- }
2394
- return new ProgramState(typeDefs, env, lastValue);
2484
+ }), list_13);
2485
+ env = fold_1((acc_1, tupledArg_8) => FSharpMap__Add(acc_1, tupledArg_8[0], tupledArg_8[1]), env, constructorValues);
2486
+ return evaluateStatements(runtime, typeDefs, env, program);
2395
2487
  }
2396
2488
 
2397
2489
  export function evalProgramWithExterns(externs, program) {