diff options
Diffstat (limited to 'ast.cpp')
-rw-r--r-- | ast.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -24,7 +24,6 @@ extern llvm::Function *curFunc; extern llvm::Value *curEnv; int ThunkAST::tcount = 0; -int ThunkAST::envidx = 0; static inline auto loadEnv(LLVMState& llvmState, llvm::Value *index) { @@ -61,7 +60,7 @@ PushAST::PushAST(const std::string& n): BaseAST(n) {} llvm::Value *PushAST::codegen(LLVMState& llvmState) const { if (auto [var, native] = Var::lookup(name, 1); var) { - auto index = llvm::ConstantInt::get(llvmState.inttype, ThunkAST::envidx++); + auto index = llvm::ConstantInt::get(llvmState.inttype, llvmState.envidx++); Var::addLocal(name, index); } @@ -85,7 +84,7 @@ llvm::Value *PopAST::codegen(LLVMState& llvmState) const if (name == "self") { v = {curFunc, true}; } else { - auto index = llvm::ConstantInt::get(llvmState.inttype, ThunkAST::envidx++); + auto index = llvm::ConstantInt::get(llvmState.inttype, llvmState.envidx++); auto pop = llvmState.createPop(); storeEnv(llvmState, index, pop); @@ -100,7 +99,7 @@ CallAST::CallAST(const std::string& n): BaseAST(n) {} llvm::Value *CallAST::codegen(LLVMState& llvmState) const { if (auto [var, native] = Var::lookup(name, 1); var && !native) { - auto index = llvm::ConstantInt::get(llvmState.inttype, ThunkAST::envidx++); + auto index = llvm::ConstantInt::get(llvmState.inttype, llvmState.envidx++); Var::addLocal(name, index); } @@ -118,6 +117,8 @@ llvm::Value *CallAST::codegen(LLVMState& llvmState) const Var::addGlobal(name, Var {fn, true}); } + llvmState.commitSp(); + bool couldRecur = Var::lookup("self").value != nullptr; auto localCount = Var::vars.back().size(); if (!couldRecur || localCount == 0) { @@ -168,12 +169,14 @@ void ThunkAST::beginGen(LLVMState& llvmState) entry = llvmState.createEntry(func); body = llvm::BasicBlock::Create(llvmState.ctx, "body", func); env = func->getArg(0); + lastSp = nullptr; llvmState.builder.SetInsertPoint(body); } void ThunkAST::endGen(LLVMState& llvmState) { + llvmState.commitSp(); llvmState.builder.CreateRetVoid(); llvmState.builder.SetInsertPoint(entry); |