Nop-Node
This commit is contained in:
+17
-23
@@ -845,32 +845,26 @@ begin
|
||||
end;
|
||||
|
||||
procedure TForm1.Test1ButtonClick(Sender: TObject);
|
||||
var
|
||||
main, callAst: IAstNode;
|
||||
result: TDataValue;
|
||||
sw: TStopwatch;
|
||||
begin
|
||||
Memo1.Lines.Clear;
|
||||
Memo1.Lines.Add('--- Simple AST Execution ---');
|
||||
sw := TStopwatch.StartNew;
|
||||
|
||||
main :=
|
||||
TAst.LambdaExpr(
|
||||
[],
|
||||
TAst.Block(
|
||||
[
|
||||
TAst.VarDecl(TAst.Identifier('a'), TAst.Constant(10)),
|
||||
TAst.VarDecl(TAst.Identifier('b'), TAst.BinaryExpr(TAst.Identifier('a'), TScalar.TBinaryOp.Multiply, TAst.Constant(2))),
|
||||
TAst.BinaryExpr(TAst.Identifier('a'), TScalar.TBinaryOp.Add, TAst.Identifier('b'))
|
||||
]
|
||||
)
|
||||
FCurrUnboundAst :=
|
||||
TAst.Block(
|
||||
[
|
||||
TAst.LambdaExpr(
|
||||
[],
|
||||
TAst.Block(
|
||||
[
|
||||
TAst.VarDecl(TAst.Identifier('a'), TAst.Nop),
|
||||
TAst.VarDecl(
|
||||
TAst.Identifier('b'),
|
||||
TAst.BinaryExpr(TAst.Identifier('a'), TScalar.TBinaryOp.Multiply, TAst.Constant(2))
|
||||
),
|
||||
TAst.BinaryExpr(TAst.Identifier('a'), TScalar.TBinaryOp.Add, TAst.Identifier('b'))
|
||||
]
|
||||
)
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
callAst := TAst.FunctionCall(main, []);
|
||||
result := ExecuteAst(callAst, FGScope);
|
||||
|
||||
sw.Stop;
|
||||
Memo1.Lines.Add(Format('Result: %s (calculated in %d ms)', [result.ToString, sw.ElapsedMilliseconds]));
|
||||
UpdateScript;
|
||||
end;
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ type
|
||||
function VisitAddSeriesItem(const Node: IAddSeriesItemNode): TAuraNode; override;
|
||||
function VisitSeriesLength(const Node: ISeriesLengthNode): TAuraNode; override;
|
||||
function VisitRecurNode(const Node: IRecurNode): TAuraNode; override;
|
||||
function VisitNop(const Node: INopNode): TAuraNode; override;
|
||||
|
||||
public
|
||||
constructor Create(AWorkspace: TAuraWorkspace; AParentControl: TControl; AExprDepth: Integer);
|
||||
@@ -525,6 +526,17 @@ type
|
||||
property Node: ISeriesLengthNode read FNode;
|
||||
end;
|
||||
|
||||
TAuraNopNode = class(TAuraNode)
|
||||
private
|
||||
FNode: INopNode;
|
||||
protected
|
||||
procedure SetupNode; override;
|
||||
public
|
||||
constructor Create(const AVisualizer: IAstVisualizer; const ANode: INopNode);
|
||||
function CreateAst: IAstNode; override;
|
||||
property Node: INopNode read FNode;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TAstVisualizer }
|
||||
@@ -716,6 +728,11 @@ begin
|
||||
Result := TAuraVariableDeclarationNode.Create(Self, Node);
|
||||
end;
|
||||
|
||||
function TAstVisualizer.VisitNop(const Node: INopNode): TAuraNode;
|
||||
begin
|
||||
Result := TAuraNopNode.Create(Self, Node);
|
||||
end;
|
||||
|
||||
{ TAutoFitControl }
|
||||
|
||||
constructor TAutoFitControl.Create(AOwner: TComponent);
|
||||
@@ -1039,7 +1056,7 @@ begin
|
||||
Canvas.FillRect(TRectF.Create(0, 0, Width, Height), 0, 0, [], 1.0);
|
||||
Canvas.Stroke.Kind := TBrushKind.Solid;
|
||||
Canvas.Stroke.Color := FBorderColor;
|
||||
Canvas.Stroke.Thickness := 1;
|
||||
Canvas.Stroke.Thickness := FBorderWidth;
|
||||
Canvas.Stroke.Dash := TStrokeDash.Dot;
|
||||
Canvas.DrawRect(TRectF.Create(0, 0, Width, Height), 0, 0, [], 1.0);
|
||||
end
|
||||
@@ -2222,4 +2239,38 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TAuraNopNode }
|
||||
|
||||
constructor TAuraNopNode.Create(const AVisualizer: IAstVisualizer; const ANode: INopNode);
|
||||
begin
|
||||
inherited Create(AVisualizer);
|
||||
FNode := ANode;
|
||||
|
||||
// Visual style for Nop: Dotted border, minimal size, clear color.
|
||||
Frameless := true;
|
||||
Alignment := TLayoutAlignment.laCenter;
|
||||
Orientation := TLayoutOrientation.loHorizontal;
|
||||
end;
|
||||
|
||||
function TAuraNopNode.CreateAst: IAstNode;
|
||||
begin
|
||||
// The visual node returns the original Nop node, which the compiler pipeline must reject.
|
||||
Result := FNode;
|
||||
end;
|
||||
|
||||
procedure TAuraNopNode.SetupNode;
|
||||
var
|
||||
lbl: TLabel;
|
||||
begin
|
||||
BeginUpdate;
|
||||
try
|
||||
// Add a placeholder text
|
||||
lbl := AddLabel(Self, '...');
|
||||
lbl.Font.Style := lbl.Font.Style + [TFontStyle.fsBold];
|
||||
lbl.Margins.Rect := TRectF.Create(8, 4, 8, 4);
|
||||
finally
|
||||
EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user