fix PR 1116 comment Ozzie
This commit is contained in:
parent
91e59fe3eb
commit
fe7fa297e3
|
@ -3,15 +3,35 @@ open Reducer_Peggy_TestHelpers
|
|||
|
||||
describe("Environment Accesss", () => {
|
||||
testToExpression(
|
||||
"environment",
|
||||
"{(:$_endOfOuterBlock_$ () (:$$_environment_$$))}",
|
||||
~v=`{sampleCount: ${ReducerInterface_InternalExpressionValue.defaultEnvironment.sampleCount->Js.Int.toString},xyPointLength: ${ReducerInterface_InternalExpressionValue.defaultEnvironment.xyPointLength->Js.Int.toString}}`,
|
||||
"Environment.sampleCount",
|
||||
"{(:$_endOfOuterBlock_$ () (:$_atIndex_$ (:$$_environment_$$) 'sampleCount'))}",
|
||||
~v=ReducerInterface_InternalExpressionValue.defaultEnvironment.sampleCount->Js.Int.toString,
|
||||
(),
|
||||
)
|
||||
testToExpression(
|
||||
"withEnvironmentSampleCount(100, environment.sampleCount)",
|
||||
"Environment.withSampleCount(100, Environment.sampleCount)",
|
||||
"{(:$_endOfOuterBlock_$ () (:$$_withEnvironmentSampleCount_$$ 100 (:$_atIndex_$ (:$$_environment_$$) 'sampleCount')))}",
|
||||
~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",
|
||||
(),
|
||||
)
|
||||
})
|
||||
|
|
|
@ -169,13 +169,15 @@ let dispatchMacroCall = (
|
|||
| InternalExpressionValue.IEvNumber(sampleCount) => {
|
||||
let newEnvironment = {...accessors.environment, sampleCount: Js.Math.floor(sampleCount)}
|
||||
let newAccessors = {...accessors, environment: newEnvironment}
|
||||
reduceExpression(expr, bindings, newAccessors)
|
||||
let exprBlock = eBlock(list{expr})
|
||||
reduceExpression(exprBlock, bindings, newAccessors)
|
||||
->ExpressionT.EValue
|
||||
->ExpressionWithContext.noContext
|
||||
}
|
||||
| _ => REExpectedType("Number", "")->Reducer_ErrorValue.toException
|
||||
}
|
||||
}
|
||||
|
||||
let expandExpressionList = (
|
||||
aList,
|
||||
bindings: ExpressionT.bindings,
|
||||
|
@ -213,8 +215,8 @@ let dispatchMacroCall = (
|
|||
| list{ExpressionT.EValue(IEvCall("$$_environment_$$"))} => doEnvironment(accessors)
|
||||
| list{
|
||||
ExpressionT.EValue(IEvCall("$$_withEnvironmentSampleCount_$$")),
|
||||
expr,
|
||||
sampleCountExpr,
|
||||
expr,
|
||||
} =>
|
||||
doWithEnvironmentSampleCount(sampleCountExpr, expr, bindings, accessors)
|
||||
| _ => ExpressionWithContext.noContext(ExpressionT.EList(aList))
|
||||
|
|
|
@ -33,7 +33,11 @@ let rec fromNode = (node: Parse.node): expression => {
|
|||
let identifier = nodeIdentifier["value"]
|
||||
// `caseIdentifier ${identifier}`->Js.log
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user