diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res index b1ae2e41..1e8b19d0 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res @@ -104,7 +104,7 @@ let callInternal = ( let doDumpBindings = (continuation: nameSpace, value: internalExpressionValue) => { // let _ = Continuation.inspect(continuation, "doDumpBindings") - accessors.continuation = continuation + accessors.states.continuation = continuation value->Ok } diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res index 3e476403..b262a327 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res @@ -107,8 +107,9 @@ let reduceReturningBindings = ( continuation: T.bindings, accessors: ProjectAccessorsT.t, ): (result, T.bindings) => { + let states = accessors.states let result = reduceExpressionInProject(expression, continuation, accessors) - (result, accessors.continuation) + (result, states.continuation) } module BackCompatible = { diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Compile.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Compile.res index b091782c..79153801 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Compile.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Type/Reducer_Type_Compile.res @@ -16,7 +16,7 @@ let ievFromTypeExpression = ( Reducer_Expression.BackCompatible.parse(sourceCode)->Belt.Result.flatMap(expr => { let accessors = ProjectAccessorsT.identityAccessors let result = reducerFn(expr, Bindings.emptyBindings, accessors) - let nameSpace = accessors.continuation + let nameSpace = accessors.states.continuation switch result { | Ok(_) => diff --git a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject.res b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject.res index 44cafc0b..9244c515 100644 --- a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject.res +++ b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject.res @@ -138,7 +138,7 @@ module Private = { } let buildProjectAccessors = (this: t): ProjectAccessorsT.t => { - continuation: Bindings.emptyBindings, + states: {continuation: Bindings.emptyBindings}, stdLib: getStdLib(this), environment: getEnvironment(this), } @@ -149,9 +149,10 @@ module Private = { continuation: ProjectItem.T.continuation, ): unit => { let accessors = buildProjectAccessors(this) + let states = accessors.states let newItem = this->getItem(sourceId)->ProjectItem.run(continuation, accessors) Belt.Map.String.set(this["items"], sourceId, newItem)->T.Private.setFieldItems(this, _) - setContinuation(this, sourceId, accessors.continuation) + setContinuation(this, sourceId, states.continuation) } type runState = (ProjectItem.T.resultArgumentType, ProjectItem.T.continuation) diff --git a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_ProjectAccessors_T.res b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_ProjectAccessors_T.res index d3becba9..9cc06e8f 100644 --- a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_ProjectAccessors_T.res +++ b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_ProjectAccessors_T.res @@ -3,22 +3,38 @@ module Bindings = Reducer_Bindings module ExpressionT = Reducer_Expression_T module InternalExpressionValue = ReducerInterface_InternalExpressionValue +type states = {mutable continuation: ProjectItemT.continuationArgumentType} + type projectAccessors = { stdLib: Reducer_Bindings.t, environment: ExpressionT.environment, - mutable continuation: ProjectItemT.continuationArgumentType, + states: states, } type t = projectAccessors let identityAccessors: t = { - continuation: Bindings.emptyBindings, + // We need the states at the end of the runtime. + // Accessors can be modified but states will stay as the same pointer + states: { + continuation: Bindings.emptyBindings, + }, stdLib: ReducerInterface_StdLib.internalStdLib, environment: InternalExpressionValue.defaultEnvironment, } let identityAccessorsWithEnvironment = (environment): t => { - continuation: Bindings.emptyBindings, + states: { + continuation: Bindings.emptyBindings, + }, stdLib: ReducerInterface_StdLib.internalStdLib, environment: environment, } + +// to support change of environment in runtime +let setEnvironment = (this: t, environment: ExpressionT.environment): t => { + { + ...this, + environment: environment, + } +}