TDataValue as new global variant type
This commit is contained in:
+12
-13
@@ -23,13 +23,14 @@ uses
|
||||
FMX.Controls.Presentation,
|
||||
Myc.Ast.Visualizer,
|
||||
Myc.Data.Scalar,
|
||||
Myc.Data.Value, // Added
|
||||
Myc.Ast.Nodes,
|
||||
Myc.Ast,
|
||||
Myc.Ast.Evaluator,
|
||||
Myc.Ast.Printer,
|
||||
FMX.Layouts,
|
||||
FMX.Objects,
|
||||
Myc.Ast.Scope; // Added for TExecutionScope
|
||||
Myc.Ast.Scope;
|
||||
|
||||
type
|
||||
// A test record
|
||||
@@ -84,7 +85,7 @@ type
|
||||
function CreateVisitor(const AScope: IExecutionScope): IAstVisitor;
|
||||
procedure WorkspaceMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
|
||||
// New helper function to encapsulate the Bind -> Evaluate pattern
|
||||
function ExecuteAst(const ANode: IAstNode; const AParentScope: IExecutionScope): TAstValue;
|
||||
function ExecuteAst(const ANode: IAstNode; const AParentScope: IExecutionScope): TDataValue;
|
||||
public
|
||||
{ Public declarations }
|
||||
end;
|
||||
@@ -95,7 +96,6 @@ var
|
||||
implementation
|
||||
|
||||
uses
|
||||
// Myc.Ast.Scope is now in the interface uses
|
||||
Myc.Data.Scalar.JSON,
|
||||
Myc.Data.Decimal,
|
||||
System.Diagnostics, // For TStopwatch
|
||||
@@ -125,7 +125,7 @@ begin
|
||||
Result := TEvaluatorVisitor.Create(AScope);
|
||||
end;
|
||||
|
||||
function TForm1.ExecuteAst(const ANode: IAstNode; const AParentScope: IExecutionScope): TAstValue;
|
||||
function TForm1.ExecuteAst(const ANode: IAstNode; const AParentScope: IExecutionScope): TDataValue;
|
||||
var
|
||||
scriptScope: IExecutionScope;
|
||||
begin
|
||||
@@ -150,7 +150,7 @@ end;
|
||||
procedure TForm1.FibonacciButtonClick(Sender: TObject);
|
||||
var
|
||||
root: IAstNode;
|
||||
result: TAstValue;
|
||||
result: TDataValue;
|
||||
sw: TStopwatch;
|
||||
begin
|
||||
Memo1.Lines.Clear;
|
||||
@@ -214,7 +214,7 @@ end;
|
||||
procedure TForm1.RecursionButtonClick(Sender: TObject);
|
||||
var
|
||||
root: IAstNode;
|
||||
result: TAstValue;
|
||||
result: TDataValue;
|
||||
sw: TStopwatch;
|
||||
begin
|
||||
Memo1.Lines.Clear;
|
||||
@@ -258,7 +258,7 @@ procedure TForm1.SeriesTestButtonClick(Sender: TObject);
|
||||
var
|
||||
scope: IExecutionScope;
|
||||
ast, callAst: IAstNode;
|
||||
resultValue: TAstValue;
|
||||
resultValue: TDataValue;
|
||||
series: TScalarRecordSeries;
|
||||
recordDef: TScalarRecordDefinition;
|
||||
i: Integer;
|
||||
@@ -286,7 +286,7 @@ begin
|
||||
)
|
||||
);
|
||||
end;
|
||||
scope.Define('ohlcvSeries', TAstValue.FromRecordSeries(series));
|
||||
scope.Define('ohlcvSeries', TDataValue.FromRecordSeries(series));
|
||||
|
||||
// 2. Act: Define and execute the script AST
|
||||
ast :=
|
||||
@@ -314,7 +314,7 @@ end;
|
||||
procedure TForm1.Test1ButtonClick(Sender: TObject);
|
||||
var
|
||||
main, callAst: IAstNode;
|
||||
result: TAstValue;
|
||||
result: TDataValue;
|
||||
sw: TStopwatch;
|
||||
begin
|
||||
Memo1.Lines.Clear;
|
||||
@@ -348,7 +348,7 @@ end;
|
||||
procedure TForm1.Test2ButtonClick(Sender: TObject);
|
||||
var
|
||||
root: IAstNode;
|
||||
result: TAstValue;
|
||||
result: TDataValue;
|
||||
sw: TStopwatch;
|
||||
begin
|
||||
Memo1.Lines.Clear;
|
||||
@@ -515,7 +515,7 @@ begin
|
||||
setupAst.Accept(CreateVisitor(scope));
|
||||
|
||||
// Declare the series variable in the scope BEFORE binding the call AST
|
||||
scope.Define('current_series', TAstValue.Void);
|
||||
scope.Define('current_series', TDataValue.Void);
|
||||
|
||||
// Create the call AST that will be executed in the loop
|
||||
var currentSeriesIdent := TAst.Identifier('current_series');
|
||||
@@ -533,7 +533,7 @@ begin
|
||||
Randomize;
|
||||
|
||||
var recDef := TRttiAstHelper.JsonToRecordDefinition(TRttiAstHelper.RecordDefinitionToJson<TOHLCV>);
|
||||
var series := TAstValue.FromRecordSeries(TScalarRecordSeries.Create(recDef));
|
||||
var series := TDataValue.FromRecordSeries(TScalarRecordSeries.Create(recDef));
|
||||
var seriesAddress := currentSeriesIdent.Address;
|
||||
|
||||
var nw := Now;
|
||||
@@ -635,7 +635,6 @@ end;
|
||||
procedure TForm1.DoTrigger2ButtonClick(Sender: TObject);
|
||||
var
|
||||
callAst: IFunctionCallNode;
|
||||
currentValue: TAstValue;
|
||||
begin
|
||||
callAst := TAst.FunctionCall(TAst.Identifier('tickHandler'), [TAst.Constant(TScalar.FromInt64(2))]);
|
||||
FLastAst := callAst;
|
||||
|
||||
Reference in New Issue
Block a user