Refactoring Binder
This commit is contained in:
@@ -32,7 +32,6 @@ uses
|
||||
Myc.Ast.Printer,
|
||||
FMX.Layouts,
|
||||
FMX.Objects,
|
||||
Myc.Ast.Scope,
|
||||
Myc.Ast.Debugger;
|
||||
|
||||
type
|
||||
@@ -103,6 +102,7 @@ implementation
|
||||
uses
|
||||
Myc.Data.Scalar.JSON,
|
||||
Myc.Data.Decimal,
|
||||
Myc.Ast.Binding,
|
||||
System.Diagnostics, // For TStopwatch
|
||||
Myc.Ast.Json; // For TAstJson serialization
|
||||
|
||||
@@ -114,7 +114,7 @@ begin
|
||||
FWorkspace.Repaint;
|
||||
|
||||
// Create and prepare the global scope once
|
||||
FGScope := TExecutionScope.Create(nil);
|
||||
FGScope := TAst.CreateScope(nil);
|
||||
RegisterNativeFunctions(FGScope);
|
||||
end;
|
||||
|
||||
@@ -122,7 +122,7 @@ function TForm1.ExecuteAst(const ANode: IAstNode; const AParentScope: IExecution
|
||||
begin
|
||||
// This helper function handles simple, one-off script executions.
|
||||
// It binds the AST and then decides whether to run a debug session or a standard evaluation.
|
||||
var scriptScope := TAst.Bind(ANode, AParentScope);
|
||||
var scriptScope := TAstBinder.Bind(ANode, AParentScope).CreateScope(AParentScope);
|
||||
var visitor := CreateVisitor(scriptScope);
|
||||
Result := ANode.Accept(visitor);
|
||||
end;
|
||||
@@ -258,7 +258,7 @@ begin
|
||||
Memo1.Lines.Clear;
|
||||
Memo1.Lines.Add('--- Series Test ---');
|
||||
|
||||
scope := TExecutionScope.Create(FGScope);
|
||||
scope := TAst.CreateScope(FGScope);
|
||||
recordDef := TRttiAstHelper.JsonToRecordDefinition(TRttiAstHelper.RecordDefinitionToJson<TOHLCV>);
|
||||
series := TScalarRecordSeries.Create(recordDef);
|
||||
for i := 0 to 4 do
|
||||
@@ -381,7 +381,8 @@ begin
|
||||
if FlowOnlyBox.IsChecked then
|
||||
visu := TVisualizationMode.vmControlFlow;
|
||||
|
||||
FWorkspace.BuildTree(FLastAst, TAst.Bind(FLastAst, FGScope), TPointF.Create(X, Y), visu);
|
||||
var descr := TAstBinder.Bind(FLastAst, FGScope);
|
||||
FWorkspace.BuildTree(FLastAst, descr.CreateScope(FGScope), TPointF.Create(X, Y), visu);
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -498,7 +499,7 @@ begin
|
||||
FLastAst := setupAst;
|
||||
|
||||
// 1. Bind and execute the setup script.
|
||||
scope := TAst.Bind(setupAst, FGScope);
|
||||
scope := TAstBinder.Bind(setupAst, FGScope).CreateScope(FGScope);
|
||||
|
||||
// This is a temporary visitor just for the setup execution.
|
||||
var setupVisitor := CreateVisitor(scope);
|
||||
@@ -510,7 +511,7 @@ begin
|
||||
var callAst := TAst.FunctionCall(TAst.Identifier('maCrossStrategy'), [currentSeriesIdent]);
|
||||
|
||||
// 3. Re-bind the scope with the new AST. This creates the FINAL scope for the loop.
|
||||
scope := TAst.Bind(callAst, scope);
|
||||
scope := TAstBinder.Bind(callAst, scope).CreateScope(scope);
|
||||
var seriesAddress := currentSeriesIdent.Address;
|
||||
|
||||
var visitor := CreateVisitor(scope);
|
||||
@@ -589,7 +590,7 @@ begin
|
||||
]
|
||||
);
|
||||
|
||||
TriggerScope := TAst.Bind(blk, FGScope);
|
||||
TriggerScope := TAstBinder.Bind(blk, FGScope).CreateScope(FGScope);
|
||||
|
||||
// This case is simple enough to just inline the logic from ExecuteAst
|
||||
var visitor := CreateVisitor(TriggerScope);
|
||||
@@ -642,7 +643,7 @@ begin
|
||||
Memo1.Lines.Clear;
|
||||
Memo1.Lines.Add('--- Calling external Delphi function from AST ---');
|
||||
|
||||
scope := TExecutionScope.Create(FGScope);
|
||||
scope := TAst.CreateScope(FGScope);
|
||||
|
||||
scope.Define(
|
||||
'delphiAdd',
|
||||
|
||||
Reference in New Issue
Block a user