From 2235923ea73318d3eeba64754f461209c23d9f2f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 24 Jun 2009 04:46:57 +0000 Subject: Funcs => AFn::Impls git-svn-id: http://svn.drobilla.net/resp/tuplr@146 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- Makefile | 10 +++++++++- llvm.cpp | 8 ++++---- tuplr.hpp | 20 ++++++++++---------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index de198e1..3ba8d84 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,15 @@ all: builddir build/tuplr builddir: mkdir -p build -build/tuplr: build/tuplr.o build/typing.o build/llvm.so build/gclib.so build/write.o build/gc.o +OBJECTS = \ + build/tuplr.o \ + build/typing.o \ + build/llvm.so \ + build/gclib.so \ + build/write.o \ + build/gc.o + +build/tuplr: $(OBJECTS) g++ -o $@ $^ $(LDFLAGS) build/%.o: %.cpp tuplr.hpp diff --git a/llvm.cpp b/llvm.cpp index 54999fc..3688845 100644 --- a/llvm.cpp +++ b/llvm.cpp @@ -215,7 +215,7 @@ AFn::lift(CEnv& cenv) cenv.pop(); AType* type = cenv.type(this); - if (funcs.find(type) || !type->concrete()) + if (impls.find(type) || !type->concrete()) return; AType* protT = type->at(1)->as(); @@ -243,7 +243,7 @@ AFn::liftCall(CEnv& cenv, const AType& argsT) } Object::pool.addRoot(thisType); - if (funcs.find(thisType)) + if (impls.find(thisType)) return; ATuple* protT = thisType->at(1)->as(); @@ -321,7 +321,7 @@ AFn::liftCall(CEnv& cenv, const AType& argsT) try { // Define value first for recursion cenv.precompile(this, f); - funcs.push_back(make_pair(thisType, f)); + impls.push_back(make_pair(thisType, f)); CValue retVal = NULL; for (size_t i = 2; i < size(); ++i) retVal = cenv.compile(at(i)); @@ -380,7 +380,7 @@ ACall::compile(CEnv& cenv) TEnv::GenericTypes::const_iterator gt = cenv.tenv.genericTypes.find(c); assert(gt != cenv.tenv.genericTypes.end()); AType fnT(loc, cenv.penv.sym("Fn"), &protT, cenv.type(this), 0); - Function* f = (Function*)c->funcs.find(&fnT); + Function* f = (Function*)c->impls.find(&fnT); THROW_IF(!f, loc, (format("callee failed to compile for type %1%") % fnT.str()).str()); vector params(size() - 1); diff --git a/tuplr.hpp b/tuplr.hpp index 2d2886e..3df6c9f 100644 --- a/tuplr.hpp +++ b/tuplr.hpp @@ -340,15 +340,6 @@ struct Subst : public map { } }; -/// Lifted system functions (of various types) for a single Tuplr function -struct Funcs : public list< pair > { - CFunction find(AType* type) const { - for (const_iterator f = begin(); f != end(); ++f) - if (*f->first == *type) - return f->second; - return NULL; - } -}; /// Closure (first-class function with captured lexical bindings) struct AFn : public ATuple { @@ -360,7 +351,16 @@ struct AFn : public ATuple { void liftCall(CEnv& cenv, const AType& argsT); CValue compile(CEnv& cenv); ATuple* prot() const { return at(1)->to(); } - Funcs funcs; + /// System level implementations of this (polymorphic) fn + struct Impls : public list< pair > { + CFunction find(AType* type) const { + for (const_iterator f = begin(); f != end(); ++f) + if (*f->first == *type) + return f->second; + return NULL; + } + }; + Impls impls; mutable Subst subst; string name; }; -- cgit v1.2.1