Skip to content

Commit 930bb6b

Browse files
committed
#61 - codegen fix
1 parent 9f57ea0 commit 930bb6b

File tree

6 files changed

+10
-11
lines changed

6 files changed

+10
-11
lines changed

src/Application/HydraScript.Application.CodeGeneration/Visitors/ExpressionInstructionProvider.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ public AddressedInstructions Visit(CallExpression visitable)
262262
return [];
263263

264264
var methodCall = !visitable.Empty();
265-
string functionId;
266265
AddressedInstructions result = [];
267266

268267
if (methodCall)
@@ -271,12 +270,6 @@ public AddressedInstructions Visit(CallExpression visitable)
271270
var lastMemberInstruction = (DotRead)memberInstructions[memberInstructions.End];
272271
memberInstructions.Remove(lastMemberInstruction);
273272
result.AddRange(memberInstructions);
274-
275-
functionId = lastMemberInstruction.Property;
276-
}
277-
else
278-
{
279-
functionId = visitable.Id;
280273
}
281274

282275
if (methodCall)
@@ -298,7 +291,7 @@ public AddressedInstructions Visit(CallExpression visitable)
298291
}
299292

300293
result.Add(new CallFunction(
301-
new FunctionInfo(functionId),
294+
new FunctionInfo(visitable.ComputedFunctionAddress),
302295
visitable.HasReturnValue));
303296

304297
return result;

src/Application/HydraScript.Application.CodeGeneration/Visitors/InstructionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public AddressedInstructions Visit(FunctionDeclaration visitable)
118118
if (!visitable.Statements.Any())
119119
return [];
120120

121-
var functionInfo = new FunctionInfo(visitable.Name);
121+
var functionInfo = new FunctionInfo(visitable.ComputedFunctionAddress);
122122

123123
var result = new AddressedInstructions
124124
{

src/Application/HydraScript.Application.StaticAnalysis/Visitors/DeclarationVisitor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ public VisitUnit Visit(FunctionDeclaration visitable)
7171
new VariableSymbol(
7272
name: x.Key,
7373
x.TypeValue.Accept(_typeBuilder))).ToList();
74-
if (_symbolTables[visitable.Parent.Scope].ContainsSymbol(
75-
new FunctionSymbolId(visitable.Name, parameters.Select(x => x.Type))))
74+
var functionSymbolId = new FunctionSymbolId(visitable.Name, parameters.Select(x => x.Type));
75+
visitable.ComputedFunctionAddress = functionSymbolId.ToString();
76+
if (_symbolTables[visitable.Parent.Scope].ContainsSymbol(functionSymbolId))
7677
throw new DeclarationAlreadyExists(visitable.Name);
7778

7879
for (var i = 0; i < parameters.Count; i++)

src/Application/HydraScript.Application.StaticAnalysis/Visitors/SemanticChecker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ public Type Visit(CallExpression visitable)
420420
?? throw new UnknownIdentifierReference(visitable.Id);
421421
}
422422

423+
visitable.ComputedFunctionAddress = functionSymbol.Id.ToString();
423424
visitable.IsEmptyCall = functionSymbol.IsEmpty;
424425
var functionReturnType = functionSymbol.Type;
425426

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Declarations/AfterTypesAreLoaded/FunctionDeclaration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public partial class FunctionDeclaration : AfterTypesAreLoadedDeclaration
1717
public BlockStatement Statements { get; }
1818
public bool IsEmpty => Statements.Count == 0;
1919

20+
public string ComputedFunctionAddress { get; set; } = default!;
21+
2022
public FunctionDeclaration(
2123
IdentifierReference name,
2224
TypeValue returnTypeValue,

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Expressions/CallExpression.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public partial class CallExpression : LeftHandSideExpression
1616
public bool IsEmptyCall { get; set; }
1717
public bool HasReturnValue { get; set; }
1818

19+
public string ComputedFunctionAddress { get; set; } = default!;
20+
1921
public CallExpression(MemberExpression member, IEnumerable<Expression> expressions)
2022
{
2123
Member = member;

0 commit comments

Comments
 (0)