@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.
Files changed (79) hide show
  1. package/README.md +5 -0
  2. package/dist/FScript.Language/Ast.js +234 -0
  3. package/dist/FScript.Language/BuiltinFunctions.js +2039 -0
  4. package/dist/FScript.Language/BuiltinSignatures.js +24 -0
  5. package/dist/FScript.Language/BuiltinTypes.js +13 -0
  6. package/dist/FScript.Language/Error.js +74 -0
  7. package/dist/FScript.Language/Eval.js +2404 -0
  8. package/dist/FScript.Language/IncludeResolver.js +806 -0
  9. package/dist/FScript.Language/Lexer.js +1067 -0
  10. package/dist/FScript.Language/Library.js +28 -0
  11. package/dist/FScript.Language/Parser.js +2368 -0
  12. package/dist/FScript.Language/Pretty.js +115 -0
  13. package/dist/FScript.Language/Span.js +33 -0
  14. package/dist/FScript.Language/Token.js +32 -0
  15. package/dist/FScript.Language/TypeInfer.js +2561 -0
  16. package/dist/FScript.Language/Types.js +205 -0
  17. package/dist/FScript.Language/Value.js +91 -0
  18. package/dist/Library.js +732 -0
  19. package/dist/fable_modules/fable-library-js.5.2.0/Array.js +1347 -0
  20. package/dist/fable_modules/fable-library-js.5.2.0/Async.js +134 -0
  21. package/dist/fable_modules/fable-library-js.5.2.0/AsyncBuilder.js +183 -0
  22. package/dist/fable_modules/fable-library-js.5.2.0/BigInt.js +306 -0
  23. package/dist/fable_modules/fable-library-js.5.2.0/BitConverter.js +138 -0
  24. package/dist/fable_modules/fable-library-js.5.2.0/Boolean.js +22 -0
  25. package/dist/fable_modules/fable-library-js.5.2.0/CHANGELOG.md +234 -0
  26. package/dist/fable_modules/fable-library-js.5.2.0/Char.js +202 -0
  27. package/dist/fable_modules/fable-library-js.5.2.0/Choice.js +184 -0
  28. package/dist/fable_modules/fable-library-js.5.2.0/CollectionUtil.js +182 -0
  29. package/dist/fable_modules/fable-library-js.5.2.0/ConditionalWeakTable.js +21 -0
  30. package/dist/fable_modules/fable-library-js.5.2.0/Date.js +841 -0
  31. package/dist/fable_modules/fable-library-js.5.2.0/DateOffset.js +261 -0
  32. package/dist/fable_modules/fable-library-js.5.2.0/DateOnly.js +124 -0
  33. package/dist/fable_modules/fable-library-js.5.2.0/Decimal.js +238 -0
  34. package/dist/fable_modules/fable-library-js.5.2.0/Double.js +47 -0
  35. package/dist/fable_modules/fable-library-js.5.2.0/Encoding.js +185 -0
  36. package/dist/fable_modules/fable-library-js.5.2.0/Event.js +93 -0
  37. package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Collections.js +45 -0
  38. package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Core.CompilerServices.js +27 -0
  39. package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Core.js +156 -0
  40. package/dist/fable_modules/fable-library-js.5.2.0/Global.js +29 -0
  41. package/dist/fable_modules/fable-library-js.5.2.0/Guid.js +161 -0
  42. package/dist/fable_modules/fable-library-js.5.2.0/Int32.js +135 -0
  43. package/dist/fable_modules/fable-library-js.5.2.0/List.js +1323 -0
  44. package/dist/fable_modules/fable-library-js.5.2.0/Long.js +47 -0
  45. package/dist/fable_modules/fable-library-js.5.2.0/MailboxProcessor.js +94 -0
  46. package/dist/fable_modules/fable-library-js.5.2.0/Map.js +1396 -0
  47. package/dist/fable_modules/fable-library-js.5.2.0/MapUtil.js +130 -0
  48. package/dist/fable_modules/fable-library-js.5.2.0/MutableMap.js +339 -0
  49. package/dist/fable_modules/fable-library-js.5.2.0/MutableSet.js +233 -0
  50. package/dist/fable_modules/fable-library-js.5.2.0/Native.js +14 -0
  51. package/dist/fable_modules/fable-library-js.5.2.0/Numeric.js +75 -0
  52. package/dist/fable_modules/fable-library-js.5.2.0/Observable.js +113 -0
  53. package/dist/fable_modules/fable-library-js.5.2.0/Option.js +104 -0
  54. package/dist/fable_modules/fable-library-js.5.2.0/README.md +3 -0
  55. package/dist/fable_modules/fable-library-js.5.2.0/Random.js +172 -0
  56. package/dist/fable_modules/fable-library-js.5.2.0/Range.js +45 -0
  57. package/dist/fable_modules/fable-library-js.5.2.0/Reflection.js +479 -0
  58. package/dist/fable_modules/fable-library-js.5.2.0/RegExp.js +141 -0
  59. package/dist/fable_modules/fable-library-js.5.2.0/Result.js +165 -0
  60. package/dist/fable_modules/fable-library-js.5.2.0/Seq.js +1417 -0
  61. package/dist/fable_modules/fable-library-js.5.2.0/Seq2.js +111 -0
  62. package/dist/fable_modules/fable-library-js.5.2.0/Set.js +1816 -0
  63. package/dist/fable_modules/fable-library-js.5.2.0/String.js +674 -0
  64. package/dist/fable_modules/fable-library-js.5.2.0/System.Collections.Generic.js +333 -0
  65. package/dist/fable_modules/fable-library-js.5.2.0/System.Text.js +200 -0
  66. package/dist/fable_modules/fable-library-js.5.2.0/System.js +283 -0
  67. package/dist/fable_modules/fable-library-js.5.2.0/TimeOnly.js +122 -0
  68. package/dist/fable_modules/fable-library-js.5.2.0/TimeSpan.js +180 -0
  69. package/dist/fable_modules/fable-library-js.5.2.0/Timer.js +67 -0
  70. package/dist/fable_modules/fable-library-js.5.2.0/Types.js +198 -0
  71. package/dist/fable_modules/fable-library-js.5.2.0/Unicode.13.0.0.js +4 -0
  72. package/dist/fable_modules/fable-library-js.5.2.0/Uri.js +165 -0
  73. package/dist/fable_modules/fable-library-js.5.2.0/Util.js +795 -0
  74. package/dist/fable_modules/fable-library-js.5.2.0/big.d.ts +338 -0
  75. package/dist/fable_modules/fable-library-js.5.2.0/lib/big.js +825 -0
  76. package/dist/fable_modules/fable-library-js.5.2.0/package.json +24 -0
  77. package/dist/fable_modules/fable-library-js.5.2.0/quotation.js +618 -0
  78. package/dist/fable_modules/project_cracked.json +1 -0
  79. package/package.json +36 -0
