always merge stdlib

This commit is contained in:
Umur Ozkul 2022-06-13 18:54:48 +02:00
parent f406ae9053
commit 28938adf53
6 changed files with 21 additions and 14 deletions

View File

@ -25,7 +25,7 @@ let expectToExpressionToBe = (expr, answer, ~v="_", ()) => {
->Result.flatMap(expr =>
Expression.reduceExpression(
expr,
ReducerInterface_DefaultExternalBindings.defaultInternalBindings,
ReducerInterface_StdLib.internalStdLib,
ExpressionValue.defaultEnvironment,
)
)

View File

@ -29,6 +29,7 @@ let expectEvalError = (expr: string) =>
let expectEvalBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) =>
Reducer.evaluateUsingOptions(expr, ~externalBindings=Some(bindings), ~environment=None)
->Reducer_Helpers.rRemoveDefaults
->ExpressionValue.toStringResult
->expect
->toBe(answer)

View File

@ -24,4 +24,4 @@ let foreignFunctionInterface = (
let defaultEnvironment = ExpressionValue.defaultEnvironment
let defaultExternalBindings = ReducerInterface_DefaultExternalBindings.defaultExternalBindings
let defaultExternalBindings = ReducerInterface_StdLib.externalStdLib

View File

@ -116,14 +116,20 @@ let evaluateUsingOptions = (
~externalBindings: option<ReducerInterface_ExpressionValue.externalBindings>,
code: string,
): result<expressionValue, errorValue> => {
let anEnvironment = switch environment {
| Some(env) => env
| None => ReducerInterface_ExpressionValue.defaultEnvironment
}
let anEnvironment = Belt.Option.getWithDefault(
environment,
ReducerInterface_ExpressionValue.defaultEnvironment,
)
let anExternalBindings = switch externalBindings {
| Some(bindings) => bindings
| None => ReducerInterface_DefaultExternalBindings.defaultExternalBindings
| Some(bindings) => {
let cloneLib = ReducerInterface_StdLib.externalStdLib->Reducer_Category_Bindings.cloneRecord
Js.Dict.entries(bindings)->Js.Array2.reduce((acc, (key, value)) => {
acc->Js.Dict.set(key, value)
acc
}, cloneLib)
}
| None => ReducerInterface_StdLib.externalStdLib
}
let bindings = anExternalBindings->Bindings.fromExternalBindings

View File

@ -1,6 +0,0 @@
module Bindings = Reducer_Category_Bindings
let defaultInternalBindings = Bindings.emptyBindings->SquiggleLibrary_Math.makeBindings
@genType
let defaultExternalBindings = defaultInternalBindings->Bindings.toRecord

View File

@ -0,0 +1,6 @@
module Bindings = Reducer_Category_Bindings
let internalStdLib = Bindings.emptyBindings->SquiggleLibrary_Math.makeBindings
@genType
let externalStdLib = internalStdLib->Bindings.toRecord