Skip to content

Commit

Permalink
fix: Fixed recursive functions not being able to call themselves in t…
Browse files Browse the repository at this point in the history
…heir body
  • Loading branch information
alinalihassan committed May 26, 2022
1 parent b2e5974 commit 51541f4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/liblesma/Backend/Codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ void Codegen::visit(FuncDecl *node) {
FunctionType *FT = FunctionType::get(ret_type, paramTypes, node->getVarArgs());
Function *F = Function::Create(FT, linkage, name, *TheModule);

auto symbol = new SymbolTableEntry(name, new SymbolType(SymbolSuperType::TY_FUNCTION));
symbol->setLLVMType(F->getFunctionType());
symbol->setLLVMValue(F);
Scope->getParent()->insertSymbol(symbol);

deferStack.push({});

BasicBlock *BB = BasicBlock::Create(*TheContext, "entry", F);
Expand Down Expand Up @@ -530,11 +535,6 @@ void Codegen::visit(FuncDecl *node) {
// Insert Function to Symbol Table
Scope = Scope->getParent();

auto symbol = new SymbolTableEntry(name, new SymbolType(SymbolSuperType::TY_FUNCTION));
symbol->setLLVMType(F->getFunctionType());
symbol->setLLVMValue(F);
Scope->insertSymbol(symbol);

// Reset Insert Point to Top Level
Builder->SetInsertPoint(&TopLevelFunc->back());
}
Expand Down

0 comments on commit 51541f4

Please sign in to comment.