@@ -0,0 +1,732 @@
1
+
2
+ import { Record } from "./fable_modules/fable-library-js.5.2.0/Types.js";
3
+ import { obj_type, class_type, record_type, list_type, string_type } from "./fable_modules/fable-library-js.5.2.0/Reflection.js";
4
+ import { Stmt_$reflection } from "./FScript.Language/Ast.js";
5
+ import { ExternalFunction, MapKey, Value, Value_$reflection, ExternalFunction_$reflection } from "./FScript.Language/Value.js";
6
+ import { inferProgramWithExterns, TypedStmt_$reflection } from "./FScript.Language/TypeInfer.js";
7
+ import { Scheme, Type, Types_typeToString, Type_$reflection } from "./FScript.Language/Types.js";
8
+ import { map, defaultArg, value as value_18, some } from "./fable_modules/fable-library-js.5.2.0/Option.js";
9
+ import { stringHash, compare, comparePrimitives, createObj, Exception } from "./fable_modules/fable-library-js.5.2.0/Util.js";
10
+ import { concat } from "./fable_modules/fable-library-js.5.2.0/String.js";
11
+ import { EvalError$, EvalException, TypeException, ParseException } from "./FScript.Language/Error.js";
12
+ import { toInt32_unchecked, fromFloat64, toInt64_unchecked } from "./fable_modules/fable-library-js.5.2.0/BigInt.js";
13
+ import { parse as parse_1 } from "./fable_modules/fable-library-js.5.2.0/Long.js";
14
+ import { parse as parse_2 } from "./fable_modules/fable-library-js.5.2.0/Int32.js";
15
+ import { append, choose, sort, filter, exists, singleton, collect, empty, ofArray, length, map as map_1, toArray } from "./fable_modules/fable-library-js.5.2.0/List.js";
16
+ import { FSharpMap__get_Item, FSharpMap__TryFind, ofList, toList } from "./fable_modules/fable-library-js.5.2.0/Map.js";
17
+ import { parseProgramFromSourceWithIncludesResolver } from "./FScript.Language/IncludeResolver.js";
18
+ import { invokeValue, evalProgramWithExterns, evalProgramWithExternsState } from "./FScript.Language/Eval.js";
19
+ import { List_distinct } from "./fable_modules/fable-library-js.5.2.0/Seq2.js";
20
+ import { FSharpSet__Contains, ofList as ofList_1 } from "./fable_modules/fable-library-js.5.2.0/Set.js";
21
+ import { valueToString } from "./FScript.Language/Pretty.js";
22
+ import { Span, Position } from "./FScript.Language/Span.js";
23
+
24
+ export class ParsedProgramHandle extends Record {
25
+ constructor(kind, program, externs) {
26
+ super();
27
+ this.kind = kind;
28
+ this.program = program;
29
+ this.externs = externs;
30
+ }
31
+ }
32
+
33
+ export function ParsedProgramHandle_$reflection() {
34
+ return record_type("FScript.JavaScript.ParsedProgramHandle", [], ParsedProgramHandle, () => [["kind", string_type], ["program", list_type(Stmt_$reflection())], ["externs", list_type(ExternalFunction_$reflection())]]);
35
+ }
36
+
37
+ export class TypedProgramHandle extends Record {
38
+ constructor(kind, typedProgram, externs) {
39
+ super();
40
+ this.kind = kind;
41
+ this.typedProgram = typedProgram;
42
+ this.externs = externs;
43
+ }
44
+ }
45
+
46
+ export function TypedProgramHandle_$reflection() {
47
+ return record_type("FScript.JavaScript.TypedProgramHandle", [], TypedProgramHandle, () => [["kind", string_type], ["typedProgram", list_type(TypedStmt_$reflection())], ["externs", list_type(ExternalFunction_$reflection())]]);
48
+ }
49
+
50
+ export class LoadedScriptHandle extends Record {
51
+ constructor(kind, typeDefs, env, exportedFunctionNames, exportedFunctionSet, exportedFunctions, exportedValueNames, exportedValueSet, exportedValues, lastValue, externs) {
52
+ super();
53
+ this.kind = kind;
54
+ this.typeDefs = typeDefs;
55
+ this.env = env;
56
+ this.exportedFunctionNames = exportedFunctionNames;
57
+ this.exportedFunctionSet = exportedFunctionSet;
58
+ this.exportedFunctions = exportedFunctions;
59
+ this.exportedValueNames = exportedValueNames;
60
+ this.exportedValueSet = exportedValueSet;
61
+ this.exportedValues = exportedValues;
62
+ this.lastValue = lastValue;
63
+ this.externs = externs;
64
+ }
65
+ }
66
+
67
+ export function LoadedScriptHandle_$reflection() {
68
+ return record_type("FScript.JavaScript.LoadedScriptHandle", [], LoadedScriptHandle, () => [["kind", string_type], ["typeDefs", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, Type_$reflection()])], ["env", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, Value_$reflection()])], ["exportedFunctionNames", list_type(string_type)], ["exportedFunctionSet", class_type("Microsoft.FSharp.Collections.FSharpSet`1", [string_type])], ["exportedFunctions", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, Value_$reflection()])], ["exportedValueNames", list_type(string_type)], ["exportedValueSet", class_type("Microsoft.FSharp.Collections.FSharpSet`1", [string_type])], ["exportedValues", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, Value_$reflection()])], ["lastValue", Value_$reflection()], ["externs", list_type(ExternalFunction_$reflection())]]);
69
+ }
70
+
71
+ export class SessionHandle extends Record {
72
+ constructor(kind, retainedProgram, options, externs) {
73
+ super();
74
+ this.kind = kind;
75
+ this.retainedProgram = retainedProgram;
76
+ this.options = options;
77
+ this.externs = externs;
78
+ }
79
+ }
80
+
81
+ export function SessionHandle_$reflection() {
82
+ return record_type("FScript.JavaScript.SessionHandle", [], SessionHandle, () => [["kind", string_type], ["retainedProgram", list_type(Stmt_$reflection())], ["options", obj_type], ["externs", list_type(ExternalFunction_$reflection())]]);
83
+ }
84
+
85
+ function tryGetProperty(name, value) {
86
+ if (typeof value === 'undefined' || value === null) {
87
+ return undefined;
88
+ }
89
+ else {
90
+ const property = value[name];
91
+ if (typeof property === 'undefined' || property === null) {
92
+ return undefined;
93
+ }
94
+ else {
95
+ return some(property);
96
+ }
97
+ }
98
+ }
99
+
100
+ function getRequiredProperty(name, value) {
101
+ const matchValue = tryGetProperty(name, value);
102
+ if (matchValue == null) {
103
+ throw new Exception(concat("Missing required property \'", name, "\'"));
104
+ }
105
+ else {
106
+ return value_18(matchValue);
107
+ }
108
+ }
109
+
110
+ function isFScriptError(value) {
111
+ const matchValue = tryGetProperty("kind", value);
112
+ if (matchValue == null) {
113
+ return false;
114
+ }
115
+ else {
116
+ return value_18(matchValue) === "fscript-error";
117
+ }
118
+ }
119
+
120
+ function positionToObj(position) {
121
+ return {
122
+ file: defaultArg(map((value) => value, position.File), null),
123
+ line: position.Line,
124
+ column: position.Column,
125
+ };
126
+ }
127
+
128
+ function spanToObj(span) {
129
+ return {
130
+ start: positionToObj(span.Start),
131
+ end: positionToObj(span.End),
132
+ };
133
+ }
134
+
135
+ function throwLanguageError(phase, message, span) {
136
+ return (() => { const e = new Error({
137
+ kind: "fscript-error",
138
+ phase: phase,
139
+ message: message,
140
+ span: spanToObj(span),
141
+ }.message); Object.assign(e, {
142
+ kind: "fscript-error",
143
+ phase: phase,
144
+ message: message,
145
+ span: spanToObj(span),
146
+ }); throw e; })();
147
+ }
148
+
149
+ function withStructuredErrors(work) {
150
+ try {
151
+ return work();
152
+ }
153
+ catch (matchValue) {
154
+ if (matchValue instanceof ParseException) {
155
+ const error = matchValue.Data0;
156
+ return throwLanguageError("parse", error.Message, error.Span);
157
+ }
158
+ else if (matchValue instanceof TypeException) {
159
+ const error_1 = matchValue.Data0;
160
+ return throwLanguageError("type", error_1.Message, error_1.Span);
161
+ }
162
+ else if (matchValue instanceof EvalException) {
163
+ const error_2 = matchValue.Data0;
164
+ return throwLanguageError("eval", error_2.Message, error_2.Span);
165
+ }
166
+ else {
167
+ const ex = matchValue;
168
+ const error_3 = ex;
169
+ return isFScriptError(error_3) ? ((() => { throw error_3; })()) : ((() => { const e = new Error({
170
+ kind: "fscript-error",
171
+ phase: "host",
172
+ message: ex.message,
173
+ }.message); Object.assign(e, {
174
+ kind: "fscript-error",
175
+ phase: "host",
176
+ message: ex.message,
177
+ }); throw e; })());
178
+ }
179
+ }
180
+ }
181
+
182
+ function int64FromObj(value) {
183
+ const matchValue = typeof value;
184
+ switch (matchValue) {
185
+ case "bigint":
186
+ return value;
187
+ case "number": {
188
+ if (!(Number.isSafeInteger(value))) {
189
+ throw new Exception("Expected a safe integer");
190
+ }
191
+ return toInt64_unchecked(fromFloat64(value));
192
+ }
193
+ case "string":
194
+ return toInt64_unchecked(parse_1(value, 511, false, 64));
195
+ default:
196
+ throw new Exception("Expected int value");
197
+ }
198
+ }
199
+
200
+ function intFromObj(value) {
201
+ const matchValue = typeof value;
202
+ switch (matchValue) {
203
+ case "number":
204
+ return ~~value | 0;
205
+ case "bigint":
206
+ return ~~toInt32_unchecked(value) | 0;
207
+ case "string":
208
+ return parse_2(value, 511, false, 32) | 0;
209
+ default:
210
+ throw new Exception("Expected numeric value");
211
+ }
212
+ }
213
+
214
+ function mapKeyToTagged(key) {
215
+ if (key.tag === 1) {
216
+ return {
217
+ kind: "int",
218
+ value: key.fields[0],
219
+ };
220
+ }
221
+ else {
222
+ return {
223
+ kind: "string",
224
+ value: key.fields[0],
225
+ };
226
+ }
227
+ }
228
+
229
+ function valueToTagged(value) {
230
+ switch (value.tag) {
231
+ case 1:
232
+ return {
233
+ kind: "int",
234
+ value: value.fields[0],
235
+ };
236
+ case 2:
237
+ return {
238
+ kind: "float",
239
+ value: value.fields[0],
240
+ };
241
+ case 3:
242
+ return {
243
+ kind: "bool",
244
+ value: value.fields[0],
245
+ };
246
+ case 4:
247
+ return {
248
+ kind: "string",
249
+ value: value.fields[0],
250
+ };
251
+ case 5:
252
+ return {
253
+ kind: "list",
254
+ values: toArray(map_1(valueToTagged, value.fields[0])),
255
+ };
256
+ case 6:
257
+ return {
258
+ kind: "tuple",
259
+ values: toArray(map_1(valueToTagged, value.fields[0])),
260
+ };
261
+ case 7:
262
+ return {
263
+ kind: "record",
264
+ fields: createObj(map_1((tupledArg) => [tupledArg[0], valueToTagged(tupledArg[1])], toList(value.fields[0]))),
265
+ };
266
+ case 8:
267
+ return {
268
+ kind: "map",
269
+ entries: toArray(map_1((tupledArg_1) => ({
270
+ key: mapKeyToTagged(tupledArg_1[0]),
271
+ value: valueToTagged(tupledArg_1[1]),
272
+ }), toList(value.fields[0]))),
273
+ };
274
+ case 9:
275
+ if (value.fields[0] != null) {
276
+ const value_7 = value.fields[0];
277
+ return {
278
+ kind: "option",
279
+ value: valueToTagged(value_7),
280
+ };
281
+ }
282
+ else {
283
+ return {
284
+ kind: "option",
285
+ value: null,
286
+ };
287
+ }
288
+ case 10:
289
+ return {
290
+ kind: "union",
291
+ typeName: value.fields[0],
292
+ caseName: value.fields[1],
293
+ value: defaultArg(map(valueToTagged, value.fields[2]), null),
294
+ };
295
+ case 11:
296
+ return {
297
+ kind: "opaque",
298
+ valueType: "union-constructor",
299
+ typeName: value.fields[0],
300
+ caseName: value.fields[1],
301
+ };
302
+ case 12:
303
+ return {
304
+ kind: "type",
305
+ name: Types_typeToString(value.fields[0]),
306
+ };
307
+ case 13:
308
+ return {
309
+ kind: "opaque",
310
+ valueType: "task",
311
+ };
312
+ case 14:
313
+ return {
314
+ kind: "opaque",
315
+ valueType: "function",
316
+ };
317
+ case 15:
318
+ return {
319
+ kind: "opaque",
320
+ valueType: "external",
321
+ name: value.fields[0].Name,
322
+ applied: length(value.fields[1]),
323
+ arity: value.fields[0].Arity,
324
+ };
325
+ default:
326
+ return {
327
+ kind: "unit",
328
+ };
329
+ }
330
+ }
331
+
332
+ function valueFromJs(value) {
333
+ let optionValue, payloadValue, payloadValue_1, payloadValue_2;
334
+ if (typeof value === 'undefined' || value === null) {
335
+ return new Value(0, []);
336
+ }
337
+ else if (Array.isArray(value)) {
338
+ return new Value(5, [map_1(valueFromJs, ofArray(value))]);
339
+ }
340
+ else {
341
+ const matchValue = typeof value;
342
+ switch (matchValue) {
343
+ case "boolean":
344
+ return new Value(3, [value]);
345
+ case "bigint":
346
+ return new Value(1, [value]);
347
+ case "number":
348
+ if ((Number.isInteger(value)) && (Number.isSafeInteger(value))) {
349
+ return new Value(1, [toInt64_unchecked(fromFloat64(value))]);
350
+ }
351
+ else {
352
+ return new Value(2, [value]);
353
+ }
354
+ case "string":
355
+ return new Value(4, [value]);
356
+ case "object": {
357
+ const matchValue_1 = tryGetProperty("kind", value);
358
+ if (matchValue_1 == null) {
359
+ return new Value(7, [ofList(map_1((name_1) => [name_1, valueFromJs(value[name_1])], ofArray(Object.keys(value))), {
360
+ Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
361
+ })]);
362
+ }
363
+ else {
364
+ const matchValue_2 = value_18(matchValue_1);
365
+ switch (matchValue_2) {
366
+ case "unit":
367
+ return new Value(0, []);
368
+ case "int":
369
+ return new Value(1, [int64FromObj(getRequiredProperty("value", value))]);
370
+ case "float":
371
+ return new Value(2, [getRequiredProperty("value", value)]);
372
+ case "bool":
373
+ return new Value(3, [getRequiredProperty("value", value)]);
374
+ case "string":
375
+ return new Value(4, [getRequiredProperty("value", value)]);
376
+ case "list":
377
+ return new Value(5, [map_1(valueFromJs, ofArray(getRequiredProperty("values", value)))]);
378
+ case "tuple":
379
+ return new Value(6, [map_1(valueFromJs, ofArray(getRequiredProperty("values", value)))]);
380
+ case "record": {
381
+ const fields = getRequiredProperty("fields", value);
382
+ return new Value(7, [ofList(map_1((name) => [name, valueFromJs(fields[name])], ofArray(Object.keys(fields))), {
383
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
384
+ })]);
385
+ }
386
+ case "map":
387
+ return new Value(8, [ofList(map_1((entry) => {
388
+ const keyValue = valueFromJs(getRequiredProperty("key", entry));
389
+ return [(keyValue.tag === 4) ? (new MapKey(0, [keyValue.fields[0]])) : ((keyValue.tag === 1) ? (new MapKey(1, [keyValue.fields[0]])) : (() => {
390
+ throw new Exception("Map key must be string or int");
391
+ })()), valueFromJs(getRequiredProperty("value", entry))];
392
+ }, ofArray(getRequiredProperty("entries", value))), {
393
+ Compare: (x_1, y_1) => (compare(x_1, y_1) | 0),
394
+ })]);
395
+ case "option": {
396
+ const matchValue_3 = tryGetProperty("value", value);
397
+ if (matchValue_3 != null) {
398
+ if ((optionValue = value_18(matchValue_3), typeof optionValue === 'undefined' || optionValue === null)) {
399
+ const optionValue_1 = value_18(matchValue_3);
400
+ return new Value(9, [undefined]);
401
+ }
402
+ else {
403
+ const optionValue_2 = value_18(matchValue_3);
404
+ return new Value(9, [valueFromJs(optionValue_2)]);
405
+ }
406
+ }
407
+ else {
408
+ return new Value(9, [undefined]);
409
+ }
410
+ }
411
+ case "union": {
412
+ let payload;
413
+ const matchValue_4 = tryGetProperty("value", value);
414
+ payload = ((matchValue_4 != null) ? (((payloadValue = value_18(matchValue_4), typeof payloadValue === 'undefined' || payloadValue === null)) ? ((payloadValue_1 = value_18(matchValue_4), undefined)) : ((payloadValue_2 = value_18(matchValue_4), valueFromJs(payloadValue_2)))) : undefined);
415
+ return new Value(10, [getRequiredProperty("typeName", value), getRequiredProperty("caseName", value), payload]);
416
+ }
417
+ default:
418
+ throw new Exception(concat("Unsupported FScript tagged value kind \'", matchValue_2, "\'"));
419
+ }
420
+ }
421
+ }
422
+ default:
423
+ throw new Exception(concat("Unsupported JavaScript value type \'", matchValue, "\'"));
424
+ }
425
+ }
426
+ }
427
+
428
+ function externsFromArray(value) {
429
+ if (typeof value === 'undefined' || value === null) {
430
+ return empty();
431
+ }
432
+ else {
433
+ return ofArray(value);
434
+ }
435
+ }
436
+
437
+ function externsFromOptions(options) {
438
+ const matchValue = tryGetProperty("externs", options);
439
+ if (matchValue == null) {
440
+ return empty();
441
+ }
442
+ else {
443
+ return externsFromArray(value_18(matchValue));
444
+ }
445
+ }
446
+
447
+ function optionString(name, fallback, options) {
448
+ const matchValue = tryGetProperty(name, options);
449
+ if (matchValue == null) {
450
+ return fallback;
451
+ }
452
+ else {
453
+ return value_18(matchValue);
454
+ }
455
+ }
456
+
457
+ function resolverFromOptions(options) {
458
+ const sourceMap = tryGetProperty("sources", options);
459
+ const callback = tryGetProperty("resolveImport", options);
460
+ return (path) => {
461
+ if (callback == null) {
462
+ if (sourceMap == null) {
463
+ return undefined;
464
+ }
465
+ else {
466
+ const sources = value_18(sourceMap);
467
+ const value_1 = sources[path];
468
+ return (typeof value_1 === 'undefined' || value_1 === null) ? undefined : value_1;
469
+ }
470
+ }
471
+ else {
472
+ const resolve = value_18(callback);
473
+ const value = resolve(path);
474
+ return (typeof value === 'undefined' || value === null) ? undefined : value;
475
+ }
476
+ };
477
+ }
478
+
479
+ function parseSource(source, options, externs) {
480
+ return new ParsedProgramHandle("program", parseProgramFromSourceWithIncludesResolver(optionString("rootDirectory", "/", options), optionString("entryFile", "/main.fss", options), source, resolverFromOptions(options)), externs);
481
+ }
482
+
483
+ function isCallable(value) {
484
+ switch (value.tag) {
485
+ case 14:
486
+ case 15:
487
+ case 11:
488
+ return true;
489
+ default:
490
+ return false;
491
+ }
492
+ }
493
+
494
+ function declaredExportedNames(program) {
495
+ return collect((_arg) => {
496
+ let matchResult, isExported_2, name_1, bindings_1, isExported_3;
497
+ switch (_arg.tag) {
498
+ case 1: {
499
+ if (_arg.fields[4]) {
500
+ matchResult = 0;
501
+ isExported_2 = _arg.fields[4];
502
+ name_1 = _arg.fields[0];
503
+ }
504
+ else {
505
+ matchResult = 2;
506
+ }
507
+ break;
508
+ }
509
+ case 3: {
510
+ if (_arg.fields[1]) {
511
+ matchResult = 1;
512
+ bindings_1 = _arg.fields[0];
513
+ isExported_3 = _arg.fields[1];
514
+ }
515
+ else {
516
+ matchResult = 2;
517
+ }
518
+ break;
519
+ }
520
+ default:
521
+ matchResult = 2;
522
+ }
523
+ switch (matchResult) {
524
+ case 0:
525
+ return singleton(name_1);
526
+ case 1:
527
+ return map_1((tupledArg) => tupledArg[0], bindings_1);
528
+ default:
529
+ return empty();
530
+ }
531
+ }, program);
532
+ }
533
+
534
+ function hasExpression(statements) {
535
+ return exists((_arg) => {
536
+ if (_arg.tag === 5) {
537
+ return true;
538
+ }
539
+ else {
540
+ return false;
541
+ }
542
+ }, statements);
543
+ }
544
+
545
+ function retainedStatements(statements) {
546
+ return filter((_arg) => {
547
+ if (_arg.tag === 5) {
548
+ return false;
549
+ }
550
+ else {
551
+ return true;
552
+ }
553
+ }, statements);
554
+ }
555
+
556
+ function loadTyped(typed, externs) {
557
+ const state = evalProgramWithExternsState(externs, typed);
558
+ const exportedNames = sort(List_distinct(declaredExportedNames(typed), {
559
+ Equals: (x, y) => (x === y),
560
+ GetHashCode: (x) => (stringHash(x) | 0),
561
+ }), {
562
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
563
+ });
564
+ const functionNames = filter((name) => {
565
+ const matchValue = FSharpMap__TryFind(state.Env, name);
566
+ if (matchValue == null) {
567
+ return false;
568
+ }
569
+ else {
570
+ return isCallable(matchValue);
571
+ }
572
+ }, exportedNames);
573
+ const functionSet = ofList_1(functionNames, {
574
+ Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
575
+ });
576
+ const functions = ofList(choose((name_1) => map((value_1) => [name_1, value_1], FSharpMap__TryFind(state.Env, name_1)), functionNames), {
577
+ Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
578
+ });
579
+ const valueNames = filter((name_2) => {
580
+ const matchValue_1 = FSharpMap__TryFind(state.Env, name_2);
581
+ if (matchValue_1 == null) {
582
+ return false;
583
+ }
584
+ else {
585
+ return !isCallable(matchValue_1);
586
+ }
587
+ }, exportedNames);
588
+ return new LoadedScriptHandle("loaded", state.TypeDefs, state.Env, functionNames, functionSet, functions, valueNames, ofList_1(valueNames, {
589
+ Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
590
+ }), ofList(choose((name_3) => map((value_3) => [name_3, value_3], FSharpMap__TryFind(state.Env, name_3)), valueNames), {
591
+ Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
592
+ }), state.LastValue, externs);
593
+ }
594
+
595
+ export function parse(source, options) {
596
+ return withStructuredErrors(() => parseSource(source, options, externsFromOptions(options)));
597
+ }
598
+
599
+ export function infer(program, externs) {
600
+ return withStructuredErrors(() => {
601
+ const parsed = program;
602
+ const externs_1 = (typeof externs === 'undefined' || externs === null) ? parsed.externs : externsFromArray(externs);
603
+ return new TypedProgramHandle("typedProgram", inferProgramWithExterns(externs_1, parsed.program), externs_1);
604
+ });
605
+ }
606
+
607
+ export function evaluate(typedProgram, externs) {
608
+ return withStructuredErrors(() => {
609
+ const typed = typedProgram;
610
+ return valueToTagged(evalProgramWithExterns((typeof externs === 'undefined' || externs === null) ? typed.externs : externsFromArray(externs), typed.typedProgram));
611
+ });
612
+ }
613
+
614
+ export function load(source, options) {
615
+ return withStructuredErrors(() => {
616
+ const externs = externsFromOptions(options);
617
+ return loadTyped(inferProgramWithExterns(externs, parseSource(source, options, externs).program), externs);
618
+ });
619
+ }
620
+
621
+ export function run(source, options) {
622
+ return withStructuredErrors(() => valueToTagged(load(source, options).lastValue));
623
+ }
624
+
625
+ export function createSession(options) {
626
+ return withStructuredErrors(() => (new SessionHandle("session", empty(), options, externsFromOptions(options))));
627
+ }
628
+
629
+ export function resetSession(session) {
630
+ return withStructuredErrors(() => {
631
+ const session_1 = session;
632
+ session_1.retainedProgram = empty();
633
+ return session_1;
634
+ });
635
+ }
636
+
637
+ export function submit(session, source) {
638
+ return withStructuredErrors(() => {
639
+ const session_1 = session;
640
+ const parsed = parseSource(source, session_1.options, session_1.externs);
641
+ const state = evalProgramWithExternsState(session_1.externs, inferProgramWithExterns(session_1.externs, append(session_1.retainedProgram, parsed.program)));
642
+ const submittedHasExpression = hasExpression(parsed.program);
643
+ session_1.retainedProgram = append(session_1.retainedProgram, retainedStatements(parsed.program));
644
+ return {
645
+ kind: "session-result",
646
+ hasValue: submittedHasExpression,
647
+ value: submittedHasExpression ? valueToTagged(state.LastValue) : (null),
648
+ text: submittedHasExpression ? valueToString(state.LastValue) : "",
649
+ retainedCount: length(session_1.retainedProgram),
650
+ };
651
+ });
652
+ }
653
+
654
+ export function listFunctions(loaded) {
655
+ return withStructuredErrors(() => toArray(loaded.exportedFunctionNames));
656
+ }
657
+
658
+ export function listValues(loaded) {
659
+ return withStructuredErrors(() => toArray(loaded.exportedValueNames));
660
+ }
661
+
662
+ export function getValue(loaded, name) {
663
+ return withStructuredErrors(() => {
664
+ const loaded_1 = loaded;
665
+ if (!FSharpSet__Contains(loaded_1.exportedValueSet, name)) {
666
+ throw new EvalException(new EvalError$(concat("Unknown exported value \'", name, "\'"), new Span(new Position(undefined, 0, 0), new Position(undefined, 0, 0))));
667
+ }
668
+ return valueToTagged(FSharpMap__get_Item(loaded_1.exportedValues, name));
669
+ });
670
+ }
671
+
672
+ export function invoke(loaded, name, args) {
673
+ return withStructuredErrors(() => {
674
+ const loaded_1 = loaded;
675
+ if (!FSharpSet__Contains(loaded_1.exportedFunctionSet, name)) {
676
+ if (FSharpSet__Contains(loaded_1.exportedValueSet, name)) {
677
+ throw new EvalException(new EvalError$(concat("\'", name, "\' is a value and cannot be invoked"), new Span(new Position(undefined, 0, 0), new Position(undefined, 0, 0))));
678
+ }
679
+ else {
680
+ throw new EvalException(new EvalError$(concat("Unknown exported function \'", name, "\'"), new Span(new Position(undefined, 0, 0), new Position(undefined, 0, 0))));
681
+ }
682
+ }
683
+ return valueToTagged(invokeValue(loaded_1.typeDefs, FSharpMap__get_Item(loaded_1.exportedFunctions, name), (typeof args === 'undefined' || args === null) ? empty() : map_1(valueFromJs, ofArray(args))));
684
+ });
685
+ }
686
+
687
+ export function formatValue(value) {
688
+ return withStructuredErrors(() => valueToString(valueFromJs(value)));
689
+ }
690
+
691
+ export function toJs(value) {
692
+ return withStructuredErrors(() => valueToTagged(value));
693
+ }
694
+
695
+ export function fromJs(value, _expectedType) {
696
+ return withStructuredErrors(() => valueFromJs(value));
697
+ }
698
+
699
+ export const T = {
700
+ unit: new Type(0, []),
701
+ int: new Type(1, []),
702
+ float: new Type(2, []),
703
+ bool: new Type(3, []),
704
+ string: new Type(4, []),
705
+ typeToken: new Type(14, []),
706
+ var: (value) => (new Type(15, [intFromObj(value)])),
707
+ list: (value_1) => (new Type(5, [value_1])),
708
+ task: (value_2) => (new Type(6, [value_2])),
709
+ option: (value_3) => (new Type(10, [value_3])),
710
+ map: (value_4) => (new Type(9, [new Type(4, []), value_4])),
711
+ tuple: (values) => (new Type(7, [map_1((value_6) => value_6, ofArray(values))])),
712
+ record: (fields) => (new Type(8, [ofList(map_1((name) => [name, fields[name]], ofArray(Object.keys(fields))), {
713
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
714
+ })])),
715
+ func: (left, right) => (new Type(11, [left, right])),
716
+ scheme: (value_8) => (new Scheme(empty(), value_8)),
717
+ forall: (vars, value_9) => (new Scheme(map_1((value_11) => (intFromObj(value_11) | 0), ofArray(vars)), value_9)),
718
+ };
719
+
720
+ export function extern(definition) {
721
+ return withStructuredErrors(() => {
722
+ const name = getRequiredProperty("name", definition);
723
+ const arity = intFromObj(getRequiredProperty("arity", definition)) | 0;
724
+ const scheme = getRequiredProperty("scheme", definition);
725
+ const invoke_1 = getRequiredProperty("invoke", definition);
726
+ return new ExternalFunction(name, scheme, (_arg, args) => {
727
+ let _arg_1;
728
+ return valueFromJs((_arg_1 = toArray(map_1(valueToTagged, args)), invoke_1(_arg_1)));
729
+ }, arity);
730
+ });
731
+ }
732
+