aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--llvm.cpp8
-rw-r--r--tuplr.hpp20
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<AType*>();
@@ -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<ATuple*>();
@@ -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<Value*> 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<const AType*,AType*,typeLessThan> {
}
};
-/// Lifted system functions (of various types) for a single Tuplr function
-struct Funcs : public list< pair<AType*, CFunction> > {
- 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<ATuple*>(); }
- Funcs funcs;
+ /// System level implementations of this (polymorphic) fn
+ struct Impls : public list< pair<AType*, CFunction> > {
+ 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;
};