@magnusopera/fscript 0.81.7 → 0.82.1
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import { toString, FSharpRef, Record } from "../fable_modules/fable-library-js.5.13.0/Types.js";
|
|
3
|
-
import { option_type, array_type, obj_type, record_type, class_type, string_type } from "../fable_modules/fable-library-js.5.13.0/Reflection.js";
|
|
3
|
+
import { option_type, array_type, bool_type, obj_type, record_type, class_type, string_type } from "../fable_modules/fable-library-js.5.13.0/Reflection.js";
|
|
4
4
|
import { Type, Types_typeToString, Type_$reflection } from "./Types.js";
|
|
5
5
|
import { ExternalCallContext, MapKey, Value, TaskHandle_$reflection, Value_$reflection } from "./Value.js";
|
|
6
6
|
import { EvalException, EvalError$, EvalError$_$reflection } from "./Error.js";
|
|
@@ -34,16 +34,17 @@ export function ProgramState_$reflection() {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
class RuntimeState extends Record {
|
|
37
|
-
constructor(SyncRoot, PendingTasks, BackgroundFailure) {
|
|
37
|
+
constructor(SyncRoot, Active, PendingTasks, BackgroundFailure) {
|
|
38
38
|
super();
|
|
39
39
|
this.SyncRoot = SyncRoot;
|
|
40
|
+
this.Active = Active;
|
|
40
41
|
this.PendingTasks = PendingTasks;
|
|
41
42
|
this.BackgroundFailure = BackgroundFailure;
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
function RuntimeState_$reflection() {
|
|
46
|
-
return record_type("FScript.Language.Eval.RuntimeState", [], RuntimeState, () => [["SyncRoot", obj_type], ["PendingTasks", array_type(TaskHandle_$reflection())], ["BackgroundFailure", option_type(EvalError$_$reflection())]]);
|
|
47
|
+
return record_type("FScript.Language.Eval.RuntimeState", [], RuntimeState, () => [["SyncRoot", obj_type], ["Active", bool_type], ["PendingTasks", array_type(TaskHandle_$reflection())], ["BackgroundFailure", option_type(EvalError$_$reflection())]]);
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
const unknownSpan = new Span(new Position(undefined, 0, 0), new Position(undefined, 0, 0));
|
|
@@ -1632,7 +1633,7 @@ function patternMatch(typeDefs_mut, pat_mut, value_mut) {
|
|
|
1632
1633
|
}
|
|
1633
1634
|
|
|
1634
1635
|
function createExternContext(runtime, typeDefs, span) {
|
|
1635
|
-
return new ExternalCallContext((fnValue, argValue) => applyFunctionValue(runtime, evalExpr, typeDefs, span, fnValue, argValue), (thunk) => spawnTaskValue(runtime, typeDefs, thunk), (taskValue) => awaitTaskValue(runtime, taskValue), () => {
|
|
1636
|
+
return new ExternalCallContext(runtime.SyncRoot, () => withRuntimeLock(runtime, () => runtime.Active), (fnValue, argValue) => applyFunctionValue(runtime, evalExpr, typeDefs, span, fnValue, argValue), (thunk) => spawnTaskValue(runtime, typeDefs, thunk), (taskValue) => awaitTaskValue(runtime, taskValue), () => {
|
|
1636
1637
|
raiseIfBackgroundFailed(runtime);
|
|
1637
1638
|
});
|
|
1638
1639
|
}
|
|
@@ -2497,7 +2498,7 @@ function evalExpr(runtime_mut, typeDefs_mut, env_mut, expr_mut) {
|
|
|
2497
2498
|
}
|
|
2498
2499
|
|
|
2499
2500
|
export function invokeValue(typeDefs, fnValue, args) {
|
|
2500
|
-
const runtime = new RuntimeState({}, [], undefined);
|
|
2501
|
+
const runtime = new RuntimeState({}, true, [], undefined);
|
|
2501
2502
|
const applyMany = (currentValue_mut, remainingArgs_mut) => {
|
|
2502
2503
|
applyMany:
|
|
2503
2504
|
while (true) {
|
|
@@ -2569,7 +2570,14 @@ export function invokeValue(typeDefs, fnValue, args) {
|
|
|
2569
2570
|
break;
|
|
2570
2571
|
}
|
|
2571
2572
|
};
|
|
2572
|
-
|
|
2573
|
+
try {
|
|
2574
|
+
return applyMany(fnValue, args);
|
|
2575
|
+
}
|
|
2576
|
+
finally {
|
|
2577
|
+
withRuntimeLock(runtime, () => {
|
|
2578
|
+
runtime.Active = false;
|
|
2579
|
+
});
|
|
2580
|
+
}
|
|
2573
2581
|
}
|
|
2574
2582
|
|
|
2575
2583
|
function validateTopLevelBindings(program) {
|
|
@@ -2711,12 +2719,20 @@ function evaluateStatements(runtime, typeDefs, initialEnv, program) {
|
|
|
2711
2719
|
}
|
|
2712
2720
|
|
|
2713
2721
|
export function evalProgramFromState(state, program) {
|
|
2714
|
-
|
|
2722
|
+
const runtime = new RuntimeState({}, true, [], undefined);
|
|
2723
|
+
try {
|
|
2724
|
+
return evaluateStatements(runtime, state.TypeDefs, state.Env, program);
|
|
2725
|
+
}
|
|
2726
|
+
finally {
|
|
2727
|
+
withRuntimeLock(runtime, () => {
|
|
2728
|
+
runtime.Active = false;
|
|
2729
|
+
});
|
|
2730
|
+
}
|
|
2715
2731
|
}
|
|
2716
2732
|
|
|
2717
2733
|
export function evalProgramWithRegistrationState(registration, program) {
|
|
2718
2734
|
const externs = registration.Functions;
|
|
2719
|
-
const runtime = new RuntimeState({}, [], undefined);
|
|
2735
|
+
const runtime = new RuntimeState({}, true, [], undefined);
|
|
2720
2736
|
const option_1 = tryFind_1((ext) => contains(ext.Name, builtinReservedNames), externs);
|
|
2721
2737
|
if (option_1 != null) {
|
|
2722
2738
|
throw new EvalException(new EvalError$(concat("Host extern \'", option_1.Name, "\' collides with reserved stdlib symbol"), unknownSpan));
|
|
@@ -2841,20 +2857,27 @@ export function evalProgramWithRegistrationState(registration, program) {
|
|
|
2841
2857
|
return ofArray([[caseName_3, value_1], [concat(descriptor.Name, ".", caseName_3), value_1]]);
|
|
2842
2858
|
}, toList(descriptor.Cases)), registration.Unions), constructorValues);
|
|
2843
2859
|
const externContext = createExternContext(runtime, typeDefs_1, unknownSpan);
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2860
|
+
try {
|
|
2861
|
+
let env;
|
|
2862
|
+
const list_15 = append(builtinExterns, externs);
|
|
2863
|
+
env = fold_1((acc_1, ext_2) => {
|
|
2864
|
+
if (ext_2.Arity === 0) {
|
|
2865
|
+
return FSharpMap__Add(acc_1, ext_2.Name, invoke(typeDefs_1, ext_2, externContext, empty()));
|
|
2866
|
+
}
|
|
2867
|
+
else {
|
|
2868
|
+
return FSharpMap__Add(acc_1, ext_2.Name, new Value(/* VExternal */ 15, [ext_2, empty()]));
|
|
2869
|
+
}
|
|
2870
|
+
}, empty_1({
|
|
2871
|
+
Compare: (x_7, y_8) => (comparePrimitives(x_7, y_8) | 0),
|
|
2872
|
+
}), list_15);
|
|
2873
|
+
env = fold_1((acc_2, tupledArg_9) => FSharpMap__Add(acc_2, tupledArg_9[0], tupledArg_9[1]), env, constructorValues_1);
|
|
2874
|
+
return evaluateStatements(runtime, typeDefs_1, env, program);
|
|
2875
|
+
}
|
|
2876
|
+
finally {
|
|
2877
|
+
withRuntimeLock(runtime, () => {
|
|
2878
|
+
runtime.Active = false;
|
|
2879
|
+
});
|
|
2880
|
+
}
|
|
2858
2881
|
}
|
|
2859
2882
|
|
|
2860
2883
|
export function evalProgramWithExterns(externs, program) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import { Record, FSharpRef, Union } from "../fable_modules/fable-library-js.5.13.0/Types.js";
|
|
3
|
-
import { int32_type,
|
|
3
|
+
import { int32_type, lambda_type, unit_type, obj_type, record_type, option_type, class_type, list_type, float64_type, union_type, bool_type, int64_type, string_type } from "../fable_modules/fable-library-js.5.13.0/Reflection.js";
|
|
4
4
|
import { HostUnionDescriptor_$reflection, Scheme_$reflection, HostTypeDescriptor_$reflection, Type_$reflection } from "./Types.js";
|
|
5
5
|
import { Expr_$reflection } from "./Ast.js";
|
|
6
6
|
import { EvalError$_$reflection } from "./Error.js";
|
|
@@ -76,8 +76,10 @@ export function TaskHandle_$reflection() {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
export class ExternalCallContext extends Record {
|
|
79
|
-
constructor(Apply, SpawnTask, AwaitTask, CheckRuntime) {
|
|
79
|
+
constructor(Session, IsActive, Apply, SpawnTask, AwaitTask, CheckRuntime) {
|
|
80
80
|
super();
|
|
81
|
+
this.Session = Session;
|
|
82
|
+
this.IsActive = IsActive;
|
|
81
83
|
this.Apply = Apply;
|
|
82
84
|
this.SpawnTask = SpawnTask;
|
|
83
85
|
this.AwaitTask = AwaitTask;
|
|
@@ -86,7 +88,7 @@ export class ExternalCallContext extends Record {
|
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
export function ExternalCallContext_$reflection() {
|
|
89
|
-
return record_type("FScript.Language.ExternalCallContext", [], ExternalCallContext, () => [["Apply", lambda_type(Value_$reflection(), lambda_type(Value_$reflection(), Value_$reflection()))], ["SpawnTask", lambda_type(Value_$reflection(), Value_$reflection())], ["AwaitTask", lambda_type(Value_$reflection(), Value_$reflection())], ["CheckRuntime", lambda_type(unit_type, unit_type)]]);
|
|
91
|
+
return record_type("FScript.Language.ExternalCallContext", [], ExternalCallContext, () => [["Session", obj_type], ["IsActive", lambda_type(unit_type, bool_type)], ["Apply", lambda_type(Value_$reflection(), lambda_type(Value_$reflection(), Value_$reflection()))], ["SpawnTask", lambda_type(Value_$reflection(), Value_$reflection())], ["AwaitTask", lambda_type(Value_$reflection(), Value_$reflection())], ["CheckRuntime", lambda_type(unit_type, unit_type)]]);
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
export class ExternalFunction extends Record {
|