|
|
|
@ -117,15 +117,17 @@ llvm::Value *CallAST::codegen(LLVMState& llvmState) const
|
|
|
|
|
Var::addGlobal(name, Var {fn, true});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto ptrty = llvmState.inttype->getPointerTo();
|
|
|
|
|
llvm::Type *type;
|
|
|
|
|
llvm::Value *mem;
|
|
|
|
|
|
|
|
|
|
if (auto sz = Var::vars.back().size(); sz > 0) {
|
|
|
|
|
type = llvm::VectorType::get(llvmState.inttype, sz, false);
|
|
|
|
|
mem = llvmState.builder.CreateAlloca(type, nullptr);
|
|
|
|
|
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 type = llvm::VectorType::get(llvmState.inttype, localCount, false);
|
|
|
|
|
auto mem = llvmState.builder.CreateAlloca(type, nullptr);
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
i = 0;
|
|
|
|
|
for (auto& [_, v] : Var::vars.back()) {
|
|
|
|
|
if (!v.native) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
int i = 0;
|
|
|
|
|
i = 0;
|
|
|
|
|
for (auto& [_, v] : Var::vars.back()) {
|
|
|
|
|
if (!v.native) {
|
|
|
|
|
auto index = llvm::ConstantInt::get(llvmState.inttype, i++);
|
|
|
|
@ -147,9 +147,9 @@ llvm::Value *CallAST::codegen(LLVMState& llvmState) const
|
|
|
|
|
storeEnv(llvmState, v.value, l);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return call;
|
|
|
|
|
return call;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ThunkAST::ThunkAST(LLVMState& llvmState):
|
|
|
|
|