Binding
This commit is contained in:
@@ -122,16 +122,10 @@ end;
|
||||
|
||||
function TForm1.ExecuteAst(const ANode: IExpressionNode; const AParentScope: IExecutionScope): TAstValue;
|
||||
var
|
||||
scriptDescriptor: IScopeDescriptor;
|
||||
scriptScope: IExecutionScope;
|
||||
begin
|
||||
// STEP 1: BIND and get the descriptor for the script's local variables.
|
||||
scriptDescriptor := TAst.Bind(ANode, AParentScope);
|
||||
scriptScope := TAst.Bind(ANode, AParentScope);
|
||||
|
||||
// STEP 2: CREATE the correctly-sized execution scope for the script.
|
||||
scriptScope := scriptDescriptor.Instantiate(AParentScope);
|
||||
|
||||
// STEP 3: EVALUATE using the new, correctly-sized scope.
|
||||
var visitor := CreateVisitor(scriptScope);
|
||||
Result := ANode.Accept(visitor);
|
||||
end;
|
||||
@@ -512,7 +506,7 @@ begin
|
||||
);
|
||||
FLastAst := setupAst;
|
||||
|
||||
var scope := TAst.Bind(setupAst, FGScope).Instantiate(FGScope);
|
||||
var scope := TAst.Bind(setupAst, FGScope);
|
||||
setupAst.Accept(CreateVisitor(scope));
|
||||
|
||||
// Declare the series variable in the scope BEFORE binding the call AST
|
||||
@@ -523,7 +517,7 @@ begin
|
||||
var callAst := TAst.FunctionCall(TAst.Identifier('maCrossStrategy'), [currentSeriesIdent]);
|
||||
|
||||
// Bind the call AST once, before the loop.
|
||||
scope := TAst.Bind(callAst, scope).Instantiate(scope);
|
||||
scope := TAst.Bind(callAst, scope);
|
||||
var visitor := CreateVisitor(scope);
|
||||
|
||||
// 4. Simulation Loop
|
||||
@@ -535,7 +529,7 @@ begin
|
||||
|
||||
var recDef := TRttiAstHelper.JsonToRecordDefinition(TRttiAstHelper.RecordDefinitionToJson<TOHLCV>);
|
||||
var series := TAstValue.FromRecordSeries(TScalarRecordSeries.Create(recDef));
|
||||
var seriesAddress := currentSeriesIdent.Resolve;
|
||||
var seriesAddress := currentSeriesIdent.Address;
|
||||
|
||||
var nw := Now;
|
||||
var ohlcvRec: TOHLCV;
|
||||
@@ -611,7 +605,7 @@ begin
|
||||
]
|
||||
);
|
||||
|
||||
TriggerScope := TAst.Bind(blk, FGScope).Instantiate(FGScope);
|
||||
TriggerScope := TAst.Bind(blk, FGScope);
|
||||
|
||||
blk.Accept(CreateVisitor(TriggerScope));
|
||||
|
||||
@@ -628,7 +622,6 @@ begin
|
||||
callAst := TAst.FunctionCall(TAst.Identifier('tickHandler'), [TAst.Constant(TScalar.FromInt64(1))]);
|
||||
FLastAst := callAst;
|
||||
|
||||
// Bind and execute the call against the persistent scope
|
||||
var X := ExecuteAst(callAst, TriggerScope);
|
||||
|
||||
Memo1.Lines.Add(Format('Tick(1)! New value of X: %s', [X.ToString]));
|
||||
@@ -642,7 +635,6 @@ begin
|
||||
callAst := TAst.FunctionCall(TAst.Identifier('tickHandler'), [TAst.Constant(TScalar.FromInt64(2))]);
|
||||
FLastAst := callAst;
|
||||
|
||||
// Bind and execute the call against the persistent scope
|
||||
var X := ExecuteAst(callAst, TriggerScope);
|
||||
|
||||
Memo1.Lines.Add(Format('Tick(2)! New value of X: %s', [X.ToString]));
|
||||
|
||||
Reference in New Issue
Block a user