Macro expander integrated in binder
This commit is contained in:
@@ -224,7 +224,7 @@ begin
|
||||
boundAst := binder.Execute(ANode, descriptor);
|
||||
|
||||
// Store the final bound AST for visualization and debugging.
|
||||
FCurrAst := ANode;
|
||||
FCurrAst := boundAst;
|
||||
FCurrDesc := descriptor;
|
||||
|
||||
// Step 2: Create the final scope and evaluator for runtime execution.
|
||||
@@ -393,6 +393,13 @@ begin
|
||||
begin
|
||||
var decl := expr as TVariableDeclarationNode;
|
||||
definitions.Add(decl.Identifier.Name, decl.Initializer);
|
||||
end
|
||||
// Handle macro definitions inside the block
|
||||
else if expr is TMacroDefinitionNode then
|
||||
begin
|
||||
var macroDef := expr as TMacroDefinitionNode;
|
||||
// Store the entire macro definition node for serialization.
|
||||
definitions.Add(macroDef.Name.Name, macroDef);
|
||||
end;
|
||||
end;
|
||||
end
|
||||
@@ -400,11 +407,17 @@ begin
|
||||
begin
|
||||
var decl := rootNode as TVariableDeclarationNode;
|
||||
definitions.Add(decl.Identifier.Name, decl.Initializer);
|
||||
end
|
||||
// Handle a single macro definition
|
||||
else if rootNode is TMacroDefinitionNode then
|
||||
begin
|
||||
var macroDef := rootNode as TMacroDefinitionNode;
|
||||
definitions.Add(macroDef.Name.Name, macroDef);
|
||||
end;
|
||||
|
||||
if definitions.Count = 0 then
|
||||
begin
|
||||
Memo1.Lines.Add('No top-level "(def ...)" definitions found in the script to save.');
|
||||
Memo1.Lines.Add('No top-level "(def ...)" or "(defmacro ...)" definitions found in the script to save.');
|
||||
exit;
|
||||
end;
|
||||
|
||||
@@ -428,7 +441,7 @@ begin
|
||||
|
||||
for var pair in definitions do
|
||||
begin
|
||||
// Track if we are adding or updating a function
|
||||
// Track if we are adding or updating a function/macro
|
||||
if jsonLib.Values[pair.Key] <> nil then
|
||||
begin
|
||||
Inc(updatedCount);
|
||||
|
||||
Reference in New Issue
Block a user