@magnusopera/fscript 0.75.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.
- package/README.md +5 -0
- package/dist/FScript.Language/Ast.js +234 -0
- package/dist/FScript.Language/BuiltinFunctions.js +2039 -0
- package/dist/FScript.Language/BuiltinSignatures.js +24 -0
- package/dist/FScript.Language/BuiltinTypes.js +13 -0
- package/dist/FScript.Language/Error.js +74 -0
- package/dist/FScript.Language/Eval.js +2404 -0
- package/dist/FScript.Language/IncludeResolver.js +806 -0
- package/dist/FScript.Language/Lexer.js +1067 -0
- package/dist/FScript.Language/Library.js +28 -0
- package/dist/FScript.Language/Parser.js +2368 -0
- package/dist/FScript.Language/Pretty.js +115 -0
- package/dist/FScript.Language/Span.js +33 -0
- package/dist/FScript.Language/Token.js +32 -0
- package/dist/FScript.Language/TypeInfer.js +2561 -0
- package/dist/FScript.Language/Types.js +205 -0
- package/dist/FScript.Language/Value.js +91 -0
- package/dist/Library.js +732 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Array.js +1347 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Async.js +134 -0
- package/dist/fable_modules/fable-library-js.5.2.0/AsyncBuilder.js +183 -0
- package/dist/fable_modules/fable-library-js.5.2.0/BigInt.js +306 -0
- package/dist/fable_modules/fable-library-js.5.2.0/BitConverter.js +138 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Boolean.js +22 -0
- package/dist/fable_modules/fable-library-js.5.2.0/CHANGELOG.md +234 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Char.js +202 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Choice.js +184 -0
- package/dist/fable_modules/fable-library-js.5.2.0/CollectionUtil.js +182 -0
- package/dist/fable_modules/fable-library-js.5.2.0/ConditionalWeakTable.js +21 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Date.js +841 -0
- package/dist/fable_modules/fable-library-js.5.2.0/DateOffset.js +261 -0
- package/dist/fable_modules/fable-library-js.5.2.0/DateOnly.js +124 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Decimal.js +238 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Double.js +47 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Encoding.js +185 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Event.js +93 -0
- package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Collections.js +45 -0
- package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Core.CompilerServices.js +27 -0
- package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Core.js +156 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Global.js +29 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Guid.js +161 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Int32.js +135 -0
- package/dist/fable_modules/fable-library-js.5.2.0/List.js +1323 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Long.js +47 -0
- package/dist/fable_modules/fable-library-js.5.2.0/MailboxProcessor.js +94 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Map.js +1396 -0
- package/dist/fable_modules/fable-library-js.5.2.0/MapUtil.js +130 -0
- package/dist/fable_modules/fable-library-js.5.2.0/MutableMap.js +339 -0
- package/dist/fable_modules/fable-library-js.5.2.0/MutableSet.js +233 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Native.js +14 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Numeric.js +75 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Observable.js +113 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Option.js +104 -0
- package/dist/fable_modules/fable-library-js.5.2.0/README.md +3 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Random.js +172 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Range.js +45 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Reflection.js +479 -0
- package/dist/fable_modules/fable-library-js.5.2.0/RegExp.js +141 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Result.js +165 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Seq.js +1417 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Seq2.js +111 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Set.js +1816 -0
- package/dist/fable_modules/fable-library-js.5.2.0/String.js +674 -0
- package/dist/fable_modules/fable-library-js.5.2.0/System.Collections.Generic.js +333 -0
- package/dist/fable_modules/fable-library-js.5.2.0/System.Text.js +200 -0
- package/dist/fable_modules/fable-library-js.5.2.0/System.js +283 -0
- package/dist/fable_modules/fable-library-js.5.2.0/TimeOnly.js +122 -0
- package/dist/fable_modules/fable-library-js.5.2.0/TimeSpan.js +180 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Timer.js +67 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Types.js +198 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Unicode.13.0.0.js +4 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Uri.js +165 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Util.js +795 -0
- package/dist/fable_modules/fable-library-js.5.2.0/big.d.ts +338 -0
- package/dist/fable_modules/fable-library-js.5.2.0/lib/big.js +825 -0
- package/dist/fable_modules/fable-library-js.5.2.0/package.json +24 -0
- package/dist/fable_modules/fable-library-js.5.2.0/quotation.js +618 -0
- package/dist/fable_modules/project_cracked.json +1 -0
- package/package.json +36 -0
|
@@ -0,0 +1,2404 @@
|
|
|
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";
|
|
4
|
+
import { Type, Types_typeToString, Type_$reflection } from "./Types.js";
|
|
5
|
+
import { ExternalCallContext, MapKey, Value, TaskHandle_$reflection, Value_$reflection } from "./Value.js";
|
|
6
|
+
import { EvalException, EvalError$, EvalError$_$reflection } from "./Error.js";
|
|
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";
|
|
16
|
+
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";
|
|
18
|
+
import { builtinReservedNames } from "./BuiltinSignatures.js";
|
|
19
|
+
import { typeDefs as typeDefs_3 } from "./BuiltinTypes.js";
|
|
20
|
+
import { builtinExterns } from "./BuiltinFunctions.js";
|
|
21
|
+
|
|
22
|
+
export class ProgramState extends Record {
|
|
23
|
+
constructor(TypeDefs, Env, LastValue) {
|
|
24
|
+
super();
|
|
25
|
+
this.TypeDefs = TypeDefs;
|
|
26
|
+
this.Env = Env;
|
|
27
|
+
this.LastValue = LastValue;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function ProgramState_$reflection() {
|
|
32
|
+
return record_type("FScript.Language.Eval.ProgramState", [], ProgramState, () => [["TypeDefs", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, Type_$reflection()])], ["Env", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, Value_$reflection()])], ["LastValue", Value_$reflection()]]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class RuntimeState extends Record {
|
|
36
|
+
constructor(SyncRoot, PendingTasks, BackgroundFailure) {
|
|
37
|
+
super();
|
|
38
|
+
this.SyncRoot = SyncRoot;
|
|
39
|
+
this.PendingTasks = PendingTasks;
|
|
40
|
+
this.BackgroundFailure = BackgroundFailure;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function RuntimeState_$reflection() {
|
|
45
|
+
return record_type("FScript.Language.Eval.RuntimeState", [], RuntimeState, () => [["SyncRoot", obj_type], ["PendingTasks", array_type(TaskHandle_$reflection())], ["BackgroundFailure", option_type(EvalError$_$reflection())]]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const unknownSpan = new Span(new Position(undefined, 0, 0), new Position(undefined, 0, 0));
|
|
49
|
+
|
|
50
|
+
function wrapTaskFailure(error) {
|
|
51
|
+
return new EvalError$(concat("Task failed: ", error.Message), error.Span);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function wrapUnexpectedTaskFailure(ex) {
|
|
55
|
+
return new EvalError$(concat("Task failed: ", ex.message), unknownSpan);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function withRuntimeLock(runtime, f) {
|
|
59
|
+
return f();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function raiseIfBackgroundFailed(runtime) {
|
|
63
|
+
withRuntimeLock(runtime, () => {
|
|
64
|
+
const matchValue = runtime.BackgroundFailure;
|
|
65
|
+
if (matchValue == null) {
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw new EvalException(matchValue);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function literalToValue(lit) {
|
|
74
|
+
switch (lit.tag) {
|
|
75
|
+
case 1:
|
|
76
|
+
return new Value(2, [lit.fields[0]]);
|
|
77
|
+
case 2:
|
|
78
|
+
return new Value(3, [lit.fields[0]]);
|
|
79
|
+
case 3:
|
|
80
|
+
return new Value(4, [lit.fields[0]]);
|
|
81
|
+
default:
|
|
82
|
+
return new Value(1, [lit.fields[0]]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function valueToInterpolationString(v) {
|
|
87
|
+
switch (v.tag) {
|
|
88
|
+
case 1:
|
|
89
|
+
return int64ToString(v.fields[0]);
|
|
90
|
+
case 2:
|
|
91
|
+
return v.fields[0].toString();
|
|
92
|
+
case 3:
|
|
93
|
+
if (v.fields[0]) {
|
|
94
|
+
return "true";
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return "false";
|
|
98
|
+
}
|
|
99
|
+
case 4:
|
|
100
|
+
return v.fields[0];
|
|
101
|
+
case 5: {
|
|
102
|
+
const arg = join(";", map(valueToInterpolationString, v.fields[0]));
|
|
103
|
+
return toText(printf("[%s]"))(arg);
|
|
104
|
+
}
|
|
105
|
+
case 6: {
|
|
106
|
+
const arg_1 = join(", ", map(valueToInterpolationString, v.fields[0]));
|
|
107
|
+
return toText(printf("(%s)"))(arg_1);
|
|
108
|
+
}
|
|
109
|
+
case 7: {
|
|
110
|
+
const arg_4 = join("; ", map((tupledArg) => {
|
|
111
|
+
const arg_3 = valueToInterpolationString(tupledArg[1]);
|
|
112
|
+
return toText(printf("%s = %s"))(tupledArg[0])(arg_3);
|
|
113
|
+
}, toList(v.fields[0])));
|
|
114
|
+
return toText(printf("{ %s }"))(arg_4);
|
|
115
|
+
}
|
|
116
|
+
case 8: {
|
|
117
|
+
const arg_7 = join("; ", map((tupledArg_1) => {
|
|
118
|
+
let arg_5;
|
|
119
|
+
const key = tupledArg_1[0];
|
|
120
|
+
arg_5 = ((key.tag === 1) ? int64ToString(key.fields[0]) : concat("\"", key.fields[0], "\""));
|
|
121
|
+
const arg_6 = valueToInterpolationString(tupledArg_1[1]);
|
|
122
|
+
return toText(printf("%s => %s"))(arg_5)(arg_6);
|
|
123
|
+
}, toList(v.fields[0])));
|
|
124
|
+
return toText(printf("map { %s }"))(arg_7);
|
|
125
|
+
}
|
|
126
|
+
case 9:
|
|
127
|
+
if (v.fields[0] != null) {
|
|
128
|
+
const value_2 = v.fields[0];
|
|
129
|
+
const arg_8 = valueToInterpolationString(value_2);
|
|
130
|
+
return toText(printf("Some %s"))(arg_8);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
return "None";
|
|
134
|
+
}
|
|
135
|
+
case 10:
|
|
136
|
+
if (v.fields[2] != null) {
|
|
137
|
+
const value_3 = v.fields[2];
|
|
138
|
+
const arg_10 = valueToInterpolationString(value_3);
|
|
139
|
+
return toText(printf("%s %s"))(v.fields[1])(arg_10);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
return v.fields[1];
|
|
143
|
+
}
|
|
144
|
+
case 12: {
|
|
145
|
+
const arg_11 = Types_typeToString(v.fields[0]);
|
|
146
|
+
return toText(printf("<type %s>"))(arg_11);
|
|
147
|
+
}
|
|
148
|
+
case 13:
|
|
149
|
+
return "<task>";
|
|
150
|
+
case 14:
|
|
151
|
+
return "<fun>";
|
|
152
|
+
case 11:
|
|
153
|
+
return toText(printf("<ctor %s>"))(v.fields[1]);
|
|
154
|
+
case 15:
|
|
155
|
+
return "<extern>";
|
|
156
|
+
default:
|
|
157
|
+
return "()";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function valueEquals(a_mut, b_mut) {
|
|
162
|
+
valueEquals:
|
|
163
|
+
while (true) {
|
|
164
|
+
const a = a_mut, b = b_mut;
|
|
165
|
+
let matchResult, x, y, x_1, y_1, x_2, y_2, x_3, y_3, xs, ys, xs_1, ys_1, xf, yf, xf_1, yf_1, x_8, y_8, cx, cy, px, py, tx, ty, tx_1, ty_1, tx_2, ty_2;
|
|
166
|
+
switch (a.tag) {
|
|
167
|
+
case 0: {
|
|
168
|
+
if (b.tag === 0) {
|
|
169
|
+
matchResult = 0;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
matchResult = 14;
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case 1: {
|
|
177
|
+
if (b.tag === 1) {
|
|
178
|
+
matchResult = 1;
|
|
179
|
+
x = a.fields[0];
|
|
180
|
+
y = b.fields[0];
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
matchResult = 14;
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
case 2: {
|
|
188
|
+
if (b.tag === 2) {
|
|
189
|
+
matchResult = 2;
|
|
190
|
+
x_1 = a.fields[0];
|
|
191
|
+
y_1 = b.fields[0];
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
matchResult = 14;
|
|
195
|
+
}
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
case 3: {
|
|
199
|
+
if (b.tag === 3) {
|
|
200
|
+
matchResult = 3;
|
|
201
|
+
x_2 = a.fields[0];
|
|
202
|
+
y_2 = b.fields[0];
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
matchResult = 14;
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case 4: {
|
|
210
|
+
if (b.tag === 4) {
|
|
211
|
+
matchResult = 4;
|
|
212
|
+
x_3 = a.fields[0];
|
|
213
|
+
y_3 = b.fields[0];
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
matchResult = 14;
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
case 5: {
|
|
221
|
+
if (b.tag === 5) {
|
|
222
|
+
matchResult = 5;
|
|
223
|
+
xs = a.fields[0];
|
|
224
|
+
ys = b.fields[0];
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
matchResult = 14;
|
|
228
|
+
}
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
case 6: {
|
|
232
|
+
if (b.tag === 6) {
|
|
233
|
+
matchResult = 6;
|
|
234
|
+
xs_1 = a.fields[0];
|
|
235
|
+
ys_1 = b.fields[0];
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
matchResult = 14;
|
|
239
|
+
}
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
case 7: {
|
|
243
|
+
if (b.tag === 7) {
|
|
244
|
+
matchResult = 7;
|
|
245
|
+
xf = a.fields[0];
|
|
246
|
+
yf = b.fields[0];
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
matchResult = 14;
|
|
250
|
+
}
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
case 8: {
|
|
254
|
+
if (b.tag === 8) {
|
|
255
|
+
matchResult = 8;
|
|
256
|
+
xf_1 = a.fields[0];
|
|
257
|
+
yf_1 = b.fields[0];
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
matchResult = 14;
|
|
261
|
+
}
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
case 9: {
|
|
265
|
+
if (a.fields[0] != null) {
|
|
266
|
+
if (b.tag === 9) {
|
|
267
|
+
if (b.fields[0] != null) {
|
|
268
|
+
matchResult = 10;
|
|
269
|
+
x_8 = a.fields[0];
|
|
270
|
+
y_8 = b.fields[0];
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
matchResult = 14;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
matchResult = 14;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else if (b.tag === 9) {
|
|
281
|
+
if (b.fields[0] == null) {
|
|
282
|
+
matchResult = 9;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
matchResult = 14;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
matchResult = 14;
|
|
290
|
+
}
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
case 10: {
|
|
294
|
+
if (b.tag === 10) {
|
|
295
|
+
matchResult = 11;
|
|
296
|
+
cx = a.fields[1];
|
|
297
|
+
cy = b.fields[1];
|
|
298
|
+
px = a.fields[2];
|
|
299
|
+
py = b.fields[2];
|
|
300
|
+
tx = a.fields[0];
|
|
301
|
+
ty = b.fields[0];
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
matchResult = 14;
|
|
305
|
+
}
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
case 12: {
|
|
309
|
+
if (b.tag === 12) {
|
|
310
|
+
matchResult = 12;
|
|
311
|
+
tx_1 = a.fields[0];
|
|
312
|
+
ty_1 = b.fields[0];
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
matchResult = 14;
|
|
316
|
+
}
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
case 13: {
|
|
320
|
+
if (b.tag === 13) {
|
|
321
|
+
matchResult = 13;
|
|
322
|
+
tx_2 = a.fields[0];
|
|
323
|
+
ty_2 = b.fields[0];
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
matchResult = 14;
|
|
327
|
+
}
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
default:
|
|
331
|
+
matchResult = 14;
|
|
332
|
+
}
|
|
333
|
+
switch (matchResult) {
|
|
334
|
+
case 0:
|
|
335
|
+
return true;
|
|
336
|
+
case 1:
|
|
337
|
+
return equals(x, y);
|
|
338
|
+
case 2:
|
|
339
|
+
return x_1 === y_1;
|
|
340
|
+
case 3:
|
|
341
|
+
return x_2 === y_2;
|
|
342
|
+
case 4:
|
|
343
|
+
return x_3 === y_3;
|
|
344
|
+
case 5:
|
|
345
|
+
if (length(xs) === length(ys)) {
|
|
346
|
+
return forAll2(valueEquals, xs, ys);
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
case 6:
|
|
352
|
+
if (length(xs_1) === length(ys_1)) {
|
|
353
|
+
return forAll2(valueEquals, xs_1, ys_1);
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
case 7:
|
|
359
|
+
if ((FSharpMap__get_Count(xf) === FSharpMap__get_Count(yf)) && ofSeq(FSharpMap__get_Keys(xf), {
|
|
360
|
+
Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
|
|
361
|
+
}).Equals(ofSeq(FSharpMap__get_Keys(yf), {
|
|
362
|
+
Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
|
|
363
|
+
}))) {
|
|
364
|
+
return forAll((k, xv) => valueEquals(xv, FSharpMap__get_Item(yf, k)), xf);
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
case 8:
|
|
370
|
+
if ((FSharpMap__get_Count(xf_1) === FSharpMap__get_Count(yf_1)) && ofSeq(FSharpMap__get_Keys(xf_1), {
|
|
371
|
+
Compare: (x_6, y_6) => (compare(x_6, y_6) | 0),
|
|
372
|
+
}).Equals(ofSeq(FSharpMap__get_Keys(yf_1), {
|
|
373
|
+
Compare: (x_7, y_7) => (compare(x_7, y_7) | 0),
|
|
374
|
+
}))) {
|
|
375
|
+
return forAll((k_1, xv_1) => valueEquals(xv_1, FSharpMap__get_Item(yf_1, k_1)), xf_1);
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
case 9:
|
|
381
|
+
return true;
|
|
382
|
+
case 10: {
|
|
383
|
+
a_mut = x_8;
|
|
384
|
+
b_mut = y_8;
|
|
385
|
+
continue valueEquals;
|
|
386
|
+
}
|
|
387
|
+
case 11:
|
|
388
|
+
if ((tx === ty) && (cx === cy)) {
|
|
389
|
+
let matchResult_1, xv_2, yv;
|
|
390
|
+
if (px != null) {
|
|
391
|
+
if (py != null) {
|
|
392
|
+
matchResult_1 = 1;
|
|
393
|
+
xv_2 = px;
|
|
394
|
+
yv = py;
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
matchResult_1 = 2;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
else if (py == null) {
|
|
401
|
+
matchResult_1 = 0;
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
matchResult_1 = 2;
|
|
405
|
+
}
|
|
406
|
+
switch (matchResult_1) {
|
|
407
|
+
case 0:
|
|
408
|
+
return true;
|
|
409
|
+
case 1: {
|
|
410
|
+
a_mut = xv_2;
|
|
411
|
+
b_mut = yv;
|
|
412
|
+
continue valueEquals;
|
|
413
|
+
}
|
|
414
|
+
default:
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
case 12:
|
|
422
|
+
return equals_1(tx_1, ty_1);
|
|
423
|
+
case 13:
|
|
424
|
+
return tx_2 === ty_2;
|
|
425
|
+
default:
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function mapKeyToValue(key) {
|
|
433
|
+
if (key.tag === 1) {
|
|
434
|
+
return new Value(1, [key.fields[0]]);
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
return new Value(4, [key.fields[0]]);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function valueToMapKey(span, value) {
|
|
442
|
+
switch (value.tag) {
|
|
443
|
+
case 4:
|
|
444
|
+
return new MapKey(0, [value.fields[0]]);
|
|
445
|
+
case 1:
|
|
446
|
+
return new MapKey(1, [value.fields[0]]);
|
|
447
|
+
default:
|
|
448
|
+
throw new EvalException(new EvalError$("Map key must be string or int", span));
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function valueMatchesTypeRef(typeDefs, tref, value) {
|
|
453
|
+
const resolve = (tref_1) => {
|
|
454
|
+
switch (tref_1.tag) {
|
|
455
|
+
case 1:
|
|
456
|
+
return map_1((Item) => (new Type(7, [Item])), resolveTypeList(tref_1.fields[0]));
|
|
457
|
+
case 2:
|
|
458
|
+
return undefined;
|
|
459
|
+
case 3:
|
|
460
|
+
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]));
|
|
469
|
+
default:
|
|
470
|
+
return undefined;
|
|
471
|
+
}
|
|
472
|
+
case 4: {
|
|
473
|
+
const shape = map_1((elements) => ofList(elements, {
|
|
474
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
475
|
+
}), resolveFieldList(tref_1.fields[0]));
|
|
476
|
+
if (shape != null) {
|
|
477
|
+
const s = shape;
|
|
478
|
+
return tryPick((tupledArg) => {
|
|
479
|
+
const t_1 = tupledArg[1];
|
|
480
|
+
let matchResult, f_1;
|
|
481
|
+
if (t_1.tag === 8) {
|
|
482
|
+
if (t_1.fields[0].Equals(s)) {
|
|
483
|
+
matchResult = 0;
|
|
484
|
+
f_1 = t_1.fields[0];
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
matchResult = 1;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
matchResult = 1;
|
|
492
|
+
}
|
|
493
|
+
switch (matchResult) {
|
|
494
|
+
case 0:
|
|
495
|
+
return new Type(12, [tupledArg[0]]);
|
|
496
|
+
default:
|
|
497
|
+
return undefined;
|
|
498
|
+
}
|
|
499
|
+
}, toSeq(typeDefs));
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
return undefined;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
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]));
|
|
509
|
+
default:
|
|
510
|
+
switch (tref_1.fields[0]) {
|
|
511
|
+
case "unit":
|
|
512
|
+
return new Type(0, []);
|
|
513
|
+
case "int":
|
|
514
|
+
return new Type(1, []);
|
|
515
|
+
case "float":
|
|
516
|
+
return new Type(2, []);
|
|
517
|
+
case "bool":
|
|
518
|
+
return new Type(3, []);
|
|
519
|
+
case "string":
|
|
520
|
+
return new Type(4, []);
|
|
521
|
+
default:
|
|
522
|
+
return tryFind(tref_1.fields[0], typeDefs);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
const resolveTypeList = (items) => {
|
|
527
|
+
if (!isEmpty(items)) {
|
|
528
|
+
const matchValue = resolve(head_2(items));
|
|
529
|
+
const matchValue_1 = resolveTypeList(tail_2(items));
|
|
530
|
+
let matchResult_1, h, t_2;
|
|
531
|
+
if (matchValue != null) {
|
|
532
|
+
if (matchValue_1 != null) {
|
|
533
|
+
matchResult_1 = 0;
|
|
534
|
+
h = matchValue;
|
|
535
|
+
t_2 = matchValue_1;
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
matchResult_1 = 1;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
matchResult_1 = 1;
|
|
543
|
+
}
|
|
544
|
+
switch (matchResult_1) {
|
|
545
|
+
case 0:
|
|
546
|
+
return cons(h, t_2);
|
|
547
|
+
default:
|
|
548
|
+
return undefined;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
return empty();
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
const resolveFieldList = (fields_2) => {
|
|
556
|
+
if (!isEmpty(fields_2)) {
|
|
557
|
+
const matchValue_3 = resolve(head_2(fields_2)[1]);
|
|
558
|
+
const matchValue_4 = resolveFieldList(tail_2(fields_2));
|
|
559
|
+
let matchResult_2, rest, t_3;
|
|
560
|
+
if (matchValue_3 != null) {
|
|
561
|
+
if (matchValue_4 != null) {
|
|
562
|
+
matchResult_2 = 0;
|
|
563
|
+
rest = matchValue_4;
|
|
564
|
+
t_3 = matchValue_3;
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
matchResult_2 = 1;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
matchResult_2 = 1;
|
|
572
|
+
}
|
|
573
|
+
switch (matchResult_2) {
|
|
574
|
+
case 0:
|
|
575
|
+
return cons([head_2(fields_2)[0], t_3], rest);
|
|
576
|
+
default:
|
|
577
|
+
return undefined;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
return empty();
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
const valueHasType = (value_1_mut, t_4_mut) => {
|
|
585
|
+
valueHasType:
|
|
586
|
+
while (true) {
|
|
587
|
+
const value_1 = value_1_mut, t_4 = t_4_mut;
|
|
588
|
+
let matchResult_3, inner_4, items_1, inner_5, items_2, inner_6, inner_7, v_1, fields_3, values, name_4, v_2;
|
|
589
|
+
switch (t_4.tag) {
|
|
590
|
+
case 0: {
|
|
591
|
+
if (value_1.tag === 0) {
|
|
592
|
+
matchResult_3 = 0;
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
matchResult_3 = 13;
|
|
596
|
+
}
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
case 1: {
|
|
600
|
+
if (value_1.tag === 1) {
|
|
601
|
+
matchResult_3 = 1;
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
matchResult_3 = 13;
|
|
605
|
+
}
|
|
606
|
+
break;
|
|
607
|
+
}
|
|
608
|
+
case 2: {
|
|
609
|
+
if (value_1.tag === 2) {
|
|
610
|
+
matchResult_3 = 2;
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
matchResult_3 = 13;
|
|
614
|
+
}
|
|
615
|
+
break;
|
|
616
|
+
}
|
|
617
|
+
case 3: {
|
|
618
|
+
if (value_1.tag === 3) {
|
|
619
|
+
matchResult_3 = 3;
|
|
620
|
+
}
|
|
621
|
+
else {
|
|
622
|
+
matchResult_3 = 13;
|
|
623
|
+
}
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
case 4: {
|
|
627
|
+
if (value_1.tag === 4) {
|
|
628
|
+
matchResult_3 = 4;
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
matchResult_3 = 13;
|
|
632
|
+
}
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
case 5: {
|
|
636
|
+
if (value_1.tag === 5) {
|
|
637
|
+
matchResult_3 = 5;
|
|
638
|
+
inner_4 = t_4.fields[0];
|
|
639
|
+
items_1 = value_1.fields[0];
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
matchResult_3 = 13;
|
|
643
|
+
}
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
case 6: {
|
|
647
|
+
if (value_1.tag === 13) {
|
|
648
|
+
matchResult_3 = 6;
|
|
649
|
+
}
|
|
650
|
+
else {
|
|
651
|
+
matchResult_3 = 13;
|
|
652
|
+
}
|
|
653
|
+
break;
|
|
654
|
+
}
|
|
655
|
+
case 7: {
|
|
656
|
+
if (value_1.tag === 6) {
|
|
657
|
+
matchResult_3 = 7;
|
|
658
|
+
inner_5 = t_4.fields[0];
|
|
659
|
+
items_2 = value_1.fields[0];
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
matchResult_3 = 13;
|
|
663
|
+
}
|
|
664
|
+
break;
|
|
665
|
+
}
|
|
666
|
+
case 10: {
|
|
667
|
+
if (value_1.tag === 9) {
|
|
668
|
+
if (value_1.fields[0] != null) {
|
|
669
|
+
matchResult_3 = 9;
|
|
670
|
+
inner_7 = t_4.fields[0];
|
|
671
|
+
v_1 = value_1.fields[0];
|
|
672
|
+
}
|
|
673
|
+
else {
|
|
674
|
+
matchResult_3 = 8;
|
|
675
|
+
inner_6 = t_4.fields[0];
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
else {
|
|
679
|
+
matchResult_3 = 13;
|
|
680
|
+
}
|
|
681
|
+
break;
|
|
682
|
+
}
|
|
683
|
+
case 9: {
|
|
684
|
+
if (value_1.tag === 8) {
|
|
685
|
+
matchResult_3 = 10;
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
matchResult_3 = 13;
|
|
689
|
+
}
|
|
690
|
+
break;
|
|
691
|
+
}
|
|
692
|
+
case 8: {
|
|
693
|
+
if (value_1.tag === 7) {
|
|
694
|
+
matchResult_3 = 11;
|
|
695
|
+
fields_3 = t_4.fields[0];
|
|
696
|
+
values = value_1.fields[0];
|
|
697
|
+
}
|
|
698
|
+
else {
|
|
699
|
+
matchResult_3 = 13;
|
|
700
|
+
}
|
|
701
|
+
break;
|
|
702
|
+
}
|
|
703
|
+
case 12: {
|
|
704
|
+
matchResult_3 = 12;
|
|
705
|
+
name_4 = t_4.fields[0];
|
|
706
|
+
v_2 = value_1;
|
|
707
|
+
break;
|
|
708
|
+
}
|
|
709
|
+
default:
|
|
710
|
+
matchResult_3 = 13;
|
|
711
|
+
}
|
|
712
|
+
switch (matchResult_3) {
|
|
713
|
+
case 0:
|
|
714
|
+
return true;
|
|
715
|
+
case 1:
|
|
716
|
+
return true;
|
|
717
|
+
case 2:
|
|
718
|
+
return true;
|
|
719
|
+
case 3:
|
|
720
|
+
return true;
|
|
721
|
+
case 4:
|
|
722
|
+
return true;
|
|
723
|
+
case 5:
|
|
724
|
+
return forAll_1((v) => valueHasType(v, inner_4), items_1);
|
|
725
|
+
case 6:
|
|
726
|
+
return true;
|
|
727
|
+
case 7:
|
|
728
|
+
if (length(inner_5) === length(items_2)) {
|
|
729
|
+
return forAll2(valueHasType, items_2, inner_5);
|
|
730
|
+
}
|
|
731
|
+
else {
|
|
732
|
+
return false;
|
|
733
|
+
}
|
|
734
|
+
case 8:
|
|
735
|
+
return true;
|
|
736
|
+
case 9: {
|
|
737
|
+
value_1_mut = v_1;
|
|
738
|
+
t_4_mut = inner_7;
|
|
739
|
+
continue valueHasType;
|
|
740
|
+
}
|
|
741
|
+
case 10:
|
|
742
|
+
return true;
|
|
743
|
+
case 11:
|
|
744
|
+
return forAll((name_3, ft) => {
|
|
745
|
+
const matchValue_7 = FSharpMap__TryFind(values, name_3);
|
|
746
|
+
if (matchValue_7 == null) {
|
|
747
|
+
return false;
|
|
748
|
+
}
|
|
749
|
+
else {
|
|
750
|
+
return valueHasType(matchValue_7, ft);
|
|
751
|
+
}
|
|
752
|
+
}, fields_3);
|
|
753
|
+
case 12: {
|
|
754
|
+
const matchValue_8 = FSharpMap__TryFind(typeDefs, name_4);
|
|
755
|
+
if (matchValue_8 == null) {
|
|
756
|
+
return false;
|
|
757
|
+
}
|
|
758
|
+
else {
|
|
759
|
+
value_1_mut = v_2;
|
|
760
|
+
t_4_mut = matchValue_8;
|
|
761
|
+
continue valueHasType;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
default:
|
|
765
|
+
return false;
|
|
766
|
+
}
|
|
767
|
+
break;
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
switch (tref.tag) {
|
|
771
|
+
case 4: {
|
|
772
|
+
const matchValue_9 = resolve(tref);
|
|
773
|
+
if (matchValue_9 == null) {
|
|
774
|
+
return false;
|
|
775
|
+
}
|
|
776
|
+
else {
|
|
777
|
+
return valueHasType(value, matchValue_9);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
case 5: {
|
|
781
|
+
const matchValue_10 = resolve(new TypeRef(5, [tref.fields[0]]));
|
|
782
|
+
if (matchValue_10 == null) {
|
|
783
|
+
return false;
|
|
784
|
+
}
|
|
785
|
+
else {
|
|
786
|
+
return valueHasType(value, matchValue_10);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
default: {
|
|
790
|
+
const matchValue_11 = resolve(tref);
|
|
791
|
+
if (matchValue_11 == null) {
|
|
792
|
+
return false;
|
|
793
|
+
}
|
|
794
|
+
else {
|
|
795
|
+
return valueHasType(value, matchValue_11);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
function patternMatch(typeDefs_mut, pat_mut, value_mut) {
|
|
802
|
+
patternMatch:
|
|
803
|
+
while (true) {
|
|
804
|
+
const typeDefs = typeDefs_mut, pat = pat_mut, value = value_mut;
|
|
805
|
+
const mergeBindings = (left, right) => {
|
|
806
|
+
let ok = true;
|
|
807
|
+
let merged = left;
|
|
808
|
+
const enumerator = getEnumerator(right);
|
|
809
|
+
try {
|
|
810
|
+
while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
811
|
+
const activePatternResult = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
812
|
+
const v = activePatternResult[1];
|
|
813
|
+
const k = activePatternResult[0];
|
|
814
|
+
const matchValue = FSharpMap__TryFind(merged, k);
|
|
815
|
+
if (matchValue == null) {
|
|
816
|
+
merged = add(k, v, merged);
|
|
817
|
+
}
|
|
818
|
+
else if (!valueEquals(matchValue, v)) {
|
|
819
|
+
const existing_1 = matchValue;
|
|
820
|
+
ok = false;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
finally {
|
|
825
|
+
disposeSafe(enumerator);
|
|
826
|
+
}
|
|
827
|
+
if (ok) {
|
|
828
|
+
return merged;
|
|
829
|
+
}
|
|
830
|
+
else {
|
|
831
|
+
return undefined;
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
const matchMapClauses = (hasExplicitClauses_mut, clauses_mut, tailPattern_mut, remaining_mut, envAcc_mut) => {
|
|
835
|
+
matchMapClauses:
|
|
836
|
+
while (true) {
|
|
837
|
+
const hasExplicitClauses = hasExplicitClauses_mut, clauses = clauses_mut, tailPattern = tailPattern_mut, remaining = remaining_mut, envAcc = envAcc_mut;
|
|
838
|
+
if (!isEmpty(clauses)) {
|
|
839
|
+
const valuePattern = head_2(clauses)[1];
|
|
840
|
+
const rest = tail_2(clauses);
|
|
841
|
+
const keyPattern = head_2(clauses)[0];
|
|
842
|
+
if (keyPattern.tag === 1) {
|
|
843
|
+
if (!FSharpMap__ContainsKey(envAcc, keyPattern.fields[0])) {
|
|
844
|
+
if (FSharpMap__get_IsEmpty(remaining)) {
|
|
845
|
+
return undefined;
|
|
846
|
+
}
|
|
847
|
+
else {
|
|
848
|
+
const head = head_3(remaining);
|
|
849
|
+
const key = head[0];
|
|
850
|
+
const nextRemaining = FSharpMap__Remove(remaining, key);
|
|
851
|
+
const matchValue_2 = patternMatch(typeDefs, keyPattern, mapKeyToValue(key));
|
|
852
|
+
const matchValue_3 = patternMatch(typeDefs, valuePattern, head[1]);
|
|
853
|
+
let matchResult, keyEnv, valueEnv;
|
|
854
|
+
if (matchValue_2 != null) {
|
|
855
|
+
if (matchValue_3 != null) {
|
|
856
|
+
matchResult = 0;
|
|
857
|
+
keyEnv = matchValue_2;
|
|
858
|
+
valueEnv = matchValue_3;
|
|
859
|
+
}
|
|
860
|
+
else {
|
|
861
|
+
matchResult = 1;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
else {
|
|
865
|
+
matchResult = 1;
|
|
866
|
+
}
|
|
867
|
+
switch (matchResult) {
|
|
868
|
+
case 0: {
|
|
869
|
+
const matchValue_5 = mergeBindings(envAcc, keyEnv);
|
|
870
|
+
if (matchValue_5 == null) {
|
|
871
|
+
return undefined;
|
|
872
|
+
}
|
|
873
|
+
else {
|
|
874
|
+
const matchValue_6 = mergeBindings(matchValue_5, valueEnv);
|
|
875
|
+
if (matchValue_6 == null) {
|
|
876
|
+
return undefined;
|
|
877
|
+
}
|
|
878
|
+
else {
|
|
879
|
+
hasExplicitClauses_mut = hasExplicitClauses;
|
|
880
|
+
clauses_mut = rest;
|
|
881
|
+
tailPattern_mut = tailPattern;
|
|
882
|
+
remaining_mut = nextRemaining;
|
|
883
|
+
envAcc_mut = matchValue_6;
|
|
884
|
+
continue matchMapClauses;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
default:
|
|
889
|
+
return undefined;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
else {
|
|
894
|
+
const matchValue_7 = FSharpMap__TryFind(envAcc, keyPattern.fields[0]);
|
|
895
|
+
if (matchValue_7 != null) {
|
|
896
|
+
const targetKeyValue = matchValue_7;
|
|
897
|
+
let targetKey;
|
|
898
|
+
switch (targetKeyValue.tag) {
|
|
899
|
+
case 4: {
|
|
900
|
+
targetKey = (new MapKey(0, [targetKeyValue.fields[0]]));
|
|
901
|
+
break;
|
|
902
|
+
}
|
|
903
|
+
case 1: {
|
|
904
|
+
targetKey = (new MapKey(1, [targetKeyValue.fields[0]]));
|
|
905
|
+
break;
|
|
906
|
+
}
|
|
907
|
+
default:
|
|
908
|
+
throw new EvalException(new EvalError$("Map key must be string or int", Ast_spanOfPattern(keyPattern)));
|
|
909
|
+
}
|
|
910
|
+
if (!FSharpMap__ContainsKey(remaining, targetKey)) {
|
|
911
|
+
return undefined;
|
|
912
|
+
}
|
|
913
|
+
else {
|
|
914
|
+
const matchValue_8 = patternMatch(typeDefs, valuePattern, FSharpMap__get_Item(remaining, targetKey));
|
|
915
|
+
if (matchValue_8 == null) {
|
|
916
|
+
return undefined;
|
|
917
|
+
}
|
|
918
|
+
else {
|
|
919
|
+
const matchValue_9 = mergeBindings(envAcc, matchValue_8);
|
|
920
|
+
if (matchValue_9 == null) {
|
|
921
|
+
return undefined;
|
|
922
|
+
}
|
|
923
|
+
else {
|
|
924
|
+
const merged_1 = matchValue_9;
|
|
925
|
+
hasExplicitClauses_mut = hasExplicitClauses;
|
|
926
|
+
clauses_mut = rest;
|
|
927
|
+
tailPattern_mut = tailPattern;
|
|
928
|
+
remaining_mut = FSharpMap__Remove(remaining, targetKey);
|
|
929
|
+
envAcc_mut = merged_1;
|
|
930
|
+
continue matchMapClauses;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
else {
|
|
936
|
+
return undefined;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
else {
|
|
941
|
+
return bind((tupledArg) => matchMapClauses(hasExplicitClauses, rest, tailPattern, FSharpMap__Remove(remaining, tupledArg[0]), tupledArg[1]), tryPick((kv) => {
|
|
942
|
+
const matchValue_10 = patternMatch(typeDefs, keyPattern, mapKeyToValue(kv[0]));
|
|
943
|
+
if (matchValue_10 == null) {
|
|
944
|
+
return undefined;
|
|
945
|
+
}
|
|
946
|
+
else {
|
|
947
|
+
const matchValue_11 = mergeBindings(envAcc, matchValue_10);
|
|
948
|
+
if (matchValue_11 == null) {
|
|
949
|
+
return undefined;
|
|
950
|
+
}
|
|
951
|
+
else {
|
|
952
|
+
const merged1_1 = matchValue_11;
|
|
953
|
+
const matchValue_12 = patternMatch(typeDefs, valuePattern, kv[1]);
|
|
954
|
+
if (matchValue_12 == null) {
|
|
955
|
+
return undefined;
|
|
956
|
+
}
|
|
957
|
+
else {
|
|
958
|
+
const matchValue_13 = mergeBindings(merged1_1, matchValue_12);
|
|
959
|
+
if (matchValue_13 == null) {
|
|
960
|
+
return undefined;
|
|
961
|
+
}
|
|
962
|
+
else {
|
|
963
|
+
return [kv[0], matchValue_13];
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}, remaining));
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
else if (tailPattern == null) {
|
|
972
|
+
if (hasExplicitClauses ? true : FSharpMap__get_IsEmpty(remaining)) {
|
|
973
|
+
return envAcc;
|
|
974
|
+
}
|
|
975
|
+
else {
|
|
976
|
+
return undefined;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
else {
|
|
980
|
+
const matchValue_1 = patternMatch(typeDefs, tailPattern, new Value(8, [remaining]));
|
|
981
|
+
if (matchValue_1 == null) {
|
|
982
|
+
return undefined;
|
|
983
|
+
}
|
|
984
|
+
else {
|
|
985
|
+
return mergeBindings(envAcc, matchValue_1);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
break;
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
let matchResult_1, name_3, v_1, lit, v_2, h, p1, p2, t, patterns_1, values_1, fields, values_2, clauses_1, tailPattern_1, values_3, p_2, v_6, caseName, payload, qualifier, valueCaseName, valuePayload, valueTypeName, tref, v_8;
|
|
992
|
+
switch (pat.tag) {
|
|
993
|
+
case 1: {
|
|
994
|
+
matchResult_1 = 1;
|
|
995
|
+
name_3 = pat.fields[0];
|
|
996
|
+
v_1 = value;
|
|
997
|
+
break;
|
|
998
|
+
}
|
|
999
|
+
case 2: {
|
|
1000
|
+
matchResult_1 = 2;
|
|
1001
|
+
lit = pat.fields[0];
|
|
1002
|
+
v_2 = value;
|
|
1003
|
+
break;
|
|
1004
|
+
}
|
|
1005
|
+
case 3: {
|
|
1006
|
+
if (value.tag === 5) {
|
|
1007
|
+
if (isEmpty(value.fields[0])) {
|
|
1008
|
+
matchResult_1 = 3;
|
|
1009
|
+
}
|
|
1010
|
+
else {
|
|
1011
|
+
matchResult_1 = 12;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
else {
|
|
1015
|
+
matchResult_1 = 12;
|
|
1016
|
+
}
|
|
1017
|
+
break;
|
|
1018
|
+
}
|
|
1019
|
+
case 4: {
|
|
1020
|
+
if (value.tag === 5) {
|
|
1021
|
+
if (!isEmpty(value.fields[0])) {
|
|
1022
|
+
matchResult_1 = 4;
|
|
1023
|
+
h = head_2(value.fields[0]);
|
|
1024
|
+
p1 = pat.fields[0];
|
|
1025
|
+
p2 = pat.fields[1];
|
|
1026
|
+
t = tail_2(value.fields[0]);
|
|
1027
|
+
}
|
|
1028
|
+
else {
|
|
1029
|
+
matchResult_1 = 12;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
else {
|
|
1033
|
+
matchResult_1 = 12;
|
|
1034
|
+
}
|
|
1035
|
+
break;
|
|
1036
|
+
}
|
|
1037
|
+
case 5: {
|
|
1038
|
+
if (value.tag === 6) {
|
|
1039
|
+
if (length(pat.fields[0]) === length(value.fields[0])) {
|
|
1040
|
+
matchResult_1 = 5;
|
|
1041
|
+
patterns_1 = pat.fields[0];
|
|
1042
|
+
values_1 = value.fields[0];
|
|
1043
|
+
}
|
|
1044
|
+
else {
|
|
1045
|
+
matchResult_1 = 12;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
else {
|
|
1049
|
+
matchResult_1 = 12;
|
|
1050
|
+
}
|
|
1051
|
+
break;
|
|
1052
|
+
}
|
|
1053
|
+
case 6: {
|
|
1054
|
+
if (value.tag === 7) {
|
|
1055
|
+
matchResult_1 = 6;
|
|
1056
|
+
fields = pat.fields[0];
|
|
1057
|
+
values_2 = value.fields[0];
|
|
1058
|
+
}
|
|
1059
|
+
else {
|
|
1060
|
+
matchResult_1 = 12;
|
|
1061
|
+
}
|
|
1062
|
+
break;
|
|
1063
|
+
}
|
|
1064
|
+
case 7: {
|
|
1065
|
+
if (value.tag === 8) {
|
|
1066
|
+
matchResult_1 = 7;
|
|
1067
|
+
clauses_1 = pat.fields[0];
|
|
1068
|
+
tailPattern_1 = pat.fields[1];
|
|
1069
|
+
values_3 = value.fields[0];
|
|
1070
|
+
}
|
|
1071
|
+
else {
|
|
1072
|
+
matchResult_1 = 12;
|
|
1073
|
+
}
|
|
1074
|
+
break;
|
|
1075
|
+
}
|
|
1076
|
+
case 8: {
|
|
1077
|
+
if (value.tag === 9) {
|
|
1078
|
+
if (value.fields[0] != null) {
|
|
1079
|
+
matchResult_1 = 8;
|
|
1080
|
+
p_2 = pat.fields[0];
|
|
1081
|
+
v_6 = value.fields[0];
|
|
1082
|
+
}
|
|
1083
|
+
else {
|
|
1084
|
+
matchResult_1 = 12;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
else {
|
|
1088
|
+
matchResult_1 = 12;
|
|
1089
|
+
}
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
case 9: {
|
|
1093
|
+
if (value.tag === 9) {
|
|
1094
|
+
if (value.fields[0] == null) {
|
|
1095
|
+
matchResult_1 = 9;
|
|
1096
|
+
}
|
|
1097
|
+
else {
|
|
1098
|
+
matchResult_1 = 12;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
else {
|
|
1102
|
+
matchResult_1 = 12;
|
|
1103
|
+
}
|
|
1104
|
+
break;
|
|
1105
|
+
}
|
|
1106
|
+
case 10: {
|
|
1107
|
+
if (value.tag === 10) {
|
|
1108
|
+
matchResult_1 = 10;
|
|
1109
|
+
caseName = pat.fields[1];
|
|
1110
|
+
payload = pat.fields[2];
|
|
1111
|
+
qualifier = pat.fields[0];
|
|
1112
|
+
valueCaseName = value.fields[1];
|
|
1113
|
+
valuePayload = value.fields[2];
|
|
1114
|
+
valueTypeName = value.fields[0];
|
|
1115
|
+
}
|
|
1116
|
+
else {
|
|
1117
|
+
matchResult_1 = 12;
|
|
1118
|
+
}
|
|
1119
|
+
break;
|
|
1120
|
+
}
|
|
1121
|
+
case 11: {
|
|
1122
|
+
matchResult_1 = 11;
|
|
1123
|
+
tref = pat.fields[0];
|
|
1124
|
+
v_8 = value;
|
|
1125
|
+
break;
|
|
1126
|
+
}
|
|
1127
|
+
default:
|
|
1128
|
+
matchResult_1 = 0;
|
|
1129
|
+
}
|
|
1130
|
+
switch (matchResult_1) {
|
|
1131
|
+
case 0:
|
|
1132
|
+
return empty_1({
|
|
1133
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
1134
|
+
});
|
|
1135
|
+
case 1:
|
|
1136
|
+
return ofList(singleton([name_3, v_1]), {
|
|
1137
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
1138
|
+
});
|
|
1139
|
+
case 2:
|
|
1140
|
+
if (valueEquals(literalToValue(lit), v_2)) {
|
|
1141
|
+
return empty_1({
|
|
1142
|
+
Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
else {
|
|
1146
|
+
return undefined;
|
|
1147
|
+
}
|
|
1148
|
+
case 3:
|
|
1149
|
+
return empty_1({
|
|
1150
|
+
Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
|
|
1151
|
+
});
|
|
1152
|
+
case 4: {
|
|
1153
|
+
const matchValue_15 = patternMatch(typeDefs, p1, h);
|
|
1154
|
+
const matchValue_16 = patternMatch(typeDefs, p2, new Value(5, [t]));
|
|
1155
|
+
let matchResult_2, env1, env2;
|
|
1156
|
+
if (matchValue_15 != null) {
|
|
1157
|
+
if (matchValue_16 != null) {
|
|
1158
|
+
matchResult_2 = 0;
|
|
1159
|
+
env1 = matchValue_15;
|
|
1160
|
+
env2 = matchValue_16;
|
|
1161
|
+
}
|
|
1162
|
+
else {
|
|
1163
|
+
matchResult_2 = 1;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
else {
|
|
1167
|
+
matchResult_2 = 1;
|
|
1168
|
+
}
|
|
1169
|
+
switch (matchResult_2) {
|
|
1170
|
+
case 0:
|
|
1171
|
+
return fold((acc, k_1, v_3) => add(k_1, v_3, acc), env1, env2);
|
|
1172
|
+
default:
|
|
1173
|
+
return undefined;
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
case 5:
|
|
1177
|
+
return fold_1((accOpt, tupledArg_1) => {
|
|
1178
|
+
const matchValue_18 = patternMatch(typeDefs, tupledArg_1[0], tupledArg_1[1]);
|
|
1179
|
+
let matchResult_3, acc_1, next;
|
|
1180
|
+
if (accOpt != null) {
|
|
1181
|
+
if (matchValue_18 != null) {
|
|
1182
|
+
matchResult_3 = 0;
|
|
1183
|
+
acc_1 = accOpt;
|
|
1184
|
+
next = matchValue_18;
|
|
1185
|
+
}
|
|
1186
|
+
else {
|
|
1187
|
+
matchResult_3 = 1;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
else {
|
|
1191
|
+
matchResult_3 = 1;
|
|
1192
|
+
}
|
|
1193
|
+
switch (matchResult_3) {
|
|
1194
|
+
case 0:
|
|
1195
|
+
return fold((state, k_2, value_3) => add(k_2, value_3, state), acc_1, next);
|
|
1196
|
+
default:
|
|
1197
|
+
return undefined;
|
|
1198
|
+
}
|
|
1199
|
+
}, empty_1({
|
|
1200
|
+
Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
|
|
1201
|
+
}), zip(patterns_1, values_1));
|
|
1202
|
+
case 6:
|
|
1203
|
+
return fold_1((accOpt_1, tupledArg_2) => {
|
|
1204
|
+
const matchValue_20 = FSharpMap__TryFind(values_2, tupledArg_2[0]);
|
|
1205
|
+
let matchResult_4, acc_2, value_4;
|
|
1206
|
+
if (accOpt_1 != null) {
|
|
1207
|
+
if (matchValue_20 != null) {
|
|
1208
|
+
matchResult_4 = 0;
|
|
1209
|
+
acc_2 = accOpt_1;
|
|
1210
|
+
value_4 = matchValue_20;
|
|
1211
|
+
}
|
|
1212
|
+
else {
|
|
1213
|
+
matchResult_4 = 1;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
else {
|
|
1217
|
+
matchResult_4 = 1;
|
|
1218
|
+
}
|
|
1219
|
+
switch (matchResult_4) {
|
|
1220
|
+
case 0: {
|
|
1221
|
+
const matchValue_22 = patternMatch(typeDefs, tupledArg_2[1], value_4);
|
|
1222
|
+
if (matchValue_22 == null) {
|
|
1223
|
+
return undefined;
|
|
1224
|
+
}
|
|
1225
|
+
else {
|
|
1226
|
+
return fold((state_2, k_3, v_5) => add(k_3, v_5, state_2), acc_2, matchValue_22);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
default:
|
|
1230
|
+
return undefined;
|
|
1231
|
+
}
|
|
1232
|
+
}, empty_1({
|
|
1233
|
+
Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
|
|
1234
|
+
}), fields);
|
|
1235
|
+
case 7:
|
|
1236
|
+
return matchMapClauses(!isEmpty(clauses_1), clauses_1, tailPattern_1, values_3, empty_1({
|
|
1237
|
+
Compare: (x_6, y_6) => (comparePrimitives(x_6, y_6) | 0),
|
|
1238
|
+
}));
|
|
1239
|
+
case 8: {
|
|
1240
|
+
typeDefs_mut = typeDefs;
|
|
1241
|
+
pat_mut = p_2;
|
|
1242
|
+
value_mut = v_6;
|
|
1243
|
+
continue patternMatch;
|
|
1244
|
+
}
|
|
1245
|
+
case 9:
|
|
1246
|
+
return empty_1({
|
|
1247
|
+
Compare: (x_7, y_7) => (comparePrimitives(x_7, y_7) | 0),
|
|
1248
|
+
});
|
|
1249
|
+
case 10:
|
|
1250
|
+
if ((caseName === valueCaseName) && ((qualifier == null) ? true : (qualifier === valueTypeName))) {
|
|
1251
|
+
let matchResult_5, p_3, v_7;
|
|
1252
|
+
if (payload != null) {
|
|
1253
|
+
if (valuePayload != null) {
|
|
1254
|
+
matchResult_5 = 1;
|
|
1255
|
+
p_3 = payload;
|
|
1256
|
+
v_7 = valuePayload;
|
|
1257
|
+
}
|
|
1258
|
+
else {
|
|
1259
|
+
matchResult_5 = 2;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
else if (valuePayload == null) {
|
|
1263
|
+
matchResult_5 = 0;
|
|
1264
|
+
}
|
|
1265
|
+
else {
|
|
1266
|
+
matchResult_5 = 2;
|
|
1267
|
+
}
|
|
1268
|
+
switch (matchResult_5) {
|
|
1269
|
+
case 0:
|
|
1270
|
+
return empty_1({
|
|
1271
|
+
Compare: (x_8, y_8) => (comparePrimitives(x_8, y_8) | 0),
|
|
1272
|
+
});
|
|
1273
|
+
case 1: {
|
|
1274
|
+
typeDefs_mut = typeDefs;
|
|
1275
|
+
pat_mut = p_3;
|
|
1276
|
+
value_mut = v_7;
|
|
1277
|
+
continue patternMatch;
|
|
1278
|
+
}
|
|
1279
|
+
default:
|
|
1280
|
+
return undefined;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
else {
|
|
1284
|
+
return undefined;
|
|
1285
|
+
}
|
|
1286
|
+
case 11:
|
|
1287
|
+
if (valueMatchesTypeRef(typeDefs, tref, v_8)) {
|
|
1288
|
+
return empty_1({
|
|
1289
|
+
Compare: (x_9, y_9) => (comparePrimitives(x_9, y_9) | 0),
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
else {
|
|
1293
|
+
return undefined;
|
|
1294
|
+
}
|
|
1295
|
+
default:
|
|
1296
|
+
return undefined;
|
|
1297
|
+
}
|
|
1298
|
+
break;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
function createExternContext(runtime, typeDefs, span) {
|
|
1303
|
+
return new ExternalCallContext((fnValue, argValue) => applyFunctionValue(runtime, evalExpr, typeDefs, span, fnValue, argValue), (thunk) => spawnTaskValue(runtime, typeDefs, thunk), (taskValue) => awaitTaskValue(runtime, taskValue), () => {
|
|
1304
|
+
raiseIfBackgroundFailed(runtime);
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
function spawnTaskValue(runtime, typeDefs, thunk) {
|
|
1309
|
+
raiseIfBackgroundFailed(runtime);
|
|
1310
|
+
throw new EvalException(new EvalError$("Task.spawn is not supported in Fable builds", unknownSpan));
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
function awaitTaskValue(runtime, taskValue) {
|
|
1314
|
+
raiseIfBackgroundFailed(runtime);
|
|
1315
|
+
throw new EvalException(new EvalError$("Task.await is not supported in Fable builds", unknownSpan));
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
function applyFunctionValue(runtime, eval$, typeDefs, span, fnValue, argValue) {
|
|
1319
|
+
raiseIfBackgroundFailed(runtime);
|
|
1320
|
+
switch (fnValue.tag) {
|
|
1321
|
+
case 14:
|
|
1322
|
+
return eval$(runtime, typeDefs, add(fnValue.fields[0], argValue, fnValue.fields[2].contents), fnValue.fields[1]);
|
|
1323
|
+
case 11:
|
|
1324
|
+
return new Value(10, [fnValue.fields[0], fnValue.fields[1], argValue]);
|
|
1325
|
+
case 15: {
|
|
1326
|
+
const ext = fnValue.fields[0];
|
|
1327
|
+
const args$0027 = cons(argValue, fnValue.fields[1]);
|
|
1328
|
+
if (length(args$0027) === ext.Arity) {
|
|
1329
|
+
return ext.Impl(createExternContext(runtime, typeDefs, span), reverse(args$0027));
|
|
1330
|
+
}
|
|
1331
|
+
else if (length(args$0027) < ext.Arity) {
|
|
1332
|
+
return new Value(15, [ext, args$0027]);
|
|
1333
|
+
}
|
|
1334
|
+
else {
|
|
1335
|
+
throw new EvalException(new EvalError$(toText(printf("External function \'%s\' received too many arguments"))(ext.Name), span));
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
default:
|
|
1339
|
+
throw new EvalException(new EvalError$("Attempted to apply non-function", span));
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
|
|
1344
|
+
evalExpr:
|
|
1345
|
+
while (true) {
|
|
1346
|
+
const runtime = runtime_mut, typeDefs = typeDefs_mut, env = env_mut, expr = expr_mut;
|
|
1347
|
+
raiseIfBackgroundFailed(runtime);
|
|
1348
|
+
switch (expr.tag) {
|
|
1349
|
+
case 1:
|
|
1350
|
+
return literalToValue(expr.fields[0]);
|
|
1351
|
+
case 2: {
|
|
1352
|
+
const name = expr.fields[0];
|
|
1353
|
+
const matchValue = tryFind(name, env);
|
|
1354
|
+
if (matchValue == null) {
|
|
1355
|
+
throw new EvalException(new EvalError$(toText(printf("Unbound variable \'%s\'"))(name), expr.fields[1]));
|
|
1356
|
+
}
|
|
1357
|
+
else {
|
|
1358
|
+
return matchValue;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
case 3: {
|
|
1362
|
+
runtime_mut = runtime;
|
|
1363
|
+
typeDefs_mut = typeDefs;
|
|
1364
|
+
env_mut = env;
|
|
1365
|
+
expr_mut = expr.fields[0];
|
|
1366
|
+
continue evalExpr;
|
|
1367
|
+
}
|
|
1368
|
+
case 4:
|
|
1369
|
+
return new Value(14, [expr.fields[0].Name, expr.fields[1], new FSharpRef(env)]);
|
|
1370
|
+
case 5:
|
|
1371
|
+
return applyFunctionValue(runtime, evalExpr, typeDefs, expr.fields[2], evalExpr(runtime, typeDefs, env, expr.fields[0]), evalExpr(runtime, typeDefs, env, expr.fields[1]));
|
|
1372
|
+
case 6: {
|
|
1373
|
+
const matchValue_1 = evalExpr(runtime, typeDefs, env, expr.fields[0]);
|
|
1374
|
+
if (matchValue_1.tag === 3) {
|
|
1375
|
+
if (matchValue_1.fields[0]) {
|
|
1376
|
+
runtime_mut = runtime;
|
|
1377
|
+
typeDefs_mut = typeDefs;
|
|
1378
|
+
env_mut = env;
|
|
1379
|
+
expr_mut = expr.fields[1];
|
|
1380
|
+
continue evalExpr;
|
|
1381
|
+
}
|
|
1382
|
+
else {
|
|
1383
|
+
runtime_mut = runtime;
|
|
1384
|
+
typeDefs_mut = typeDefs;
|
|
1385
|
+
env_mut = env;
|
|
1386
|
+
expr_mut = expr.fields[2];
|
|
1387
|
+
continue evalExpr;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
else {
|
|
1391
|
+
throw new EvalException(new EvalError$("Condition must be bool", expr.fields[3]));
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
case 7: {
|
|
1395
|
+
const span_3 = expr.fields[1];
|
|
1396
|
+
const matchValue_2 = evalExpr(runtime, typeDefs, env, expr.fields[0]);
|
|
1397
|
+
if (matchValue_2.tag === 4) {
|
|
1398
|
+
throw new EvalException(new EvalError$(matchValue_2.fields[0], span_3));
|
|
1399
|
+
}
|
|
1400
|
+
else {
|
|
1401
|
+
throw new EvalException(new EvalError$("raise expects a string", span_3));
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
case 8: {
|
|
1405
|
+
const matchValue_3 = evalExpr(runtime, typeDefs, env, expr.fields[1]);
|
|
1406
|
+
if (matchValue_3.tag === 5) {
|
|
1407
|
+
const enumerator = getEnumerator(matchValue_3.fields[0]);
|
|
1408
|
+
try {
|
|
1409
|
+
while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1410
|
+
evalExpr(runtime, typeDefs, add(expr.fields[0], enumerator["System.Collections.Generic.IEnumerator`1.get_Current"](), env), expr.fields[2]);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
finally {
|
|
1414
|
+
disposeSafe(enumerator);
|
|
1415
|
+
}
|
|
1416
|
+
return new Value(0, []);
|
|
1417
|
+
}
|
|
1418
|
+
else {
|
|
1419
|
+
throw new EvalException(new EvalError$("For loop source must be list", expr.fields[3]));
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
case 10: {
|
|
1423
|
+
const value_1 = expr.fields[1];
|
|
1424
|
+
const name_2 = expr.fields[0];
|
|
1425
|
+
const body_2 = expr.fields[2];
|
|
1426
|
+
if (expr.fields[3]) {
|
|
1427
|
+
if (value_1.tag === 4) {
|
|
1428
|
+
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);
|
|
1430
|
+
runtime_mut = runtime;
|
|
1431
|
+
typeDefs_mut = typeDefs;
|
|
1432
|
+
env_mut = recEnv.contents;
|
|
1433
|
+
expr_mut = body_2;
|
|
1434
|
+
continue evalExpr;
|
|
1435
|
+
}
|
|
1436
|
+
else {
|
|
1437
|
+
throw new EvalException(new EvalError$("let rec requires a function binding", expr.fields[5]));
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
else {
|
|
1441
|
+
runtime_mut = runtime;
|
|
1442
|
+
typeDefs_mut = typeDefs;
|
|
1443
|
+
env_mut = add(name_2, evalExpr(runtime, typeDefs, env, value_1), env);
|
|
1444
|
+
expr_mut = body_2;
|
|
1445
|
+
continue evalExpr;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
case 11: {
|
|
1449
|
+
const matchValue_4 = patternMatch(typeDefs, expr.fields[0], evalExpr(runtime, typeDefs, env, expr.fields[1]));
|
|
1450
|
+
if (matchValue_4 == null) {
|
|
1451
|
+
throw new EvalException(new EvalError$("Let pattern did not match value", expr.fields[3]));
|
|
1452
|
+
}
|
|
1453
|
+
else {
|
|
1454
|
+
runtime_mut = runtime;
|
|
1455
|
+
typeDefs_mut = typeDefs;
|
|
1456
|
+
env_mut = fold((acc, k, value_3) => add(k, value_3, acc), env, matchValue_4);
|
|
1457
|
+
expr_mut = expr.fields[2];
|
|
1458
|
+
continue evalExpr;
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
case 12: {
|
|
1462
|
+
const body_4 = expr.fields[1];
|
|
1463
|
+
const bindings_1 = expr.fields[0];
|
|
1464
|
+
if (isEmpty(bindings_1)) {
|
|
1465
|
+
runtime_mut = runtime;
|
|
1466
|
+
typeDefs_mut = typeDefs;
|
|
1467
|
+
env_mut = env;
|
|
1468
|
+
expr_mut = body_4;
|
|
1469
|
+
continue evalExpr;
|
|
1470
|
+
}
|
|
1471
|
+
else {
|
|
1472
|
+
const recEnv_1 = new FSharpRef(env);
|
|
1473
|
+
const finalEnv = fold_1((acc_1, tupledArg_1) => add(tupledArg_1[0], tupledArg_1[1], acc_1), env, map((tupledArg) => {
|
|
1474
|
+
const args = tupledArg[1];
|
|
1475
|
+
const bindingSpan = tupledArg[4];
|
|
1476
|
+
if (isEmpty(args)) {
|
|
1477
|
+
throw new EvalException(new EvalError$("\'let rec ... and ...\' requires function arguments for each binding", bindingSpan));
|
|
1478
|
+
}
|
|
1479
|
+
const folded = foldBack((arg_2, accExpr) => (new Expr(4, [arg_2, accExpr, bindingSpan])), args, tupledArg[3]);
|
|
1480
|
+
if (folded.tag === 4) {
|
|
1481
|
+
return [tupledArg[0], new Value(14, [folded.fields[0].Name, folded.fields[1], recEnv_1])];
|
|
1482
|
+
}
|
|
1483
|
+
else {
|
|
1484
|
+
throw new EvalException(new EvalError$("let rec requires a function binding", expr.fields[2]));
|
|
1485
|
+
}
|
|
1486
|
+
}, bindings_1));
|
|
1487
|
+
recEnv_1.contents = finalEnv;
|
|
1488
|
+
runtime_mut = runtime;
|
|
1489
|
+
typeDefs_mut = typeDefs;
|
|
1490
|
+
env_mut = finalEnv;
|
|
1491
|
+
expr_mut = body_4;
|
|
1492
|
+
continue evalExpr;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
case 9: {
|
|
1496
|
+
const span_8 = expr.fields[2];
|
|
1497
|
+
const v_3 = evalExpr(runtime, typeDefs, env, expr.fields[0]);
|
|
1498
|
+
const tryCases = (cs_mut) => {
|
|
1499
|
+
tryCases:
|
|
1500
|
+
while (true) {
|
|
1501
|
+
const cs = cs_mut;
|
|
1502
|
+
if (!isEmpty(cs)) {
|
|
1503
|
+
const rest = tail_2(cs);
|
|
1504
|
+
const guard = head_2(cs)[1];
|
|
1505
|
+
const body_5 = head_2(cs)[2];
|
|
1506
|
+
const matchValue_5 = patternMatch(typeDefs, head_2(cs)[0], v_3);
|
|
1507
|
+
if (matchValue_5 == null) {
|
|
1508
|
+
cs_mut = rest;
|
|
1509
|
+
continue tryCases;
|
|
1510
|
+
}
|
|
1511
|
+
else {
|
|
1512
|
+
const env$0027_3 = fold((acc_2, k_1, v_4) => add(k_1, v_4, acc_2), env, matchValue_5);
|
|
1513
|
+
if (guard == null) {
|
|
1514
|
+
return evalExpr(runtime, typeDefs, env$0027_3, body_5);
|
|
1515
|
+
}
|
|
1516
|
+
else {
|
|
1517
|
+
const matchValue_6 = evalExpr(runtime, typeDefs, env$0027_3, guard);
|
|
1518
|
+
if (matchValue_6.tag === 3) {
|
|
1519
|
+
if (matchValue_6.fields[0]) {
|
|
1520
|
+
return evalExpr(runtime, typeDefs, env$0027_3, body_5);
|
|
1521
|
+
}
|
|
1522
|
+
else {
|
|
1523
|
+
cs_mut = rest;
|
|
1524
|
+
continue tryCases;
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
else {
|
|
1528
|
+
throw new EvalException(new EvalError$("Match guard must evaluate to bool", span_8));
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
else {
|
|
1534
|
+
throw new EvalException(new EvalError$("No match cases matched", span_8));
|
|
1535
|
+
}
|
|
1536
|
+
break;
|
|
1537
|
+
}
|
|
1538
|
+
};
|
|
1539
|
+
return tryCases(expr.fields[1]);
|
|
1540
|
+
}
|
|
1541
|
+
case 13:
|
|
1542
|
+
return new Value(5, [map((expr_2) => evalExpr(runtime, typeDefs, env, expr_2), expr.fields[0])]);
|
|
1543
|
+
case 14: {
|
|
1544
|
+
const startValue = evalExpr(runtime, typeDefs, env, expr.fields[0]);
|
|
1545
|
+
const endValue = evalExpr(runtime, typeDefs, env, expr.fields[1]);
|
|
1546
|
+
let matchResult, e, s;
|
|
1547
|
+
if (startValue.tag === 1) {
|
|
1548
|
+
if (endValue.tag === 1) {
|
|
1549
|
+
matchResult = 0;
|
|
1550
|
+
e = endValue.fields[0];
|
|
1551
|
+
s = startValue.fields[0];
|
|
1552
|
+
}
|
|
1553
|
+
else {
|
|
1554
|
+
matchResult = 1;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
else {
|
|
1558
|
+
matchResult = 1;
|
|
1559
|
+
}
|
|
1560
|
+
switch (matchResult) {
|
|
1561
|
+
case 0: {
|
|
1562
|
+
const step = (compare_1(s, e) <= 0) ? (1n) : (-1n);
|
|
1563
|
+
const build = (acc_3_mut, current_mut) => {
|
|
1564
|
+
build:
|
|
1565
|
+
while (true) {
|
|
1566
|
+
const acc_3 = acc_3_mut, current = current_mut;
|
|
1567
|
+
if (((compare_1(step, 0n) > 0) && (compare_1(current, e) > 0)) ? true : ((compare_1(step, 0n) < 0) && (compare_1(current, e) < 0))) {
|
|
1568
|
+
return reverse(acc_3);
|
|
1569
|
+
}
|
|
1570
|
+
else {
|
|
1571
|
+
acc_3_mut = cons(new Value(1, [current]), acc_3);
|
|
1572
|
+
current_mut = toInt64_unchecked(op_Addition(current, step));
|
|
1573
|
+
continue build;
|
|
1574
|
+
}
|
|
1575
|
+
break;
|
|
1576
|
+
}
|
|
1577
|
+
};
|
|
1578
|
+
return new Value(5, [build(empty(), s)]);
|
|
1579
|
+
}
|
|
1580
|
+
default:
|
|
1581
|
+
throw new EvalException(new EvalError$("Range endpoints must be int", expr.fields[2]));
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
case 15:
|
|
1585
|
+
return new Value(6, [map((expr_3) => evalExpr(runtime, typeDefs, env, expr_3), expr.fields[0])]);
|
|
1586
|
+
case 16:
|
|
1587
|
+
return new Value(7, [ofList(map((tupledArg_2) => [tupledArg_2[0], evalExpr(runtime, typeDefs, env, tupledArg_2[1])], expr.fields[0]), {
|
|
1588
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
1589
|
+
})]);
|
|
1590
|
+
case 17:
|
|
1591
|
+
return new Value(7, [ofList(map((tupledArg_3) => [tupledArg_3[0], evalExpr(runtime, typeDefs, env, tupledArg_3[1])], expr.fields[0]), {
|
|
1592
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
1593
|
+
})]);
|
|
1594
|
+
case 18:
|
|
1595
|
+
return new Value(8, [fold_1((acc_4, entry) => {
|
|
1596
|
+
if (entry.tag === 1) {
|
|
1597
|
+
const spreadExpr = entry.fields[0];
|
|
1598
|
+
const matchValue_8 = evalExpr(runtime, typeDefs, env, spreadExpr);
|
|
1599
|
+
if (matchValue_8.tag === 8) {
|
|
1600
|
+
return fold((state, key, value_5) => {
|
|
1601
|
+
if (FSharpMap__ContainsKey(state, key)) {
|
|
1602
|
+
return state;
|
|
1603
|
+
}
|
|
1604
|
+
else {
|
|
1605
|
+
return add(key, value_5, state);
|
|
1606
|
+
}
|
|
1607
|
+
}, acc_4, matchValue_8.fields[0]);
|
|
1608
|
+
}
|
|
1609
|
+
else {
|
|
1610
|
+
throw new EvalException(new EvalError$("Map spread value must be a map", Ast_spanOfExpr(spreadExpr)));
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
else {
|
|
1614
|
+
const keyExpr = entry.fields[0];
|
|
1615
|
+
const keyValue = evalExpr(runtime, typeDefs, env, keyExpr);
|
|
1616
|
+
switch (keyValue.tag) {
|
|
1617
|
+
case 4:
|
|
1618
|
+
case 1:
|
|
1619
|
+
return FSharpMap__Add(acc_4, valueToMapKey(Ast_spanOfExpr(keyExpr), keyValue), evalExpr(runtime, typeDefs, env, entry.fields[1]));
|
|
1620
|
+
default:
|
|
1621
|
+
throw new EvalException(new EvalError$("Map literal keys must be string or int", Ast_spanOfExpr(keyExpr)));
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
}, empty_1({
|
|
1625
|
+
Compare: (x_2, y_2) => (compare(x_2, y_2) | 0),
|
|
1626
|
+
}), expr.fields[0])]);
|
|
1627
|
+
case 19: {
|
|
1628
|
+
const span_10 = expr.fields[2];
|
|
1629
|
+
const matchValue_9 = evalExpr(runtime, typeDefs, env, expr.fields[0]);
|
|
1630
|
+
if (matchValue_9.tag === 7) {
|
|
1631
|
+
return new Value(7, [fold_1((acc_5, tupledArg_4) => {
|
|
1632
|
+
const name_7 = tupledArg_4[0];
|
|
1633
|
+
if (containsKey(name_7, acc_5)) {
|
|
1634
|
+
return add(name_7, evalExpr(runtime, typeDefs, env, tupledArg_4[1]), acc_5);
|
|
1635
|
+
}
|
|
1636
|
+
else {
|
|
1637
|
+
throw new EvalException(new EvalError$(toText(printf("Record field \'%s\' not found"))(name_7), span_10));
|
|
1638
|
+
}
|
|
1639
|
+
}, matchValue_9.fields[0], expr.fields[1])]);
|
|
1640
|
+
}
|
|
1641
|
+
else {
|
|
1642
|
+
throw new EvalException(new EvalError$("Record update requires a record value", span_10));
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
case 20: {
|
|
1646
|
+
const matchValue_10 = evalExpr(runtime, typeDefs, env, expr.fields[0]);
|
|
1647
|
+
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])]);
|
|
1649
|
+
}
|
|
1650
|
+
else {
|
|
1651
|
+
throw new EvalException(new EvalError$("Structural record update requires a record value", expr.fields[2]));
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
case 21: {
|
|
1655
|
+
const target_2 = expr.fields[0];
|
|
1656
|
+
const span_12 = expr.fields[2];
|
|
1657
|
+
const fieldName = expr.fields[1];
|
|
1658
|
+
let matchResult_1, moduleName_1;
|
|
1659
|
+
if (target_2.tag === 2) {
|
|
1660
|
+
if (!FSharpMap__ContainsKey(env, target_2.fields[0])) {
|
|
1661
|
+
matchResult_1 = 0;
|
|
1662
|
+
moduleName_1 = target_2.fields[0];
|
|
1663
|
+
}
|
|
1664
|
+
else {
|
|
1665
|
+
matchResult_1 = 1;
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
else {
|
|
1669
|
+
matchResult_1 = 1;
|
|
1670
|
+
}
|
|
1671
|
+
switch (matchResult_1) {
|
|
1672
|
+
case 0: {
|
|
1673
|
+
const matchValue_11 = FSharpMap__TryFind(env, concat(moduleName_1, ".", fieldName));
|
|
1674
|
+
if (matchValue_11 == null) {
|
|
1675
|
+
const matchValue_12 = evalExpr(runtime, typeDefs, env, target_2);
|
|
1676
|
+
if (matchValue_12.tag === 7) {
|
|
1677
|
+
const matchValue_13 = FSharpMap__TryFind(matchValue_12.fields[0], fieldName);
|
|
1678
|
+
if (matchValue_13 == null) {
|
|
1679
|
+
throw new EvalException(new EvalError$(toText(printf("Record field \'%s\' not found"))(fieldName), span_12));
|
|
1680
|
+
}
|
|
1681
|
+
else {
|
|
1682
|
+
return matchValue_13;
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
else {
|
|
1686
|
+
throw new EvalException(new EvalError$("Field access requires a record value", span_12));
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
else {
|
|
1690
|
+
return matchValue_11;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
default: {
|
|
1694
|
+
const matchValue_14 = evalExpr(runtime, typeDefs, env, target_2);
|
|
1695
|
+
if (matchValue_14.tag === 7) {
|
|
1696
|
+
const matchValue_15 = FSharpMap__TryFind(matchValue_14.fields[0], fieldName);
|
|
1697
|
+
if (matchValue_15 == null) {
|
|
1698
|
+
throw new EvalException(new EvalError$(toText(printf("Record field \'%s\' not found"))(fieldName), span_12));
|
|
1699
|
+
}
|
|
1700
|
+
else {
|
|
1701
|
+
return matchValue_15;
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
else {
|
|
1705
|
+
throw new EvalException(new EvalError$("Field access requires a record value", span_12));
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
case 22: {
|
|
1711
|
+
const span_13 = expr.fields[2];
|
|
1712
|
+
const targetValue = evalExpr(runtime, typeDefs, env, expr.fields[0]);
|
|
1713
|
+
const keyValue_1 = evalExpr(runtime, typeDefs, env, expr.fields[1]);
|
|
1714
|
+
let matchResult_2, index, values, mapValue;
|
|
1715
|
+
switch (targetValue.tag) {
|
|
1716
|
+
case 5: {
|
|
1717
|
+
if (keyValue_1.tag === 1) {
|
|
1718
|
+
matchResult_2 = 0;
|
|
1719
|
+
index = keyValue_1.fields[0];
|
|
1720
|
+
values = targetValue.fields[0];
|
|
1721
|
+
}
|
|
1722
|
+
else {
|
|
1723
|
+
matchResult_2 = 3;
|
|
1724
|
+
}
|
|
1725
|
+
break;
|
|
1726
|
+
}
|
|
1727
|
+
case 8: {
|
|
1728
|
+
switch (keyValue_1.tag) {
|
|
1729
|
+
case 4: {
|
|
1730
|
+
matchResult_2 = 1;
|
|
1731
|
+
mapValue = targetValue.fields[0];
|
|
1732
|
+
break;
|
|
1733
|
+
}
|
|
1734
|
+
case 1: {
|
|
1735
|
+
matchResult_2 = 1;
|
|
1736
|
+
mapValue = targetValue.fields[0];
|
|
1737
|
+
break;
|
|
1738
|
+
}
|
|
1739
|
+
default:
|
|
1740
|
+
matchResult_2 = 2;
|
|
1741
|
+
}
|
|
1742
|
+
break;
|
|
1743
|
+
}
|
|
1744
|
+
default:
|
|
1745
|
+
matchResult_2 = 4;
|
|
1746
|
+
}
|
|
1747
|
+
switch (matchResult_2) {
|
|
1748
|
+
case 0: {
|
|
1749
|
+
const loop = (remaining_mut, current_1_mut) => {
|
|
1750
|
+
loop:
|
|
1751
|
+
while (true) {
|
|
1752
|
+
const remaining = remaining_mut, current_1 = current_1_mut;
|
|
1753
|
+
if (!isEmpty(remaining)) {
|
|
1754
|
+
if (equals(current_1, index)) {
|
|
1755
|
+
return some(head_2(remaining));
|
|
1756
|
+
}
|
|
1757
|
+
else {
|
|
1758
|
+
remaining_mut = tail_2(remaining);
|
|
1759
|
+
current_1_mut = toInt64_unchecked(op_Addition(current_1, 1n));
|
|
1760
|
+
continue loop;
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
else {
|
|
1764
|
+
return undefined;
|
|
1765
|
+
}
|
|
1766
|
+
break;
|
|
1767
|
+
}
|
|
1768
|
+
};
|
|
1769
|
+
if (compare_1(index, 0n) < 0) {
|
|
1770
|
+
return new Value(9, [undefined]);
|
|
1771
|
+
}
|
|
1772
|
+
else {
|
|
1773
|
+
return new Value(9, [loop(values, 0n)]);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
case 1:
|
|
1777
|
+
return new Value(9, [FSharpMap__TryFind(mapValue, valueToMapKey(span_13, keyValue_1))]);
|
|
1778
|
+
case 2:
|
|
1779
|
+
throw new EvalException(new EvalError$("Map index key must be string or int", span_13));
|
|
1780
|
+
case 3:
|
|
1781
|
+
throw new EvalException(new EvalError$("List index must be int", span_13));
|
|
1782
|
+
default:
|
|
1783
|
+
throw new EvalException(new EvalError$("Index access requires a list or map value", span_13));
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
case 23: {
|
|
1787
|
+
const h = evalExpr(runtime, typeDefs, env, expr.fields[0]);
|
|
1788
|
+
const t = evalExpr(runtime, typeDefs, env, expr.fields[1]);
|
|
1789
|
+
if (t.tag === 5) {
|
|
1790
|
+
return new Value(5, [cons(h, t.fields[0])]);
|
|
1791
|
+
}
|
|
1792
|
+
else {
|
|
1793
|
+
throw new EvalException(new EvalError$("Right side of \'::\' must be list", expr.fields[2]));
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
case 24: {
|
|
1797
|
+
const av = evalExpr(runtime, typeDefs, env, expr.fields[0]);
|
|
1798
|
+
const bv = evalExpr(runtime, typeDefs, env, expr.fields[1]);
|
|
1799
|
+
let matchResult_3, xs_1, ys;
|
|
1800
|
+
if (av.tag === 5) {
|
|
1801
|
+
if (bv.tag === 5) {
|
|
1802
|
+
matchResult_3 = 0;
|
|
1803
|
+
xs_1 = av.fields[0];
|
|
1804
|
+
ys = bv.fields[0];
|
|
1805
|
+
}
|
|
1806
|
+
else {
|
|
1807
|
+
matchResult_3 = 1;
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
else {
|
|
1811
|
+
matchResult_3 = 1;
|
|
1812
|
+
}
|
|
1813
|
+
switch (matchResult_3) {
|
|
1814
|
+
case 0:
|
|
1815
|
+
return new Value(5, [append(xs_1, ys)]);
|
|
1816
|
+
default:
|
|
1817
|
+
throw new EvalException(new EvalError$("Both sides of \'@\' must be lists", expr.fields[2]));
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
case 25: {
|
|
1821
|
+
const span_16 = expr.fields[3];
|
|
1822
|
+
const op = expr.fields[0];
|
|
1823
|
+
const av_1 = evalExpr(runtime, typeDefs, env, expr.fields[1]);
|
|
1824
|
+
const bv_1 = evalExpr(runtime, typeDefs, env, expr.fields[2]);
|
|
1825
|
+
const arith = (fInt, fFloat) => {
|
|
1826
|
+
let matchResult_4, x_3, y_3, x_4, y_4;
|
|
1827
|
+
switch (av_1.tag) {
|
|
1828
|
+
case 1: {
|
|
1829
|
+
if (bv_1.tag === 1) {
|
|
1830
|
+
matchResult_4 = 0;
|
|
1831
|
+
x_3 = av_1.fields[0];
|
|
1832
|
+
y_3 = bv_1.fields[0];
|
|
1833
|
+
}
|
|
1834
|
+
else {
|
|
1835
|
+
matchResult_4 = 2;
|
|
1836
|
+
}
|
|
1837
|
+
break;
|
|
1838
|
+
}
|
|
1839
|
+
case 2: {
|
|
1840
|
+
if (bv_1.tag === 2) {
|
|
1841
|
+
matchResult_4 = 1;
|
|
1842
|
+
x_4 = av_1.fields[0];
|
|
1843
|
+
y_4 = bv_1.fields[0];
|
|
1844
|
+
}
|
|
1845
|
+
else {
|
|
1846
|
+
matchResult_4 = 2;
|
|
1847
|
+
}
|
|
1848
|
+
break;
|
|
1849
|
+
}
|
|
1850
|
+
default:
|
|
1851
|
+
matchResult_4 = 2;
|
|
1852
|
+
}
|
|
1853
|
+
switch (matchResult_4) {
|
|
1854
|
+
case 0:
|
|
1855
|
+
return new Value(1, [fInt(x_3)(y_3)]);
|
|
1856
|
+
case 1:
|
|
1857
|
+
return new Value(2, [fFloat(x_4)(y_4)]);
|
|
1858
|
+
default:
|
|
1859
|
+
throw new EvalException(new EvalError$("Numeric operands required", span_16));
|
|
1860
|
+
}
|
|
1861
|
+
};
|
|
1862
|
+
switch (op) {
|
|
1863
|
+
case "|>":
|
|
1864
|
+
return applyFunctionValue(runtime, evalExpr, typeDefs, span_16, bv_1, av_1);
|
|
1865
|
+
case "+":
|
|
1866
|
+
return arith((x_5) => ((y_5) => toInt64_unchecked(op_Addition(x_5, y_5))), (x_6) => ((y_6) => (x_6 + y_6)));
|
|
1867
|
+
case "-":
|
|
1868
|
+
return arith((x_7) => ((y_7) => toInt64_unchecked(op_Subtraction(x_7, y_7))), (x_8) => ((y_8) => (x_8 - y_8)));
|
|
1869
|
+
case "*":
|
|
1870
|
+
return arith((x_9) => ((y_9) => toInt64_unchecked(op_Multiply(x_9, y_9))), (x_10) => ((y_10) => (x_10 * y_10)));
|
|
1871
|
+
case "/": {
|
|
1872
|
+
let matchResult_5, x_11, y_11, x_12, y_12;
|
|
1873
|
+
switch (av_1.tag) {
|
|
1874
|
+
case 1: {
|
|
1875
|
+
if (bv_1.tag === 1) {
|
|
1876
|
+
matchResult_5 = 0;
|
|
1877
|
+
x_11 = av_1.fields[0];
|
|
1878
|
+
y_11 = bv_1.fields[0];
|
|
1879
|
+
}
|
|
1880
|
+
else {
|
|
1881
|
+
matchResult_5 = 2;
|
|
1882
|
+
}
|
|
1883
|
+
break;
|
|
1884
|
+
}
|
|
1885
|
+
case 2: {
|
|
1886
|
+
if (bv_1.tag === 2) {
|
|
1887
|
+
matchResult_5 = 1;
|
|
1888
|
+
x_12 = av_1.fields[0];
|
|
1889
|
+
y_12 = bv_1.fields[0];
|
|
1890
|
+
}
|
|
1891
|
+
else {
|
|
1892
|
+
matchResult_5 = 2;
|
|
1893
|
+
}
|
|
1894
|
+
break;
|
|
1895
|
+
}
|
|
1896
|
+
default:
|
|
1897
|
+
matchResult_5 = 2;
|
|
1898
|
+
}
|
|
1899
|
+
switch (matchResult_5) {
|
|
1900
|
+
case 0:
|
|
1901
|
+
return new Value(1, [toInt64_unchecked(op_Division(x_11, y_11))]);
|
|
1902
|
+
case 1:
|
|
1903
|
+
return new Value(2, [x_12 / y_12]);
|
|
1904
|
+
default:
|
|
1905
|
+
throw new EvalException(new EvalError$("Numeric operands required", span_16));
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
case "%": {
|
|
1909
|
+
let matchResult_6, x_13, y_13;
|
|
1910
|
+
if (av_1.tag === 1) {
|
|
1911
|
+
if (bv_1.tag === 1) {
|
|
1912
|
+
matchResult_6 = 0;
|
|
1913
|
+
x_13 = av_1.fields[0];
|
|
1914
|
+
y_13 = bv_1.fields[0];
|
|
1915
|
+
}
|
|
1916
|
+
else {
|
|
1917
|
+
matchResult_6 = 1;
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
else {
|
|
1921
|
+
matchResult_6 = 1;
|
|
1922
|
+
}
|
|
1923
|
+
switch (matchResult_6) {
|
|
1924
|
+
case 0:
|
|
1925
|
+
return new Value(1, [toInt64_unchecked(op_Modulus(x_13, y_13))]);
|
|
1926
|
+
default:
|
|
1927
|
+
throw new EvalException(new EvalError$("Integer operands required", span_16));
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
case "=":
|
|
1931
|
+
return new Value(3, [valueEquals(av_1, bv_1)]);
|
|
1932
|
+
case "<":
|
|
1933
|
+
case ">":
|
|
1934
|
+
case "<=":
|
|
1935
|
+
case ">=": {
|
|
1936
|
+
let matchResult_7, x_14, y_14, x_15, y_15;
|
|
1937
|
+
switch (av_1.tag) {
|
|
1938
|
+
case 1: {
|
|
1939
|
+
if (bv_1.tag === 1) {
|
|
1940
|
+
matchResult_7 = 0;
|
|
1941
|
+
x_14 = av_1.fields[0];
|
|
1942
|
+
y_14 = bv_1.fields[0];
|
|
1943
|
+
}
|
|
1944
|
+
else {
|
|
1945
|
+
matchResult_7 = 2;
|
|
1946
|
+
}
|
|
1947
|
+
break;
|
|
1948
|
+
}
|
|
1949
|
+
case 2: {
|
|
1950
|
+
if (bv_1.tag === 2) {
|
|
1951
|
+
matchResult_7 = 1;
|
|
1952
|
+
x_15 = av_1.fields[0];
|
|
1953
|
+
y_15 = bv_1.fields[0];
|
|
1954
|
+
}
|
|
1955
|
+
else {
|
|
1956
|
+
matchResult_7 = 2;
|
|
1957
|
+
}
|
|
1958
|
+
break;
|
|
1959
|
+
}
|
|
1960
|
+
default:
|
|
1961
|
+
matchResult_7 = 2;
|
|
1962
|
+
}
|
|
1963
|
+
switch (matchResult_7) {
|
|
1964
|
+
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))))]);
|
|
1966
|
+
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))))]);
|
|
1968
|
+
default:
|
|
1969
|
+
throw new EvalException(new EvalError$("Numeric operands required", span_16));
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
case "&&":
|
|
1973
|
+
case "||": {
|
|
1974
|
+
let matchResult_8, x_16, y_16;
|
|
1975
|
+
if (av_1.tag === 3) {
|
|
1976
|
+
if (bv_1.tag === 3) {
|
|
1977
|
+
matchResult_8 = 0;
|
|
1978
|
+
x_16 = av_1.fields[0];
|
|
1979
|
+
y_16 = bv_1.fields[0];
|
|
1980
|
+
}
|
|
1981
|
+
else {
|
|
1982
|
+
matchResult_8 = 1;
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
else {
|
|
1986
|
+
matchResult_8 = 1;
|
|
1987
|
+
}
|
|
1988
|
+
switch (matchResult_8) {
|
|
1989
|
+
case 0:
|
|
1990
|
+
return new Value(3, [(op === "&&") ? (x_16 && y_16) : (x_16 ? true : y_16)]);
|
|
1991
|
+
default:
|
|
1992
|
+
throw new EvalException(new EvalError$("Boolean operands required", span_16));
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
case "::":
|
|
1996
|
+
if (bv_1.tag === 5) {
|
|
1997
|
+
return new Value(5, [cons(av_1, bv_1.fields[0])]);
|
|
1998
|
+
}
|
|
1999
|
+
else {
|
|
2000
|
+
throw new EvalException(new EvalError$("Right side of \'::\' must be list", span_16));
|
|
2001
|
+
}
|
|
2002
|
+
case "@": {
|
|
2003
|
+
let matchResult_9, xs_3, ys_1;
|
|
2004
|
+
if (av_1.tag === 5) {
|
|
2005
|
+
if (bv_1.tag === 5) {
|
|
2006
|
+
matchResult_9 = 0;
|
|
2007
|
+
xs_3 = av_1.fields[0];
|
|
2008
|
+
ys_1 = bv_1.fields[0];
|
|
2009
|
+
}
|
|
2010
|
+
else {
|
|
2011
|
+
matchResult_9 = 1;
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
else {
|
|
2015
|
+
matchResult_9 = 1;
|
|
2016
|
+
}
|
|
2017
|
+
switch (matchResult_9) {
|
|
2018
|
+
case 0:
|
|
2019
|
+
return new Value(5, [append(xs_3, ys_1)]);
|
|
2020
|
+
default:
|
|
2021
|
+
throw new EvalException(new EvalError$("Both sides of \'@\' must be lists", span_16));
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
default:
|
|
2025
|
+
throw new EvalException(new EvalError$(toText(printf("Unknown operator %s"))(op), span_16));
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
case 26:
|
|
2029
|
+
return new Value(9, [evalExpr(runtime, typeDefs, env, expr.fields[0])]);
|
|
2030
|
+
case 27:
|
|
2031
|
+
return new Value(9, [undefined]);
|
|
2032
|
+
case 28: {
|
|
2033
|
+
const name_9 = expr.fields[0];
|
|
2034
|
+
const matchValue_24 = FSharpMap__TryFind(typeDefs, name_9);
|
|
2035
|
+
if (matchValue_24 == null) {
|
|
2036
|
+
throw new EvalException(new EvalError$(concat("Unknown type \'", name_9, "\'"), expr.fields[1]));
|
|
2037
|
+
}
|
|
2038
|
+
else {
|
|
2039
|
+
return new Value(12, [matchValue_24]);
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
case 29: {
|
|
2043
|
+
const name_10 = expr.fields[0];
|
|
2044
|
+
if (FSharpMap__ContainsKey(env, name_10)) {
|
|
2045
|
+
return new Value(4, [name_10]);
|
|
2046
|
+
}
|
|
2047
|
+
else {
|
|
2048
|
+
throw new EvalException(new EvalError$(concat("Unbound variable \'", name_10, "\'"), expr.fields[1]));
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
case 30: {
|
|
2052
|
+
const sb = StringBuilder_$ctor();
|
|
2053
|
+
const enumerator_1 = getEnumerator(expr.fields[0]);
|
|
2054
|
+
try {
|
|
2055
|
+
while (enumerator_1["System.Collections.IEnumerator.MoveNext"]()) {
|
|
2056
|
+
const part = enumerator_1["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
2057
|
+
if (part.tag === 1) {
|
|
2058
|
+
StringBuilder__Append_Z721C83C5(sb, valueToInterpolationString(evalExpr(runtime, typeDefs, env, part.fields[0])));
|
|
2059
|
+
}
|
|
2060
|
+
else {
|
|
2061
|
+
StringBuilder__Append_Z721C83C5(sb, part.fields[0]);
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
finally {
|
|
2066
|
+
disposeSafe(enumerator_1);
|
|
2067
|
+
}
|
|
2068
|
+
return new Value(4, [toString(sb)]);
|
|
2069
|
+
}
|
|
2070
|
+
default:
|
|
2071
|
+
return new Value(0, []);
|
|
2072
|
+
}
|
|
2073
|
+
break;
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
export function invokeValue(typeDefs, fnValue, args) {
|
|
2078
|
+
const runtime = new RuntimeState({}, [], undefined);
|
|
2079
|
+
const applyMany = (currentValue_mut, remainingArgs_mut) => {
|
|
2080
|
+
applyMany:
|
|
2081
|
+
while (true) {
|
|
2082
|
+
const currentValue = currentValue_mut, remainingArgs = remainingArgs_mut;
|
|
2083
|
+
if (!isEmpty(remainingArgs)) {
|
|
2084
|
+
switch (currentValue.tag) {
|
|
2085
|
+
case 15: {
|
|
2086
|
+
const ext = currentValue.fields[0];
|
|
2087
|
+
const allArgs = append(reverse(currentValue.fields[1]), remainingArgs);
|
|
2088
|
+
if (length(allArgs) === ext.Arity) {
|
|
2089
|
+
return ext.Impl(createExternContext(runtime, typeDefs, unknownSpan), allArgs);
|
|
2090
|
+
}
|
|
2091
|
+
else if (length(allArgs) < ext.Arity) {
|
|
2092
|
+
return new Value(15, [ext, reverse(allArgs)]);
|
|
2093
|
+
}
|
|
2094
|
+
else {
|
|
2095
|
+
throw new EvalException(new EvalError$(toText(printf("External function \'%s\' received too many arguments"))(ext.Name), unknownSpan));
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
case 14: {
|
|
2099
|
+
const bindLambdaChain = (envAcc_mut, exprAcc_mut, argsAcc_mut) => {
|
|
2100
|
+
bindLambdaChain:
|
|
2101
|
+
while (true) {
|
|
2102
|
+
const envAcc = envAcc_mut, exprAcc = exprAcc_mut, argsAcc = argsAcc_mut;
|
|
2103
|
+
let matchResult, nextArg, nextBody, param, rest;
|
|
2104
|
+
if (exprAcc.tag === 4) {
|
|
2105
|
+
if (!isEmpty(argsAcc)) {
|
|
2106
|
+
matchResult = 0;
|
|
2107
|
+
nextArg = head_2(argsAcc);
|
|
2108
|
+
nextBody = exprAcc.fields[1];
|
|
2109
|
+
param = exprAcc.fields[0];
|
|
2110
|
+
rest = tail_2(argsAcc);
|
|
2111
|
+
}
|
|
2112
|
+
else {
|
|
2113
|
+
matchResult = 1;
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
else {
|
|
2117
|
+
matchResult = 1;
|
|
2118
|
+
}
|
|
2119
|
+
switch (matchResult) {
|
|
2120
|
+
case 0: {
|
|
2121
|
+
envAcc_mut = add(param.Name, nextArg, envAcc);
|
|
2122
|
+
exprAcc_mut = nextBody;
|
|
2123
|
+
argsAcc_mut = rest;
|
|
2124
|
+
continue bindLambdaChain;
|
|
2125
|
+
}
|
|
2126
|
+
default:
|
|
2127
|
+
return [envAcc, exprAcc, argsAcc];
|
|
2128
|
+
}
|
|
2129
|
+
break;
|
|
2130
|
+
}
|
|
2131
|
+
};
|
|
2132
|
+
const patternInput = bindLambdaChain(add(currentValue.fields[0], head_2(remainingArgs), currentValue.fields[2].contents), currentValue.fields[1], tail_2(remainingArgs));
|
|
2133
|
+
currentValue_mut = evalExpr(runtime, typeDefs, patternInput[0], patternInput[1]);
|
|
2134
|
+
remainingArgs_mut = patternInput[2];
|
|
2135
|
+
continue applyMany;
|
|
2136
|
+
}
|
|
2137
|
+
default: {
|
|
2138
|
+
currentValue_mut = applyFunctionValue(runtime, evalExpr, typeDefs, unknownSpan, currentValue, head_2(remainingArgs));
|
|
2139
|
+
remainingArgs_mut = tail_2(remainingArgs);
|
|
2140
|
+
continue applyMany;
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
else {
|
|
2145
|
+
return currentValue;
|
|
2146
|
+
}
|
|
2147
|
+
break;
|
|
2148
|
+
}
|
|
2149
|
+
};
|
|
2150
|
+
return applyMany(fnValue, args);
|
|
2151
|
+
}
|
|
2152
|
+
|
|
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) => {
|
|
2161
|
+
let matchResult, name_1, bindings, bindings_1;
|
|
2162
|
+
switch (_arg.tag) {
|
|
2163
|
+
case 1: {
|
|
2164
|
+
if (contains(_arg.fields[0], builtinReservedNames)) {
|
|
2165
|
+
matchResult = 0;
|
|
2166
|
+
name_1 = _arg.fields[0];
|
|
2167
|
+
}
|
|
2168
|
+
else {
|
|
2169
|
+
matchResult = 3;
|
|
2170
|
+
}
|
|
2171
|
+
break;
|
|
2172
|
+
}
|
|
2173
|
+
case 2: {
|
|
2174
|
+
matchResult = 1;
|
|
2175
|
+
bindings = _arg.fields[2];
|
|
2176
|
+
break;
|
|
2177
|
+
}
|
|
2178
|
+
case 3: {
|
|
2179
|
+
matchResult = 2;
|
|
2180
|
+
bindings_1 = _arg.fields[0];
|
|
2181
|
+
break;
|
|
2182
|
+
}
|
|
2183
|
+
default:
|
|
2184
|
+
matchResult = 3;
|
|
2185
|
+
}
|
|
2186
|
+
switch (matchResult) {
|
|
2187
|
+
case 0:
|
|
2188
|
+
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));
|
|
2193
|
+
default:
|
|
2194
|
+
return undefined;
|
|
2195
|
+
}
|
|
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];
|
|
2200
|
+
return [def_1.Name, def_1];
|
|
2201
|
+
}
|
|
2202
|
+
else {
|
|
2203
|
+
return undefined;
|
|
2204
|
+
}
|
|
2205
|
+
}, program)), {
|
|
2206
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
2207
|
+
});
|
|
2208
|
+
const fromRef = (stack, tref) => {
|
|
2209
|
+
switch (tref.tag) {
|
|
2210
|
+
case 1:
|
|
2211
|
+
return new Type(7, [map(curry2(fromRef)(stack), tref.fields[0])]);
|
|
2212
|
+
case 2:
|
|
2213
|
+
return new Type(11, [fromRef(stack, tref.fields[0]), fromRef(stack, tref.fields[1])]);
|
|
2214
|
+
case 3:
|
|
2215
|
+
switch (tref.fields[1]) {
|
|
2216
|
+
case "list":
|
|
2217
|
+
return new Type(5, [fromRef(stack, tref.fields[0])]);
|
|
2218
|
+
case "task":
|
|
2219
|
+
return new Type(6, [fromRef(stack, tref.fields[0])]);
|
|
2220
|
+
case "option":
|
|
2221
|
+
return new Type(10, [fromRef(stack, tref.fields[0])]);
|
|
2222
|
+
case "map":
|
|
2223
|
+
return new Type(9, [new Type(4, []), fromRef(stack, tref.fields[0])]);
|
|
2224
|
+
default:
|
|
2225
|
+
throw new EvalException(new EvalError$(concat("Unsupported type suffix ", tref.fields[1]), unknownSpan));
|
|
2226
|
+
}
|
|
2227
|
+
case 4:
|
|
2228
|
+
return new Type(8, [ofList(map((tupledArg_5) => [tupledArg_5[0], fromRef(stack, tupledArg_5[1])], tref.fields[0]), {
|
|
2229
|
+
Compare: (x_3, y_4) => (comparePrimitives(x_3, y_4) | 0),
|
|
2230
|
+
})]);
|
|
2231
|
+
case 5:
|
|
2232
|
+
return new Type(8, [ofList(map((tupledArg_6) => [tupledArg_6[0], fromRef(stack, tupledArg_6[1])], tref.fields[0]), {
|
|
2233
|
+
Compare: (x_4, y_5) => (comparePrimitives(x_4, y_5) | 0),
|
|
2234
|
+
})]);
|
|
2235
|
+
default:
|
|
2236
|
+
switch (tref.fields[0]) {
|
|
2237
|
+
case "unit":
|
|
2238
|
+
return new Type(0, []);
|
|
2239
|
+
case "int":
|
|
2240
|
+
return new Type(1, []);
|
|
2241
|
+
case "float":
|
|
2242
|
+
return new Type(2, []);
|
|
2243
|
+
case "bool":
|
|
2244
|
+
return new Type(3, []);
|
|
2245
|
+
case "string":
|
|
2246
|
+
return new Type(4, []);
|
|
2247
|
+
default: {
|
|
2248
|
+
const matchValue = FSharpMap__TryFind(decls, tref.fields[0]);
|
|
2249
|
+
if (matchValue == null) {
|
|
2250
|
+
return new Type(12, [tref.fields[0]]);
|
|
2251
|
+
}
|
|
2252
|
+
else {
|
|
2253
|
+
const d = matchValue;
|
|
2254
|
+
const matchValue_1 = tryFindIndex((y_1) => (tref.fields[0] === y_1), stack);
|
|
2255
|
+
if (matchValue_1 == null) {
|
|
2256
|
+
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), {
|
|
2258
|
+
Compare: (x_1, y_2) => (comparePrimitives(x_1, y_2) | 0),
|
|
2259
|
+
})]);
|
|
2260
|
+
}
|
|
2261
|
+
else {
|
|
2262
|
+
return new Type(8, [ofList(map((tupledArg_4) => [tupledArg_4[0], fromRef(cons(tref.fields[0], stack), tupledArg_4[1])], d.Fields), {
|
|
2263
|
+
Compare: (x_2, y_3) => (comparePrimitives(x_2, y_3) | 0),
|
|
2264
|
+
})]);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
else if (matchValue_1 === 0) {
|
|
2268
|
+
if (d.IsRecursive) {
|
|
2269
|
+
return new Type(12, [tref.fields[0]]);
|
|
2270
|
+
}
|
|
2271
|
+
else {
|
|
2272
|
+
throw new EvalException(new EvalError$(concat("Recursive type \'", tref.fields[0], "\' requires \'type rec\'"), unknownSpan));
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
else {
|
|
2276
|
+
throw new EvalException(new EvalError$("Mutual recursive types are not supported", unknownSpan));
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
};
|
|
2283
|
+
const typeDefs = map_2((name_8, def_2) => {
|
|
2284
|
+
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), {
|
|
2286
|
+
Compare: (x_5, y_6) => (comparePrimitives(x_5, y_6) | 0),
|
|
2287
|
+
})]);
|
|
2288
|
+
}
|
|
2289
|
+
else {
|
|
2290
|
+
return new Type(8, [ofList(map((tupledArg_8) => [tupledArg_8[0], fromRef(singleton(name_8), tupledArg_8[1])], def_2.Fields), {
|
|
2291
|
+
Compare: (x_6, y_7) => (comparePrimitives(x_6, y_7) | 0),
|
|
2292
|
+
})]);
|
|
2293
|
+
}
|
|
2294
|
+
}, 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]));
|
|
2300
|
+
return ofArray([[caseName_2, value], [concat(typeName, ".", caseName_2), value]]);
|
|
2301
|
+
}, tupledArg_9[1].Cases);
|
|
2302
|
+
}, toList(decls));
|
|
2303
|
+
const externContext = createExternContext(runtime, typeDefs, unknownSpan);
|
|
2304
|
+
let env;
|
|
2305
|
+
const list_16 = append(builtinExterns, externs);
|
|
2306
|
+
env = fold_1((acc, ext_2) => {
|
|
2307
|
+
if (ext_2.Arity === 0) {
|
|
2308
|
+
return FSharpMap__Add(acc, ext_2.Name, ext_2.Impl(externContext, empty()));
|
|
2309
|
+
}
|
|
2310
|
+
else {
|
|
2311
|
+
return FSharpMap__Add(acc, ext_2.Name, new Value(15, [ext_2, empty()]));
|
|
2312
|
+
}
|
|
2313
|
+
}, empty_1({
|
|
2314
|
+
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);
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
export function evalProgramWithExterns(externs, program) {
|
|
2398
|
+
return evalProgramWithExternsState(externs, program).LastValue;
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
export function evalProgram(program) {
|
|
2402
|
+
return evalProgramWithExterns(empty(), program);
|
|
2403
|
+
}
|
|
2404
|
+
|