@magnusopera/fscript 0.80.1 → 0.81.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,21 +1,22 @@
1
1
 
2
2
  import { Record } from "../fable_modules/fable-library-js.5.13.0/Types.js";
3
- import { ExternalFunction, Value, ExternalFunction_$reflection } from "./Value.js";
4
- import { int32_type, record_type, option_type, class_type, string_type, list_type } from "../fable_modules/fable-library-js.5.13.0/Reflection.js";
3
+ import { ExtensionRegistration, ExternalFunction, Value, ExternalFunction_$reflection, ExtensionRegistration_$reflection } from "./Value.js";
5
4
  import { Stmt_$reflection } from "./Ast.js";
6
- import { evalProgramFromState, evalProgramWithExternsState, ProgramState_$reflection } from "./Eval.js";
7
- import { inferProgramWithExterns, TypedStmt_$reflection } from "./TypeInfer.js";
5
+ import { int32_type, record_type, option_type, class_type, string_type, list_type } from "../fable_modules/fable-library-js.5.13.0/Reflection.js";
6
+ import { evalProgramFromState, evalProgramWithRegistrationState, ProgramState_$reflection } from "./Eval.js";
7
+ import { inferProgramWithRegistration, TypedStmt_$reflection } from "./TypeInfer.js";
8
8
  import { skip, reverse, append, exists, length, empty, choose, cons, fold, filter } from "../fable_modules/fable-library-js.5.13.0/List.js";
9
9
  import { toList } from "../fable_modules/fable-library-js.5.13.0/Set.js";
10
10
  import { Scheme, Types_ftvType } from "./Types.js";
11
11
  import { values, empty as empty_1, add, fold as fold_1 } from "../fable_modules/fable-library-js.5.13.0/Map.js";
12
12
  import { comparePrimitives } from "../fable_modules/fable-library-js.5.13.0/Util.js";
13
13
  import { toList as toList_1 } from "../fable_modules/fable-library-js.5.13.0/Seq.js";
14
+ import { ofExterns } from "./HostInterop.js";
14
15
 
15
16
  export class Session extends Record {
16
- constructor(Externs, RetainedProgramRev, TypeDeclarations, InferenceBindings, EvaluationState) {
17
+ constructor(Registration, RetainedProgramRev, TypeDeclarations, InferenceBindings, EvaluationState) {
17
18
  super();
18
- this.Externs = Externs;
19
+ this.Registration = Registration;
19
20
  this.RetainedProgramRev = RetainedProgramRev;
20
21
  this.TypeDeclarations = TypeDeclarations;
21
22
  this.InferenceBindings = InferenceBindings;
@@ -24,7 +25,7 @@ export class Session extends Record {
24
25
  }
25
26
 
26
27
  export function Session_$reflection() {
27
- return record_type("FScript.Language.Interactive.Session", [], Session, () => [["Externs", list_type(ExternalFunction_$reflection())], ["RetainedProgramRev", list_type(Stmt_$reflection())], ["TypeDeclarations", list_type(Stmt_$reflection())], ["InferenceBindings", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, ExternalFunction_$reflection()])], ["EvaluationState", option_type(ProgramState_$reflection())]]);
28
+ return record_type("FScript.Language.Interactive.Session", [], Session, () => [["Registration", ExtensionRegistration_$reflection()], ["RetainedProgramRev", list_type(Stmt_$reflection())], ["TypeDeclarations", list_type(Stmt_$reflection())], ["InferenceBindings", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, ExternalFunction_$reflection()])], ["EvaluationState", option_type(ProgramState_$reflection())]]);
28
29
  }
29
30
 
30
31
  export class Submission extends Record {
@@ -99,8 +100,8 @@ function updateInferenceBindings(bindings, typedProgram) {
99
100
  }, bindings, typedProgram);
100
101
  }
101
102
 
