diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/llvm.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/llvm.cpp b/src/llvm.cpp index b01724e..ec2c2a4 100644 --- a/src/llvm.cpp +++ b/src/llvm.cpp @@ -51,15 +51,15 @@ llType(const AType* t) if (t->at(0)->str() == "Int") return Type::Int32Ty; if (t->at(0)->str() == "Float") return Type::FloatTy; throw Error(t->loc, string("Unknown primitive type `") + t->str() + "'"); - /*} else if (t->kind == AType::EXPR && t->at(0)->str() == "Fn") { - AType* retT = t->at(2)->as<AType*>(); + } else if (t->kind == AType::EXPR && t->at(0)->str() == "Fn") { + const AType* retT = t->at(2)->as<const AType*>(); if (!llType(retT)) return NULL; vector<const Type*> cprot; - const ATuple* prot = t->at(1)->to<ATuple*>(); + const ATuple* prot = t->at(1)->to<const ATuple*>(); for (size_t i = 0; i < prot->size(); ++i) { - AType* at = prot->at(i)->to<AType*>(); + const AType* at = prot->at(i)->to<const AType*>(); const Type* lt = llType(at); if (lt) cprot.push_back(lt); @@ -69,7 +69,6 @@ llType(const AType* t) FunctionType* fT = FunctionType::get(llType(retT), cprot, false); return PointerType::get(fT, 0); - */ } return NULL; // non-primitive type } @@ -174,7 +173,7 @@ struct LLVMEngine : public Engine { ss << showpoint << ((float (*)())fp)(); else if (t == Type::Int1Ty) ss << (((bool (*)())fp)() ? "#t" : "#f"); - else + else if (t != Type::VoidTy) ss << ((void* (*)())fp)(); return ss.str(); } @@ -389,7 +388,20 @@ AFn::liftCall(CEnv& cenv, const AType& argsT) CValue AFn::compile(CEnv& cenv) { - return NULL; + AType* aFnT = cenv.type(this); + const Type* fnT = llType(aFnT); + return fnT ? static_cast<Function*>(impls.find(aFnT)) : NULL; + + /*vector<const Type*> types; + types.push_back(PointerType::get(fnT, 0)); + types.push_back(PointerType::get(Type::VoidTy, 0)); + IRBuilder<> builder = llEngine(cenv)->builder; + Value* tag = ConstantInt::get(Type::Int8Ty, GC::TAG_FRAME); + StructType* tupT = StructType::get(types, false); + Value* tupSize = ConstantInt::get(Type::Int32Ty, sizeof(void*) * 2); + Value* tup = builder.CreateCall2(llEngine(cenv)->alloc, tupSize, tag, "fn"); + Value* tupPtr = builder.CreateBitCast(tup, PointerType::get(tupT, 0)); + return tupPtr;*/ } void |