Skip to content

Commit

Permalink
Merged branch 'master' into 'feature/fields'.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktMagnus committed Feb 29, 2024
2 parents 2810fc2 + d852047 commit f9a931a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/intermediateLowerer/intermediateLowerer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ export class IntermediateLowerer

this.lowerFields(file.fields);

// Pre-lowering of the function symbols for them to be available in every other function regardless of their order:
for (const functionNode of file.functions)
{
this.lowerFunctionSymbol(functionNode.symbol, file.module);
}

for (const functionNode of file.functions)
{
this.lowerFunction(functionNode);
Expand Down Expand Up @@ -346,7 +352,14 @@ export class IntermediateLowerer
throw new Error(`Intermediate Lowerer error: Current module is null while lowering a function.`);
}

const functionSymbol = this.lowerFunctionSymbol(functionDeclaration.symbol, this.currentModule);
const functionSymbol = this.functionSymbolMap.get(functionDeclaration.symbol.namespace.qualifiedName);

if (functionSymbol === undefined)
{
throw new Error(
`Intermediate Lowerer error: No pre-lowered symbol found for function "${functionDeclaration.symbol.namespace.qualifiedName}".`
);
}

if (functionDeclaration.symbol.isHeader)
{
Expand Down
14 changes: 14 additions & 0 deletions tests/endToEnd/runWithOutput/inputs/functionCall/main.ph
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module FunctionCall;

import Standard.Io;

function main ()
{
print();
}

// This includes testing that the order of the functions does not matter ("main" can call "print" even if it is defined later):
function print ()
{
Io.writeLine('Print called.');
}
1 change: 1 addition & 0 deletions tests/endToEnd/runWithOutput/outputs/functionCall.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Print called.

0 comments on commit f9a931a

Please sign in to comment.