fix PR 1116 comment Ozzie

This commit is contained in:
Umur Ozkul 2022-09-11 22:45:22 +02:00
parent 91e59fe3eb
commit fe7fa297e3
3 changed files with 33 additions and 7 deletions

View File

@ -3,15 +3,35 @@ open Reducer_Peggy_TestHelpers
describe("Environment Accesss", () => { describe("Environment Accesss", () => {
testToExpression( testToExpression(
"environment", "Environment.sampleCount",
"{(:$_endOfOuterBlock_$ () (:$$_environment_$$))}", "{(:$_endOfOuterBlock_$ () (:$_atIndex_$ (:$$_environment_$$) 'sampleCount'))}",
~v=`{sampleCount: ${ReducerInterface_InternalExpressionValue.defaultEnvironment.sampleCount->Js.Int.toString},xyPointLength: ${ReducerInterface_InternalExpressionValue.defaultEnvironment.xyPointLength->Js.Int.toString}}`, ~v=ReducerInterface_InternalExpressionValue.defaultEnvironment.sampleCount->Js.Int.toString,
(), (),
) )
testToExpression( testToExpression(
"withEnvironmentSampleCount(100, environment.sampleCount)", "Environment.withSampleCount(100, Environment.sampleCount)",
"{(:$_endOfOuterBlock_$ () (:$$_withEnvironmentSampleCount_$$ 100 (:$_atIndex_$ (:$$_environment_$$) 'sampleCount')))}", "{(:$_endOfOuterBlock_$ () (:$$_withEnvironmentSampleCount_$$ 100 (:$_atIndex_$ (:$$_environment_$$) 'sampleCount')))}",
~v="100", ~v="100",
(), (),
) )
testToExpression(
"Environment.withSampleCount(100, 99)",
"{(:$_endOfOuterBlock_$ () (:$$_withEnvironmentSampleCount_$$ 100 99))}",
~v="99",
(),
)
testToExpression(
"f(x) = Environment.withSampleCount(999, Environment.sampleCount+1); f(1)",
"{(:$_let_$ :f (:$$_lambda_$$ [x] {(:$$_withEnvironmentSampleCount_$$ 999 (:add (:$_atIndex_$ (:$$_environment_$$) 'sampleCount') 1))})); (:$_endOfOuterBlock_$ () (:f 1))}",
~v="1000",
(),
)
testToExpression(
"f(x) = Environment.sampleCount+1; Environment.withSampleCount(999, f(1))",
"{(:$_let_$ :f (:$$_lambda_$$ [x] {(:add (:$_atIndex_$ (:$$_environment_$$) 'sampleCount') 1)})); (:$_endOfOuterBlock_$ () (:$$_withEnvironmentSampleCount_$$ 999 (:f 1)))}",
~v="1000",
(),
)
}) })

View File

@ -169,13 +169,15 @@ let dispatchMacroCall = (
| InternalExpressionValue.IEvNumber(sampleCount) => { | InternalExpressionValue.IEvNumber(sampleCount) => {
let newEnvironment = {...accessors.environment, sampleCount: Js.Math.floor(sampleCount)} let newEnvironment = {...accessors.environment, sampleCount: Js.Math.floor(sampleCount)}
let newAccessors = {...accessors, environment: newEnvironment} let newAccessors = {...accessors, environment: newEnvironment}
reduceExpression(expr, bindings, newAccessors) let exprBlock = eBlock(list{expr})
reduceExpression(exprBlock, bindings, newAccessors)
->ExpressionT.EValue ->ExpressionT.EValue
->ExpressionWithContext.noContext ->ExpressionWithContext.noContext
} }
| _ => REExpectedType("Number", "")->Reducer_ErrorValue.toException | _ => REExpectedType("Number", "")->Reducer_ErrorValue.toException
} }
} }
let expandExpressionList = ( let expandExpressionList = (
aList, aList,
bindings: ExpressionT.bindings, bindings: ExpressionT.bindings,
@ -213,8 +215,8 @@ let dispatchMacroCall = (
| list{ExpressionT.EValue(IEvCall("$$_environment_$$"))} => doEnvironment(accessors) | list{ExpressionT.EValue(IEvCall("$$_environment_$$"))} => doEnvironment(accessors)
| list{ | list{
ExpressionT.EValue(IEvCall("$$_withEnvironmentSampleCount_$$")), ExpressionT.EValue(IEvCall("$$_withEnvironmentSampleCount_$$")),
expr,
sampleCountExpr, sampleCountExpr,
expr,
} => } =>
doWithEnvironmentSampleCount(sampleCountExpr, expr, bindings, accessors) doWithEnvironmentSampleCount(sampleCountExpr, expr, bindings, accessors)
| _ => ExpressionWithContext.noContext(ExpressionT.EList(aList)) | _ => ExpressionWithContext.noContext(ExpressionT.EList(aList))

View File

@ -33,7 +33,11 @@ let rec fromNode = (node: Parse.node): expression => {
let identifier = nodeIdentifier["value"] let identifier = nodeIdentifier["value"]
// `caseIdentifier ${identifier}`->Js.log // `caseIdentifier ${identifier}`->Js.log
switch identifier { switch identifier {
| "System.environment" => "$$_environment_$$"->ExpressionBuilder.eFunction(list{}) | "Environment.sampleCount" =>
"$_atIndex_$"->ExpressionBuilder.eFunction(list{
"$$_environment_$$"->ExpressionBuilder.eFunction(list{}),
ExpressionBuilder.eString("sampleCount"),
})
| symbol => symbol->ExpressionBuilder.eSymbol | symbol => symbol->ExpressionBuilder.eSymbol
} }
} }