102
- export function create(externs) {
103
- return new Session(externs, empty(), empty(), empty_1({
103
+ export function createWithRegistration(registration) {
104
+ return new Session(registration, empty(), empty(), empty_1({
104
105
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
105
106
  }), undefined);
106
107
  }
@@ -123,27 +124,31 @@ export function submit(session, program) {
123
124
  const matchValue = session.EvaluationState;
124
125
  if (matchValue != null) {
125
126
  if (containsTypeDeclaration) {
126
- const typed_1 = inferProgramWithExterns(session.Externs, append(reverse(session.RetainedProgramRev), program));
127
- const state_1 = evalProgramWithExternsState(session.Externs, typed_1);
127
+ const typed_1 = inferProgramWithRegistration(session.Registration, append(reverse(session.RetainedProgramRev), program));
128
+ const state_1 = evalProgramWithRegistrationState(session.Registration, typed_1);
128
129
  const submittedTyped = skip(length(session.RetainedProgramRev), typed_1);
129
- return new Submission(new Session(session.Externs, retainedRev, typeDeclarations(reverse(retainedRev)), updateInferenceBindings(empty_1({
130
+ return new Submission(new Session(session.Registration, retainedRev, typeDeclarations(reverse(retainedRev)), updateInferenceBindings(empty_1({
130
131
  Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
131
132
  }), typed_1), state_1), submittedTyped, state_1, retainedCount_1);
132
133
  }
133
134
  else {
134
135
  const previousState = matchValue;
135
- const typed_2 = inferProgramWithExterns(append(session.Externs, toList_1(values(session.InferenceBindings))), append(session.TypeDeclarations, program));
136
+ const typed_2 = inferProgramWithRegistration(new ExtensionRegistration(session.Registration.Types, append(session.Registration.Functions, toList_1(values(session.InferenceBindings)))), append(session.TypeDeclarations, program));
136
137
  const submittedTyped_1 = skip(length(session.TypeDeclarations), typed_2);
137
138
  const state_2 = evalProgramFromState(previousState, submittedTyped_1);
138
- return new Submission(new Session(session.Externs, retainedRev, session.TypeDeclarations, updateInferenceBindings(session.InferenceBindings, submittedTyped_1), state_2), submittedTyped_1, state_2, retainedCount_1);
139
+ return new Submission(new Session(session.Registration, retainedRev, session.TypeDeclarations, updateInferenceBindings(session.InferenceBindings, submittedTyped_1), state_2), submittedTyped_1, state_2, retainedCount_1);
139
140
  }
140
141
  }
141
142
  else {
142
- const typed = inferProgramWithExterns(session.Externs, program);
143
- const state = evalProgramWithExternsState(session.Externs, typed);
144
- return new Submission(new Session(session.Externs, retainedRev, typeDeclarations(retainedStatements(program)), updateInferenceBindings(empty_1({
143
+ const typed = inferProgramWithRegistration(session.Registration, program);
144
+ const state = evalProgramWithRegistrationState(session.Registration, typed);
145
+ return new Submission(new Session(session.Registration, retainedRev, typeDeclarations(retainedStatements(program)), updateInferenceBindings(empty_1({
145
146
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
146
147
  }), typed), state), typed, state, retainedCount_1);
147
148
  }
148
149
  }
149
150
 
151
+ export function create(externs) {
152
+ return createWithRegistration(ofExterns(externs));
153
+ }
154
+
@@ -1,8 +1,8 @@
1
1
 
2
2
  import { parseProgramWithSourceName, parseProgram } from "./Parser.js";
3
3
  import { parseProgramFromSourceWithIncludesResolver, parseProgramFromSourceWithIncludes, parseProgramFromFile } from "./IncludeResolver.js";
4
- import { inferProgramWithExterns, inferProgram } from "./TypeInfer.js";
5
- import { evalProgramWithExterns, evalProgram } from "./Eval.js";
4
+ import { inferProgramWithRegistration, inferProgramWithExterns, inferProgram } from "./TypeInfer.js";
5
+ import { evalProgramWithExterns, evalProgram, evalProgramWithRegistration } from "./Eval.js";
6
6
 
7
7
  export const parse = parseProgram;
8
8
 
@@ -18,6 +18,10 @@ export const infer = inferProgram;
18
18
 
19
19
  export const inferWithExterns = (externs) => ((program) => inferProgramWithExterns(externs, program));
20
20
 
21
+ export const inferWithRegistration = (registration) => ((program) => inferProgramWithRegistration(registration, program));
22
+
23
+ export const evalWithRegistration = (registration) => ((program) => evalProgramWithRegistration(registration, program));
24
+
21
25
  export const eval$ = evalProgram;
22
26
 
23
27
  export const evalWithExterns = (externs) => ((program) => evalProgramWithExterns(externs, program));