aboutsummaryrefslogtreecommitdiffstats
path: root/ast.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ast.cpp')
-rw-r--r--ast.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/ast.cpp b/ast.cpp
index 3543ee1..a528cc3 100644
--- a/ast.cpp
+++ b/ast.cpp
@@ -58,12 +58,20 @@ PopAST::PopAST(const std::string& n): BaseAST(n) {}
llvm::Value *PopAST::codegen(LLVMState& llvmState) const
{
- auto gep = llvmState.createPop();
- auto var = llvmState.createVariable(name);
- auto load = llvmState.builder.CreateLoad(llvmState.inttype, gep);
- llvmState.builder.CreateStore(load, var, false);
+ if (name == "self") {
+ extern std::list<ThunkAST> scope;
+ auto func = scope.back().func;
+ auto var = llvmState.createVariable(name);
+ llvmState.builder.CreateStore(func, var, false);
+ return Var::addLocal(name, var).value;
+ } else {
+ auto gep = llvmState.createPop();
+ auto var = llvmState.createVariable(name);
+ auto load = llvmState.builder.CreateLoad(llvmState.inttype, gep);
+ llvmState.builder.CreateStore(load, var, false);
- return Var::addLocal(name, var).value;
+ return Var::addLocal(name, var).value;
+ }
}
CallAST::CallAST(const std::string& n): BaseAST(n) {}