Refactoring Binder
This commit is contained in:
@@ -14,7 +14,9 @@ uses
|
||||
Myc.Ast.Debugger in '..\Src\AST\Myc.Ast.Debugger.pas',
|
||||
Myc.Fmx.AstEditor.Node in 'Myc.Fmx.AstEditor.Node.pas',
|
||||
Myc.Fmx.AstEditor.Workspace in 'Myc.Fmx.AstEditor.Workspace.pas',
|
||||
Myc.Fmx.AstEditor.Text in 'Myc.Fmx.AstEditor.Text.pas';
|
||||
Myc.Fmx.AstEditor.Text in 'Myc.Fmx.AstEditor.Text.pas',
|
||||
Myc.Ast.Traverser in '..\Src\AST\Myc.Ast.Traverser.pas',
|
||||
Myc.Ast.Binding in '..\Src\AST\Myc.Ast.Binding.pas';
|
||||
|
||||
{$R *.res}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<ProjectVersion>20.3</ProjectVersion>
|
||||
<FrameworkType>FMX</FrameworkType>
|
||||
<Base>True</Base>
|
||||
<Config Condition="'$(Config)'==''">Debug</Config>
|
||||
<Config Condition="'$(Config)'==''">Release</Config>
|
||||
<Platform Condition="'$(Platform)'==''">Win64</Platform>
|
||||
<ProjectName Condition="'$(ProjectName)'==''">ASTPlayground</ProjectName>
|
||||
<TargetedPlatforms>2</TargetedPlatforms>
|
||||
@@ -146,6 +146,8 @@
|
||||
<DCCReference Include="Myc.Fmx.AstEditor.Node.pas"/>
|
||||
<DCCReference Include="Myc.Fmx.AstEditor.Workspace.pas"/>
|
||||
<DCCReference Include="Myc.Fmx.AstEditor.Text.pas"/>
|
||||
<DCCReference Include="..\Src\AST\Myc.Ast.Traverser.pas"/>
|
||||
<DCCReference Include="..\Src\AST\Myc.Ast.Binding.pas"/>
|
||||
<BuildConfiguration Include="Base">
|
||||
<Key>Base</Key>
|
||||
</BuildConfiguration>
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -14,7 +14,8 @@ uses
|
||||
FMX.Graphics,
|
||||
FMX.Objects,
|
||||
Myc.Ast,
|
||||
Myc.Ast.Nodes;
|
||||
Myc.Ast.Nodes,
|
||||
Myc.Ast.Binding;
|
||||
|
||||
type
|
||||
TPinConnection = record
|
||||
@@ -119,7 +120,7 @@ begin
|
||||
connections := TList<TPinConnection>.Create;
|
||||
try
|
||||
// Create the scope descriptor from the execution scope provided by the binder.
|
||||
rootDescriptor := TAst.CreateDescriptor(RootScope);
|
||||
rootDescriptor := TAstBinder.CreateDescriptor(RootScope);
|
||||
RootNode.Accept(TAstToAuraNodeVisitor.Create(Self, Self, Position, connections, nil, AMode, nil, nil, rootDescriptor));
|
||||
FConnections := FConnections + connections.ToArray;
|
||||
finally
|
||||
|
||||
Reference in New Issue
Block a user