@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,2039 @@
|
|
|
1
|
+
|
|
2
|
+
import { Span, Position } from "./Span.js";
|
|
3
|
+
import { EvalException, EvalError$ } from "./Error.js";
|
|
4
|
+
import { FSharpMap__Remove, iterate as iterate_1, fold as fold_1, add, FSharpMap__Add, FSharpMap__ContainsKey, FSharpMap__TryFind, empty as empty_1, FSharpMap__get_Item, forAll, FSharpMap__get_Keys, FSharpMap__get_Count, tryFind } from "../fable_modules/fable-library-js.5.2.0/Map.js";
|
|
5
|
+
import { builtinSchemes } from "./BuiltinSignatures.js";
|
|
6
|
+
import { equals as equals_1, compare, comparePrimitives, Exception } from "../fable_modules/fable-library-js.5.2.0/Util.js";
|
|
7
|
+
import { endsWith, split, join, substring, replace, format, concat } from "../fable_modules/fable-library-js.5.2.0/String.js";
|
|
8
|
+
import { tryParse } from "../fable_modules/fable-library-js.5.2.0/Long.js";
|
|
9
|
+
import { FSharpRef } from "../fable_modules/fable-library-js.5.2.0/Types.js";
|
|
10
|
+
import { tryParse as tryParse_1 } from "../fable_modules/fable-library-js.5.2.0/Double.js";
|
|
11
|
+
import { append, tryHead, tryFindIndex, tryFind as tryFind_1, filter, collect, choose, iterate, ofArray, map, exists, fold, forAll2, length as length_1, empty, reverse, cons, tail as tail_1, head as head_1, isEmpty } from "../fable_modules/fable-library-js.5.2.0/List.js";
|
|
12
|
+
import { ExternalFunction, Value as Value_1, MapKey } from "./Value.js";
|
|
13
|
+
import { compare as compare_1, op_Addition, toInt32_unchecked, fromInt32, toInt64_unchecked, equals } from "../fable_modules/fable-library-js.5.2.0/BigInt.js";
|
|
14
|
+
import { ofSeq } from "../fable_modules/fable-library-js.5.2.0/Set.js";
|
|
15
|
+
import { tryParse as tryParse_2 } from "../fable_modules/fable-library-js.5.2.0/Boolean.js";
|
|
16
|
+
import { some, map as map_1 } from "../fable_modules/fable-library-js.5.2.0/Option.js";
|
|
17
|
+
|
|
18
|
+
const unknownSpan = new Span(new Position(undefined, 0, 0), new Position(undefined, 0, 0));
|
|
19
|
+
|
|
20
|
+
function fail(message) {
|
|
21
|
+
throw new EvalException(new EvalError$(message, unknownSpan));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function scheme(name) {
|
|
25
|
+
const matchValue = tryFind(name, builtinSchemes);
|
|
26
|
+
if (matchValue == null) {
|
|
27
|
+
throw new Exception(concat("Missing builtin signature for \'", name, "\'"));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return matchValue;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function tryParseInt64(text) {
|
|
35
|
+
let matchValue;
|
|
36
|
+
let outArg = 0n;
|
|
37
|
+
matchValue = [tryParse(text, 511, false, 64, new FSharpRef(() => outArg, (v) => {
|
|
38
|
+
outArg = v;
|
|
39
|
+
})), outArg];
|
|
40
|
+
if (matchValue[0]) {
|
|
41
|
+
return matchValue[1];
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function tryParseDouble(text) {
|
|
49
|
+
let matchValue;
|
|
50
|
+
let outArg = 0;
|
|
51
|
+
matchValue = [tryParse_1(text, new FSharpRef(() => outArg, (v) => {
|
|
52
|
+
outArg = v;
|
|
53
|
+
})), outArg];
|
|
54
|
+
if (matchValue[0]) {
|
|
55
|
+
return matchValue[1];
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function expectString(functionName, args) {
|
|
63
|
+
let matchResult, value;
|
|
64
|
+
if (!isEmpty(args)) {
|
|
65
|
+
if (head_1(args).tag === 4) {
|
|
66
|
+
if (isEmpty(tail_1(args))) {
|
|
67
|
+
matchResult = 0;
|
|
68
|
+
value = head_1(args).fields[0];
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
matchResult = 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
matchResult = 1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
matchResult = 1;
|
|
80
|
+
}
|
|
81
|
+
switch (matchResult) {
|
|
82
|
+
case 0:
|
|
83
|
+
return value;
|
|
84
|
+
default:
|
|
85
|
+
return fail(`${functionName} expects (string)`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function expectInt(functionName, args) {
|
|
90
|
+
let matchResult, value;
|
|
91
|
+
if (!isEmpty(args)) {
|
|
92
|
+
if (head_1(args).tag === 1) {
|
|
93
|
+
if (isEmpty(tail_1(args))) {
|
|
94
|
+
matchResult = 0;
|
|
95
|
+
value = head_1(args).fields[0];
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
matchResult = 1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
matchResult = 1;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
matchResult = 1;
|
|
107
|
+
}
|
|
108
|
+
switch (matchResult) {
|
|
109
|
+
case 0:
|
|
110
|
+
return value;
|
|
111
|
+
default:
|
|
112
|
+
return fail(`${functionName} expects (int)`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function expectBool(functionName, args) {
|
|
117
|
+
let matchResult, value;
|
|
118
|
+
if (!isEmpty(args)) {
|
|
119
|
+
if (head_1(args).tag === 3) {
|
|
120
|
+
if (isEmpty(tail_1(args))) {
|
|
121
|
+
matchResult = 0;
|
|
122
|
+
value = head_1(args).fields[0];
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
matchResult = 1;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
matchResult = 1;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
matchResult = 1;
|
|
134
|
+
}
|
|
135
|
+
switch (matchResult) {
|
|
136
|
+
case 0:
|
|
137
|
+
return value;
|
|
138
|
+
default:
|
|
139
|
+
return fail(`${functionName} expects (bool)`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function expectMap(functionName, args) {
|
|
144
|
+
let matchResult, value;
|
|
145
|
+
if (!isEmpty(args)) {
|
|
146
|
+
if (head_1(args).tag === 8) {
|
|
147
|
+
if (isEmpty(tail_1(args))) {
|
|
148
|
+
matchResult = 0;
|
|
149
|
+
value = head_1(args).fields[0];
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
matchResult = 1;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
matchResult = 1;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
matchResult = 1;
|
|
161
|
+
}
|
|
162
|
+
switch (matchResult) {
|
|
163
|
+
case 0:
|
|
164
|
+
return value;
|
|
165
|
+
default:
|
|
166
|
+
return fail(`${functionName} expects (map)`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function expectList(functionName, args) {
|
|
171
|
+
let matchResult, value;
|
|
172
|
+
if (!isEmpty(args)) {
|
|
173
|
+
if (head_1(args).tag === 5) {
|
|
174
|
+
if (isEmpty(tail_1(args))) {
|
|
175
|
+
matchResult = 0;
|
|
176
|
+
value = head_1(args).fields[0];
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
matchResult = 1;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
matchResult = 1;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
matchResult = 1;
|
|
188
|
+
}
|
|
189
|
+
switch (matchResult) {
|
|
190
|
+
case 0:
|
|
191
|
+
return value;
|
|
192
|
+
default:
|
|
193
|
+
return fail(`${functionName} expects (list)`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function asStringKey(functionName, value) {
|
|
198
|
+
if (value.tag === 4) {
|
|
199
|
+
return new MapKey(0, [value.fields[0]]);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
return fail(`${functionName} expects string key`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function asStringList(functionName, values) {
|
|
207
|
+
const loop = (remaining_mut, acc_mut) => {
|
|
208
|
+
loop:
|
|
209
|
+
while (true) {
|
|
210
|
+
const remaining = remaining_mut, acc = acc_mut;
|
|
211
|
+
if (!isEmpty(remaining)) {
|
|
212
|
+
if (head_1(remaining).tag === 4) {
|
|
213
|
+
remaining_mut = tail_1(remaining);
|
|
214
|
+
acc_mut = cons(head_1(remaining).fields[0], acc);
|
|
215
|
+
continue loop;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
return fail(`${functionName} expects (string, string list)`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
return reverse(acc);
|
|
223
|
+
}
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
return loop(values, empty());
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function mapKeyToValue(key) {
|
|
231
|
+
if (key.tag === 1) {
|
|
232
|
+
return new Value_1(1, [key.fields[0]]);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
return new Value_1(4, [key.fields[0]]);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function valueEquals(a_mut, b_mut) {
|
|
240
|
+
valueEquals:
|
|
241
|
+
while (true) {
|
|
242
|
+
const a = a_mut, b = b_mut;
|
|
243
|
+
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;
|
|
244
|
+
switch (a.tag) {
|
|
245
|
+
case 0: {
|
|
246
|
+
if (b.tag === 0) {
|
|
247
|
+
matchResult = 0;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
matchResult = 13;
|
|
251
|
+
}
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
case 1: {
|
|
255
|
+
if (b.tag === 1) {
|
|
256
|
+
matchResult = 1;
|
|
257
|
+
x = a.fields[0];
|
|
258
|
+
y = b.fields[0];
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
matchResult = 13;
|
|
262
|
+
}
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
case 2: {
|
|
266
|
+
if (b.tag === 2) {
|
|
267
|
+
matchResult = 2;
|
|
268
|
+
x_1 = a.fields[0];
|
|
269
|
+
y_1 = b.fields[0];
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
matchResult = 13;
|
|
273
|
+
}
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
case 3: {
|
|
277
|
+
if (b.tag === 3) {
|
|
278
|
+
matchResult = 3;
|
|
279
|
+
x_2 = a.fields[0];
|
|
280
|
+
y_2 = b.fields[0];
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
matchResult = 13;
|
|
284
|
+
}
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
case 4: {
|
|
288
|
+
if (b.tag === 4) {
|
|
289
|
+
matchResult = 4;
|
|
290
|
+
x_3 = a.fields[0];
|
|
291
|
+
y_3 = b.fields[0];
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
matchResult = 13;
|
|
295
|
+
}
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
case 5: {
|
|
299
|
+
if (b.tag === 5) {
|
|
300
|
+
matchResult = 5;
|
|
301
|
+
xs = a.fields[0];
|
|
302
|
+
ys = b.fields[0];
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
matchResult = 13;
|
|
306
|
+
}
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
case 6: {
|
|
310
|
+
if (b.tag === 6) {
|
|
311
|
+
matchResult = 6;
|
|
312
|
+
xs_1 = a.fields[0];
|
|
313
|
+
ys_1 = b.fields[0];
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
matchResult = 13;
|
|
317
|
+
}
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
case 7: {
|
|
321
|
+
if (b.tag === 7) {
|
|
322
|
+
matchResult = 7;
|
|
323
|
+
xf = a.fields[0];
|
|
324
|
+
yf = b.fields[0];
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
matchResult = 13;
|
|
328
|
+
}
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
case 8: {
|
|
332
|
+
if (b.tag === 8) {
|
|
333
|
+
matchResult = 8;
|
|
334
|
+
xf_1 = a.fields[0];
|
|
335
|
+
yf_1 = b.fields[0];
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
matchResult = 13;
|
|
339
|
+
}
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
case 9: {
|
|
343
|
+
if (a.fields[0] != null) {
|
|
344
|
+
if (b.tag === 9) {
|
|
345
|
+
if (b.fields[0] != null) {
|
|
346
|
+
matchResult = 10;
|
|
347
|
+
x_8 = a.fields[0];
|
|
348
|
+
y_8 = b.fields[0];
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
matchResult = 13;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
matchResult = 13;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
else if (b.tag === 9) {
|
|
359
|
+
if (b.fields[0] == null) {
|
|
360
|
+
matchResult = 9;
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
matchResult = 13;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
matchResult = 13;
|
|
368
|
+
}
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
case 10: {
|
|
372
|
+
if (b.tag === 10) {
|
|
373
|
+
matchResult = 11;
|
|
374
|
+
cx = a.fields[1];
|
|
375
|
+
cy = b.fields[1];
|
|
376
|
+
px = a.fields[2];
|
|
377
|
+
py = b.fields[2];
|
|
378
|
+
tx = a.fields[0];
|
|
379
|
+
ty = b.fields[0];
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
matchResult = 13;
|
|
383
|
+
}
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
case 12: {
|
|
387
|
+
if (b.tag === 12) {
|
|
388
|
+
matchResult = 12;
|
|
389
|
+
tx_1 = a.fields[0];
|
|
390
|
+
ty_1 = b.fields[0];
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
matchResult = 13;
|
|
394
|
+
}
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
default:
|
|
398
|
+
matchResult = 13;
|
|
399
|
+
}
|
|
400
|
+
switch (matchResult) {
|
|
401
|
+
case 0:
|
|
402
|
+
return true;
|
|
403
|
+
case 1:
|
|
404
|
+
return equals(x, y);
|
|
405
|
+
case 2:
|
|
406
|
+
return x_1 === y_1;
|
|
407
|
+
case 3:
|
|
408
|
+
return x_2 === y_2;
|
|
409
|
+
case 4:
|
|
410
|
+
return x_3 === y_3;
|
|
411
|
+
case 5:
|
|
412
|
+
if (length_1(xs) === length_1(ys)) {
|
|
413
|
+
return forAll2(valueEquals, xs, ys);
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
case 6:
|
|
419
|
+
if (length_1(xs_1) === length_1(ys_1)) {
|
|
420
|
+
return forAll2(valueEquals, xs_1, ys_1);
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
case 7:
|
|
426
|
+
if ((FSharpMap__get_Count(xf) === FSharpMap__get_Count(yf)) && ofSeq(FSharpMap__get_Keys(xf), {
|
|
427
|
+
Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
|
|
428
|
+
}).Equals(ofSeq(FSharpMap__get_Keys(yf), {
|
|
429
|
+
Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
|
|
430
|
+
}))) {
|
|
431
|
+
return forAll((k, xv) => valueEquals(xv, FSharpMap__get_Item(yf, k)), xf);
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
case 8:
|
|
437
|
+
if ((FSharpMap__get_Count(xf_1) === FSharpMap__get_Count(yf_1)) && ofSeq(FSharpMap__get_Keys(xf_1), {
|
|
438
|
+
Compare: (x_6, y_6) => (compare(x_6, y_6) | 0),
|
|
439
|
+
}).Equals(ofSeq(FSharpMap__get_Keys(yf_1), {
|
|
440
|
+
Compare: (x_7, y_7) => (compare(x_7, y_7) | 0),
|
|
441
|
+
}))) {
|
|
442
|
+
return forAll((k_1, xv_1) => valueEquals(xv_1, FSharpMap__get_Item(yf_1, k_1)), xf_1);
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
case 9:
|
|
448
|
+
return true;
|
|
449
|
+
case 10: {
|
|
450
|
+
a_mut = x_8;
|
|
451
|
+
b_mut = y_8;
|
|
452
|
+
continue valueEquals;
|
|
453
|
+
}
|
|
454
|
+
case 11:
|
|
455
|
+
if ((tx === ty) && (cx === cy)) {
|
|
456
|
+
let matchResult_1, xv_2, yv;
|
|
457
|
+
if (px != null) {
|
|
458
|
+
if (py != null) {
|
|
459
|
+
matchResult_1 = 1;
|
|
460
|
+
xv_2 = px;
|
|
461
|
+
yv = py;
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
matchResult_1 = 2;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
else if (py == null) {
|
|
468
|
+
matchResult_1 = 0;
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
matchResult_1 = 2;
|
|
472
|
+
}
|
|
473
|
+
switch (matchResult_1) {
|
|
474
|
+
case 0:
|
|
475
|
+
return true;
|
|
476
|
+
case 1: {
|
|
477
|
+
a_mut = xv_2;
|
|
478
|
+
b_mut = yv;
|
|
479
|
+
continue valueEquals;
|
|
480
|
+
}
|
|
481
|
+
default:
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
case 12:
|
|
489
|
+
return equals_1(tx_1, ty_1);
|
|
490
|
+
default:
|
|
491
|
+
return false;
|
|
492
|
+
}
|
|
493
|
+
break;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function distinctValues(values) {
|
|
498
|
+
return reverse(fold((acc, value) => {
|
|
499
|
+
if (exists((existing) => valueEquals(existing, value), acc)) {
|
|
500
|
+
return acc;
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
return cons(value, acc);
|
|
504
|
+
}
|
|
505
|
+
}, empty(), values));
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const builtinIgnore = new ExternalFunction("ignore", scheme("ignore"), (_arg, _arg_1) => (new Value_1(0, [])), 1);
|
|
509
|
+
|
|
510
|
+
const builtinIntTryParse = new ExternalFunction("Int.tryParse", scheme("Int.tryParse"), (_arg, args) => {
|
|
511
|
+
const matchValue = tryParseInt64(expectString("Int.tryParse", args));
|
|
512
|
+
return (matchValue == null) ? (new Value_1(9, [undefined])) : (new Value_1(9, [new Value_1(1, [matchValue])]));
|
|
513
|
+
}, 1);
|
|
514
|
+
|
|
515
|
+
const builtinFloatTryParse = new ExternalFunction("Float.tryParse", scheme("Float.tryParse"), (_arg, args) => {
|
|
516
|
+
const matchValue = tryParseDouble(expectString("Float.tryParse", args));
|
|
517
|
+
return (matchValue == null) ? (new Value_1(9, [undefined])) : (new Value_1(9, [new Value_1(2, [matchValue])]));
|
|
518
|
+
}, 1);
|
|
519
|
+
|
|
520
|
+
const builtinBoolTryParse = new ExternalFunction("Bool.tryParse", scheme("Bool.tryParse"), (_arg, args) => {
|
|
521
|
+
let matchValue;
|
|
522
|
+
let outArg = false;
|
|
523
|
+
matchValue = [tryParse_2(expectString("Bool.tryParse", args), new FSharpRef(() => outArg, (v) => {
|
|
524
|
+
outArg = v;
|
|
525
|
+
})), outArg];
|
|
526
|
+
return matchValue[0] ? (new Value_1(9, [new Value_1(3, [matchValue[1]])])) : (new Value_1(9, [undefined]));
|
|
527
|
+
}, 1);
|
|
528
|
+
|
|
529
|
+
const builtinIntToString = new ExternalFunction("Int.toString", scheme("Int.toString"), (_arg, args) => (new Value_1(4, [String(expectInt("Int.toString", args))])), 1);
|
|
530
|
+
|
|
531
|
+
const builtinFloatToString = new ExternalFunction("Float.toString", scheme("Float.toString"), (_arg, args) => {
|
|
532
|
+
let matchResult, value;
|
|
533
|
+
if (!isEmpty(args)) {
|
|
534
|
+
if (head_1(args).tag === 2) {
|
|
535
|
+
if (isEmpty(tail_1(args))) {
|
|
536
|
+
matchResult = 0;
|
|
537
|
+
value = head_1(args).fields[0];
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
matchResult = 1;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
matchResult = 1;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
matchResult = 1;
|
|
549
|
+
}
|
|
550
|
+
switch (matchResult) {
|
|
551
|
+
case 0:
|
|
552
|
+
return new Value_1(4, [format('{0:' + "G17" + '}', value)]);
|
|
553
|
+
default:
|
|
554
|
+
return fail("Float.toString expects (float)");
|
|
555
|
+
}
|
|
556
|
+
}, 1);
|
|
557
|
+
|
|
558
|
+
const builtinBoolToString = new ExternalFunction("Bool.toString", scheme("Bool.toString"), (_arg, args) => (new Value_1(4, [expectBool("Bool.toString", args) ? "true" : "false"])), 1);
|
|
559
|
+
|
|
560
|
+
const builtinStringReplace = new ExternalFunction("String.replace", scheme("String.replace"), (_arg, args) => {
|
|
561
|
+
let matchResult, newValue, oldValue, source;
|
|
562
|
+
if (!isEmpty(args)) {
|
|
563
|
+
if (head_1(args).tag === 4) {
|
|
564
|
+
if (!isEmpty(tail_1(args))) {
|
|
565
|
+
if (head_1(tail_1(args)).tag === 4) {
|
|
566
|
+
if (!isEmpty(tail_1(tail_1(args)))) {
|
|
567
|
+
if (head_1(tail_1(tail_1(args))).tag === 4) {
|
|
568
|
+
if (isEmpty(tail_1(tail_1(tail_1(args))))) {
|
|
569
|
+
matchResult = 0;
|
|
570
|
+
newValue = head_1(tail_1(args)).fields[0];
|
|
571
|
+
oldValue = head_1(args).fields[0];
|
|
572
|
+
source = head_1(tail_1(tail_1(args))).fields[0];
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
matchResult = 1;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
matchResult = 1;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
matchResult = 1;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
matchResult = 1;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
matchResult = 1;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
matchResult = 1;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
matchResult = 1;
|
|
600
|
+
}
|
|
601
|
+
switch (matchResult) {
|
|
602
|
+
case 0:
|
|
603
|
+
return new Value_1(4, [replace(source, oldValue, newValue)]);
|
|
604
|
+
default:
|
|
605
|
+
return fail("String.replace expects (string, string, string)");
|
|
606
|
+
}
|
|
607
|
+
}, 3);
|
|
608
|
+
|
|
609
|
+
const builtinStringIndexOf = new ExternalFunction("String.indexOf", scheme("String.indexOf"), (_arg, args) => {
|
|
610
|
+
let matchResult, source, value;
|
|
611
|
+
if (!isEmpty(args)) {
|
|
612
|
+
if (head_1(args).tag === 4) {
|
|
613
|
+
if (!isEmpty(tail_1(args))) {
|
|
614
|
+
if (head_1(tail_1(args)).tag === 4) {
|
|
615
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
616
|
+
matchResult = 0;
|
|
617
|
+
source = head_1(tail_1(args)).fields[0];
|
|
618
|
+
value = head_1(args).fields[0];
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
matchResult = 1;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
matchResult = 1;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
matchResult = 1;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
matchResult = 1;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
else {
|
|
637
|
+
matchResult = 1;
|
|
638
|
+
}
|
|
639
|
+
switch (matchResult) {
|
|
640
|
+
case 0: {
|
|
641
|
+
const index = source.indexOf(value) | 0;
|
|
642
|
+
return (index >= 0) ? (new Value_1(9, [new Value_1(1, [toInt64_unchecked(fromInt32(index))])])) : (new Value_1(9, [undefined]));
|
|
643
|
+
}
|
|
644
|
+
default:
|
|
645
|
+
return fail("String.indexOf expects (string, string)");
|
|
646
|
+
}
|
|
647
|
+
}, 2);
|
|
648
|
+
|
|
649
|
+
const builtinStringToLower = new ExternalFunction("String.toLower", scheme("String.toLower"), (_arg, args) => {
|
|
650
|
+
const source = expectString("String.toLower", args);
|
|
651
|
+
return new Value_1(4, [source.toLowerCase()]);
|
|
652
|
+
}, 1);
|
|
653
|
+
|
|
654
|
+
const builtinStringToUpper = new ExternalFunction("String.toUpper", scheme("String.toUpper"), (_arg, args) => {
|
|
655
|
+
const source = expectString("String.toUpper", args);
|
|
656
|
+
return new Value_1(4, [source.toUpperCase()]);
|
|
657
|
+
}, 1);
|
|
658
|
+
|
|
659
|
+
const builtinStringSubstring = new ExternalFunction("String.substring", scheme("String.substring"), (_arg, args) => {
|
|
660
|
+
let matchResult, length, source, start;
|
|
661
|
+
if (!isEmpty(args)) {
|
|
662
|
+
if (head_1(args).tag === 1) {
|
|
663
|
+
if (!isEmpty(tail_1(args))) {
|
|
664
|
+
if (head_1(tail_1(args)).tag === 1) {
|
|
665
|
+
if (!isEmpty(tail_1(tail_1(args)))) {
|
|
666
|
+
if (head_1(tail_1(tail_1(args))).tag === 4) {
|
|
667
|
+
if (isEmpty(tail_1(tail_1(tail_1(args))))) {
|
|
668
|
+
matchResult = 0;
|
|
669
|
+
length = head_1(tail_1(args)).fields[0];
|
|
670
|
+
source = head_1(tail_1(tail_1(args))).fields[0];
|
|
671
|
+
start = head_1(args).fields[0];
|
|
672
|
+
}
|
|
673
|
+
else {
|
|
674
|
+
matchResult = 1;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
matchResult = 1;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
matchResult = 1;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
matchResult = 1;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
matchResult = 1;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
matchResult = 1;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
else {
|
|
698
|
+
matchResult = 1;
|
|
699
|
+
}
|
|
700
|
+
switch (matchResult) {
|
|
701
|
+
case 0: {
|
|
702
|
+
const startIndex = ~~toInt32_unchecked(start) | 0;
|
|
703
|
+
const sliceLength = ~~toInt32_unchecked(length) | 0;
|
|
704
|
+
return ((((startIndex < 0) ? true : (sliceLength < 0)) ? true : (startIndex > source.length)) ? true : ((startIndex + sliceLength) > source.length)) ? (new Value_1(9, [undefined])) : (new Value_1(9, [new Value_1(4, [substring(source, startIndex, sliceLength)])]));
|
|
705
|
+
}
|
|
706
|
+
default:
|
|
707
|
+
return fail("String.substring expects (string, int, int)");
|
|
708
|
+
}
|
|
709
|
+
}, 3);
|
|
710
|
+
|
|
711
|
+
const builtinStringConcat = new ExternalFunction("String.concat", scheme("String.concat"), (_arg, args) => {
|
|
712
|
+
let matchResult, separator, values;
|
|
713
|
+
if (!isEmpty(args)) {
|
|
714
|
+
if (head_1(args).tag === 4) {
|
|
715
|
+
if (!isEmpty(tail_1(args))) {
|
|
716
|
+
if (head_1(tail_1(args)).tag === 5) {
|
|
717
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
718
|
+
matchResult = 0;
|
|
719
|
+
separator = head_1(args).fields[0];
|
|
720
|
+
values = head_1(tail_1(args)).fields[0];
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
matchResult = 1;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
else {
|
|
727
|
+
matchResult = 1;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
else {
|
|
731
|
+
matchResult = 1;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
else {
|
|
735
|
+
matchResult = 1;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
matchResult = 1;
|
|
740
|
+
}
|
|
741
|
+
switch (matchResult) {
|
|
742
|
+
case 0:
|
|
743
|
+
return new Value_1(4, [join(separator, asStringList("String.concat", values))]);
|
|
744
|
+
default:
|
|
745
|
+
return fail("String.concat expects (string, string list)");
|
|
746
|
+
}
|
|
747
|
+
}, 2);
|
|
748
|
+
|
|
749
|
+
const builtinStringSplit = new ExternalFunction("String.split", scheme("String.split"), (_arg, args) => {
|
|
750
|
+
let matchResult, separator, source;
|
|
751
|
+
if (!isEmpty(args)) {
|
|
752
|
+
if (head_1(args).tag === 4) {
|
|
753
|
+
if (!isEmpty(tail_1(args))) {
|
|
754
|
+
if (head_1(tail_1(args)).tag === 4) {
|
|
755
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
756
|
+
matchResult = 0;
|
|
757
|
+
separator = head_1(args).fields[0];
|
|
758
|
+
source = head_1(tail_1(args)).fields[0];
|
|
759
|
+
}
|
|
760
|
+
else {
|
|
761
|
+
matchResult = 1;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
else {
|
|
765
|
+
matchResult = 1;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
matchResult = 1;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
else {
|
|
773
|
+
matchResult = 1;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
else {
|
|
777
|
+
matchResult = 1;
|
|
778
|
+
}
|
|
779
|
+
switch (matchResult) {
|
|
780
|
+
case 0:
|
|
781
|
+
return new Value_1(5, [map((Item) => (new Value_1(4, [Item])), ofArray(split(source, [separator], undefined, 0)))]);
|
|
782
|
+
default:
|
|
783
|
+
return fail("String.split expects (string, string)");
|
|
784
|
+
}
|
|
785
|
+
}, 2);
|
|
786
|
+
|
|
787
|
+
const builtinStringEndsWith = new ExternalFunction("String.endsWith", scheme("String.endsWith"), (_arg, args) => {
|
|
788
|
+
let matchResult, source, suffix;
|
|
789
|
+
if (!isEmpty(args)) {
|
|
790
|
+
if (head_1(args).tag === 4) {
|
|
791
|
+
if (!isEmpty(tail_1(args))) {
|
|
792
|
+
if (head_1(tail_1(args)).tag === 4) {
|
|
793
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
794
|
+
matchResult = 0;
|
|
795
|
+
source = head_1(tail_1(args)).fields[0];
|
|
796
|
+
suffix = head_1(args).fields[0];
|
|
797
|
+
}
|
|
798
|
+
else {
|
|
799
|
+
matchResult = 1;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
else {
|
|
803
|
+
matchResult = 1;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
else {
|
|
807
|
+
matchResult = 1;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
else {
|
|
811
|
+
matchResult = 1;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
matchResult = 1;
|
|
816
|
+
}
|
|
817
|
+
switch (matchResult) {
|
|
818
|
+
case 0:
|
|
819
|
+
return new Value_1(3, [endsWith(source, suffix, 4)]);
|
|
820
|
+
default:
|
|
821
|
+
return fail("String.endsWith expects (string, string)");
|
|
822
|
+
}
|
|
823
|
+
}, 2);
|
|
824
|
+
|
|
825
|
+
const builtinListEmpty = new ExternalFunction("List.empty", scheme("List.empty"), (_arg, _arg_1) => (new Value_1(5, [empty()])), 0);
|
|
826
|
+
|
|
827
|
+
const builtinListMap = new ExternalFunction("List.map", scheme("List.map"), (ctx, args) => {
|
|
828
|
+
let matchResult, mapper, values;
|
|
829
|
+
if (!isEmpty(args)) {
|
|
830
|
+
if (!isEmpty(tail_1(args))) {
|
|
831
|
+
if (head_1(tail_1(args)).tag === 5) {
|
|
832
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
833
|
+
matchResult = 0;
|
|
834
|
+
mapper = head_1(args);
|
|
835
|
+
values = head_1(tail_1(args)).fields[0];
|
|
836
|
+
}
|
|
837
|
+
else {
|
|
838
|
+
matchResult = 1;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
else {
|
|
842
|
+
matchResult = 1;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
else {
|
|
846
|
+
matchResult = 1;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
else {
|
|
850
|
+
matchResult = 1;
|
|
851
|
+
}
|
|
852
|
+
switch (matchResult) {
|
|
853
|
+
case 0:
|
|
854
|
+
return new Value_1(5, [map((value) => ctx.Apply(mapper, value), values)]);
|
|
855
|
+
default:
|
|
856
|
+
return fail("List.map expects (mapper, values)");
|
|
857
|
+
}
|
|
858
|
+
}, 2);
|
|
859
|
+
|
|
860
|
+
const builtinListIter = new ExternalFunction("List.iter", scheme("List.iter"), (ctx, args) => {
|
|
861
|
+
let matchResult, iterator, values;
|
|
862
|
+
if (!isEmpty(args)) {
|
|
863
|
+
if (!isEmpty(tail_1(args))) {
|
|
864
|
+
if (head_1(tail_1(args)).tag === 5) {
|
|
865
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
866
|
+
matchResult = 0;
|
|
867
|
+
iterator = head_1(args);
|
|
868
|
+
values = head_1(tail_1(args)).fields[0];
|
|
869
|
+
}
|
|
870
|
+
else {
|
|
871
|
+
matchResult = 1;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
else {
|
|
875
|
+
matchResult = 1;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
else {
|
|
879
|
+
matchResult = 1;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
else {
|
|
883
|
+
matchResult = 1;
|
|
884
|
+
}
|
|
885
|
+
switch (matchResult) {
|
|
886
|
+
case 0: {
|
|
887
|
+
iterate((value) => {
|
|
888
|
+
ctx.Apply(iterator, value);
|
|
889
|
+
}, values);
|
|
890
|
+
return new Value_1(0, []);
|
|
891
|
+
}
|
|
892
|
+
default:
|
|
893
|
+
return fail("List.iter expects (iterator, values)");
|
|
894
|
+
}
|
|
895
|
+
}, 2);
|
|
896
|
+
|
|
897
|
+
const builtinListChoose = new ExternalFunction("List.choose", scheme("List.choose"), (ctx, args) => {
|
|
898
|
+
let matchResult, chooser, values;
|
|
899
|
+
if (!isEmpty(args)) {
|
|
900
|
+
if (!isEmpty(tail_1(args))) {
|
|
901
|
+
if (head_1(tail_1(args)).tag === 5) {
|
|
902
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
903
|
+
matchResult = 0;
|
|
904
|
+
chooser = head_1(args);
|
|
905
|
+
values = head_1(tail_1(args)).fields[0];
|
|
906
|
+
}
|
|
907
|
+
else {
|
|
908
|
+
matchResult = 1;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
else {
|
|
912
|
+
matchResult = 1;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
else {
|
|
916
|
+
matchResult = 1;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
else {
|
|
920
|
+
matchResult = 1;
|
|
921
|
+
}
|
|
922
|
+
switch (matchResult) {
|
|
923
|
+
case 0:
|
|
924
|
+
return new Value_1(5, [choose((value) => {
|
|
925
|
+
const matchValue = ctx.Apply(chooser, value);
|
|
926
|
+
if (matchValue.tag === 9) {
|
|
927
|
+
return matchValue.fields[0];
|
|
928
|
+
}
|
|
929
|
+
else {
|
|
930
|
+
return fail("List.choose chooser must return option");
|
|
931
|
+
}
|
|
932
|
+
}, values)]);
|
|
933
|
+
default:
|
|
934
|
+
return fail("List.choose expects (chooser, values)");
|
|
935
|
+
}
|
|
936
|
+
}, 2);
|
|
937
|
+
|
|
938
|
+
const builtinListCollect = new ExternalFunction("List.collect", scheme("List.collect"), (ctx, args) => {
|
|
939
|
+
let matchResult, collector, values;
|
|
940
|
+
if (!isEmpty(args)) {
|
|
941
|
+
if (!isEmpty(tail_1(args))) {
|
|
942
|
+
if (head_1(tail_1(args)).tag === 5) {
|
|
943
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
944
|
+
matchResult = 0;
|
|
945
|
+
collector = head_1(args);
|
|
946
|
+
values = head_1(tail_1(args)).fields[0];
|
|
947
|
+
}
|
|
948
|
+
else {
|
|
949
|
+
matchResult = 1;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
else {
|
|
953
|
+
matchResult = 1;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
else {
|
|
957
|
+
matchResult = 1;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
else {
|
|
961
|
+
matchResult = 1;
|
|
962
|
+
}
|
|
963
|
+
switch (matchResult) {
|
|
964
|
+
case 0:
|
|
965
|
+
return new Value_1(5, [collect((value) => {
|
|
966
|
+
const matchValue = ctx.Apply(collector, value);
|
|
967
|
+
if (matchValue.tag === 5) {
|
|
968
|
+
return matchValue.fields[0];
|
|
969
|
+
}
|
|
970
|
+
else {
|
|
971
|
+
return fail("List.collect collector must return list");
|
|
972
|
+
}
|
|
973
|
+
}, values)]);
|
|
974
|
+
default:
|
|
975
|
+
return fail("List.collect expects (collector, values)");
|
|
976
|
+
}
|
|
977
|
+
}, 2);
|
|
978
|
+
|
|
979
|
+
const builtinListExists = new ExternalFunction("List.exists", scheme("List.exists"), (ctx, args) => {
|
|
980
|
+
let matchResult, predicate, values;
|
|
981
|
+
if (!isEmpty(args)) {
|
|
982
|
+
if (!isEmpty(tail_1(args))) {
|
|
983
|
+
if (head_1(tail_1(args)).tag === 5) {
|
|
984
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
985
|
+
matchResult = 0;
|
|
986
|
+
predicate = head_1(args);
|
|
987
|
+
values = head_1(tail_1(args)).fields[0];
|
|
988
|
+
}
|
|
989
|
+
else {
|
|
990
|
+
matchResult = 1;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
else {
|
|
994
|
+
matchResult = 1;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
else {
|
|
998
|
+
matchResult = 1;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
else {
|
|
1002
|
+
matchResult = 1;
|
|
1003
|
+
}
|
|
1004
|
+
switch (matchResult) {
|
|
1005
|
+
case 0:
|
|
1006
|
+
return new Value_1(3, [exists((value) => {
|
|
1007
|
+
const matchValue = ctx.Apply(predicate, value);
|
|
1008
|
+
if (matchValue.tag === 3) {
|
|
1009
|
+
return matchValue.fields[0];
|
|
1010
|
+
}
|
|
1011
|
+
else {
|
|
1012
|
+
return fail("List.exists predicate must return bool");
|
|
1013
|
+
}
|
|
1014
|
+
}, values)]);
|
|
1015
|
+
default:
|
|
1016
|
+
return fail("List.exists expects (predicate, values)");
|
|
1017
|
+
}
|
|
1018
|
+
}, 2);
|
|
1019
|
+
|
|
1020
|
+
const builtinListContains = new ExternalFunction("List.contains", scheme("List.contains"), (_arg, args) => {
|
|
1021
|
+
let matchResult, needle, values;
|
|
1022
|
+
if (!isEmpty(args)) {
|
|
1023
|
+
if (!isEmpty(tail_1(args))) {
|
|
1024
|
+
if (head_1(tail_1(args)).tag === 5) {
|
|
1025
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1026
|
+
matchResult = 0;
|
|
1027
|
+
needle = head_1(args);
|
|
1028
|
+
values = head_1(tail_1(args)).fields[0];
|
|
1029
|
+
}
|
|
1030
|
+
else {
|
|
1031
|
+
matchResult = 1;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
else {
|
|
1035
|
+
matchResult = 1;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
else {
|
|
1039
|
+
matchResult = 1;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
else {
|
|
1043
|
+
matchResult = 1;
|
|
1044
|
+
}
|
|
1045
|
+
switch (matchResult) {
|
|
1046
|
+
case 0:
|
|
1047
|
+
return new Value_1(3, [exists((value) => {
|
|
1048
|
+
let matchResult_1, x, y, x_1, y_1, x_2, y_2, x_3, y_3;
|
|
1049
|
+
switch (value.tag) {
|
|
1050
|
+
case 0: {
|
|
1051
|
+
if (needle.tag === 0) {
|
|
1052
|
+
matchResult_1 = 0;
|
|
1053
|
+
}
|
|
1054
|
+
else {
|
|
1055
|
+
matchResult_1 = 5;
|
|
1056
|
+
}
|
|
1057
|
+
break;
|
|
1058
|
+
}
|
|
1059
|
+
case 1: {
|
|
1060
|
+
if (needle.tag === 1) {
|
|
1061
|
+
matchResult_1 = 1;
|
|
1062
|
+
x = value.fields[0];
|
|
1063
|
+
y = needle.fields[0];
|
|
1064
|
+
}
|
|
1065
|
+
else {
|
|
1066
|
+
matchResult_1 = 5;
|
|
1067
|
+
}
|
|
1068
|
+
break;
|
|
1069
|
+
}
|
|
1070
|
+
case 2: {
|
|
1071
|
+
if (needle.tag === 2) {
|
|
1072
|
+
matchResult_1 = 2;
|
|
1073
|
+
x_1 = value.fields[0];
|
|
1074
|
+
y_1 = needle.fields[0];
|
|
1075
|
+
}
|
|
1076
|
+
else {
|
|
1077
|
+
matchResult_1 = 5;
|
|
1078
|
+
}
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
case 3: {
|
|
1082
|
+
if (needle.tag === 3) {
|
|
1083
|
+
matchResult_1 = 3;
|
|
1084
|
+
x_2 = value.fields[0];
|
|
1085
|
+
y_2 = needle.fields[0];
|
|
1086
|
+
}
|
|
1087
|
+
else {
|
|
1088
|
+
matchResult_1 = 5;
|
|
1089
|
+
}
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
case 4: {
|
|
1093
|
+
if (needle.tag === 4) {
|
|
1094
|
+
matchResult_1 = 4;
|
|
1095
|
+
x_3 = value.fields[0];
|
|
1096
|
+
y_3 = needle.fields[0];
|
|
1097
|
+
}
|
|
1098
|
+
else {
|
|
1099
|
+
matchResult_1 = 5;
|
|
1100
|
+
}
|
|
1101
|
+
break;
|
|
1102
|
+
}
|
|
1103
|
+
default:
|
|
1104
|
+
matchResult_1 = 5;
|
|
1105
|
+
}
|
|
1106
|
+
switch (matchResult_1) {
|
|
1107
|
+
case 0:
|
|
1108
|
+
return true;
|
|
1109
|
+
case 1:
|
|
1110
|
+
return equals(x, y);
|
|
1111
|
+
case 2:
|
|
1112
|
+
return x_1 === y_1;
|
|
1113
|
+
case 3:
|
|
1114
|
+
return x_2 === y_2;
|
|
1115
|
+
case 4:
|
|
1116
|
+
return x_3 === y_3;
|
|
1117
|
+
default:
|
|
1118
|
+
return false;
|
|
1119
|
+
}
|
|
1120
|
+
}, values)]);
|
|
1121
|
+
default:
|
|
1122
|
+
return fail("List.contains expects (needle, values)");
|
|
1123
|
+
}
|
|
1124
|
+
}, 2);
|
|
1125
|
+
|
|
1126
|
+
const builtinListRev = new ExternalFunction("List.rev", scheme("List.rev"), (_arg, args) => (new Value_1(5, [reverse(expectList("List.rev", args))])), 1);
|
|
1127
|
+
|
|
1128
|
+
const builtinListDistinct = new ExternalFunction("List.distinct", scheme("List.distinct"), (_arg, args) => (new Value_1(5, [distinctValues(expectList("List.distinct", args))])), 1);
|
|
1129
|
+
|
|
1130
|
+
const builtinListFold = new ExternalFunction("List.fold", scheme("List.fold"), (ctx, args) => {
|
|
1131
|
+
let matchResult, folder, state, values;
|
|
1132
|
+
if (!isEmpty(args)) {
|
|
1133
|
+
if (!isEmpty(tail_1(args))) {
|
|
1134
|
+
if (!isEmpty(tail_1(tail_1(args)))) {
|
|
1135
|
+
if (head_1(tail_1(tail_1(args))).tag === 5) {
|
|
1136
|
+
if (isEmpty(tail_1(tail_1(tail_1(args))))) {
|
|
1137
|
+
matchResult = 0;
|
|
1138
|
+
folder = head_1(args);
|
|
1139
|
+
state = head_1(tail_1(args));
|
|
1140
|
+
values = head_1(tail_1(tail_1(args))).fields[0];
|
|
1141
|
+
}
|
|
1142
|
+
else {
|
|
1143
|
+
matchResult = 1;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
else {
|
|
1147
|
+
matchResult = 1;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
else {
|
|
1151
|
+
matchResult = 1;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
else {
|
|
1155
|
+
matchResult = 1;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
else {
|
|
1159
|
+
matchResult = 1;
|
|
1160
|
+
}
|
|
1161
|
+
switch (matchResult) {
|
|
1162
|
+
case 0:
|
|
1163
|
+
return fold((acc, value) => ctx.Apply(ctx.Apply(folder, acc), value), state, values);
|
|
1164
|
+
default:
|
|
1165
|
+
return fail("List.fold expects (folder, state, values)");
|
|
1166
|
+
}
|
|
1167
|
+
}, 3);
|
|
1168
|
+
|
|
1169
|
+
const builtinListFilter = new ExternalFunction("List.filter", scheme("List.filter"), (ctx, args) => {
|
|
1170
|
+
let matchResult, predicate, values;
|
|
1171
|
+
if (!isEmpty(args)) {
|
|
1172
|
+
if (!isEmpty(tail_1(args))) {
|
|
1173
|
+
if (head_1(tail_1(args)).tag === 5) {
|
|
1174
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1175
|
+
matchResult = 0;
|
|
1176
|
+
predicate = head_1(args);
|
|
1177
|
+
values = head_1(tail_1(args)).fields[0];
|
|
1178
|
+
}
|
|
1179
|
+
else {
|
|
1180
|
+
matchResult = 1;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
else {
|
|
1184
|
+
matchResult = 1;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
else {
|
|
1188
|
+
matchResult = 1;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
else {
|
|
1192
|
+
matchResult = 1;
|
|
1193
|
+
}
|
|
1194
|
+
switch (matchResult) {
|
|
1195
|
+
case 0:
|
|
1196
|
+
return new Value_1(5, [filter((value) => {
|
|
1197
|
+
const matchValue = ctx.Apply(predicate, value);
|
|
1198
|
+
if (matchValue.tag === 3) {
|
|
1199
|
+
return matchValue.fields[0];
|
|
1200
|
+
}
|
|
1201
|
+
else {
|
|
1202
|
+
return fail("List.filter predicate must return bool");
|
|
1203
|
+
}
|
|
1204
|
+
}, values)]);
|
|
1205
|
+
default:
|
|
1206
|
+
return fail("List.filter expects (predicate, values)");
|
|
1207
|
+
}
|
|
1208
|
+
}, 2);
|
|
1209
|
+
|
|
1210
|
+
const builtinListLength = new ExternalFunction("List.length", scheme("List.length"), (_arg, args) => (new Value_1(1, [toInt64_unchecked(fromInt32(length_1(expectList("List.length", args))))])), 1);
|
|
1211
|
+
|
|
1212
|
+
const builtinListTryFind = new ExternalFunction("List.tryFind", scheme("List.tryFind"), (ctx, args) => {
|
|
1213
|
+
let matchResult, predicate, values;
|
|
1214
|
+
if (!isEmpty(args)) {
|
|
1215
|
+
if (!isEmpty(tail_1(args))) {
|
|
1216
|
+
if (head_1(tail_1(args)).tag === 5) {
|
|
1217
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1218
|
+
matchResult = 0;
|
|
1219
|
+
predicate = head_1(args);
|
|
1220
|
+
values = head_1(tail_1(args)).fields[0];
|
|
1221
|
+
}
|
|
1222
|
+
else {
|
|
1223
|
+
matchResult = 1;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
else {
|
|
1227
|
+
matchResult = 1;
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
else {
|
|
1231
|
+
matchResult = 1;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
else {
|
|
1235
|
+
matchResult = 1;
|
|
1236
|
+
}
|
|
1237
|
+
switch (matchResult) {
|
|
1238
|
+
case 0:
|
|
1239
|
+
return new Value_1(9, [tryFind_1((value) => {
|
|
1240
|
+
const matchValue = ctx.Apply(predicate, value);
|
|
1241
|
+
if (matchValue.tag === 3) {
|
|
1242
|
+
return matchValue.fields[0];
|
|
1243
|
+
}
|
|
1244
|
+
else {
|
|
1245
|
+
return fail("List.tryFind predicate must return bool");
|
|
1246
|
+
}
|
|
1247
|
+
}, values)]);
|
|
1248
|
+
default:
|
|
1249
|
+
return fail("List.tryFind expects (predicate, values)");
|
|
1250
|
+
}
|
|
1251
|
+
}, 2);
|
|
1252
|
+
|
|
1253
|
+
const builtinListTryGet = new ExternalFunction("List.tryGet", scheme("List.tryGet"), (ctx, args) => {
|
|
1254
|
+
let matchResult, predicate, values;
|
|
1255
|
+
if (!isEmpty(args)) {
|
|
1256
|
+
if (!isEmpty(tail_1(args))) {
|
|
1257
|
+
if (head_1(tail_1(args)).tag === 5) {
|
|
1258
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1259
|
+
matchResult = 0;
|
|
1260
|
+
predicate = head_1(args);
|
|
1261
|
+
values = head_1(tail_1(args)).fields[0];
|
|
1262
|
+
}
|
|
1263
|
+
else {
|
|
1264
|
+
matchResult = 1;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
else {
|
|
1268
|
+
matchResult = 1;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
else {
|
|
1272
|
+
matchResult = 1;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
else {
|
|
1276
|
+
matchResult = 1;
|
|
1277
|
+
}
|
|
1278
|
+
switch (matchResult) {
|
|
1279
|
+
case 0:
|
|
1280
|
+
return new Value_1(9, [map_1((arg) => (new Value_1(1, [toInt64_unchecked(fromInt32(arg))])), tryFindIndex((value) => {
|
|
1281
|
+
const matchValue = ctx.Apply(predicate, value);
|
|
1282
|
+
if (matchValue.tag === 3) {
|
|
1283
|
+
return matchValue.fields[0];
|
|
1284
|
+
}
|
|
1285
|
+
else {
|
|
1286
|
+
return fail("List.tryGet predicate must return bool");
|
|
1287
|
+
}
|
|
1288
|
+
}, values))]);
|
|
1289
|
+
default:
|
|
1290
|
+
return fail("List.tryGet expects (predicate, values)");
|
|
1291
|
+
}
|
|
1292
|
+
}, 2);
|
|
1293
|
+
|
|
1294
|
+
const builtinListTryItem = new ExternalFunction("List.tryItem", scheme("List.tryItem"), (_arg, args) => {
|
|
1295
|
+
let matchResult, index, values;
|
|
1296
|
+
if (!isEmpty(args)) {
|
|
1297
|
+
if (head_1(args).tag === 1) {
|
|
1298
|
+
if (!isEmpty(tail_1(args))) {
|
|
1299
|
+
if (head_1(tail_1(args)).tag === 5) {
|
|
1300
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1301
|
+
matchResult = 0;
|
|
1302
|
+
index = head_1(args).fields[0];
|
|
1303
|
+
values = head_1(tail_1(args)).fields[0];
|
|
1304
|
+
}
|
|
1305
|
+
else {
|
|
1306
|
+
matchResult = 1;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
else {
|
|
1310
|
+
matchResult = 1;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
else {
|
|
1314
|
+
matchResult = 1;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
else {
|
|
1318
|
+
matchResult = 1;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
else {
|
|
1322
|
+
matchResult = 1;
|
|
1323
|
+
}
|
|
1324
|
+
switch (matchResult) {
|
|
1325
|
+
case 0: {
|
|
1326
|
+
const loop = (remaining_mut, current_mut) => {
|
|
1327
|
+
loop:
|
|
1328
|
+
while (true) {
|
|
1329
|
+
const remaining = remaining_mut, current = current_mut;
|
|
1330
|
+
if (!isEmpty(remaining)) {
|
|
1331
|
+
if (equals(current, index)) {
|
|
1332
|
+
return some(head_1(remaining));
|
|
1333
|
+
}
|
|
1334
|
+
else {
|
|
1335
|
+
remaining_mut = tail_1(remaining);
|
|
1336
|
+
current_mut = toInt64_unchecked(op_Addition(current, 1n));
|
|
1337
|
+
continue loop;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
else {
|
|
1341
|
+
return undefined;
|
|
1342
|
+
}
|
|
1343
|
+
break;
|
|
1344
|
+
}
|
|
1345
|
+
};
|
|
1346
|
+
return (compare_1(index, 0n) < 0) ? (new Value_1(9, [undefined])) : (new Value_1(9, [loop(values, 0n)]));
|
|
1347
|
+
}
|
|
1348
|
+
default:
|
|
1349
|
+
return fail("List.tryItem expects (index, values)");
|
|
1350
|
+
}
|
|
1351
|
+
}, 2);
|
|
1352
|
+
|
|
1353
|
+
const builtinListTryHead = new ExternalFunction("List.tryHead", scheme("List.tryHead"), (_arg, args) => (new Value_1(9, [tryHead(expectList("List.tryHead", args))])), 1);
|
|
1354
|
+
|
|
1355
|
+
const builtinListTail = new ExternalFunction("List.tail", scheme("List.tail"), (_arg, args) => {
|
|
1356
|
+
const matchValue = expectList("List.tail", args);
|
|
1357
|
+
return !isEmpty(matchValue) ? (new Value_1(5, [tail_1(matchValue)])) : fail("List.tail expects a non-empty list");
|
|
1358
|
+
}, 1);
|
|
1359
|
+
|
|
1360
|
+
const builtinListAppend = new ExternalFunction("List.append", scheme("List.append"), (_arg, args) => {
|
|
1361
|
+
let matchResult, left, right;
|
|
1362
|
+
if (!isEmpty(args)) {
|
|
1363
|
+
if (head_1(args).tag === 5) {
|
|
1364
|
+
if (!isEmpty(tail_1(args))) {
|
|
1365
|
+
if (head_1(tail_1(args)).tag === 5) {
|
|
1366
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1367
|
+
matchResult = 0;
|
|
1368
|
+
left = head_1(args).fields[0];
|
|
1369
|
+
right = head_1(tail_1(args)).fields[0];
|
|
1370
|
+
}
|
|
1371
|
+
else {
|
|
1372
|
+
matchResult = 1;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
else {
|
|
1376
|
+
matchResult = 1;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
else {
|
|
1380
|
+
matchResult = 1;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
else {
|
|
1384
|
+
matchResult = 1;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
else {
|
|
1388
|
+
matchResult = 1;
|
|
1389
|
+
}
|
|
1390
|
+
switch (matchResult) {
|
|
1391
|
+
case 0:
|
|
1392
|
+
return new Value_1(5, [append(left, right)]);
|
|
1393
|
+
default:
|
|
1394
|
+
return fail("List.append expects (left, right)");
|
|
1395
|
+
}
|
|
1396
|
+
}, 2);
|
|
1397
|
+
|
|
1398
|
+
const builtinOptionDefaultValue = new ExternalFunction("Option.defaultValue", scheme("Option.defaultValue"), (_arg, args) => {
|
|
1399
|
+
let matchResult, current, fallback, fallback_1;
|
|
1400
|
+
if (!isEmpty(args)) {
|
|
1401
|
+
if (!isEmpty(tail_1(args))) {
|
|
1402
|
+
if (head_1(tail_1(args)).tag === 9) {
|
|
1403
|
+
if (head_1(tail_1(args)).fields[0] == null) {
|
|
1404
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1405
|
+
matchResult = 1;
|
|
1406
|
+
fallback_1 = head_1(args);
|
|
1407
|
+
}
|
|
1408
|
+
else {
|
|
1409
|
+
matchResult = 2;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
else if (isEmpty(tail_1(tail_1(args)))) {
|
|
1413
|
+
matchResult = 0;
|
|
1414
|
+
current = head_1(tail_1(args)).fields[0];
|
|
1415
|
+
fallback = head_1(args);
|
|
1416
|
+
}
|
|
1417
|
+
else {
|
|
1418
|
+
matchResult = 2;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
else {
|
|
1422
|
+
matchResult = 2;
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
else {
|
|
1426
|
+
matchResult = 2;
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
else {
|
|
1430
|
+
matchResult = 2;
|
|
1431
|
+
}
|
|
1432
|
+
switch (matchResult) {
|
|
1433
|
+
case 0:
|
|
1434
|
+
return current;
|
|
1435
|
+
case 1:
|
|
1436
|
+
return fallback_1;
|
|
1437
|
+
default:
|
|
1438
|
+
return fail("Option.defaultValue expects (fallback, value)");
|
|
1439
|
+
}
|
|
1440
|
+
}, 2);
|
|
1441
|
+
|
|
1442
|
+
const builtinOptionDefaultWith = new ExternalFunction("Option.defaultWith", scheme("Option.defaultWith"), (ctx, args) => {
|
|
1443
|
+
let matchResult, current, fallback, fallback_1;
|
|
1444
|
+
if (!isEmpty(args)) {
|
|
1445
|
+
if (!isEmpty(tail_1(args))) {
|
|
1446
|
+
if (head_1(tail_1(args)).tag === 9) {
|
|
1447
|
+
if (head_1(tail_1(args)).fields[0] == null) {
|
|
1448
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1449
|
+
matchResult = 1;
|
|
1450
|
+
fallback_1 = head_1(args);
|
|
1451
|
+
}
|
|
1452
|
+
else {
|
|
1453
|
+
matchResult = 2;
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
else if (isEmpty(tail_1(tail_1(args)))) {
|
|
1457
|
+
matchResult = 0;
|
|
1458
|
+
current = head_1(tail_1(args)).fields[0];
|
|
1459
|
+
fallback = head_1(args);
|
|
1460
|
+
}
|
|
1461
|
+
else {
|
|
1462
|
+
matchResult = 2;
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
else {
|
|
1466
|
+
matchResult = 2;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
else {
|
|
1470
|
+
matchResult = 2;
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
else {
|
|
1474
|
+
matchResult = 2;
|
|
1475
|
+
}
|
|
1476
|
+
switch (matchResult) {
|
|
1477
|
+
case 0:
|
|
1478
|
+
return current;
|
|
1479
|
+
case 1:
|
|
1480
|
+
return ctx.Apply(fallback_1, new Value_1(0, []));
|
|
1481
|
+
default:
|
|
1482
|
+
return fail("Option.defaultWith expects (fallback, value)");
|
|
1483
|
+
}
|
|
1484
|
+
}, 2);
|
|
1485
|
+
|
|
1486
|
+
const builtinOptionIsNone = new ExternalFunction("Option.isNone", scheme("Option.isNone"), (_arg, args) => {
|
|
1487
|
+
let matchResult;
|
|
1488
|
+
if (!isEmpty(args)) {
|
|
1489
|
+
if (head_1(args).tag === 9) {
|
|
1490
|
+
if (head_1(args).fields[0] != null) {
|
|
1491
|
+
if (isEmpty(tail_1(args))) {
|
|
1492
|
+
matchResult = 1;
|
|
1493
|
+
}
|
|
1494
|
+
else {
|
|
1495
|
+
matchResult = 2;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
else if (isEmpty(tail_1(args))) {
|
|
1499
|
+
matchResult = 0;
|
|
1500
|
+
}
|
|
1501
|
+
else {
|
|
1502
|
+
matchResult = 2;
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
else {
|
|
1506
|
+
matchResult = 2;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
else {
|
|
1510
|
+
matchResult = 2;
|
|
1511
|
+
}
|
|
1512
|
+
switch (matchResult) {
|
|
1513
|
+
case 0:
|
|
1514
|
+
return new Value_1(3, [true]);
|
|
1515
|
+
case 1:
|
|
1516
|
+
return new Value_1(3, [false]);
|
|
1517
|
+
default:
|
|
1518
|
+
return fail("Option.isNone expects (value)");
|
|
1519
|
+
}
|
|
1520
|
+
}, 1);
|
|
1521
|
+
|
|
1522
|
+
const builtinOptionIsSome = new ExternalFunction("Option.isSome", scheme("Option.isSome"), (_arg, args) => {
|
|
1523
|
+
let matchResult;
|
|
1524
|
+
if (!isEmpty(args)) {
|
|
1525
|
+
if (head_1(args).tag === 9) {
|
|
1526
|
+
if (head_1(args).fields[0] != null) {
|
|
1527
|
+
if (isEmpty(tail_1(args))) {
|
|
1528
|
+
matchResult = 1;
|
|
1529
|
+
}
|
|
1530
|
+
else {
|
|
1531
|
+
matchResult = 2;
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
else if (isEmpty(tail_1(args))) {
|
|
1535
|
+
matchResult = 0;
|
|
1536
|
+
}
|
|
1537
|
+
else {
|
|
1538
|
+
matchResult = 2;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
else {
|
|
1542
|
+
matchResult = 2;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
else {
|
|
1546
|
+
matchResult = 2;
|
|
1547
|
+
}
|
|
1548
|
+
switch (matchResult) {
|
|
1549
|
+
case 0:
|
|
1550
|
+
return new Value_1(3, [false]);
|
|
1551
|
+
case 1:
|
|
1552
|
+
return new Value_1(3, [true]);
|
|
1553
|
+
default:
|
|
1554
|
+
return fail("Option.isSome expects (value)");
|
|
1555
|
+
}
|
|
1556
|
+
}, 1);
|
|
1557
|
+
|
|
1558
|
+
const builtinOptionMap = new ExternalFunction("Option.map", scheme("Option.map"), (ctx, args) => {
|
|
1559
|
+
let matchResult, current, mapper;
|
|
1560
|
+
if (!isEmpty(args)) {
|
|
1561
|
+
if (!isEmpty(tail_1(args))) {
|
|
1562
|
+
if (head_1(tail_1(args)).tag === 9) {
|
|
1563
|
+
if (head_1(tail_1(args)).fields[0] == null) {
|
|
1564
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1565
|
+
matchResult = 1;
|
|
1566
|
+
}
|
|
1567
|
+
else {
|
|
1568
|
+
matchResult = 2;
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
else if (isEmpty(tail_1(tail_1(args)))) {
|
|
1572
|
+
matchResult = 0;
|
|
1573
|
+
current = head_1(tail_1(args)).fields[0];
|
|
1574
|
+
mapper = head_1(args);
|
|
1575
|
+
}
|
|
1576
|
+
else {
|
|
1577
|
+
matchResult = 2;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
else {
|
|
1581
|
+
matchResult = 2;
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
else {
|
|
1585
|
+
matchResult = 2;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
else {
|
|
1589
|
+
matchResult = 2;
|
|
1590
|
+
}
|
|
1591
|
+
switch (matchResult) {
|
|
1592
|
+
case 0:
|
|
1593
|
+
return new Value_1(9, [ctx.Apply(mapper, current)]);
|
|
1594
|
+
case 1:
|
|
1595
|
+
return new Value_1(9, [undefined]);
|
|
1596
|
+
default:
|
|
1597
|
+
return fail("Option.map expects (mapper, value)");
|
|
1598
|
+
}
|
|
1599
|
+
}, 2);
|
|
1600
|
+
|
|
1601
|
+
const builtinMapEmpty = new ExternalFunction("Map.empty", scheme("Map.empty"), (_arg, _arg_1) => (new Value_1(8, [empty_1({
|
|
1602
|
+
Compare: (x, y) => (compare(x, y) | 0),
|
|
1603
|
+
})])), 0);
|
|
1604
|
+
|
|
1605
|
+
const builtinMapTryGet = new ExternalFunction("Map.tryGet", scheme("Map.tryGet"), (_arg, args) => {
|
|
1606
|
+
let matchResult, key, values;
|
|
1607
|
+
if (!isEmpty(args)) {
|
|
1608
|
+
if (head_1(args).tag === 4) {
|
|
1609
|
+
if (!isEmpty(tail_1(args))) {
|
|
1610
|
+
if (head_1(tail_1(args)).tag === 8) {
|
|
1611
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1612
|
+
matchResult = 0;
|
|
1613
|
+
key = head_1(args).fields[0];
|
|
1614
|
+
values = head_1(tail_1(args)).fields[0];
|
|
1615
|
+
}
|
|
1616
|
+
else {
|
|
1617
|
+
matchResult = 1;
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
else {
|
|
1621
|
+
matchResult = 1;
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
else {
|
|
1625
|
+
matchResult = 1;
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
else {
|
|
1629
|
+
matchResult = 1;
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
else {
|
|
1633
|
+
matchResult = 1;
|
|
1634
|
+
}
|
|
1635
|
+
switch (matchResult) {
|
|
1636
|
+
case 0:
|
|
1637
|
+
return new Value_1(9, [FSharpMap__TryFind(values, new MapKey(0, [key]))]);
|
|
1638
|
+
default:
|
|
1639
|
+
return fail("Map.tryGet expects (key, values)");
|
|
1640
|
+
}
|
|
1641
|
+
}, 2);
|
|
1642
|
+
|
|
1643
|
+
const builtinMapContainsKey = new ExternalFunction("Map.containsKey", scheme("Map.containsKey"), (_arg, args) => {
|
|
1644
|
+
let matchResult, key, values;
|
|
1645
|
+
if (!isEmpty(args)) {
|
|
1646
|
+
if (head_1(args).tag === 4) {
|
|
1647
|
+
if (!isEmpty(tail_1(args))) {
|
|
1648
|
+
if (head_1(tail_1(args)).tag === 8) {
|
|
1649
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1650
|
+
matchResult = 0;
|
|
1651
|
+
key = head_1(args).fields[0];
|
|
1652
|
+
values = head_1(tail_1(args)).fields[0];
|
|
1653
|
+
}
|
|
1654
|
+
else {
|
|
1655
|
+
matchResult = 1;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
else {
|
|
1659
|
+
matchResult = 1;
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
else {
|
|
1663
|
+
matchResult = 1;
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
else {
|
|
1667
|
+
matchResult = 1;
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
else {
|
|
1671
|
+
matchResult = 1;
|
|
1672
|
+
}
|
|
1673
|
+
switch (matchResult) {
|
|
1674
|
+
case 0:
|
|
1675
|
+
return new Value_1(3, [FSharpMap__ContainsKey(values, new MapKey(0, [key]))]);
|
|
1676
|
+
default:
|
|
1677
|
+
return fail("Map.containsKey expects (key, values)");
|
|
1678
|
+
}
|
|
1679
|
+
}, 2);
|
|
1680
|
+
|
|
1681
|
+
const builtinMapAdd = new ExternalFunction("Map.add", scheme("Map.add"), (_arg, args) => {
|
|
1682
|
+
let matchResult, key, value, values;
|
|
1683
|
+
if (!isEmpty(args)) {
|
|
1684
|
+
if (head_1(args).tag === 4) {
|
|
1685
|
+
if (!isEmpty(tail_1(args))) {
|
|
1686
|
+
if (!isEmpty(tail_1(tail_1(args)))) {
|
|
1687
|
+
if (head_1(tail_1(tail_1(args))).tag === 8) {
|
|
1688
|
+
if (isEmpty(tail_1(tail_1(tail_1(args))))) {
|
|
1689
|
+
matchResult = 0;
|
|
1690
|
+
key = head_1(args).fields[0];
|
|
1691
|
+
value = head_1(tail_1(args));
|
|
1692
|
+
values = head_1(tail_1(tail_1(args))).fields[0];
|
|
1693
|
+
}
|
|
1694
|
+
else {
|
|
1695
|
+
matchResult = 1;
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
else {
|
|
1699
|
+
matchResult = 1;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
else {
|
|
1703
|
+
matchResult = 1;
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
else {
|
|
1707
|
+
matchResult = 1;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
else {
|
|
1711
|
+
matchResult = 1;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
else {
|
|
1715
|
+
matchResult = 1;
|
|
1716
|
+
}
|
|
1717
|
+
switch (matchResult) {
|
|
1718
|
+
case 0:
|
|
1719
|
+
return new Value_1(8, [FSharpMap__Add(values, new MapKey(0, [key]), value)]);
|
|
1720
|
+
default:
|
|
1721
|
+
return fail("Map.add expects (key, value, values)");
|
|
1722
|
+
}
|
|
1723
|
+
}, 3);
|
|
1724
|
+
|
|
1725
|
+
const builtinMapOfList = new ExternalFunction("Map.ofList", scheme("Map.ofList"), (_arg, args) => {
|
|
1726
|
+
let matchResult, pairs;
|
|
1727
|
+
if (!isEmpty(args)) {
|
|
1728
|
+
if (head_1(args).tag === 5) {
|
|
1729
|
+
if (isEmpty(tail_1(args))) {
|
|
1730
|
+
matchResult = 0;
|
|
1731
|
+
pairs = head_1(args).fields[0];
|
|
1732
|
+
}
|
|
1733
|
+
else {
|
|
1734
|
+
matchResult = 1;
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
else {
|
|
1738
|
+
matchResult = 1;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
else {
|
|
1742
|
+
matchResult = 1;
|
|
1743
|
+
}
|
|
1744
|
+
switch (matchResult) {
|
|
1745
|
+
case 0:
|
|
1746
|
+
return new Value_1(8, [fold((state, entry) => {
|
|
1747
|
+
let matchResult_1, key, value;
|
|
1748
|
+
if (entry.tag === 6) {
|
|
1749
|
+
if (!isEmpty(entry.fields[0])) {
|
|
1750
|
+
if (head_1(entry.fields[0]).tag === 4) {
|
|
1751
|
+
if (!isEmpty(tail_1(entry.fields[0]))) {
|
|
1752
|
+
if (isEmpty(tail_1(tail_1(entry.fields[0])))) {
|
|
1753
|
+
matchResult_1 = 0;
|
|
1754
|
+
key = head_1(entry.fields[0]).fields[0];
|
|
1755
|
+
value = head_1(tail_1(entry.fields[0]));
|
|
1756
|
+
}
|
|
1757
|
+
else {
|
|
1758
|
+
matchResult_1 = 1;
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
else {
|
|
1762
|
+
matchResult_1 = 1;
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
else {
|
|
1766
|
+
matchResult_1 = 1;
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
else {
|
|
1770
|
+
matchResult_1 = 1;
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
else {
|
|
1774
|
+
matchResult_1 = 1;
|
|
1775
|
+
}
|
|
1776
|
+
switch (matchResult_1) {
|
|
1777
|
+
case 0:
|
|
1778
|
+
return add(new MapKey(0, [key]), value, state);
|
|
1779
|
+
default:
|
|
1780
|
+
return fail("Map.ofList expects [(string * value)]");
|
|
1781
|
+
}
|
|
1782
|
+
}, empty_1({
|
|
1783
|
+
Compare: (x, y) => (compare(x, y) | 0),
|
|
1784
|
+
}), pairs)]);
|
|
1785
|
+
default:
|
|
1786
|
+
return fail("Map.ofList expects (pairs)");
|
|
1787
|
+
}
|
|
1788
|
+
}, 1);
|
|
1789
|
+
|
|
1790
|
+
const builtinMapFold = new ExternalFunction("Map.fold", scheme("Map.fold"), (ctx, args) => {
|
|
1791
|
+
let matchResult, folder, state, values;
|
|
1792
|
+
if (!isEmpty(args)) {
|
|
1793
|
+
if (!isEmpty(tail_1(args))) {
|
|
1794
|
+
if (!isEmpty(tail_1(tail_1(args)))) {
|
|
1795
|
+
if (head_1(tail_1(tail_1(args))).tag === 8) {
|
|
1796
|
+
if (isEmpty(tail_1(tail_1(tail_1(args))))) {
|
|
1797
|
+
matchResult = 0;
|
|
1798
|
+
folder = head_1(args);
|
|
1799
|
+
state = head_1(tail_1(args));
|
|
1800
|
+
values = head_1(tail_1(tail_1(args))).fields[0];
|
|
1801
|
+
}
|
|
1802
|
+
else {
|
|
1803
|
+
matchResult = 1;
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
else {
|
|
1807
|
+
matchResult = 1;
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
else {
|
|
1811
|
+
matchResult = 1;
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
else {
|
|
1815
|
+
matchResult = 1;
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
else {
|
|
1819
|
+
matchResult = 1;
|
|
1820
|
+
}
|
|
1821
|
+
switch (matchResult) {
|
|
1822
|
+
case 0:
|
|
1823
|
+
return fold_1((acc, key, value) => ctx.Apply(ctx.Apply(ctx.Apply(folder, acc), mapKeyToValue(key)), value), state, values);
|
|
1824
|
+
default:
|
|
1825
|
+
return fail("Map.fold expects (folder, state, values)");
|
|
1826
|
+
}
|
|
1827
|
+
}, 3);
|
|
1828
|
+
|
|
1829
|
+
const builtinMapCount = new ExternalFunction("Map.count", scheme("Map.count"), (_arg, args) => (new Value_1(1, [toInt64_unchecked(fromInt32(FSharpMap__get_Count(expectMap("Map.count", args))))])), 1);
|
|
1830
|
+
|
|
1831
|
+
const builtinMapFilter = new ExternalFunction("Map.filter", scheme("Map.filter"), (ctx, args) => {
|
|
1832
|
+
let matchResult, predicate, values;
|
|
1833
|
+
if (!isEmpty(args)) {
|
|
1834
|
+
if (!isEmpty(tail_1(args))) {
|
|
1835
|
+
if (head_1(tail_1(args)).tag === 8) {
|
|
1836
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1837
|
+
matchResult = 0;
|
|
1838
|
+
predicate = head_1(args);
|
|
1839
|
+
values = head_1(tail_1(args)).fields[0];
|
|
1840
|
+
}
|
|
1841
|
+
else {
|
|
1842
|
+
matchResult = 1;
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
else {
|
|
1846
|
+
matchResult = 1;
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
else {
|
|
1850
|
+
matchResult = 1;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
else {
|
|
1854
|
+
matchResult = 1;
|
|
1855
|
+
}
|
|
1856
|
+
switch (matchResult) {
|
|
1857
|
+
case 0:
|
|
1858
|
+
return new Value_1(8, [fold_1((acc, key, value) => {
|
|
1859
|
+
const matchValue = ctx.Apply(ctx.Apply(predicate, mapKeyToValue(key)), value);
|
|
1860
|
+
if (matchValue.tag === 3) {
|
|
1861
|
+
if (matchValue.fields[0]) {
|
|
1862
|
+
return add(key, value, acc);
|
|
1863
|
+
}
|
|
1864
|
+
else {
|
|
1865
|
+
return acc;
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
else {
|
|
1869
|
+
return fail("Map.filter predicate must return bool");
|
|
1870
|
+
}
|
|
1871
|
+
}, empty_1({
|
|
1872
|
+
Compare: (x, y) => (compare(x, y) | 0),
|
|
1873
|
+
}), values)]);
|
|
1874
|
+
default:
|
|
1875
|
+
return fail("Map.filter expects (predicate, values)");
|
|
1876
|
+
}
|
|
1877
|
+
}, 2);
|
|
1878
|
+
|
|
1879
|
+
const builtinMapChoose = new ExternalFunction("Map.choose", scheme("Map.choose"), (ctx, args) => {
|
|
1880
|
+
let matchResult, chooser, values;
|
|
1881
|
+
if (!isEmpty(args)) {
|
|
1882
|
+
if (!isEmpty(tail_1(args))) {
|
|
1883
|
+
if (head_1(tail_1(args)).tag === 8) {
|
|
1884
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1885
|
+
matchResult = 0;
|
|
1886
|
+
chooser = head_1(args);
|
|
1887
|
+
values = head_1(tail_1(args)).fields[0];
|
|
1888
|
+
}
|
|
1889
|
+
else {
|
|
1890
|
+
matchResult = 1;
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
else {
|
|
1894
|
+
matchResult = 1;
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
else {
|
|
1898
|
+
matchResult = 1;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
else {
|
|
1902
|
+
matchResult = 1;
|
|
1903
|
+
}
|
|
1904
|
+
switch (matchResult) {
|
|
1905
|
+
case 0:
|
|
1906
|
+
return new Value_1(8, [fold_1((acc, key, value) => {
|
|
1907
|
+
const matchValue = ctx.Apply(ctx.Apply(chooser, mapKeyToValue(key)), value);
|
|
1908
|
+
if (matchValue.tag === 9) {
|
|
1909
|
+
if (matchValue.fields[0] == null) {
|
|
1910
|
+
return acc;
|
|
1911
|
+
}
|
|
1912
|
+
else {
|
|
1913
|
+
const chosen = matchValue.fields[0];
|
|
1914
|
+
return add(key, chosen, acc);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
else {
|
|
1918
|
+
return fail("Map.choose chooser must return option");
|
|
1919
|
+
}
|
|
1920
|
+
}, empty_1({
|
|
1921
|
+
Compare: (x, y) => (compare(x, y) | 0),
|
|
1922
|
+
}), values)]);
|
|
1923
|
+
default:
|
|
1924
|
+
return fail("Map.choose expects (chooser, values)");
|
|
1925
|
+
}
|
|
1926
|
+
}, 2);
|
|
1927
|
+
|
|
1928
|
+
const builtinMapMap = new ExternalFunction("Map.map", scheme("Map.map"), (ctx, args) => {
|
|
1929
|
+
let matchResult, mapper, values;
|
|
1930
|
+
if (!isEmpty(args)) {
|
|
1931
|
+
if (!isEmpty(tail_1(args))) {
|
|
1932
|
+
if (head_1(tail_1(args)).tag === 8) {
|
|
1933
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1934
|
+
matchResult = 0;
|
|
1935
|
+
mapper = head_1(args);
|
|
1936
|
+
values = head_1(tail_1(args)).fields[0];
|
|
1937
|
+
}
|
|
1938
|
+
else {
|
|
1939
|
+
matchResult = 1;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
else {
|
|
1943
|
+
matchResult = 1;
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
else {
|
|
1947
|
+
matchResult = 1;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
else {
|
|
1951
|
+
matchResult = 1;
|
|
1952
|
+
}
|
|
1953
|
+
switch (matchResult) {
|
|
1954
|
+
case 0:
|
|
1955
|
+
return new Value_1(8, [fold_1((acc, key, value) => add(key, ctx.Apply(mapper, value), acc), empty_1({
|
|
1956
|
+
Compare: (x, y) => (compare(x, y) | 0),
|
|
1957
|
+
}), values)]);
|
|
1958
|
+
default:
|
|
1959
|
+
return fail("Map.map expects (mapper, values)");
|
|
1960
|
+
}
|
|
1961
|
+
}, 2);
|
|
1962
|
+
|
|
1963
|
+
const builtinMapIter = new ExternalFunction("Map.iter", scheme("Map.iter"), (ctx, args) => {
|
|
1964
|
+
let matchResult, iterator, values;
|
|
1965
|
+
if (!isEmpty(args)) {
|
|
1966
|
+
if (!isEmpty(tail_1(args))) {
|
|
1967
|
+
if (head_1(tail_1(args)).tag === 8) {
|
|
1968
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
1969
|
+
matchResult = 0;
|
|
1970
|
+
iterator = head_1(args);
|
|
1971
|
+
values = head_1(tail_1(args)).fields[0];
|
|
1972
|
+
}
|
|
1973
|
+
else {
|
|
1974
|
+
matchResult = 1;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
else {
|
|
1978
|
+
matchResult = 1;
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
else {
|
|
1982
|
+
matchResult = 1;
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
else {
|
|
1986
|
+
matchResult = 1;
|
|
1987
|
+
}
|
|
1988
|
+
switch (matchResult) {
|
|
1989
|
+
case 0: {
|
|
1990
|
+
iterate_1((key, value) => {
|
|
1991
|
+
ctx.Apply(ctx.Apply(iterator, mapKeyToValue(key)), value);
|
|
1992
|
+
}, values);
|
|
1993
|
+
return new Value_1(0, []);
|
|
1994
|
+
}
|
|
1995
|
+
default:
|
|
1996
|
+
return fail("Map.iter expects (iterator, values)");
|
|
1997
|
+
}
|
|
1998
|
+
}, 2);
|
|
1999
|
+
|
|
2000
|
+
const builtinMapRemove = new ExternalFunction("Map.remove", scheme("Map.remove"), (_arg, args) => {
|
|
2001
|
+
let matchResult, key, values;
|
|
2002
|
+
if (!isEmpty(args)) {
|
|
2003
|
+
if (head_1(args).tag === 4) {
|
|
2004
|
+
if (!isEmpty(tail_1(args))) {
|
|
2005
|
+
if (head_1(tail_1(args)).tag === 8) {
|
|
2006
|
+
if (isEmpty(tail_1(tail_1(args)))) {
|
|
2007
|
+
matchResult = 0;
|
|
2008
|
+
key = head_1(args).fields[0];
|
|
2009
|
+
values = head_1(tail_1(args)).fields[0];
|
|
2010
|
+
}
|
|
2011
|
+
else {
|
|
2012
|
+
matchResult = 1;
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
else {
|
|
2016
|
+
matchResult = 1;
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
else {
|
|
2020
|
+
matchResult = 1;
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
else {
|
|
2024
|
+
matchResult = 1;
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
else {
|
|
2028
|
+
matchResult = 1;
|
|
2029
|
+
}
|
|
2030
|
+
switch (matchResult) {
|
|
2031
|
+
case 0:
|
|
2032
|
+
return new Value_1(8, [FSharpMap__Remove(values, new MapKey(0, [key]))]);
|
|
2033
|
+
default:
|
|
2034
|
+
return fail("Map.remove expects (key, values)");
|
|
2035
|
+
}
|
|
2036
|
+
}, 2);
|
|
2037
|
+
|
|
2038
|
+
export const builtinExterns = ofArray([builtinIgnore, builtinIntTryParse, builtinFloatTryParse, builtinBoolTryParse, builtinIntToString, builtinFloatToString, builtinBoolToString, builtinStringReplace, builtinStringIndexOf, builtinStringToLower, builtinStringToUpper, builtinStringSubstring, builtinStringConcat, builtinStringSplit, builtinStringEndsWith, builtinListEmpty, builtinListMap, builtinListIter, builtinListChoose, builtinListCollect, builtinListExists, builtinListContains, builtinListRev, builtinListDistinct, builtinListFold, builtinListFilter, builtinListLength, builtinListTryFind, builtinListTryGet, builtinListTryItem, builtinListTryHead, builtinListTail, builtinListAppend, builtinOptionDefaultValue, builtinOptionDefaultWith, builtinOptionIsNone, builtinOptionIsSome, builtinOptionMap, builtinMapEmpty, builtinMapTryGet, builtinMapContainsKey, builtinMapAdd, builtinMapOfList, builtinMapFold, builtinMapCount, builtinMapFilter, builtinMapChoose, builtinMapMap, builtinMapIter, builtinMapRemove]);
|
|
2039
|
+
|