Skip to content

Commit

Permalink
Update FunctionBodyCodegen.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Oct 13, 2023
1 parent bcaa9bc commit bb68005
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Draco.Compiler/Internal/OptimizingIr/FunctionBodyCodegen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

namespace Draco.Compiler.Internal.OptimizingIr;

// TODO: Operators and calls became identical, can we merge them?
// During lowering we could turn operators into calls

/// <summary>
/// Generates IR code on function-local level.
/// </summary>
Expand Down Expand Up @@ -272,21 +275,28 @@ public override IOperand VisitSequencePointExpression(BoundSequencePointExpressi

public override IOperand VisitCallExpression(BoundCallExpression node)
{
// TODO: Lots of duplication, we should merge these instructions...
var receiver = this.CompileReceiver(node);
var args = node.Arguments
.Zip(node.Method.Parameters)
.Select(pair => this.BoxIfNeeded(pair.Second.Type, this.Compile(pair.First)))
.ToList();
.ToImmutableArray();
var callResult = this.DefineRegister(node.TypeRequired);
var proc = this.TranslateFunctionSymbol(node.Method);
if (receiver is null)

if (node.Method is IrFunctionSymbol irFunc)
{
this.Write(Call(callResult, proc, args));
irFunc.Codegen(this, callResult, args);
}
else
{
this.Write(MemberCall(callResult, proc, receiver, args));
var proc = this.TranslateFunctionSymbol(node.Method);
if (receiver is null)
{
this.Write(Call(callResult, proc, args));
}
else
{
this.Write(MemberCall(callResult, proc, receiver, args));
}
}
return callResult;
}
Expand Down Expand Up @@ -397,7 +407,7 @@ public override IOperand VisitAssignmentExpression(BoundAssignmentExpression nod
}
else
{
// TOO
// TODO
throw new System.NotImplementedException();
}
}
Expand Down

0 comments on commit bb68005

Please sign in to comment.