|
|
@ -117,15 +117,17 @@ llvm::Value *CallAST::codegen(LLVMState& llvmState) const
|
|
|
|
Var::addGlobal(name, Var {fn, true});
|
|
|
|
Var::addGlobal(name, Var {fn, true});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool couldRecur = Var::lookup("self").value != nullptr;
|
|
|
|
|
|
|
|
auto localCount = Var::vars.back().size();
|
|
|
|
|
|
|
|
if (!couldRecur || localCount == 0) {
|
|
|
|
|
|
|
|
return llvmState.builder.CreateCall(llvmState.ftype, fn, llvm::ArrayRef {scope.back().env});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
int i;
|
|
|
|
auto ptrty = llvmState.inttype->getPointerTo();
|
|
|
|
auto ptrty = llvmState.inttype->getPointerTo();
|
|
|
|
llvm::Type *type;
|
|
|
|
auto type = llvm::VectorType::get(llvmState.inttype, localCount, false);
|
|
|
|
llvm::Value *mem;
|
|
|
|
auto mem = llvmState.builder.CreateAlloca(type, nullptr);
|
|
|
|
|
|
|
|
|
|
|
|
if (auto sz = Var::vars.back().size(); sz > 0) {
|
|
|
|
|
|
|
|
type = llvm::VectorType::get(llvmState.inttype, sz, false);
|
|
|
|
|
|
|
|
mem = llvmState.builder.CreateAlloca(type, nullptr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
i = 0;
|
|
|
|
for (auto& [_, v] : Var::vars.back()) {
|
|
|
|
for (auto& [_, v] : Var::vars.back()) {
|
|
|
|
if (!v.native) {
|
|
|
|
if (!v.native) {
|
|
|
|
auto index = llvm::ConstantInt::get(llvmState.inttype, i++);
|
|
|
|
auto index = llvm::ConstantInt::get(llvmState.inttype, i++);
|
|
|
@ -133,12 +135,10 @@ llvm::Value *CallAST::codegen(LLVMState& llvmState) const
|
|
|
|
llvmState.builder.CreateStore(loadEnv(llvmState, v.value), m, false);
|
|
|
|
llvmState.builder.CreateStore(loadEnv(llvmState, v.value), m, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto call = llvmState.builder.CreateCall(llvmState.ftype, fn, llvm::ArrayRef {scope.back().env});
|
|
|
|
auto call = llvmState.builder.CreateCall(llvmState.ftype, fn, llvm::ArrayRef {scope.back().env});
|
|
|
|
|
|
|
|
|
|
|
|
if (auto sz = Var::vars.back().size(); sz > 0) {
|
|
|
|
i = 0;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (auto& [_, v] : Var::vars.back()) {
|
|
|
|
for (auto& [_, v] : Var::vars.back()) {
|
|
|
|
if (!v.native) {
|
|
|
|
if (!v.native) {
|
|
|
|
auto index = llvm::ConstantInt::get(llvmState.inttype, i++);
|
|
|
|
auto index = llvm::ConstantInt::get(llvmState.inttype, i++);
|
|
|
@ -147,10 +147,10 @@ llvm::Value *CallAST::codegen(LLVMState& llvmState) const
|
|
|
|
storeEnv(llvmState, v.value, l);
|
|
|
|
storeEnv(llvmState, v.value, l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return call;
|
|
|
|
return call;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ThunkAST::ThunkAST(LLVMState& llvmState):
|
|
|
|
ThunkAST::ThunkAST(LLVMState& llvmState):
|
|
|
|
ThunkAST(llvmState, std::string("__t") + std::to_string(tcount++)) {}
|
|
|
|
ThunkAST(llvmState, std::string("__t") + std::to_string(tcount++)) {}
|
|
|
|