Beginning Editor
This commit is contained in:
@@ -8,7 +8,9 @@ uses
|
|||||||
Myc.Ast.Printer in '..\Src\AST\Myc.Ast.Printer.pas',
|
Myc.Ast.Printer in '..\Src\AST\Myc.Ast.Printer.pas',
|
||||||
Myc.Ast.Nodes in '..\Src\AST\Myc.Ast.Nodes.pas',
|
Myc.Ast.Nodes in '..\Src\AST\Myc.Ast.Nodes.pas',
|
||||||
Myc.Ast.Scope in '..\Src\AST\Myc.Ast.Scope.pas',
|
Myc.Ast.Scope in '..\Src\AST\Myc.Ast.Scope.pas',
|
||||||
Myc.Ast.Visualizer in 'Myc.Ast.Visualizer.pas';
|
Myc.Ast.Visualizer in 'Myc.Ast.Visualizer.pas',
|
||||||
|
Myc.Ast.ViewModel in '..\Src\AST\Myc.Ast.ViewModel.pas',
|
||||||
|
Myc.Ast.Persistence in '..\Src\AST\Myc.Ast.Persistence.pas';
|
||||||
|
|
||||||
{$R *.res}
|
{$R *.res}
|
||||||
|
|
||||||
|
|||||||
@@ -140,6 +140,8 @@
|
|||||||
<DCCReference Include="..\Src\AST\Myc.Ast.Nodes.pas"/>
|
<DCCReference Include="..\Src\AST\Myc.Ast.Nodes.pas"/>
|
||||||
<DCCReference Include="..\Src\AST\Myc.Ast.Scope.pas"/>
|
<DCCReference Include="..\Src\AST\Myc.Ast.Scope.pas"/>
|
||||||
<DCCReference Include="Myc.Ast.Visualizer.pas"/>
|
<DCCReference Include="Myc.Ast.Visualizer.pas"/>
|
||||||
|
<DCCReference Include="..\Src\AST\Myc.Ast.ViewModel.pas"/>
|
||||||
|
<DCCReference Include="..\Src\AST\Myc.Ast.Persistence.pas"/>
|
||||||
<BuildConfiguration Include="Base">
|
<BuildConfiguration Include="Base">
|
||||||
<Key>Base</Key>
|
<Key>Base</Key>
|
||||||
</BuildConfiguration>
|
</BuildConfiguration>
|
||||||
@@ -189,6 +191,18 @@
|
|||||||
<Overwrite>true</Overwrite>
|
<Overwrite>true</Overwrite>
|
||||||
</Platform>
|
</Platform>
|
||||||
</DeployFile>
|
</DeployFile>
|
||||||
|
<DeployFile LocalName="Win64\Debug\ASTPlayground.exe" Configuration="Debug" Class="ProjectOutput">
|
||||||
|
<Platform Name="Win64">
|
||||||
|
<RemoteName>ASTPlayground.exe</RemoteName>
|
||||||
|
<Overwrite>true</Overwrite>
|
||||||
|
</Platform>
|
||||||
|
</DeployFile>
|
||||||
|
<DeployFile LocalName="Win64\Debug\ASTPlayground.rsm" Configuration="Debug" Class="DebugSymbols">
|
||||||
|
<Platform Name="Win64">
|
||||||
|
<RemoteName>ASTPlayground.rsm</RemoteName>
|
||||||
|
<Overwrite>true</Overwrite>
|
||||||
|
</Platform>
|
||||||
|
</DeployFile>
|
||||||
<DeployFile LocalName="Win64\Release\ASTPlayground.exe" Configuration="Release" Class="ProjectOutput">
|
<DeployFile LocalName="Win64\Release\ASTPlayground.exe" Configuration="Release" Class="ProjectOutput">
|
||||||
<Platform Name="Win64">
|
<Platform Name="Win64">
|
||||||
<RemoteName>ASTPlayground.exe</RemoteName>
|
<RemoteName>ASTPlayground.exe</RemoteName>
|
||||||
|
|||||||
@@ -130,6 +130,22 @@ object Form1: TForm1
|
|||||||
TabOrder = 15
|
TabOrder = 15
|
||||||
Text = 'Debug'
|
Text = 'Debug'
|
||||||
end
|
end
|
||||||
|
object FromJSONButton: TButton
|
||||||
|
Position.X = 24.000000000000000000
|
||||||
|
Position.Y = 520.000000000000000000
|
||||||
|
TabOrder = 16
|
||||||
|
Text = 'From JSON'
|
||||||
|
TextSettings.Trimming = None
|
||||||
|
OnClick = FromJSONButtonClick
|
||||||
|
end
|
||||||
|
object ToJSONButton: TButton
|
||||||
|
Position.X = 24.000000000000000000
|
||||||
|
Position.Y = 550.000000000000000000
|
||||||
|
TabOrder = 17
|
||||||
|
Text = 'To JSON'
|
||||||
|
TextSettings.Trimming = None
|
||||||
|
OnClick = ToJSONButtonClick
|
||||||
|
end
|
||||||
end
|
end
|
||||||
object Panel2: TPanel
|
object Panel2: TPanel
|
||||||
Align = Client
|
Align = Client
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ uses
|
|||||||
Myc.Ast,
|
Myc.Ast,
|
||||||
Myc.Ast.Evaluator,
|
Myc.Ast.Evaluator,
|
||||||
Myc.Ast.Printer,
|
Myc.Ast.Printer,
|
||||||
|
Myc.Ast.Persistence,
|
||||||
FMX.Layouts,
|
FMX.Layouts,
|
||||||
FMX.Objects,
|
FMX.Objects,
|
||||||
Myc.Ast.Scope; // Added for TExecutionScope
|
Myc.Ast.Scope; // Added for TExecutionScope
|
||||||
@@ -60,6 +61,8 @@ type
|
|||||||
SeriesTestButton: TButton;
|
SeriesTestButton: TButton;
|
||||||
OHLCButton: TButton;
|
OHLCButton: TButton;
|
||||||
DebugBox: TCheckBox;
|
DebugBox: TCheckBox;
|
||||||
|
FromJSONButton: TButton;
|
||||||
|
ToJSONButton: TButton;
|
||||||
procedure ClearButtonClick(Sender: TObject);
|
procedure ClearButtonClick(Sender: TObject);
|
||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
procedure CreateTriggerExampleButtonClick(Sender: TObject);
|
procedure CreateTriggerExampleButtonClick(Sender: TObject);
|
||||||
@@ -72,15 +75,17 @@ type
|
|||||||
procedure SeriesTestButtonClick(Sender: TObject);
|
procedure SeriesTestButtonClick(Sender: TObject);
|
||||||
procedure Test1ButtonClick(Sender: TObject);
|
procedure Test1ButtonClick(Sender: TObject);
|
||||||
procedure Test2ButtonClick(Sender: TObject);
|
procedure Test2ButtonClick(Sender: TObject);
|
||||||
|
procedure FromJSONButtonClick(Sender: TObject);
|
||||||
|
procedure ToJSONButtonClick(Sender: TObject);
|
||||||
private
|
private
|
||||||
// Stores the last AST generated by Test1 or Test2 button clicks.
|
// Stores the last AST generated by Test1 or Test2 button clicks.
|
||||||
FLastAst: IExpressionNode;
|
FLastAst: IAstNode;
|
||||||
FGScope: IExecutionScope;
|
FGScope: IExecutionScope;
|
||||||
FWorkspace: TAuraWorkspace;
|
FWorkspace: TAuraWorkspace;
|
||||||
function CreateVisitor(const AScope: IExecutionScope): IAstVisitor;
|
function CreateVisitor(const AScope: IExecutionScope): IAstVisitor;
|
||||||
procedure WorkspaceMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
|
procedure WorkspaceMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
|
||||||
// New helper function to encapsulate the Bind -> Evaluate pattern
|
// New helper function to encapsulate the Bind -> Evaluate pattern
|
||||||
function ExecuteAst(const ANode: IExpressionNode; const AParentScope: IExecutionScope): TAstValue;
|
function ExecuteAst(const ANode: IAstNode; const AParentScope: IExecutionScope): TAstValue;
|
||||||
public
|
public
|
||||||
{ Public declarations }
|
{ Public declarations }
|
||||||
end;
|
end;
|
||||||
@@ -120,7 +125,7 @@ begin
|
|||||||
Result := TEvaluatorVisitor.Create(AScope);
|
Result := TEvaluatorVisitor.Create(AScope);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TForm1.ExecuteAst(const ANode: IExpressionNode; const AParentScope: IExecutionScope): TAstValue;
|
function TForm1.ExecuteAst(const ANode: IAstNode; const AParentScope: IExecutionScope): TAstValue;
|
||||||
var
|
var
|
||||||
scriptScope: IExecutionScope;
|
scriptScope: IExecutionScope;
|
||||||
begin
|
begin
|
||||||
@@ -144,7 +149,7 @@ end;
|
|||||||
|
|
||||||
procedure TForm1.FibonacciButtonClick(Sender: TObject);
|
procedure TForm1.FibonacciButtonClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
root: IExpressionNode;
|
root: IAstNode;
|
||||||
result: TAstValue;
|
result: TAstValue;
|
||||||
sw: TStopwatch;
|
sw: TStopwatch;
|
||||||
begin
|
begin
|
||||||
@@ -208,7 +213,7 @@ end;
|
|||||||
|
|
||||||
procedure TForm1.RecursionButtonClick(Sender: TObject);
|
procedure TForm1.RecursionButtonClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
root: IExpressionNode;
|
root: IAstNode;
|
||||||
result: TAstValue;
|
result: TAstValue;
|
||||||
sw: TStopwatch;
|
sw: TStopwatch;
|
||||||
begin
|
begin
|
||||||
@@ -252,7 +257,7 @@ end;
|
|||||||
procedure TForm1.SeriesTestButtonClick(Sender: TObject);
|
procedure TForm1.SeriesTestButtonClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
scope: IExecutionScope;
|
scope: IExecutionScope;
|
||||||
ast, callAst: IExpressionNode;
|
ast, callAst: IAstNode;
|
||||||
resultValue: TAstValue;
|
resultValue: TAstValue;
|
||||||
series: TScalarRecordSeries;
|
series: TScalarRecordSeries;
|
||||||
recordDef: TScalarRecordDefinition;
|
recordDef: TScalarRecordDefinition;
|
||||||
@@ -308,7 +313,7 @@ end;
|
|||||||
|
|
||||||
procedure TForm1.Test1ButtonClick(Sender: TObject);
|
procedure TForm1.Test1ButtonClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
main, callAst: IExpressionNode;
|
main, callAst: IAstNode;
|
||||||
result: TAstValue;
|
result: TAstValue;
|
||||||
sw: TStopwatch;
|
sw: TStopwatch;
|
||||||
begin
|
begin
|
||||||
@@ -342,7 +347,7 @@ end;
|
|||||||
|
|
||||||
procedure TForm1.Test2ButtonClick(Sender: TObject);
|
procedure TForm1.Test2ButtonClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
root: IExpressionNode;
|
root: IAstNode;
|
||||||
result: TAstValue;
|
result: TAstValue;
|
||||||
sw: TStopwatch;
|
sw: TStopwatch;
|
||||||
begin
|
begin
|
||||||
@@ -584,7 +589,7 @@ var
|
|||||||
|
|
||||||
procedure TForm1.CreateTriggerExampleButtonClick(Sender: TObject);
|
procedure TForm1.CreateTriggerExampleButtonClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
blk: IExpressionNode;
|
blk: IAstNode;
|
||||||
begin
|
begin
|
||||||
// This is a setup script, so its goal is to create and populate FGScope.
|
// This is a setup script, so its goal is to create and populate FGScope.
|
||||||
Memo1.Lines.Clear;
|
Memo1.Lines.Clear;
|
||||||
@@ -640,4 +645,58 @@ begin
|
|||||||
Memo1.Lines.Add(Format('Tick(2)! New value of X: %s', [X.ToString]));
|
Memo1.Lines.Add(Format('Tick(2)! New value of X: %s', [X.ToString]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.FromJSONButtonClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
// Reads an AST JSON string from the memo and deserializes it into FLastAst.
|
||||||
|
if Memo1.Lines.Text.IsEmpty then
|
||||||
|
begin
|
||||||
|
Memo1.Lines.Text := 'Memo is empty. Paste an AST JSON structure here first.';
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
try
|
||||||
|
Memo1.Lines.Insert(0, '--- Deserializing AST from JSON ---');
|
||||||
|
FLastAst := TAstProjectPersistence.JsonStringToAstNode(Memo1.Lines.Text);
|
||||||
|
if Assigned(FLastAst) then
|
||||||
|
begin
|
||||||
|
Memo1.Lines.Add('--- Deserialization successful. ---');
|
||||||
|
Memo1.Lines.Add('Middle-click on the right panel to visualize the new AST.');
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
Memo1.Lines.Add('--- Deserialization failed. Invalid JSON or data structure. ---');
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on E: Exception do
|
||||||
|
begin
|
||||||
|
Memo1.Lines.Add('--- ERROR during deserialization ---');
|
||||||
|
Memo1.Lines.Add(E.ClassName + ': ' + E.Message);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.ToJSONButtonClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
// Serializes the current FLastAst to a JSON string and displays it in the memo.
|
||||||
|
Memo1.Lines.Clear;
|
||||||
|
Memo1.Lines.Add('--- Serializing AST to JSON ---');
|
||||||
|
|
||||||
|
if not Assigned(FLastAst) then
|
||||||
|
begin
|
||||||
|
Memo1.Lines.Add('No AST available to serialize. Generate one first.');
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
try
|
||||||
|
Memo1.Lines.Text := TAstProjectPersistence.AstNodeToJsonString(FLastAst);
|
||||||
|
except
|
||||||
|
on E: Exception do
|
||||||
|
begin
|
||||||
|
Memo1.Lines.Clear;
|
||||||
|
Memo1.Lines.Add('--- ERROR during serialization ---');
|
||||||
|
Memo1.Lines.Add(E.ClassName + ': ' + E.Message);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ type
|
|||||||
const ChildVisitorProc: TChildVisitorProc
|
const ChildVisitorProc: TChildVisitorProc
|
||||||
): TAuraNode;
|
): TAuraNode;
|
||||||
function VisitOperatorNode(
|
function VisitOperatorNode(
|
||||||
const InputExpressions: TArray<IExpressionNode>;
|
const InputExpressions: TArray<IAstNode>;
|
||||||
const CreateParentProc: TCreateParentNodeProc;
|
const CreateParentProc: TCreateParentNodeProc;
|
||||||
Alignment: TVerticalAlignment = vaCenter
|
Alignment: TVerticalAlignment = vaCenter
|
||||||
): TAuraNode;
|
): TAuraNode;
|
||||||
@@ -1073,7 +1073,7 @@ end;
|
|||||||
function TAstToAuraNodeVisitor.VisitAddSeriesItem(const Node: IAddSeriesItemNode): TAstValue;
|
function TAstToAuraNodeVisitor.VisitAddSeriesItem(const Node: IAddSeriesItemNode): TAstValue;
|
||||||
var
|
var
|
||||||
details: string;
|
details: string;
|
||||||
inputs: TArray<IExpressionNode>;
|
inputs: TArray<IAstNode>;
|
||||||
begin
|
begin
|
||||||
if (FMode = vmControlFlow) and TryGetDescr(Node, details) then
|
if (FMode = vmControlFlow) and TryGetDescr(Node, details) then
|
||||||
begin
|
begin
|
||||||
@@ -1235,7 +1235,7 @@ begin
|
|||||||
false,
|
false,
|
||||||
procedure(const Visitor: IAstVisitor)
|
procedure(const Visitor: IAstVisitor)
|
||||||
var
|
var
|
||||||
expression: IExpressionNode;
|
expression: IAstNode;
|
||||||
begin
|
begin
|
||||||
for expression in Node.Expressions do
|
for expression in Node.Expressions do
|
||||||
expression.Accept(Visitor);
|
expression.Accept(Visitor);
|
||||||
@@ -1391,7 +1391,7 @@ end;
|
|||||||
|
|
||||||
function TAstToAuraNodeVisitor.VisitFunctionCall(const Node: IFunctionCallNode): TAstValue;
|
function TAstToAuraNodeVisitor.VisitFunctionCall(const Node: IFunctionCallNode): TAstValue;
|
||||||
var
|
var
|
||||||
inputExpressions: TArray<IExpressionNode>;
|
inputExpressions: TArray<IAstNode>;
|
||||||
begin
|
begin
|
||||||
var details: String;
|
var details: String;
|
||||||
if (FMode = vmControlFlow) and TryGetDescr(Node, details) then
|
if (FMode = vmControlFlow) and TryGetDescr(Node, details) then
|
||||||
@@ -1665,13 +1665,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TAstToAuraNodeVisitor.VisitOperatorNode(
|
function TAstToAuraNodeVisitor.VisitOperatorNode(
|
||||||
const InputExpressions: TArray<IExpressionNode>;
|
const InputExpressions: TArray<IAstNode>;
|
||||||
const CreateParentProc: TCreateParentNodeProc;
|
const CreateParentProc: TCreateParentNodeProc;
|
||||||
Alignment: TVerticalAlignment
|
Alignment: TVerticalAlignment
|
||||||
): TAuraNode;
|
): TAuraNode;
|
||||||
var
|
var
|
||||||
inputResults: TAuraNodeResultList;
|
inputResults: TAuraNodeResultList;
|
||||||
inputNode: IExpressionNode;
|
inputNode: IAstNode;
|
||||||
startPosition: TPointF;
|
startPosition: TPointF;
|
||||||
endY, maxChildWidth: Single;
|
endY, maxChildWidth: Single;
|
||||||
parentNode: TAuraNode;
|
parentNode: TAuraNode;
|
||||||
|
|||||||
+54
-66
@@ -1,80 +1,68 @@
|
|||||||
### **Projektplan: Visueller AST-Editor für Handelsstrategien**
|
### **Roadmap: Implementierung des Interaktiven Semantischen Editors**
|
||||||
|
|
||||||
* **Datum:** 08.09.2025 11:38
|
**Leitprinzip:** Die Serialisierung ist kein nachträgliches Feature, sondern das Fundament. Das Datenformat wird zuerst vollständig definiert und implementiert. Die Visualisierungs- und Editierfunktionen bauen darauf auf.
|
||||||
|
|
||||||
#### **Motivation**
|
|
||||||
|
|
||||||
Ziel ist die Schaffung eines Systems, das es Fachexperten ohne Programmierkenntnisse ermöglicht, komplexe Handelsstrategien visuell zu entwerfen, zu debuggen und zu backtesten. Die traditionelle Hürde der textbasierten Programmierung wird durch einen rein visuellen, geführten Ansatz eliminiert, der Fehler von vornherein vermeidet. Eine Kernanforderung ist die robuste Schnittstelle für den Import und Export von Logik aus externen Quellen, insbesondere LLMs.
|
|
||||||
|
|
||||||
#### **Ziel**
|
|
||||||
|
|
||||||
Die Entwicklung einer dualen Systemarchitektur, die eine intuitive, fehlerresistente Entwicklungsumgebung von einer hochperformanten Backtesting-Engine trennt. Die Architektur muss eine strikte Trennung zwischen dem logischen Modell (AST) und dem visuellen Zustand (UI-Metadaten) gewährleisten, um eine hohe Datenintegrität bei internen und externen Bearbeitungen sicherzustellen und eine nahtlose Persistenz von Projekten zu ermöglichen.
|
|
||||||
|
|
||||||
#### **Ergebnis: Architekturentwurf**
|
|
||||||
|
|
||||||
Der Editor basiert auf einer verfeinerten Model-View-ViewModel-Architektur, die maximale Robustheit und Flexibilität gewährleistet.
|
|
||||||
|
|
||||||
1. **Das Model: Der High-Level AST (HAST)**
|
|
||||||
* Der IAstNode-Baum ist die alleinige "Source of Truth" und enthält ausschließlich die reine, zustandslose Programmlogik. Diese Datenreinheit ist die Voraussetzung für die einfache Serialisierung und die Interaktion mit externen Systemen.
|
|
||||||
2. **Der Vermittler: Die ViewModel-Schicht**
|
|
||||||
* Ein parallel zum HAST existierender Baum aus TVisualNodeViewModel-Objekten dient als Brücke zur UI.
|
|
||||||
* Jedes ViewModel erhält eine **stabile, permanente ID** (TViewModelID), die es unabhängig von seiner Position im Baum macht. Diese ID ist der Schlüssel zur Lösung für stabile Bearbeitungen und Metadaten.
|
|
||||||
3. **Die Ansicht: Deterministisches Layout mit Overrides**
|
|
||||||
* Die visuelle Darstellung (TAuraNode-Controls) wird durch einen deterministischen Algorithmus aus dem ViewModel-Baum generiert (View \= f(ViewModel)).
|
|
||||||
* Manuelle Layout-Änderungen durch den Benutzer werden als "Overrides" in einer separaten Metadaten-Struktur gespeichert und über die stabile TViewModelID zugeordnet.
|
|
||||||
4. **Zweifaches Metadaten-System**
|
|
||||||
* **Logische Metadaten** (z.B. Farbkodierung) werden an den IAstNode gekoppelt und gelten für alle seine visuellen Instanzen.
|
|
||||||
* **Visuelle Instanz-Metadaten** (z.B. Position, IsCollapsed) werden an die stabile TViewModelID gekoppelt und gelten nur für eine spezifische Instanz.
|
|
||||||
5. **Duale Ausführungs-Engines & Serialisierung**
|
|
||||||
* Ein **HAST-Interpreter** arbeitet im Debug-Modus direkt auf dem HAST für eine reichhaltige UI-Erfahrung.
|
|
||||||
* Ein **CAST-Evaluator** arbeitet im Backtest-Modus auf einer optimierten Repräsentation (Core AST) für maximale Performance.
|
|
||||||
* Ein **duales Clipboard/Dateiformat** serialisiert entweder nur den reinen HAST (für LLMs) oder den HAST inklusive aller Metadaten (für Projekte).
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### **TODO: Priorisierte Roadmap**
|
#### **Phase 1: Das Fundament – Datenmodell & Persistenz**
|
||||||
|
|
||||||
#### **Phase 1: Minimales Architektur-Fundament**
|
**Ziel:** Eine robuste Serialisierungs-Engine zu schaffen, die den gesamten Zustand des Editors (AST, logische Metadaten, Instanz-Metadaten) verlustfrei speichern und laden kann, *bevor* eine einzige visuelle Komponente existiert.
|
||||||
|
|
||||||
* **Ziel:** Die technische Basis für alle weiteren Schritte schaffen. Dieser Schritt ist die Voraussetzung für die Serialisierung.
|
1. **Definition der Kern-Datenstrukturen:**
|
||||||
* **Schritte:**
|
* **TViewModelID**: Ein Int64-Typ als eindeutige, stabile ID für jede visuelle Knoteninstanz.
|
||||||
1. **ViewModel-Schicht implementieren:** Die TVisualNodeViewModel-Klasse mit der stabilen TViewModelID erstellen.
|
* **TVisualNodeViewModel**: Die Vermittlerklasse zwischen IAstNode und TAuraNode. Enthält eine Referenz auf den IAstNode und seine eigene TViewModelID.
|
||||||
2. **Metadaten-Strukturen aufbauen:** Die beiden Dictionaries für TLogicalMetadata (gekoppelt an IAstNode) und TVisualInstanceMetadata (gekoppelt an TViewModelID) definieren und implementieren.
|
* **TLogicalMetadata**: Record für Metadaten, die an einen IAstNode gebunden sind (z.B. semantische Farbcodierung).
|
||||||
3. **Visitor refaktorisieren:** Den TAstToAuraNodeVisitor so umbauen, dass er den ViewModel-Baum erzeugt und dabei die stabilen IDs vergibt.
|
* **TVisualInstanceMetadata**: Record für Metadaten, die an eine TViewModelID gebunden sind. **Hier wird die neue Anforderung verankert:**
|
||||||
4. **Layout-Engine implementieren:** Den deterministischen Layout-Algorithmus umsetzen, der die Basis-Positionierung vornimmt. Die Engine muss bereits in der Lage sein, Positions-Overrides aus den TVisualInstanceMetadata zu berücksichtigen.
|
* PositionOverride: TPointF
|
||||||
|
* IsCollapsed: Boolean
|
||||||
|
* VisualizationMode: (vmSyntactic, vmSemantic) // Definiert, wie DIESE Instanz ihre Kinder darstellt.
|
||||||
|
2. **Festlegung des finalen JSON-Formats:**
|
||||||
|
* Das JSON-Format wird von Anfang an so entworfen, dass es alle zukünftigen Anforderungen abbilden kann. Es besteht aus drei Hauptteilen:
|
||||||
|
1. **ast**: Der reine IAstNode-Baum. Zur Persistenz wird jedem IAstNode beim Speichern eine temporäre, datei-interne Integer-ID zugewiesen.
|
||||||
|
2. **logicalMetadata**: Ein Dictionary, das die temporären IAstNode-IDs auf ihre TLogicalMetadata abbildet.
|
||||||
|
3. **instanceMetadata**: Ein Dictionary, das die stabilen TViewModelIDs auf ihre TVisualInstanceMetadata abbildet (inklusive des neuen VisualizationMode).
|
||||||
|
3. **Implementierung des Serialisierungs- & Deserialisierungs-Backbones:**
|
||||||
|
* Entwicklung der Routinen, die einen IAstNode-Baum und die dazugehörigen Metadaten-Dictionaries entgegennehmen und eine JSON-Datei gemäß Schritt 1.2 erzeugen.
|
||||||
|
* Entwicklung der Gegenstücke, die eine solche JSON-Datei einlesen und die In-Memory-Strukturen (IAstNode-Baum, Dictionaries für Metadaten) vollständig und konsistent wiederherstellen.
|
||||||
|
* **Wichtig:** Diese Logik arbeitet komplett ohne UI-Komponenten.
|
||||||
|
|
||||||
#### **Phase 2: Kern-Feature – Persistenz & Interoperabilität**
|
**Ergebnis von Phase 1:** Eine voll funktionsfähige "headless" Lade- & Speicher-Bibliothek. Man kann einen Editor-Zustand programmatisch erzeugen, speichern, wieder laden und die Datenintegrität per Unit-Tests verifizieren. **Die Serialisierung ist damit vom ersten Tag an das stabilste Element der Architektur.**
|
||||||
|
|
||||||
* **Ziel:** Das System schnellstmöglich nutzbar machen, indem Projekte gespeichert/geladen und Logik extern ausgetauscht werden kann.
|
---
|
||||||
* **Schritte:**
|
|
||||||
1. **Duale JSON-Serialisierung entwickeln:**
|
|
||||||
* **Routine A (Projekt):** Serialisiert den HAST und beide Metadaten-Systeme.
|
|
||||||
* **Routine B (Logik-Clipboard):** Serialisiert ausschließlich den reinen HAST.
|
|
||||||
2. **Deserialisierung implementieren:**
|
|
||||||
* **"Projekt laden":** Stellt den HAST, den ViewModel-Baum und alle Metadaten aus der Projektdatei vollständig wieder her.
|
|
||||||
* **"Logik einfügen":** Eine pragmatische erste Version, die einen reinen HAST-Teilbaum deserialisiert, dafür neue ViewModels mit neuen IDs erzeugt und ihn von der Layout-Engine automatisch positionieren lässt.
|
|
||||||
3. **UI-Anbindung:** Die Aktionen "Projekt speichern", "Projekt laden", "Logik als JSON kopieren" und "Logik aus JSON einfügen" in der UI implementieren.
|
|
||||||
|
|
||||||
#### **Phase 3: Interaktivität & Benutzerführung**
|
#### **Phase 2: Die Flexible Visualisierungs-Engine**
|
||||||
|
|
||||||
* **Ziel:** Den Editor um die volle, geführte Bearbeitungsfunktionalität erweitern.
|
**Ziel:** Die in Phase 1 definierten Datenstrukturen sichtbar machen und den Wechsel zwischen syntaktischer und semantischer Darstellung ermöglichen.
|
||||||
* **Schritte:**
|
|
||||||
1. **Command Pattern umsetzen:** IEditorCommand-Schnittstelle und TCommandManager für Undo/Redo erstellen.
|
|
||||||
2. **Socket-basierte Controller-Logik entwickeln:** Die Interaktion implementieren, bei der Klicks auf Input-Sockets kontextsensitive Menüs mit validen Optionen öffnen. Jede Aktion wird über das Command-System abgewickelt.
|
|
||||||
3. **Refactoring-Funktionen implementieren:** Visuelle Operationen wie "Zu Funktion zusammenfassen" umsetzen.
|
|
||||||
|
|
||||||
#### **Phase 4: Ausführung & Debugging**
|
1. **Der "ViewModel-Builder"-Visitor:**
|
||||||
|
* Dieser Visitor nimmt einen IAstNode (HAST) sowie die Metadaten entgegen und erzeugt den TVisualNodeViewModel-Graphen.
|
||||||
|
* Er arbeitet modus-abhängig, basierend auf dem VisualizationMode des Eltern-ViewModels:
|
||||||
|
* **Im vmSyntactic-Modus:** Erzeugt für jeden Kind-IAstNode eine neue, einzigartige TVisualNodeViewModel-Instanz mit einer neuen TViewModelID. Das Ergebnis ist ein Baum.
|
||||||
|
* **Im vmSemantic-Modus:** Nutzt nach dem obligatorischen Binding-Schritt einen TDictionary\<TResolvedAddress, TVisualNodeViewModel\>, um für bereits visualisierte semantische Entitäten das existierende ViewModel wiederzuverwenden. Das Ergebnis ist ein DAG.
|
||||||
|
2. **Die Layout- & Rendering-Engine (TAuraLayoutEngine):**
|
||||||
|
* Diese Engine nimmt den TVisualNodeViewModel-Graphen (der ein Baum oder DAG sein kann) und erzeugt die visuellen TAuraNode-Controls.
|
||||||
|
* Für jedes ViewModel liest sie die TVisualInstanceMetadata (über die TViewModelID) und wendet Position, Kollaps-Zustand etc. an.
|
||||||
|
* Sie muss in der Lage sein, die Verbindungen für eine DAG-Struktur korrekt zu zeichnen (d.h. Linien von mehreren Eltern zu einem Kind).
|
||||||
|
3. **Implementierung des Modus-Wechsels:**
|
||||||
|
* Schaffung einer UI-Aktion (z.B. Kontextmenü auf einem TAuraNode), um den VisualizationMode in den Metadaten einer ViewModel-Instanz zu ändern.
|
||||||
|
* Diese Änderung löst eine Aktualisierung aus: Der ViewModel-Builder wird für den betroffenen Teilbaum neu ausgeführt, und die Layout-Engine zeichnet den Bereich neu.
|
||||||
|
|
||||||
* **Ziel:** Den im Editor erstellten HAST interaktiv ausführbar und debuggbar machen.
|
**Ergebnis von Phase 2:** Ein interaktiver Viewer. Projekte können geladen, in beiden Modi (syntaktisch/semantisch) dargestellt und per Knoten umgeschaltet werden.
|
||||||
* **Schritte:**
|
|
||||||
1. Den **HAST-Interpreter** (Debugger) implementieren oder ausbauen.
|
|
||||||
2. Den Interpreter tief mit der UI und dem ViewModel-Baum koppeln, um Debugging-Features zu realisieren (visuelles Hervorheben, Breakpoints, Step-Logik etc.).
|
|
||||||
|
|
||||||
#### **Phase 5: Performance & Optimierung**
|
---
|
||||||
|
|
||||||
* **Ziel:** Die Ausführung von Strategien für die Massen-Datenverarbeitung optimieren und die UX verfeinern.
|
#### **Phase 3: Der Interaktive Editor**
|
||||||
* **Schritte:**
|
|
||||||
1. Die **CAST-Struktur** (Core AST) definieren.
|
**Ziel:** Dem Benutzer die sichere und strukturierte Bearbeitung des Graphen zu ermöglichen.
|
||||||
2. Den **HAST-zu-CAST-Expander** (Compiler/Visitor) entwickeln.
|
|
||||||
3. Den "headless" **CAST-Evaluator** (Backtester) implementieren.
|
1. **Implementierung des Command Patterns:**
|
||||||
4. Den **"Smart Paste"-Algorithmus** (Diff & Merge) als finale Verfeinerung für das Einfügen von Logik nachrüsten.
|
* Jede Änderung am AST (Knoten hinzufügen, löschen, Eigenschaft ändern) wird als IEditorCommand mit Execute und Unexecute implementiert, um Undo/Redo zu ermöglichen.
|
||||||
|
* Ein Command modifiziert **immer nur das HAST-Modell**, niemals direkt das ViewModel oder die View.
|
||||||
|
2. **Entwicklung des Socket-basierten Controllers:**
|
||||||
|
* Implementierung der Logik, die Benutzerinteraktionen (Klick auf ein "Socket") in die Erzeugung und Ausführung des passenden Commands übersetzt.
|
||||||
|
3. **Etablierung des Update-Zyklus:**
|
||||||
|
* Nachdem ein Command das HAST-Modell erfolgreich modifiziert hat, wird der Update-Prozess angestoßen:
|
||||||
|
1. Der "ViewModel-Builder" läuft über den geänderten Teil des HAST. Er versucht dabei, existierende ViewModels (anhand ihrer IAstNode-Referenz) wiederzuverwenden, um deren stabile IDs und damit die UI-Zustände zu erhalten. Nur für neue IAstNodes werden neue ViewModels erzeugt.
|
||||||
|
2. Die TAuraLayoutEngine rendert die neuen TAuraNode-Controls.
|
||||||
|
|
||||||
|
**Ergebnis von Phase 3:** Ein voll funktionsfähiger, interaktiver Editor mit robustem Zustandsmanagement, flexibler Visualisierung und Undo/Redo-Funktionalität.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
### **Projektplan: Visueller Editor für Handelsstrategien (Revision 1\)**
|
||||||
|
|
||||||
|
* **Datum:** 08.09.2025 14:20
|
||||||
|
|
||||||
|
#### **Motivation**
|
||||||
|
|
||||||
|
Ziel ist die Schaffung eines Systems, das es Fachexperten ermöglicht, die **Logik und den Datenfluss** von Handelsstrategien visuell zu entwerfen. Statt der reinen Syntax wird der **semantische Graph** abgebildet, um Redundanzen zu eliminieren und die tatsächlichen Beziehungen zwischen den Variablen und Operationen in den Vordergrund zu stellen. Dies schafft ein intuitiveres Verständnis der Strategie-Logik.
|
||||||
|
|
||||||
|
#### **Ziel**
|
||||||
|
|
||||||
|
Die Entwicklung einer Architektur, die den **semantisch korrekten Graphen** einer Strategie visualisiert. Dies erfordert eine klare Abfolge der Verarbeitungsschritte: Zuerst muss eine semantische Analyse (Binding) des rohen Abstract Syntax Tree (AST) erfolgen. Erst auf Basis dieses angereicherten, semantischen Modells wird der visuelle Graph (ein Directed Acyclic Graph, DAG) erzeugt, in dem semantisch identische Entitäten (z.B. Verwendungen derselben Variable) zu einem einzigen visuellen Knoten zusammengefasst werden.
|
||||||
|
|
||||||
|
#### **Ergebnis: Architekturentwurf (Revision 1\)**
|
||||||
|
|
||||||
|
Die Architektur wird angepasst, um den semantischen Graphen als "Source of Truth" für die Visualisierung zu nutzen.
|
||||||
|
|
||||||
|
1. **Semantische Analyse als Voraussetzung:** Der Bind-Prozess ist der obligatorische erste Schritt vor jeder Visualisierung. Er analysiert den AST und reichert die Knoten, insbesondere die Identifier, mit semantischen Adressinformationen (TResolvedAddress) an.
|
||||||
|
2. **Der Builder (TAstToViewModelVisitor):** Der Visitor wird intelligent. Er übersetzt den AST nicht mehr 1:1, sondern erzeugt einen TVisualNodeViewModel-Graphen (DAG). Dazu nutzt er einen internen Cache (TDictionary\<TResolvedAddress, TVisualNodeViewModel\>), um bereits erstellte ViewModels für semantisch identische Identifier wiederzuverwenden.
|
||||||
|
3. **Das Modell (TVisualNodeViewModel):** Die Struktur der ViewModels ist nicht länger ein Baum, sondern ein DAG, da ein Knoten (z.B. für eine Variable) nun von mehreren Elternknoten referenziert werden kann.
|
||||||
|
4. **Die Ansicht (TAuraLayoutEngine):** Die Layout-Engine muss in der Lage sein, die resultierende DAG-Struktur korrekt darzustellen, inklusive der Verbindungen von mehreren Eltern zu einem Kind.
|
||||||
|
|
||||||
@@ -90,11 +90,11 @@ type
|
|||||||
|
|
||||||
TClosureValue = class(TInterfacedObject, TAstValue.IClosure)
|
TClosureValue = class(TInterfacedObject, TAstValue.IClosure)
|
||||||
private
|
private
|
||||||
FBody: IExpressionNode;
|
FBody: IAstNode;
|
||||||
FClosureScope: IExecutionScope;
|
FClosureScope: IExecutionScope;
|
||||||
FLambdaNode: ILambdaExpressionNode;
|
FLambdaNode: ILambdaExpressionNode;
|
||||||
FUpvalues: TArray<IValueCell>;
|
FUpvalues: TArray<IValueCell>;
|
||||||
function GetBody: IExpressionNode;
|
function GetBody: IAstNode;
|
||||||
function GetParameters: TArray<IIdentifierNode>;
|
function GetParameters: TArray<IIdentifierNode>;
|
||||||
function GetClosureScope: IExecutionScope;
|
function GetClosureScope: IExecutionScope;
|
||||||
function GetUpvalues: TArray<IValueCell>;
|
function GetUpvalues: TArray<IValueCell>;
|
||||||
@@ -113,7 +113,7 @@ type
|
|||||||
TNativeClosure = class(TInterfacedObject, TAstValue.IClosure)
|
TNativeClosure = class(TInterfacedObject, TAstValue.IClosure)
|
||||||
private
|
private
|
||||||
FMethod: TNativeFunction;
|
FMethod: TNativeFunction;
|
||||||
function GetBody: IExpressionNode;
|
function GetBody: IAstNode;
|
||||||
function GetParameters: TArray<IIdentifierNode>;
|
function GetParameters: TArray<IIdentifierNode>;
|
||||||
function GetClosureScope: IExecutionScope;
|
function GetClosureScope: IExecutionScope;
|
||||||
function GetUpvalues: TArray<IValueCell>;
|
function GetUpvalues: TArray<IValueCell>;
|
||||||
@@ -167,7 +167,7 @@ begin
|
|||||||
FUpvalues := AUpvalues; // Store the captured cells
|
FUpvalues := AUpvalues; // Store the captured cells
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TClosureValue.GetBody: IExpressionNode;
|
function TClosureValue.GetBody: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FBody;
|
Result := FBody;
|
||||||
end;
|
end;
|
||||||
@@ -195,7 +195,7 @@ begin
|
|||||||
FMethod := AMethod;
|
FMethod := AMethod;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TNativeClosure.GetBody: IExpressionNode;
|
function TNativeClosure.GetBody: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := nil;
|
Result := nil;
|
||||||
end;
|
end;
|
||||||
@@ -639,7 +639,7 @@ end;
|
|||||||
|
|
||||||
function TEvaluatorVisitor.VisitBlockExpression(const Node: IBlockExpressionNode): TAstValue;
|
function TEvaluatorVisitor.VisitBlockExpression(const Node: IBlockExpressionNode): TAstValue;
|
||||||
var
|
var
|
||||||
expression: IExpressionNode;
|
expression: IAstNode;
|
||||||
begin
|
begin
|
||||||
// The result of a block is the result of its last expression.
|
// The result of a block is the result of its last expression.
|
||||||
Result := TAstValue.Void;
|
Result := TAstValue.Void;
|
||||||
|
|||||||
+58
-62
@@ -27,7 +27,6 @@ type
|
|||||||
// --- Forward Declarations to break cycles ---
|
// --- Forward Declarations to break cycles ---
|
||||||
IAstVisitor = interface;
|
IAstVisitor = interface;
|
||||||
IAstNode = interface;
|
IAstNode = interface;
|
||||||
IExpressionNode = interface;
|
|
||||||
IIdentifierNode = interface;
|
IIdentifierNode = interface;
|
||||||
IConstantNode = interface;
|
IConstantNode = interface;
|
||||||
IBinaryExpressionNode = interface;
|
IBinaryExpressionNode = interface;
|
||||||
@@ -54,12 +53,12 @@ type
|
|||||||
type
|
type
|
||||||
IClosure = interface
|
IClosure = interface
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetBody: IExpressionNode;
|
function GetBody: IAstNode;
|
||||||
function GetClosureScope: IExecutionScope;
|
function GetClosureScope: IExecutionScope;
|
||||||
function GetParameters: TArray<IIdentifierNode>;
|
function GetParameters: TArray<IIdentifierNode>;
|
||||||
function GetUpvalues: TArray<IValueCell>;
|
function GetUpvalues: TArray<IValueCell>;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Body: IExpressionNode read GetBody;
|
property Body: IAstNode read GetBody;
|
||||||
property ClosureScope: IExecutionScope read GetClosureScope;
|
property ClosureScope: IExecutionScope read GetClosureScope;
|
||||||
property Parameters: TArray<IIdentifierNode> read GetParameters;
|
property Parameters: TArray<IIdentifierNode> read GetParameters;
|
||||||
property Upvalues: TArray<IValueCell> read GetUpvalues;
|
property Upvalues: TArray<IValueCell> read GetUpvalues;
|
||||||
@@ -170,17 +169,14 @@ type
|
|||||||
function Accept(const Visitor: IAstVisitor): TAstValue;
|
function Accept(const Visitor: IAstVisitor): TAstValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
IExpressionNode = interface(IAstNode)
|
IConstantNode = interface(IAstNode)
|
||||||
end;
|
|
||||||
|
|
||||||
IConstantNode = interface(IExpressionNode)
|
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetValue: TScalar;
|
function GetValue: TScalar;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Value: TScalar read GetValue;
|
property Value: TScalar read GetValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
IIdentifierNode = interface(IExpressionNode)
|
IIdentifierNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetIsResolved: Boolean;
|
function GetIsResolved: Boolean;
|
||||||
function GetAddress: TResolvedAddress;
|
function GetAddress: TResolvedAddress;
|
||||||
@@ -191,119 +187,119 @@ type
|
|||||||
property Address: TResolvedAddress read GetAddress;
|
property Address: TResolvedAddress read GetAddress;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
IBinaryExpressionNode = interface(IExpressionNode)
|
IBinaryExpressionNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetLeft: IExpressionNode;
|
function GetLeft: IAstNode;
|
||||||
function GetOperator: TBinaryOperator;
|
function GetOperator: TBinaryOperator;
|
||||||
function GetRight: IExpressionNode;
|
function GetRight: IAstNode;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Left: IExpressionNode read GetLeft;
|
property Left: IAstNode read GetLeft;
|
||||||
property Operator: TBinaryOperator read GetOperator;
|
property Operator: TBinaryOperator read GetOperator;
|
||||||
property Right: IExpressionNode read GetRight;
|
property Right: IAstNode read GetRight;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
IUnaryExpressionNode = interface(IExpressionNode)
|
IUnaryExpressionNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetOperator: TUnaryOperator;
|
function GetOperator: TUnaryOperator;
|
||||||
function GetRight: IExpressionNode;
|
function GetRight: IAstNode;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Operator: TUnaryOperator read GetOperator;
|
property Operator: TUnaryOperator read GetOperator;
|
||||||
property Right: IExpressionNode read GetRight;
|
property Right: IAstNode read GetRight;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Represents an if-statement for control flow.
|
// Represents an if-statement for control flow.
|
||||||
IIfExpressionNode = interface(IExpressionNode)
|
IIfExpressionNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetCondition: IExpressionNode;
|
function GetCondition: IAstNode;
|
||||||
function GetThenBranch: IExpressionNode;
|
function GetThenBranch: IAstNode;
|
||||||
function GetElseBranch: IExpressionNode;
|
function GetElseBranch: IAstNode;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Condition: IExpressionNode read GetCondition;
|
property Condition: IAstNode read GetCondition;
|
||||||
property ThenBranch: IExpressionNode read GetThenBranch;
|
property ThenBranch: IAstNode read GetThenBranch;
|
||||||
property ElseBranch: IExpressionNode read GetElseBranch;
|
property ElseBranch: IAstNode read GetElseBranch;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Represents a ternary expression (e.g., condition ? true_expr : false_expr) for value selection.
|
// Represents a ternary expression (e.g., condition ? true_expr : false_expr) for value selection.
|
||||||
ITernaryExpressionNode = interface(IExpressionNode)
|
ITernaryExpressionNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetCondition: IExpressionNode;
|
function GetCondition: IAstNode;
|
||||||
function GetThenBranch: IExpressionNode;
|
function GetThenBranch: IAstNode;
|
||||||
function GetElseBranch: IExpressionNode;
|
function GetElseBranch: IAstNode;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Condition: IExpressionNode read GetCondition;
|
property Condition: IAstNode read GetCondition;
|
||||||
property ThenBranch: IExpressionNode read GetThenBranch;
|
property ThenBranch: IAstNode read GetThenBranch;
|
||||||
property ElseBranch: IExpressionNode read GetElseBranch;
|
property ElseBranch: IAstNode read GetElseBranch;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ILambdaExpressionNode = interface(IExpressionNode)
|
ILambdaExpressionNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetParameters: TArray<IIdentifierNode>;
|
function GetParameters: TArray<IIdentifierNode>;
|
||||||
function GetBody: IExpressionNode;
|
function GetBody: IAstNode;
|
||||||
function GetScopeDescriptor: IScopeDescriptor;
|
function GetScopeDescriptor: IScopeDescriptor;
|
||||||
function GetUpvalues: TArray<TResolvedAddress>;
|
function GetUpvalues: TArray<TResolvedAddress>;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Parameters: TArray<IIdentifierNode> read GetParameters;
|
property Parameters: TArray<IIdentifierNode> read GetParameters;
|
||||||
property Body: IExpressionNode read GetBody;
|
property Body: IAstNode read GetBody;
|
||||||
property ScopeDescriptor: IScopeDescriptor read GetScopeDescriptor;
|
property ScopeDescriptor: IScopeDescriptor read GetScopeDescriptor;
|
||||||
property Upvalues: TArray<TResolvedAddress> read GetUpvalues;
|
property Upvalues: TArray<TResolvedAddress> read GetUpvalues;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
IFunctionCallNode = interface(IExpressionNode)
|
IFunctionCallNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetCallee: IExpressionNode;
|
function GetCallee: IAstNode;
|
||||||
function GetArguments: TList<IExpressionNode>;
|
function GetArguments: TList<IAstNode>;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Callee: IExpressionNode read GetCallee;
|
property Callee: IAstNode read GetCallee;
|
||||||
property Arguments: TList<IExpressionNode> read GetArguments;
|
property Arguments: TList<IAstNode> read GetArguments;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
IBlockExpressionNode = interface(IExpressionNode)
|
IBlockExpressionNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetExpressions: TList<IExpressionNode>;
|
function GetExpressions: TList<IAstNode>;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Expressions: TList<IExpressionNode> read GetExpressions;
|
property Expressions: TList<IAstNode> read GetExpressions;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
IVariableDeclarationNode = interface(IExpressionNode)
|
IVariableDeclarationNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetIdentifier: IIdentifierNode;
|
function GetIdentifier: IIdentifierNode;
|
||||||
function GetInitializer: IExpressionNode;
|
function GetInitializer: IAstNode;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Identifier: IIdentifierNode read GetIdentifier;
|
property Identifier: IIdentifierNode read GetIdentifier;
|
||||||
property Initializer: IExpressionNode read GetInitializer;
|
property Initializer: IAstNode read GetInitializer;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
IAssignmentNode = interface(IExpressionNode)
|
IAssignmentNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetIdentifier: IIdentifierNode;
|
function GetIdentifier: IIdentifierNode;
|
||||||
function GetValue: IExpressionNode;
|
function GetValue: IAstNode;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Identifier: IIdentifierNode read GetIdentifier;
|
property Identifier: IIdentifierNode read GetIdentifier;
|
||||||
property Value: IExpressionNode read GetValue;
|
property Value: IAstNode read GetValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Represents an index access expression (e.g., series[index]).
|
// Represents an index access expression (e.g., series[index]).
|
||||||
IIndexerNode = interface(IExpressionNode)
|
IIndexerNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetBase: IExpressionNode;
|
function GetBase: IAstNode;
|
||||||
function GetIndex: IExpressionNode;
|
function GetIndex: IAstNode;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Base: IExpressionNode read GetBase;
|
property Base: IAstNode read GetBase;
|
||||||
property Index: IExpressionNode read GetIndex;
|
property Index: IAstNode read GetIndex;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Represents a member access expression (e.g., series.field or record.field).
|
// Represents a member access expression (e.g., series.field or record.field).
|
||||||
IMemberAccessNode = interface(IExpressionNode)
|
IMemberAccessNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetBase: IExpressionNode;
|
function GetBase: IAstNode;
|
||||||
function GetMember: IIdentifierNode;
|
function GetMember: IIdentifierNode;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Base: IExpressionNode read GetBase;
|
property Base: IAstNode read GetBase;
|
||||||
property Member: IIdentifierNode read GetMember;
|
property Member: IIdentifierNode read GetMember;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Represents creating a new, empty series (e.g., new series(int)).
|
// Represents creating a new, empty series (e.g., new series(int)).
|
||||||
ICreateSeriesNode = interface(IExpressionNode)
|
ICreateSeriesNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetDefinition: String;
|
function GetDefinition: String;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
@@ -311,18 +307,18 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Represents adding a value to a series (e.g., my_series.add(value, 100)).
|
// Represents adding a value to a series (e.g., my_series.add(value, 100)).
|
||||||
IAddSeriesItemNode = interface(IExpressionNode)
|
IAddSeriesItemNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetSeries: IIdentifierNode;
|
function GetSeries: IIdentifierNode;
|
||||||
function GetValue: IExpressionNode;
|
function GetValue: IAstNode;
|
||||||
function GetLookback: IExpressionNode;
|
function GetLookback: IAstNode;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
property Series: IIdentifierNode read GetSeries;
|
property Series: IIdentifierNode read GetSeries;
|
||||||
property Value: IExpressionNode read GetValue;
|
property Value: IAstNode read GetValue;
|
||||||
property Lookback: IExpressionNode read GetLookback;
|
property Lookback: IAstNode read GetLookback;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ISeriesLengthNode = interface(IExpressionNode)
|
ISeriesLengthNode = interface(IAstNode)
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetSeries: IIdentifierNode;
|
function GetSeries: IIdentifierNode;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -182,7 +182,7 @@ end;
|
|||||||
|
|
||||||
function TPrettyPrintVisitor.VisitFunctionCall(const Node: IFunctionCallNode): TAstValue;
|
function TPrettyPrintVisitor.VisitFunctionCall(const Node: IFunctionCallNode): TAstValue;
|
||||||
var
|
var
|
||||||
arg: IExpressionNode;
|
arg: IAstNode;
|
||||||
begin
|
begin
|
||||||
AppendLine('FunctionCall');
|
AppendLine('FunctionCall');
|
||||||
Indent;
|
Indent;
|
||||||
@@ -201,7 +201,7 @@ end;
|
|||||||
|
|
||||||
function TPrettyPrintVisitor.VisitBlockExpression(const Node: IBlockExpressionNode): TAstValue;
|
function TPrettyPrintVisitor.VisitBlockExpression(const Node: IBlockExpressionNode): TAstValue;
|
||||||
var
|
var
|
||||||
expr: IExpressionNode;
|
expr: IAstNode;
|
||||||
begin
|
begin
|
||||||
AppendLine('Block');
|
AppendLine('Block');
|
||||||
Indent;
|
Indent;
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
unit Myc.Ast.ViewModel;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
System.SysUtils,
|
||||||
|
System.Types,
|
||||||
|
System.Generics.Collections,
|
||||||
|
Myc.Ast.Nodes;
|
||||||
|
|
||||||
|
type
|
||||||
|
// An enum to identify the specific type of an AST node without relying on RTTI or GUIDs.
|
||||||
|
// This allows the renderer to depend only on the ViewModel layer.
|
||||||
|
TAstNodeType = (
|
||||||
|
antUndefined,
|
||||||
|
antConstant,
|
||||||
|
antIdentifier,
|
||||||
|
antBinaryExpression,
|
||||||
|
antUnaryExpression,
|
||||||
|
antIfExpression,
|
||||||
|
antTernaryExpression,
|
||||||
|
antLambdaExpression,
|
||||||
|
antFunctionCall,
|
||||||
|
antBlockExpression,
|
||||||
|
antVariableDeclaration,
|
||||||
|
antAssignment,
|
||||||
|
antIndexer,
|
||||||
|
antMemberAccess,
|
||||||
|
antCreateSeries,
|
||||||
|
antAddSeriesItem,
|
||||||
|
antSeriesLength
|
||||||
|
);
|
||||||
|
|
||||||
|
// A unique, stable identifier for a visual node instance.
|
||||||
|
TViewModelID = NativeInt;
|
||||||
|
|
||||||
|
// Defines how a view model displays its children.
|
||||||
|
TVisualizationMode = (vmSyntactic, vmSemantic);
|
||||||
|
|
||||||
|
// Metadata tied to a logical IAstNode. All visual instances of this node will share this data.
|
||||||
|
TLogicalMetadata = record
|
||||||
|
// The concrete type of the IAstNode, used for type-safe operations in the renderer.
|
||||||
|
NodeType: TAstNodeType;
|
||||||
|
Description: String;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Metadata tied to a specific visual instance of a node, identified by its TViewModelID.
|
||||||
|
TVisualInstanceMetadata = record
|
||||||
|
PositionOverride: TPointF;
|
||||||
|
IsCollapsed: Boolean;
|
||||||
|
VisualizationMode: TVisualizationMode;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// The ViewModel for a node in the visual graph.
|
||||||
|
TVisualNodeViewModel = class
|
||||||
|
private
|
||||||
|
FId: TViewModelID;
|
||||||
|
FNode: IAstNode;
|
||||||
|
FLogicalMetadata: TLogicalMetadata;
|
||||||
|
FParents: TList<TVisualNodeViewModel>;
|
||||||
|
FChildren: TList<TVisualNodeViewModel>;
|
||||||
|
public
|
||||||
|
constructor Create(const ANode: IAstNode; const AId: TViewModelID; const ALogicalMetadata: TLogicalMetadata);
|
||||||
|
destructor Destroy; override;
|
||||||
|
|
||||||
|
procedure AddChild(const AChild: TVisualNodeViewModel);
|
||||||
|
|
||||||
|
property Id: TViewModelID read FId;
|
||||||
|
property Node: IAstNode read FNode;
|
||||||
|
property LogicalMetadata: TLogicalMetadata read FLogicalMetadata;
|
||||||
|
property Children: TList<TVisualNodeViewModel> read FChildren;
|
||||||
|
property Parents: TList<TVisualNodeViewModel> read FParents;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{ TVisualNodeViewModel }
|
||||||
|
|
||||||
|
constructor TVisualNodeViewModel.Create(const ANode: IAstNode; const AId: TViewModelID; const ALogicalMetadata: TLogicalMetadata);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
FNode := ANode;
|
||||||
|
FId := AId;
|
||||||
|
FLogicalMetadata := ALogicalMetadata;
|
||||||
|
FParents := TList<TVisualNodeViewModel>.Create;
|
||||||
|
FChildren := TList<TVisualNodeViewModel>.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TVisualNodeViewModel.Destroy;
|
||||||
|
begin
|
||||||
|
FParents.Free;
|
||||||
|
FChildren.Free;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TVisualNodeViewModel.AddChild(const AChild: TVisualNodeViewModel);
|
||||||
|
begin
|
||||||
|
FChildren.Add(AChild);
|
||||||
|
AChild.FParents.Add(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
+120
-134
@@ -17,38 +17,28 @@ type
|
|||||||
// --- Existing factory functions ---
|
// --- Existing factory functions ---
|
||||||
class function Constant(AValue: TScalar): IConstantNode; static;
|
class function Constant(AValue: TScalar): IConstantNode; static;
|
||||||
class function Identifier(AName: string): IIdentifierNode; static;
|
class function Identifier(AName: string): IIdentifierNode; static;
|
||||||
class function BinaryExpr(
|
class function BinaryExpr(ALeft: IAstNode; AOperator: TBinaryOperator; ARight: IAstNode): IBinaryExpressionNode; static;
|
||||||
ALeft: IExpressionNode;
|
class function UnaryExpr(const AOperator: TUnaryOperator; const ARight: IAstNode): IUnaryExpressionNode; static;
|
||||||
AOperator: TBinaryOperator;
|
class function IfExpr(const ACondition: IAstNode; const AThenBranch, AElseBranch: IAstNode): IIfExpressionNode; static;
|
||||||
ARight: IExpressionNode
|
class function TernaryExpr(const ACondition: IAstNode; const AThenBranch, AElseBranch: IAstNode): ITernaryExpressionNode; static;
|
||||||
): IBinaryExpressionNode; static;
|
class function LambdaExpr(const AParameters: TArray<IIdentifierNode>; const ABody: IAstNode): ILambdaExpressionNode; static;
|
||||||
class function UnaryExpr(const AOperator: TUnaryOperator; const ARight: IExpressionNode): IUnaryExpressionNode; static;
|
class function FunctionCall(const ACallee: IAstNode; const AArguments: array of IAstNode): IFunctionCallNode; static;
|
||||||
class function IfExpr(
|
class function Block(const AExpressions: array of IAstNode): IBlockExpressionNode; static;
|
||||||
const ACondition: IExpressionNode;
|
class function VarDecl(const AIdentifier: IIdentifierNode; AInitializer: IAstNode): IVariableDeclarationNode; static;
|
||||||
const AThenBranch, AElseBranch: IExpressionNode
|
class function Assign(const AIdentifier: IIdentifierNode; const AValue: IAstNode): IAssignmentNode; static;
|
||||||
): IIfExpressionNode; static;
|
class function AssignResult(const AValue: IAstNode): IAssignmentNode; static; deprecated;
|
||||||
class function TernaryExpr(
|
class function Indexer(const ABase: IAstNode; const AIndex: IAstNode): IIndexerNode; static;
|
||||||
const ACondition: IExpressionNode;
|
class function MemberAccess(const ABase: IAstNode; const AMember: IIdentifierNode): IMemberAccessNode; static;
|
||||||
const AThenBranch, AElseBranch: IExpressionNode
|
|
||||||
): ITernaryExpressionNode; static;
|
|
||||||
class function LambdaExpr(const AParameters: TArray<IIdentifierNode>; const ABody: IExpressionNode): ILambdaExpressionNode; static;
|
|
||||||
class function FunctionCall(const ACallee: IExpressionNode; const AArguments: array of IExpressionNode): IFunctionCallNode; static;
|
|
||||||
class function Block(const AExpressions: array of IExpressionNode): IBlockExpressionNode; static;
|
|
||||||
class function VarDecl(const AIdentifier: IIdentifierNode; AInitializer: IExpressionNode): IVariableDeclarationNode; static;
|
|
||||||
class function Assign(const AIdentifier: IIdentifierNode; const AValue: IExpressionNode): IAssignmentNode; static;
|
|
||||||
class function AssignResult(const AValue: IExpressionNode): IAssignmentNode; static; deprecated;
|
|
||||||
class function Indexer(const ABase: IExpressionNode; const AIndex: IExpressionNode): IIndexerNode; static;
|
|
||||||
class function MemberAccess(const ABase: IExpressionNode; const AMember: IIdentifierNode): IMemberAccessNode; static;
|
|
||||||
class function CreateSeries(const ADefinition: String): ICreateSeriesNode; static;
|
class function CreateSeries(const ADefinition: String): ICreateSeriesNode; static;
|
||||||
class function AddSeriesItem(
|
class function AddSeriesItem(
|
||||||
const ASeries: IIdentifierNode;
|
const ASeries: IIdentifierNode;
|
||||||
const AValue: IExpressionNode;
|
const AValue: IAstNode;
|
||||||
const ALookback: IExpressionNode = nil
|
const ALookback: IAstNode = nil
|
||||||
): IAddSeriesItemNode; static;
|
): IAddSeriesItemNode; static;
|
||||||
class function SeriesLength(const ASeries: IIdentifierNode): ISeriesLengthNode; static;
|
class function SeriesLength(const ASeries: IIdentifierNode): ISeriesLengthNode; static;
|
||||||
|
|
||||||
class function CreateDescriptor(const Scope: IExecutionScope): IScopeDescriptor; static;
|
class function CreateDescriptor(const Scope: IExecutionScope): IScopeDescriptor; static;
|
||||||
class function Bind(const RootNode: IExpressionNode; const ParentScope: IExecutionScope): IExecutionScope; static;
|
class function Bind(const RootNode: IAstNode; const ParentScope: IExecutionScope): IExecutionScope; static;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// TAstTraverser provides a default AST traversal implementation.
|
// TAstTraverser provides a default AST traversal implementation.
|
||||||
@@ -94,7 +84,7 @@ type
|
|||||||
|
|
||||||
{ TAstNode }
|
{ TAstNode }
|
||||||
// Common base class for AST nodes to reduce boilerplate.
|
// Common base class for AST nodes to reduce boilerplate.
|
||||||
TAstNode = class(TInterfacedObject, IExpressionNode)
|
TAstNode = class(TInterfacedObject, IAstNode)
|
||||||
public
|
public
|
||||||
function Accept(const Visitor: IAstVisitor): TAstValue; virtual; abstract;
|
function Accept(const Visitor: IAstVisitor): TAstValue; virtual; abstract;
|
||||||
end;
|
end;
|
||||||
@@ -130,14 +120,14 @@ type
|
|||||||
{ TBinaryExpressionNode }
|
{ TBinaryExpressionNode }
|
||||||
TBinaryExpressionNode = class(TAstNode, IBinaryExpressionNode)
|
TBinaryExpressionNode = class(TAstNode, IBinaryExpressionNode)
|
||||||
private
|
private
|
||||||
FLeft: IExpressionNode;
|
FLeft: IAstNode;
|
||||||
FOperator: TBinaryOperator;
|
FOperator: TBinaryOperator;
|
||||||
FRight: IExpressionNode;
|
FRight: IAstNode;
|
||||||
function GetLeft: IExpressionNode;
|
function GetLeft: IAstNode;
|
||||||
function GetOperator: TBinaryOperator;
|
function GetOperator: TBinaryOperator;
|
||||||
function GetRight: IExpressionNode;
|
function GetRight: IAstNode;
|
||||||
public
|
public
|
||||||
constructor Create(ALeft: IExpressionNode; AOperator: TBinaryOperator; ARight: IExpressionNode);
|
constructor Create(ALeft: IAstNode; AOperator: TBinaryOperator; ARight: IAstNode);
|
||||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -145,39 +135,39 @@ type
|
|||||||
TUnaryExpressionNode = class(TAstNode, IUnaryExpressionNode)
|
TUnaryExpressionNode = class(TAstNode, IUnaryExpressionNode)
|
||||||
private
|
private
|
||||||
FOperator: TUnaryOperator;
|
FOperator: TUnaryOperator;
|
||||||
FRight: IExpressionNode;
|
FRight: IAstNode;
|
||||||
function GetOperator: TUnaryOperator;
|
function GetOperator: TUnaryOperator;
|
||||||
function GetRight: IExpressionNode;
|
function GetRight: IAstNode;
|
||||||
public
|
public
|
||||||
constructor Create(const AOperator: TUnaryOperator; const ARight: IExpressionNode);
|
constructor Create(const AOperator: TUnaryOperator; const ARight: IAstNode);
|
||||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TIfExpressionNode }
|
{ TIfExpressionNode }
|
||||||
TIfExpressionNode = class(TAstNode, IIfExpressionNode)
|
TIfExpressionNode = class(TAstNode, IIfExpressionNode)
|
||||||
private
|
private
|
||||||
FCondition: IExpressionNode;
|
FCondition: IAstNode;
|
||||||
FThenBranch: IExpressionNode;
|
FThenBranch: IAstNode;
|
||||||
FElseBranch: IExpressionNode;
|
FElseBranch: IAstNode;
|
||||||
function GetCondition: IExpressionNode;
|
function GetCondition: IAstNode;
|
||||||
function GetThenBranch: IExpressionNode;
|
function GetThenBranch: IAstNode;
|
||||||
function GetElseBranch: IExpressionNode;
|
function GetElseBranch: IAstNode;
|
||||||
public
|
public
|
||||||
constructor Create(const ACondition, AThenBranch, AElseBranch: IExpressionNode);
|
constructor Create(const ACondition, AThenBranch, AElseBranch: IAstNode);
|
||||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TTernaryExpressionNode }
|
{ TTernaryExpressionNode }
|
||||||
TTernaryExpressionNode = class(TAstNode, ITernaryExpressionNode)
|
TTernaryExpressionNode = class(TAstNode, ITernaryExpressionNode)
|
||||||
private
|
private
|
||||||
FCondition: IExpressionNode;
|
FCondition: IAstNode;
|
||||||
FThenBranch: IExpressionNode;
|
FThenBranch: IAstNode;
|
||||||
FElseBranch: IExpressionNode;
|
FElseBranch: IAstNode;
|
||||||
function GetCondition: IExpressionNode;
|
function GetCondition: IAstNode;
|
||||||
function GetThenBranch: IExpressionNode;
|
function GetThenBranch: IAstNode;
|
||||||
function GetElseBranch: IExpressionNode;
|
function GetElseBranch: IAstNode;
|
||||||
public
|
public
|
||||||
constructor Create(const ACondition, AThenBranch, AElseBranch: IExpressionNode);
|
constructor Create(const ACondition, AThenBranch, AElseBranch: IAstNode);
|
||||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -185,15 +175,15 @@ type
|
|||||||
TLambdaExpressionNode = class(TAstNode, ILambdaExpressionNode)
|
TLambdaExpressionNode = class(TAstNode, ILambdaExpressionNode)
|
||||||
private
|
private
|
||||||
FParameters: TArray<IIdentifierNode>;
|
FParameters: TArray<IIdentifierNode>;
|
||||||
FBody: IExpressionNode;
|
FBody: IAstNode;
|
||||||
FScopeDescriptor: IScopeDescriptor;
|
FScopeDescriptor: IScopeDescriptor;
|
||||||
FUpvalues: TArray<TResolvedAddress>;
|
FUpvalues: TArray<TResolvedAddress>;
|
||||||
function GetParameters: TArray<IIdentifierNode>;
|
function GetParameters: TArray<IIdentifierNode>;
|
||||||
function GetBody: IExpressionNode;
|
function GetBody: IAstNode;
|
||||||
function GetScopeDescriptor: IScopeDescriptor;
|
function GetScopeDescriptor: IScopeDescriptor;
|
||||||
function GetUpvalues: TArray<TResolvedAddress>;
|
function GetUpvalues: TArray<TResolvedAddress>;
|
||||||
public
|
public
|
||||||
constructor Create(const AParameters: TArray<IIdentifierNode>; const ABody: IExpressionNode);
|
constructor Create(const AParameters: TArray<IIdentifierNode>; const ABody: IAstNode);
|
||||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||||
property ScopeDescriptor: IScopeDescriptor read GetScopeDescriptor;
|
property ScopeDescriptor: IScopeDescriptor read GetScopeDescriptor;
|
||||||
end;
|
end;
|
||||||
@@ -201,12 +191,12 @@ type
|
|||||||
{ TFunctionCallNode }
|
{ TFunctionCallNode }
|
||||||
TFunctionCallNode = class(TAstNode, IFunctionCallNode)
|
TFunctionCallNode = class(TAstNode, IFunctionCallNode)
|
||||||
private
|
private
|
||||||
FCallee: IExpressionNode;
|
FCallee: IAstNode;
|
||||||
FArguments: TList<IExpressionNode>;
|
FArguments: TList<IAstNode>;
|
||||||
function GetCallee: IExpressionNode;
|
function GetCallee: IAstNode;
|
||||||
function GetArguments: TList<IExpressionNode>;
|
function GetArguments: TList<IAstNode>;
|
||||||
public
|
public
|
||||||
constructor Create(const ACallee: IExpressionNode; const AArguments: array of IExpressionNode);
|
constructor Create(const ACallee: IAstNode; const AArguments: array of IAstNode);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||||
end;
|
end;
|
||||||
@@ -214,10 +204,10 @@ type
|
|||||||
{ TBlockExpressionNode }
|
{ TBlockExpressionNode }
|
||||||
TBlockExpressionNode = class(TAstNode, IBlockExpressionNode)
|
TBlockExpressionNode = class(TAstNode, IBlockExpressionNode)
|
||||||
private
|
private
|
||||||
FExpressions: TList<IExpressionNode>;
|
FExpressions: TList<IAstNode>;
|
||||||
function GetExpressions: TList<IExpressionNode>;
|
function GetExpressions: TList<IAstNode>;
|
||||||
public
|
public
|
||||||
constructor Create(const AExpressions: array of IExpressionNode);
|
constructor Create(const AExpressions: array of IAstNode);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||||
end;
|
end;
|
||||||
@@ -226,11 +216,11 @@ type
|
|||||||
TVariableDeclarationNode = class(TAstNode, IVariableDeclarationNode)
|
TVariableDeclarationNode = class(TAstNode, IVariableDeclarationNode)
|
||||||
private
|
private
|
||||||
FIdentifier: IIdentifierNode;
|
FIdentifier: IIdentifierNode;
|
||||||
FInitializer: IExpressionNode;
|
FInitializer: IAstNode;
|
||||||
function GetIdentifier: IIdentifierNode;
|
function GetIdentifier: IIdentifierNode;
|
||||||
function GetInitializer: IExpressionNode;
|
function GetInitializer: IAstNode;
|
||||||
public
|
public
|
||||||
constructor Create(const AIdentifier: IIdentifierNode; AInitializer: IExpressionNode);
|
constructor Create(const AIdentifier: IIdentifierNode; AInitializer: IAstNode);
|
||||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -238,35 +228,35 @@ type
|
|||||||
TAssignmentNode = class(TAstNode, IAssignmentNode)
|
TAssignmentNode = class(TAstNode, IAssignmentNode)
|
||||||
private
|
private
|
||||||
FIdentifier: IIdentifierNode;
|
FIdentifier: IIdentifierNode;
|
||||||
FValue: IExpressionNode;
|
FValue: IAstNode;
|
||||||
function GetIdentifier: IIdentifierNode;
|
function GetIdentifier: IIdentifierNode;
|
||||||
function GetValue: IExpressionNode;
|
function GetValue: IAstNode;
|
||||||
public
|
public
|
||||||
constructor Create(const AIdentifier: IIdentifierNode; const AValue: IExpressionNode);
|
constructor Create(const AIdentifier: IIdentifierNode; const AValue: IAstNode);
|
||||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TIndexerNode }
|
{ TIndexerNode }
|
||||||
TIndexerNode = class(TAstNode, IIndexerNode)
|
TIndexerNode = class(TAstNode, IIndexerNode)
|
||||||
private
|
private
|
||||||
FBase: IExpressionNode;
|
FBase: IAstNode;
|
||||||
FIndex: IExpressionNode;
|
FIndex: IAstNode;
|
||||||
function GetBase: IExpressionNode;
|
function GetBase: IAstNode;
|
||||||
function GetIndex: IExpressionNode;
|
function GetIndex: IAstNode;
|
||||||
public
|
public
|
||||||
constructor Create(const ABase: IExpressionNode; const AIndex: IExpressionNode);
|
constructor Create(const ABase: IAstNode; const AIndex: IAstNode);
|
||||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TMemberAccessNode }
|
{ TMemberAccessNode }
|
||||||
TMemberAccessNode = class(TAstNode, IMemberAccessNode)
|
TMemberAccessNode = class(TAstNode, IMemberAccessNode)
|
||||||
private
|
private
|
||||||
FBase: IExpressionNode;
|
FBase: IAstNode;
|
||||||
FMember: IIdentifierNode;
|
FMember: IIdentifierNode;
|
||||||
function GetBase: IExpressionNode;
|
function GetBase: IAstNode;
|
||||||
function GetMember: IIdentifierNode;
|
function GetMember: IIdentifierNode;
|
||||||
public
|
public
|
||||||
constructor Create(const ABase: IExpressionNode; const AMember: IIdentifierNode);
|
constructor Create(const ABase: IAstNode; const AMember: IIdentifierNode);
|
||||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -284,13 +274,13 @@ type
|
|||||||
TAddSeriesItemNode = class(TAstNode, IAddSeriesItemNode)
|
TAddSeriesItemNode = class(TAstNode, IAddSeriesItemNode)
|
||||||
private
|
private
|
||||||
FSeries: IIdentifierNode;
|
FSeries: IIdentifierNode;
|
||||||
FValue: IExpressionNode;
|
FValue: IAstNode;
|
||||||
FLookback: IExpressionNode;
|
FLookback: IAstNode;
|
||||||
function GetSeries: IIdentifierNode;
|
function GetSeries: IIdentifierNode;
|
||||||
function GetValue: IExpressionNode;
|
function GetValue: IAstNode;
|
||||||
function GetLookback: IExpressionNode;
|
function GetLookback: IAstNode;
|
||||||
public
|
public
|
||||||
constructor Create(const ASeries: IIdentifierNode; const AValue: IExpressionNode; const ALookback: IExpressionNode);
|
constructor Create(const ASeries: IIdentifierNode; const AValue: IAstNode; const ALookback: IAstNode);
|
||||||
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
function Accept(const Visitor: IAstVisitor): TAstValue; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -459,7 +449,7 @@ end;
|
|||||||
|
|
||||||
{ TBinaryExpressionNode }
|
{ TBinaryExpressionNode }
|
||||||
|
|
||||||
constructor TBinaryExpressionNode.Create(ALeft: IExpressionNode; AOperator: TBinaryOperator; ARight: IExpressionNode);
|
constructor TBinaryExpressionNode.Create(ALeft: IAstNode; AOperator: TBinaryOperator; ARight: IAstNode);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FLeft := ALeft;
|
FLeft := ALeft;
|
||||||
@@ -472,7 +462,7 @@ begin
|
|||||||
Result := Visitor.VisitBinaryExpression(Self);
|
Result := Visitor.VisitBinaryExpression(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TBinaryExpressionNode.GetLeft: IExpressionNode;
|
function TBinaryExpressionNode.GetLeft: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FLeft;
|
Result := FLeft;
|
||||||
end;
|
end;
|
||||||
@@ -482,14 +472,14 @@ begin
|
|||||||
Result := FOperator;
|
Result := FOperator;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TBinaryExpressionNode.GetRight: IExpressionNode;
|
function TBinaryExpressionNode.GetRight: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FRight;
|
Result := FRight;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TUnaryExpressionNode }
|
{ TUnaryExpressionNode }
|
||||||
|
|
||||||
constructor TUnaryExpressionNode.Create(const AOperator: TUnaryOperator; const ARight: IExpressionNode);
|
constructor TUnaryExpressionNode.Create(const AOperator: TUnaryOperator; const ARight: IAstNode);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FOperator := AOperator;
|
FOperator := AOperator;
|
||||||
@@ -506,14 +496,14 @@ begin
|
|||||||
Result := FOperator;
|
Result := FOperator;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TUnaryExpressionNode.GetRight: IExpressionNode;
|
function TUnaryExpressionNode.GetRight: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FRight;
|
Result := FRight;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TIfExpressionNode }
|
{ TIfExpressionNode }
|
||||||
|
|
||||||
constructor TIfExpressionNode.Create(const ACondition, AThenBranch, AElseBranch: IExpressionNode);
|
constructor TIfExpressionNode.Create(const ACondition, AThenBranch, AElseBranch: IAstNode);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FCondition := ACondition;
|
FCondition := ACondition;
|
||||||
@@ -526,24 +516,24 @@ begin
|
|||||||
Result := Visitor.VisitIfExpression(Self);
|
Result := Visitor.VisitIfExpression(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TIfExpressionNode.GetCondition: IExpressionNode;
|
function TIfExpressionNode.GetCondition: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FCondition;
|
Result := FCondition;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TIfExpressionNode.GetElseBranch: IExpressionNode;
|
function TIfExpressionNode.GetElseBranch: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FElseBranch;
|
Result := FElseBranch;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TIfExpressionNode.GetThenBranch: IExpressionNode;
|
function TIfExpressionNode.GetThenBranch: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FThenBranch;
|
Result := FThenBranch;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TTernaryExpressionNode }
|
{ TTernaryExpressionNode }
|
||||||
|
|
||||||
constructor TTernaryExpressionNode.Create(const ACondition, AThenBranch, AElseBranch: IExpressionNode);
|
constructor TTernaryExpressionNode.Create(const ACondition, AThenBranch, AElseBranch: IAstNode);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FCondition := ACondition;
|
FCondition := ACondition;
|
||||||
@@ -556,24 +546,24 @@ begin
|
|||||||
Result := Visitor.VisitTernaryExpression(Self);
|
Result := Visitor.VisitTernaryExpression(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TTernaryExpressionNode.GetCondition: IExpressionNode;
|
function TTernaryExpressionNode.GetCondition: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FCondition;
|
Result := FCondition;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TTernaryExpressionNode.GetElseBranch: IExpressionNode;
|
function TTernaryExpressionNode.GetElseBranch: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FElseBranch;
|
Result := FElseBranch;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TTernaryExpressionNode.GetThenBranch: IExpressionNode;
|
function TTernaryExpressionNode.GetThenBranch: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FThenBranch;
|
Result := FThenBranch;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TLambdaExpressionNode }
|
{ TLambdaExpressionNode }
|
||||||
|
|
||||||
constructor TLambdaExpressionNode.Create(const AParameters: TArray<IIdentifierNode>; const ABody: IExpressionNode);
|
constructor TLambdaExpressionNode.Create(const AParameters: TArray<IIdentifierNode>; const ABody: IAstNode);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FBody := ABody;
|
FBody := ABody;
|
||||||
@@ -591,7 +581,7 @@ begin
|
|||||||
Result := Visitor.VisitLambdaExpression(Self);
|
Result := Visitor.VisitLambdaExpression(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TLambdaExpressionNode.GetBody: IExpressionNode;
|
function TLambdaExpressionNode.GetBody: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FBody;
|
Result := FBody;
|
||||||
end;
|
end;
|
||||||
@@ -608,13 +598,13 @@ end;
|
|||||||
|
|
||||||
{ TFunctionCallNode }
|
{ TFunctionCallNode }
|
||||||
|
|
||||||
constructor TFunctionCallNode.Create(const ACallee: IExpressionNode; const AArguments: array of IExpressionNode);
|
constructor TFunctionCallNode.Create(const ACallee: IAstNode; const AArguments: array of IAstNode);
|
||||||
var
|
var
|
||||||
arg: IExpressionNode;
|
arg: IAstNode;
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FCallee := ACallee;
|
FCallee := ACallee;
|
||||||
FArguments := TList<IExpressionNode>.Create;
|
FArguments := TList<IAstNode>.Create;
|
||||||
for arg in AArguments do
|
for arg in AArguments do
|
||||||
FArguments.Add(arg);
|
FArguments.Add(arg);
|
||||||
end;
|
end;
|
||||||
@@ -630,24 +620,24 @@ begin
|
|||||||
Result := Visitor.VisitFunctionCall(Self);
|
Result := Visitor.VisitFunctionCall(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFunctionCallNode.GetArguments: TList<IExpressionNode>;
|
function TFunctionCallNode.GetArguments: TList<IAstNode>;
|
||||||
begin
|
begin
|
||||||
Result := FArguments;
|
Result := FArguments;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFunctionCallNode.GetCallee: IExpressionNode;
|
function TFunctionCallNode.GetCallee: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FCallee;
|
Result := FCallee;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TBlockExpressionNode }
|
{ TBlockExpressionNode }
|
||||||
|
|
||||||
constructor TBlockExpressionNode.Create(const AExpressions: array of IExpressionNode);
|
constructor TBlockExpressionNode.Create(const AExpressions: array of IAstNode);
|
||||||
var
|
var
|
||||||
expr: IExpressionNode;
|
expr: IAstNode;
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FExpressions := TList<IExpressionNode>.Create;
|
FExpressions := TList<IAstNode>.Create;
|
||||||
for expr in AExpressions do
|
for expr in AExpressions do
|
||||||
FExpressions.Add(expr);
|
FExpressions.Add(expr);
|
||||||
end;
|
end;
|
||||||
@@ -663,14 +653,14 @@ begin
|
|||||||
Result := Visitor.VisitBlockExpression(Self);
|
Result := Visitor.VisitBlockExpression(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TBlockExpressionNode.GetExpressions: TList<IExpressionNode>;
|
function TBlockExpressionNode.GetExpressions: TList<IAstNode>;
|
||||||
begin
|
begin
|
||||||
Result := FExpressions;
|
Result := FExpressions;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TVariableDeclarationNode }
|
{ TVariableDeclarationNode }
|
||||||
|
|
||||||
constructor TVariableDeclarationNode.Create(const AIdentifier: IIdentifierNode; AInitializer: IExpressionNode);
|
constructor TVariableDeclarationNode.Create(const AIdentifier: IIdentifierNode; AInitializer: IAstNode);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FIdentifier := AIdentifier;
|
FIdentifier := AIdentifier;
|
||||||
@@ -687,14 +677,14 @@ begin
|
|||||||
Result := FIdentifier;
|
Result := FIdentifier;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TVariableDeclarationNode.GetInitializer: IExpressionNode;
|
function TVariableDeclarationNode.GetInitializer: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FInitializer;
|
Result := FInitializer;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TAssignmentNode }
|
{ TAssignmentNode }
|
||||||
|
|
||||||
constructor TAssignmentNode.Create(const AIdentifier: IIdentifierNode; const AValue: IExpressionNode);
|
constructor TAssignmentNode.Create(const AIdentifier: IIdentifierNode; const AValue: IAstNode);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FIdentifier := AIdentifier;
|
FIdentifier := AIdentifier;
|
||||||
@@ -711,14 +701,14 @@ begin
|
|||||||
Result := FIdentifier;
|
Result := FIdentifier;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TAssignmentNode.GetValue: IExpressionNode;
|
function TAssignmentNode.GetValue: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FValue;
|
Result := FValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TIndexerNode }
|
{ TIndexerNode }
|
||||||
|
|
||||||
constructor TIndexerNode.Create(const ABase, AIndex: IExpressionNode);
|
constructor TIndexerNode.Create(const ABase, AIndex: IAstNode);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FBase := ABase;
|
FBase := ABase;
|
||||||
@@ -730,19 +720,19 @@ begin
|
|||||||
Result := Visitor.VisitIndexer(Self);
|
Result := Visitor.VisitIndexer(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TIndexerNode.GetBase: IExpressionNode;
|
function TIndexerNode.GetBase: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FBase;
|
Result := FBase;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TIndexerNode.GetIndex: IExpressionNode;
|
function TIndexerNode.GetIndex: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FIndex;
|
Result := FIndex;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TMemberAccessNode }
|
{ TMemberAccessNode }
|
||||||
|
|
||||||
constructor TMemberAccessNode.Create(const ABase: IExpressionNode; const AMember: IIdentifierNode);
|
constructor TMemberAccessNode.Create(const ABase: IAstNode; const AMember: IIdentifierNode);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FBase := ABase;
|
FBase := ABase;
|
||||||
@@ -754,7 +744,7 @@ begin
|
|||||||
Result := Visitor.VisitMemberAccess(Self);
|
Result := Visitor.VisitMemberAccess(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMemberAccessNode.GetBase: IExpressionNode;
|
function TMemberAccessNode.GetBase: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FBase;
|
Result := FBase;
|
||||||
end;
|
end;
|
||||||
@@ -784,7 +774,7 @@ end;
|
|||||||
|
|
||||||
{ TAddSeriesItemNode }
|
{ TAddSeriesItemNode }
|
||||||
|
|
||||||
constructor TAddSeriesItemNode.Create(const ASeries: IIdentifierNode; const AValue, ALookback: IExpressionNode);
|
constructor TAddSeriesItemNode.Create(const ASeries: IIdentifierNode; const AValue, ALookback: IAstNode);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FSeries := ASeries;
|
FSeries := ASeries;
|
||||||
@@ -797,7 +787,7 @@ begin
|
|||||||
Result := Visitor.VisitAddSeriesItem(Self);
|
Result := Visitor.VisitAddSeriesItem(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TAddSeriesItemNode.GetLookback: IExpressionNode;
|
function TAddSeriesItemNode.GetLookback: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FLookback;
|
Result := FLookback;
|
||||||
end;
|
end;
|
||||||
@@ -807,7 +797,7 @@ begin
|
|||||||
Result := FSeries;
|
Result := FSeries;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TAddSeriesItemNode.GetValue: IExpressionNode;
|
function TAddSeriesItemNode.GetValue: IAstNode;
|
||||||
begin
|
begin
|
||||||
Result := FValue;
|
Result := FValue;
|
||||||
end;
|
end;
|
||||||
@@ -968,7 +958,7 @@ end;
|
|||||||
|
|
||||||
{ TAst }
|
{ TAst }
|
||||||
|
|
||||||
class function TAst.Bind(const RootNode: IExpressionNode; const ParentScope: IExecutionScope): IExecutionScope;
|
class function TAst.Bind(const RootNode: IAstNode; const ParentScope: IExecutionScope): IExecutionScope;
|
||||||
var
|
var
|
||||||
binder: TBinder;
|
binder: TBinder;
|
||||||
visitor: IAstVisitor;
|
visitor: IAstVisitor;
|
||||||
@@ -990,26 +980,22 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TAst.AddSeriesItem(
|
class function TAst.AddSeriesItem(const ASeries: IIdentifierNode; const AValue: IAstNode; const ALookback: IAstNode): IAddSeriesItemNode;
|
||||||
const ASeries: IIdentifierNode;
|
|
||||||
const AValue: IExpressionNode;
|
|
||||||
const ALookback: IExpressionNode
|
|
||||||
): IAddSeriesItemNode;
|
|
||||||
begin
|
begin
|
||||||
Result := TAddSeriesItemNode.Create(ASeries, AValue, ALookback);
|
Result := TAddSeriesItemNode.Create(ASeries, AValue, ALookback);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TAst.Assign(const AIdentifier: IIdentifierNode; const AValue: IExpressionNode): IAssignmentNode;
|
class function TAst.Assign(const AIdentifier: IIdentifierNode; const AValue: IAstNode): IAssignmentNode;
|
||||||
begin
|
begin
|
||||||
Result := TAssignmentNode.Create(AIdentifier, AValue);
|
Result := TAssignmentNode.Create(AIdentifier, AValue);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TAst.AssignResult(const AValue: IExpressionNode): IAssignmentNode;
|
class function TAst.AssignResult(const AValue: IAstNode): IAssignmentNode;
|
||||||
begin
|
begin
|
||||||
Result := Assign(TAst.Identifier('Result'), AValue);
|
Result := Assign(TAst.Identifier('Result'), AValue);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TAst.Block(const AExpressions: array of IExpressionNode): IBlockExpressionNode;
|
class function TAst.Block(const AExpressions: array of IAstNode): IBlockExpressionNode;
|
||||||
begin
|
begin
|
||||||
Result := TBlockExpressionNode.Create(AExpressions);
|
Result := TBlockExpressionNode.Create(AExpressions);
|
||||||
end;
|
end;
|
||||||
@@ -1024,7 +1010,7 @@ begin
|
|||||||
Result := TCreateSeriesNode.Create(ADefinition);
|
Result := TCreateSeriesNode.Create(ADefinition);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TAst.BinaryExpr(ALeft: IExpressionNode; AOperator: TBinaryOperator; ARight: IExpressionNode): IBinaryExpressionNode;
|
class function TAst.BinaryExpr(ALeft: IAstNode; AOperator: TBinaryOperator; ARight: IAstNode): IBinaryExpressionNode;
|
||||||
begin
|
begin
|
||||||
Result := TBinaryExpressionNode.Create(ALeft, AOperator, ARight);
|
Result := TBinaryExpressionNode.Create(ALeft, AOperator, ARight);
|
||||||
end;
|
end;
|
||||||
@@ -1040,7 +1026,7 @@ begin
|
|||||||
Result := TScopeDescriptor.Create(nil);
|
Result := TScopeDescriptor.Create(nil);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TAst.FunctionCall(const ACallee: IExpressionNode; const AArguments: array of IExpressionNode): IFunctionCallNode;
|
class function TAst.FunctionCall(const ACallee: IAstNode; const AArguments: array of IAstNode): IFunctionCallNode;
|
||||||
begin
|
begin
|
||||||
Result := TFunctionCallNode.Create(ACallee, AArguments);
|
Result := TFunctionCallNode.Create(ACallee, AArguments);
|
||||||
end;
|
end;
|
||||||
@@ -1050,17 +1036,17 @@ begin
|
|||||||
Result := TIdentifierNode.Create(AName);
|
Result := TIdentifierNode.Create(AName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TAst.IfExpr(const ACondition: IExpressionNode; const AThenBranch, AElseBranch: IExpressionNode): IIfExpressionNode;
|
class function TAst.IfExpr(const ACondition: IAstNode; const AThenBranch, AElseBranch: IAstNode): IIfExpressionNode;
|
||||||
begin
|
begin
|
||||||
Result := TIfExpressionNode.Create(ACondition, AThenBranch, AElseBranch);
|
Result := TIfExpressionNode.Create(ACondition, AThenBranch, AElseBranch);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TAst.Indexer(const ABase, AIndex: IExpressionNode): IIndexerNode;
|
class function TAst.Indexer(const ABase, AIndex: IAstNode): IIndexerNode;
|
||||||
begin
|
begin
|
||||||
Result := TIndexerNode.Create(ABase, AIndex);
|
Result := TIndexerNode.Create(ABase, AIndex);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TAst.MemberAccess(const ABase: IExpressionNode; const AMember: IIdentifierNode): IMemberAccessNode;
|
class function TAst.MemberAccess(const ABase: IAstNode; const AMember: IIdentifierNode): IMemberAccessNode;
|
||||||
begin
|
begin
|
||||||
Result := TMemberAccessNode.Create(ABase, AMember);
|
Result := TMemberAccessNode.Create(ABase, AMember);
|
||||||
end;
|
end;
|
||||||
@@ -1070,22 +1056,22 @@ begin
|
|||||||
Result := TSeriesLengthNode.Create(ASeries);
|
Result := TSeriesLengthNode.Create(ASeries);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TAst.TernaryExpr(const ACondition: IExpressionNode; const AThenBranch, AElseBranch: IExpressionNode): ITernaryExpressionNode;
|
class function TAst.TernaryExpr(const ACondition: IAstNode; const AThenBranch, AElseBranch: IAstNode): ITernaryExpressionNode;
|
||||||
begin
|
begin
|
||||||
Result := TTernaryExpressionNode.Create(ACondition, AThenBranch, AElseBranch);
|
Result := TTernaryExpressionNode.Create(ACondition, AThenBranch, AElseBranch);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TAst.LambdaExpr(const AParameters: TArray<IIdentifierNode>; const ABody: IExpressionNode): ILambdaExpressionNode;
|
class function TAst.LambdaExpr(const AParameters: TArray<IIdentifierNode>; const ABody: IAstNode): ILambdaExpressionNode;
|
||||||
begin
|
begin
|
||||||
Result := TLambdaExpressionNode.Create(AParameters, ABody);
|
Result := TLambdaExpressionNode.Create(AParameters, ABody);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TAst.UnaryExpr(const AOperator: TUnaryOperator; const ARight: IExpressionNode): IUnaryExpressionNode;
|
class function TAst.UnaryExpr(const AOperator: TUnaryOperator; const ARight: IAstNode): IUnaryExpressionNode;
|
||||||
begin
|
begin
|
||||||
Result := TUnaryExpressionNode.Create(AOperator, ARight);
|
Result := TUnaryExpressionNode.Create(AOperator, ARight);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TAst.VarDecl(const AIdentifier: IIdentifierNode; AInitializer: IExpressionNode): IVariableDeclarationNode;
|
class function TAst.VarDecl(const AIdentifier: IIdentifierNode; AInitializer: IAstNode): IVariableDeclarationNode;
|
||||||
begin
|
begin
|
||||||
Result := TVariableDeclarationNode.Create(AIdentifier, AInitializer);
|
Result := TVariableDeclarationNode.Create(AIdentifier, AInitializer);
|
||||||
end;
|
end;
|
||||||
@@ -1114,7 +1100,7 @@ end;
|
|||||||
|
|
||||||
function TAstTraverser.VisitBlockExpression(const Node: IBlockExpressionNode): TAstValue;
|
function TAstTraverser.VisitBlockExpression(const Node: IBlockExpressionNode): TAstValue;
|
||||||
var
|
var
|
||||||
expr: IExpressionNode;
|
expr: IAstNode;
|
||||||
begin
|
begin
|
||||||
for expr in Node.Expressions do
|
for expr in Node.Expressions do
|
||||||
expr.Accept(Self);
|
expr.Accept(Self);
|
||||||
@@ -1130,7 +1116,7 @@ end;
|
|||||||
|
|
||||||
function TAstTraverser.VisitFunctionCall(const Node: IFunctionCallNode): TAstValue;
|
function TAstTraverser.VisitFunctionCall(const Node: IFunctionCallNode): TAstValue;
|
||||||
var
|
var
|
||||||
arg: IExpressionNode;
|
arg: IAstNode;
|
||||||
begin
|
begin
|
||||||
Node.Callee.Accept(Self);
|
Node.Callee.Accept(Self);
|
||||||
for arg in Node.Arguments do
|
for arg in Node.Arguments do
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ uses
|
|||||||
System.SysUtils,
|
System.SysUtils,
|
||||||
System.Rtti,
|
System.Rtti,
|
||||||
System.TypInfo,
|
System.TypInfo,
|
||||||
|
System.JSON,
|
||||||
Myc.Data.Scalar;
|
Myc.Data.Scalar;
|
||||||
|
|
||||||
type
|
type
|
||||||
@@ -24,8 +25,7 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Myc.Data.Decimal,
|
Myc.Data.Decimal,
|
||||||
System.Generics.Collections,
|
System.Generics.Collections;
|
||||||
System.JSON;
|
|
||||||
|
|
||||||
{ TRttiAstHelper }
|
{ TRttiAstHelper }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user