Visualizer node aggregates

Fix in macro expander
This commit is contained in:
Michael Schimmel
2025-11-04 17:45:47 +01:00
parent 2fd85be923
commit 2b8a3effed
8 changed files with 1100 additions and 915 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -4,7 +4,7 @@
<ProjectVersion>20.3</ProjectVersion>
<FrameworkType>FMX</FrameworkType>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Release</Config>
<Config Condition="'$(Config)'==''">Debug</Config>
<Platform Condition="'$(Platform)'==''">Win64</Platform>
<ProjectName Condition="'$(ProjectName)'==''">ASTPlayground</ProjectName>
<TargetedPlatforms>2</TargetedPlatforms>
+21
View File
@@ -234,8 +234,29 @@ object Form1: TForm1
object ScriptMemo: TMemo
Touch.InteractiveGestures = [Pan, LongTap, DoubleTap]
DataDetectorTypes = []
Lines.Strings = (
'(do'
'(defmacro repeat [n body]'
' `(do'
' (def loop (fn [counter]'
' (if (> counter 0)'
' (do'
' ~body'
' (recur (- counter 1))'
' )'
' (do'
' )'
' )'
' ))'
' (loop ~n)'
' )'
')'
''
'(repeat 5 "hi")'
')')
StyledSettings = [Size, Style, FontColor]
TextSettings.Font.Family = 'Consolas'
OnChange = ScriptMemoChange
OnChangeTracking = ScriptMemoChange
Align = Right
Position.X = 920.000000000000000000
+10 -8
View File
@@ -1348,14 +1348,16 @@ procedure TForm1.ShowVizualization(X, Y: Single);
begin
FWorkspace.DeleteChildren;
if FCurrAst <> nil then
begin
FWorkspace.Build(FCurrAst, TPointF.Create(X, Y));
end
else if FCurrUnboundAst <> nil then
begin
FWorkspace.Build(FCurrUnboundAst, TPointF.Create(X, Y));
end;
FWorkspace.Build(FCurrUnboundAst, TPointF.Create(X, Y));
//
// if FCurrAst <> nil then
// begin
// FWorkspace.Build(FCurrAst, TPointF.Create(X, Y));
// end
// else if FCurrUnboundAst <> nil then
// begin
// FWorkspace.Build(FCurrUnboundAst, TPointF.Create(X, Y));
// end;
end;
end.
File diff suppressed because it is too large Load Diff
+5 -3
View File
@@ -181,9 +181,11 @@ end;
function TAstBinder.VisitMacroExpansionNode(const Node: IMacroExpansionNode): IAstNode;
begin
// The MacroExpander (Phase 1) should have unwrapped this.
// We only visit the *expanded* body.
Result := Accept(Node.ExpandedBody);
// The MacroExpander (Phase 1) created this node.
// We must bind the ExpandedBody, but keep the MacroExpansionNode wrapper.
// The base TAstTransformer implementation already does exactly this
// by visiting Callee, Arguments, and ExpandedBody.
Result := inherited VisitMacroExpansionNode(Node);
end;
function TAstBinder.VisitFunctionCall(const Node: IFunctionCallNode): IAstNode;
+9 -8
View File
@@ -1,3 +1,6 @@
//==================================================================================================
//== FULL UNIT START: Myc.Ast.MacroExpander (from Myc.Ast.MacroExpander.pas)
//==================================================================================================
unit Myc.Ast.MacroExpander;
interface
@@ -280,7 +283,8 @@ begin
// --- It is a macro, expand it ---
// 1. Create the temporary scope for the macro parameters
var expansionScope := TAst.CreateScope(nil);
// It must be parented to the *initial* scope to find other macros/globals.
var expansionScope := TAst.CreateScope(FInitialScope);
var params := macroDef.Parameters;
if Length(Node.Arguments) <> Length(params) then
raise Exception
@@ -301,14 +305,11 @@ begin
boundSubAst: IAstNode;
begin
// This is the compile-time evaluation (Binder + Evaluator)
// It runs in the *current* context (FInitialScope + FCurrentDescriptor)
var tempInitScope := TScope.CreateScope(FInitialScope.Parent, FCurrentDescriptor, nil);
// [FIX] It must run in the 'expansionScope' which contains the parameters.
boundSubAst := TAstBinder.Bind(expansionScope, ANodeToEvaluate, subDescriptor);
// Bind (mutates ANodeToEvaluate) and get its descriptor
boundSubAst := TAstBinder.Bind(tempInitScope, ANodeToEvaluate, subDescriptor);
// Create eval scope from the new descriptor
evalScope := subDescriptor.CreateScope(tempInitScope);
// Create eval scope from the new descriptor, parented to the expansion scope
evalScope := subDescriptor.CreateScope(expansionScope);
evaluator := FEvaluatorFactory(evalScope);
Result := evaluator.Execute(boundSubAst);
+18 -1
View File
@@ -68,6 +68,12 @@ type
akNop // Added Nop
);
// Helper for TAstNodeKind providing a string representation
TAstNodeKindHelper = record helper for TAstNodeKind
public
function ToString: string;
end;
// --- Concrete Type Definitions ---
// Defines how an identifier's address was resolved.
@@ -377,7 +383,18 @@ type
implementation
uses
System.Classes;
System.Classes,
System.Rtti,
System.StrUtils;
{ TAstNodeKindHelper }
function TAstNodeKindHelper.ToString: string;
begin
Result := TRttiEnumerationType.GetName<TAstNodeKind>(Self);
Assert(StartsText('ak', Result));
Result := Result.Substring(2);
end;
{ TResolvedAddress }