Skip to content

Commit a25183f

Browse files
committed
Feature(Backend\LLVM): Resolve Identifier to Function
1 parent 230d5fb commit a25183f

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/Backend/LLVM/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ function buildFromCallExpression(
7979
expr: CallExpression,
8080
builder: llvm.IRBuilder
8181
) {
82-
const callle = ctx.llvmModule.getFunction('puts');
82+
const callle = buildFromExpression(expr.callee, ctx, builder);
8383
if (!callle) {
8484
throw new Error(
85-
`Unknown fn: "puts"`
85+
`We cannot prepare expression to call this function`
8686
);
8787
}
8888

@@ -96,8 +96,14 @@ function buildFromCallExpression(
9696
);
9797
}
9898

99+
function buildFromIdentifier(block: Identifier, ctx: Context, builder: llvm.IRBuilder): llvm.Value {
100+
return ctx.llvmModule.getFunction(block.name);
101+
}
102+
99103
function buildFromExpression(block: Expression, ctx: Context, builder: llvm.IRBuilder): llvm.Value {
100104
switch (block.type) {
105+
case 'Identifier':
106+
return buildFromIdentifier(block, ctx, builder);
101107
case 'NumericLiteral':
102108
return buildFromNumberValue(ctx, block.value, builder);
103109
case 'StringLiteral':

src/Frontend/TypeScript/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const example = `
88
99
returnVoid();
1010
11-
console.log("Hello World!");
11+
puts("Hello World!");
1212
}
1313
`;
1414

0 commit comments

Comments
 (0)