diff options
author | David Robillard <d@drobilla.net> | 2010-12-03 00:52:49 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-12-03 00:52:49 +0000 |
commit | a2a6e8e4cefda1bb1cbdae53aab9d00b9a8688ca (patch) | |
tree | 29591923e314b9e11d111c5f402f50f50c2d17e4 | |
parent | bbad3fe368b2086ec93f082a9436b1dfbc8f0e84 (diff) | |
download | resp-a2a6e8e4cefda1bb1cbdae53aab9d00b9a8688ca.tar.gz resp-a2a6e8e4cefda1bb1cbdae53aab9d00b9a8688ca.tar.bz2 resp-a2a6e8e4cefda1bb1cbdae53aab9d00b9a8688ca.zip |
Merge ACall and ATuple.
git-svn-id: http://svn.drobilla.net/resp/resp@285 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r-- | src/c.cpp | 16 | ||||
-rw-r--r-- | src/compile.cpp | 16 | ||||
-rw-r--r-- | src/constrain.cpp | 36 | ||||
-rw-r--r-- | src/cps.cpp | 16 | ||||
-rw-r--r-- | src/lift.cpp | 28 | ||||
-rw-r--r-- | src/llvm.cpp | 16 | ||||
-rw-r--r-- | src/parse.cpp | 10 | ||||
-rw-r--r-- | src/repl.cpp | 2 | ||||
-rw-r--r-- | src/resp.cpp | 4 | ||||
-rw-r--r-- | src/resp.hpp | 33 |
10 files changed, 78 insertions, 99 deletions
@@ -134,7 +134,7 @@ struct CEngine : public Engine { return f; } - void pushFunctionArgs(CEnv& cenv, const ACall* fn, const AType* type, CFunc f); + void pushFunctionArgs(CEnv& cenv, const ATuple* fn, const AType* type, CFunc f); void finishFunction(CEnv& cenv, CFunc f, CVal ret) { out += "return " + *(Value*)ret + ";\n}\n\n"; @@ -158,9 +158,9 @@ struct CEngine : public Engine { CVal compileDot(CEnv& cenv, CVal tup, int32_t index); CVal compileLiteral(CEnv& cenv, const AST* lit); CVal compileString(CEnv& cenv, const char* str); - CVal compilePrimitive(CEnv& cenv, const ACall* prim); - CVal compileIf(CEnv& cenv, const ACall* aif); - CVal compileMatch(CEnv& cenv, const ACall* match); + CVal compilePrimitive(CEnv& cenv, const ATuple* prim); + CVal compileIf(CEnv& cenv, const ATuple* aif); + CVal compileMatch(CEnv& cenv, const ATuple* match); CVal compileGlobal(CEnv& cenv, const AType* type, const string& sym, CVal val); CVal getGlobal(CEnv& cenv, const string& sym, CVal val); @@ -211,7 +211,7 @@ CEngine::compileString(CEnv& cenv, const char* str) } void -CEngine::pushFunctionArgs(CEnv& cenv, const ACall* fn, const AType* type, CFunc f) +CEngine::pushFunctionArgs(CEnv& cenv, const ATuple* fn, const AType* type, CFunc f) { cenv.push(); @@ -230,7 +230,7 @@ CEngine::pushFunctionArgs(CEnv& cenv, const ACall* fn, const AType* type, CFunc } CVal -CEngine::compileIf(CEnv& cenv, const ACall* aif) +CEngine::compileIf(CEnv& cenv, const ATuple* aif) { Value* varname = new string(cenv.penv.gensymstr("if")); out += (format("%s %s;\n") % *llType(cenv.type(aif)) % *varname).str(); @@ -262,13 +262,13 @@ CEngine::compileIf(CEnv& cenv, const ACall* aif) } CVal -CEngine::compileMatch(CEnv& cenv, const ACall* match) +CEngine::compileMatch(CEnv& cenv, const ATuple* match) { return NULL; } CVal -CEngine::compilePrimitive(CEnv& cenv, const ACall* prim) +CEngine::compilePrimitive(CEnv& cenv, const ATuple* prim) { ATuple::const_iterator i = prim->begin(); ++i; diff --git a/src/compile.cpp b/src/compile.cpp index 14cd562..88accf4 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -34,7 +34,7 @@ compile_symbol(CEnv& cenv, const ASymbol* sym) throw() } static CVal -compile_fn(CEnv& cenv, const ACall* fn) throw() +compile_fn(CEnv& cenv, const ATuple* fn) throw() { const AType* type = cenv.type(fn); CFunc f = cenv.findImpl(fn, type); @@ -82,7 +82,7 @@ compile_type(CEnv& cenv, const AType* type) throw() } static CVal -compile_call(CEnv& cenv, const ACall* call) throw() +compile_call(CEnv& cenv, const ATuple* call) throw() { CFunc f = resp_compile(cenv, *call->begin()); @@ -90,14 +90,14 @@ compile_call(CEnv& cenv, const ACall* call) throw() f = cenv.currentFn; // Recursive call (callee defined as a stub) vector<CVal> args; - for (ACall::const_iterator e = call->iter_at(1); e != call->end(); ++e) + for (ATuple::const_iterator e = call->iter_at(1); e != call->end(); ++e) args.push_back(resp_compile(cenv, *e)); return cenv.engine()->compileCall(cenv, f, cenv.type(call->head()), args); } static CVal -compile_def(CEnv& cenv, const ACall* def) throw() +compile_def(CEnv& cenv, const ATuple* def) throw() { const ASymbol* const sym = def->list_ref(1)->as<const ASymbol*>(); const AST* const body = def->list_ref(2); @@ -113,7 +113,7 @@ compile_def(CEnv& cenv, const ACall* def) throw() } static CVal -compile_cons(CEnv& cenv, const ACall* cons) throw() +compile_cons(CEnv& cenv, const ATuple* cons) throw() { AType* type = new AType(const_cast<ASymbol*>(cons->head()->as<const ASymbol*>()), NULL, Cursor()); TList tlist(type); @@ -126,7 +126,7 @@ compile_cons(CEnv& cenv, const ACall* cons) throw() } static CVal -compile_dot(CEnv& cenv, const ACall* dot) throw() +compile_dot(CEnv& cenv, const ATuple* dot) throw() { ATuple::const_iterator i = dot->begin(); const AST* tup = *++i; @@ -159,12 +159,12 @@ resp_compile(CEnv& cenv, const AST* ast) throw() if (type) return compile_type(cenv, type); - const ACall* const call = ast->to<const ACall*>(); + const ATuple* const call = ast->to<const ATuple*>(); if (call) { const ASymbol* const sym = call->head()->to<const ASymbol*>(); const std::string form = sym ? sym->cppstr : ""; if (is_primitive(cenv.penv, call)) - return cenv.engine()->compilePrimitive(cenv, ast->as<const ACall*>()); + return cenv.engine()->compilePrimitive(cenv, ast->as<const ATuple*>()); else if (form == "fn") return compile_fn(cenv, call); else if (form == "def") diff --git a/src/constrain.cpp b/src/constrain.cpp index 2e23f7c..8d16218 100644 --- a/src/constrain.cpp +++ b/src/constrain.cpp @@ -53,20 +53,8 @@ ASymbol::constrain(TEnv& tenv, Constraints& c) const throw(Error) c.constrain(tenv, this, *ref); } -void -ATuple::constrain(TEnv& tenv, Constraints& c) const throw(Error) -{ - TList t; - FOREACHP(const_iterator, p, this) { - (*p)->constrain(tenv, c); - t.push_back(const_cast<AType*>(tenv.var(*p))); - } - t.head->loc = loc; - c.constrain(tenv, this, t); -} - static void -constrain_fn(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) +constrain_fn(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { set<const ASymbol*> defs; TEnv::Frame frame; @@ -93,7 +81,7 @@ constrain_fn(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) // Add internal definitions to environment frame for (++i; i != call->end(); ++i) { const AST* exp = *i; - const ACall* call = exp->to<const ACall*>(); + const ATuple* call = exp->to<const ATuple*>(); if (call && is_form(call, "def")) { const ASymbol* sym = call->list_ref(1)->as<const ASymbol*>(); THROW_IF(defs.count(sym) != 0, call->loc, @@ -121,7 +109,7 @@ constrain_fn(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) } static void -constrain_def(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) +constrain_def(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { THROW_IF(call->list_len() != 3, call->loc, "`def' requires exactly 2 arguments"); const ASymbol* const sym = call->list_ref(1)->as<const ASymbol*>(); @@ -136,7 +124,7 @@ constrain_def(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) } static void -constrain_def_type(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) +constrain_def_type(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { THROW_IF(call->list_len() < 3, call->loc, "`def-type' requires at least 2 arguments"); ATuple::const_iterator i = call->iter_at(1); @@ -164,7 +152,7 @@ constrain_def_type(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) } static void -constrain_match(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) +constrain_match(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { THROW_IF(call->list_len() < 5, call->loc, "`match' requires at least 4 arguments"); const AST* matchee = call->list_ref(1); @@ -195,7 +183,7 @@ constrain_match(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) } static void -constrain_if(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) +constrain_if(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { THROW_IF(call->list_len() < 4, call->loc, "`if' requires at least 3 arguments"); THROW_IF(call->list_len() % 2 != 0, call->loc, "`if' missing final else clause"); @@ -217,7 +205,7 @@ constrain_if(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) } static void -constrain_cons(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) +constrain_cons(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { const ASymbol* sym = (*call->begin())->as<const ASymbol*>(); const AType* type = NULL; @@ -242,7 +230,7 @@ constrain_cons(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) } static void -constrain_dot(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) +constrain_dot(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { THROW_IF(call->list_len() != 3, call->loc, "`.' requires exactly 2 arguments"); ATuple::const_iterator i = call->begin(); @@ -263,14 +251,14 @@ constrain_dot(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) } static void -constrain_quote(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) +constrain_quote(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { c.constrain(tenv, call, tenv.named("Quote")); call->list_ref(1)->constrain(tenv, c); } static void -constrain_call(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) +constrain_call(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { const AST* const head = call->head(); @@ -299,7 +287,7 @@ constrain_call(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) } static void -constrain_primitive(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) +constrain_primitive(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { const string n = call->head()->to<const ASymbol*>()->str(); enum { ARITHMETIC, BINARY, LOGICAL, COMPARISON } type; @@ -355,7 +343,7 @@ constrain_primitive(TEnv& tenv, Constraints& c, const ACall* call) throw(Error) } void -ACall::constrain(TEnv& tenv, Constraints& c) const throw(Error) +ATuple::constrain(TEnv& tenv, Constraints& c) const throw(Error) { const ASymbol* const sym = head()->to<const ASymbol*>(); if (!sym) { diff --git a/src/cps.cpp b/src/cps.cpp index 6f14d97..889a716 100644 --- a/src/cps.cpp +++ b/src/cps.cpp @@ -26,7 +26,7 @@ AST* AST::cps(TEnv& tenv, AST* cont) const { - return tup<ACall>(loc, cont, this, 0); + return tup<ATuple>(loc, cont, this, 0); } /** (cps (fn (a ...) body) cont) => (cont (fn (a ... k) (cps body k)) */ @@ -41,18 +41,18 @@ AFn::cps(TEnv& tenv, AST* cont) const ++(++p); for (; p != end(); ++p) copy->push_back((*p)->cps(tenv, contArg)); - return tup<ACall>(loc, cont, copy, 0); + return tup<ATuple>(loc, cont, copy, 0); } AST* APrimitive::cps(TEnv& tenv, AST* cont) const { - return value() ? tup<ACall>(loc, cont, this, 0) : ACall::cps(tenv, cont); + return value() ? tup<ATuple>(loc, cont, this, 0) : ATuple::cps(tenv, cont); } /** (cps (f a b ...)) => (a (fn (x) (b (fn (y) ... (cont (f x y ...)) */ AST* -ACall::cps(TEnv& tenv, AST* cont) const +ATuple::cps(TEnv& tenv, AST* cont) const { std::vector< std::pair<AFn*, AST*> > funcs; AFn* fn = NULL; @@ -91,7 +91,7 @@ ACall::cps(TEnv& tenv, AST* cont) const if (firstFnIter != end()) { // Call this call's callee in the last argument evaluator - ACall* call = tup<ACall>(loc, 0); + ATuple* call = tup<ATuple>(loc, 0); assert(funcs.size() == size()); for (size_t i = 0; i < funcs.size(); ++i) call->push_back(funcs[i].second); @@ -101,7 +101,7 @@ ACall::cps(TEnv& tenv, AST* cont) const return (*firstFnIter)->cps(tenv, firstFn); } else { assert(head()->value()); - ACall* ret = tup<ACall>(loc, 0); + ATuple* ret = tup<ATuple>(loc, 0); FOREACHP(const_iterator, i, this) ret->push_back((*i)); if (!is_primitive(this)) @@ -115,8 +115,8 @@ AST* ADef::cps(TEnv& tenv, AST* cont) const { AST* val = body()->cps(tenv, cont); - ACall* valCall = val->to<ACall*>(); - ACall::iterator i = valCall->begin(); + ATuple* valCall = val->to<ATuple*>(); + ATuple::iterator i = valCall->begin(); return tup<ADef>(loc, tenv.penv.sym("def"), sym(), *++i, 0); } diff --git a/src/lift.cpp b/src/lift.cpp index 2df27c9..f39239e 100644 --- a/src/lift.cpp +++ b/src/lift.cpp @@ -40,7 +40,7 @@ lift_symbol(CEnv& cenv, Code& code, ASymbol* sym) throw() const int32_t index = cenv.liftStack.top().index(sym); // Replace symbol with code to access free variable from closure - return tup<ACall>(sym->loc, cenv.penv.sym("."), + return tup<ATuple>(sym->loc, cenv.penv.sym("."), cenv.penv.sym("_me"), new ALiteral<int32_t>(index, Cursor()), NULL); @@ -50,9 +50,9 @@ lift_symbol(CEnv& cenv, Code& code, ASymbol* sym) throw() } static AST* -lift_fn(CEnv& cenv, Code& code, ACall* fn) throw() +lift_fn(CEnv& cenv, Code& code, ATuple* fn) throw() { - ACall* impl = new ACall(fn); + ATuple* impl = new ATuple(*fn); const string fnName = cenv.name(fn); const string nameBase = cenv.penv.gensymstr(((fnName != "") ? fnName : "fn").c_str()); const string implNameStr = string("_") + nameBase; @@ -99,13 +99,13 @@ lift_fn(CEnv& cenv, Code& code, ACall* fn) throw() // Create definition for implementation fn ASymbol* implName = cenv.penv.sym(implNameStr); - ACall* def = tup<ACall>(fn->loc, cenv.penv.sym("def"), implName, impl, NULL); + ATuple* def = tup<ATuple>(fn->loc, cenv.penv.sym("def"), implName, impl, NULL); code.push_back(def); AType* implT = new AType(*type); // Type of the implementation function TList tupT(fn->loc, cenv.tenv.Tup, cenv.tenv.var(), NULL); TList consT(fn->loc, cenv.tenv.Tup, implT, NULL); - List<ACall, AST> cons(fn->loc, cenv.penv.sym("Closure"), implName, NULL); + List<ATuple, AST> cons(fn->loc, cenv.penv.sym("Closure"), implName, NULL); implT->list_ref(1) = implProtT; @@ -131,9 +131,9 @@ lift_fn(CEnv& cenv, Code& code, ACall* fn) throw() } static AST* -lift_call(CEnv& cenv, Code& code, ACall* call) throw() +lift_call(CEnv& cenv, Code& code, ATuple* call) throw() { - List<ACall, AST> copy; + List<ATuple, AST> copy; // Lift all children (callee and arguments, recursively) for (ATuple::iterator i = call->begin(); i != call->end(); ++i) @@ -164,7 +164,7 @@ lift_call(CEnv& cenv, Code& code, ACall* call) throw() copyT = implT->list_ref(2)->as<const AType*>(); } else { // Call to a closure, prepend code to access implementation function - ACall* getFn = tup<ACall>(call->loc, cenv.penv.sym("."), + ATuple* getFn = tup<ATuple>(call->loc, cenv.penv.sym("."), copy.head->head(), new ALiteral<int32_t>(0, Cursor()), NULL); const AType* calleeT = cenv.type(copy.head->head()); @@ -180,17 +180,17 @@ lift_call(CEnv& cenv, Code& code, ACall* call) throw() } static AST* -lift_def(CEnv& cenv, Code& code, ACall* def) throw() +lift_def(CEnv& cenv, Code& code, ATuple* def) throw() { // Define stub first for recursion const ASymbol* const sym = def->list_ref(1)->as<const ASymbol*>(); AST* const body = def->list_ref(2); cenv.def(sym, body, cenv.type(body), NULL); if (is_form(body, "fn")) - cenv.setName(body->as<const ACall*>(), sym->str()); + cenv.setName(body->as<const ATuple*>(), sym->str()); assert(def->list_ref(1)->to<const ASymbol*>()); - List<ACall, AST> copy; + List<ATuple, AST> copy; copy.push_back(def->head()); copy.push_back(resp_lift(cenv, code, def->list_ref(1))); for (ATuple::iterator t = def->iter_at(2); t != def->end(); ++t) @@ -209,9 +209,9 @@ lift_def(CEnv& cenv, Code& code, ACall* def) throw() } static AST* -lift_builtin_call(CEnv& cenv, Code& code, ACall* call) throw() +lift_builtin_call(CEnv& cenv, Code& code, ATuple* call) throw() { - List<ACall, AST> copy; + List<ATuple, AST> copy; copy.push_back(call->head()); // Lift all arguments @@ -229,7 +229,7 @@ resp_lift(CEnv& cenv, Code& code, AST* ast) throw() if (sym) return lift_symbol(cenv, code, sym); - ACall* const call = ast->to<ACall*>(); + ATuple* const call = ast->to<ATuple*>(); if (call) { const ASymbol* const sym = call->head()->to<const ASymbol*>(); const std::string form = sym ? sym->cppstr : ""; diff --git a/src/llvm.cpp b/src/llvm.cpp index 82d2f79..31e6f6d 100644 --- a/src/llvm.cpp +++ b/src/llvm.cpp @@ -166,7 +166,7 @@ struct LLVMEngine : public Engine { return f; } - void pushFunctionArgs(CEnv& cenv, const ACall* fn, const AType* type, CFunc f); + void pushFunctionArgs(CEnv& cenv, const ATuple* fn, const AType* type, CFunc f); void finishFunction(CEnv& cenv, CFunc f, CVal ret) { builder.CreateRet(llVal(ret)); @@ -196,9 +196,9 @@ struct LLVMEngine : public Engine { CVal compileDot(CEnv& cenv, CVal tup, int32_t index); CVal compileLiteral(CEnv& cenv, const AST* lit); CVal compileString(CEnv& cenv, const char* str); - CVal compilePrimitive(CEnv& cenv, const ACall* prim); - CVal compileIf(CEnv& cenv, const ACall* aif); - CVal compileMatch(CEnv& cenv, const ACall* match); + CVal compilePrimitive(CEnv& cenv, const ATuple* prim); + CVal compileIf(CEnv& cenv, const ATuple* aif); + CVal compileMatch(CEnv& cenv, const ATuple* match); CVal compileGlobal(CEnv& cenv, const AType* type, const string& sym, CVal val); CVal getGlobal(CEnv& cenv, const string& sym, CVal val); @@ -330,7 +330,7 @@ LLVMEngine::compileString(CEnv& cenv, const char* str) } void -LLVMEngine::pushFunctionArgs(CEnv& cenv, const ACall* fn, const AType* type, CFunc f) +LLVMEngine::pushFunctionArgs(CEnv& cenv, const ATuple* fn, const AType* type, CFunc f) { cenv.push(); @@ -351,7 +351,7 @@ LLVMEngine::pushFunctionArgs(CEnv& cenv, const ACall* fn, const AType* type, CFu } CVal -LLVMEngine::compileIf(CEnv& cenv, const ACall* aif) +LLVMEngine::compileIf(CEnv& cenv, const ATuple* aif) { typedef vector< pair<Value*, BasicBlock*> > Branches; LLVMEngine* engine = reinterpret_cast<LLVMEngine*>(cenv.engine()); @@ -402,7 +402,7 @@ LLVMEngine::compileIf(CEnv& cenv, const ACall* aif) } CVal -LLVMEngine::compileMatch(CEnv& cenv, const ACall* match) +LLVMEngine::compileMatch(CEnv& cenv, const ATuple* match) { typedef vector< pair<Value*, BasicBlock*> > Branches; Value* matchee = llVal(resp_compile(cenv, match->list_ref(1))); @@ -457,7 +457,7 @@ LLVMEngine::compileMatch(CEnv& cenv, const ACall* match) } CVal -LLVMEngine::compilePrimitive(CEnv& cenv, const ACall* prim) +LLVMEngine::compilePrimitive(CEnv& cenv, const ATuple* prim) { ATuple::const_iterator i = prim->begin(); diff --git a/src/parse.cpp b/src/parse.cpp index 35765a9..e7825bc 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -58,10 +58,10 @@ PEnv::parse(const AST* exp) return h->func(*this, exp, h->arg); // Parse special form if (isupper(form->c_str()[0])) // Call constructor (any uppercase symbol) - return parseTuple<ACall>(*this, tup); + return parseTuple<ATuple>(*this, tup); } - return parseTuple<ACall>(*this, tup); // Parse regular call + return parseTuple<ATuple>(*this, tup); // Parse regular call } const ALexeme* lex = exp->to<const ALexeme*>(); @@ -132,7 +132,7 @@ macDef(PEnv& penv, const AST* exp) inline AST* parseCall(PEnv& penv, const AST* exp, void* arg) { - return parseTuple<ACall>(penv, exp->to<const ATuple*>()); + return parseTuple<ATuple>(penv, exp->to<const ATuple*>()); } template<typename T> @@ -154,7 +154,7 @@ parseFn(PEnv& penv, const AST* exp, void* arg) while (a != texp->end()) ret.push_back(penv.parse(*a++)); ret.head->loc = exp->loc; - return new ACall(ret.head); + return new ATuple(*ret.head); } inline AST* @@ -164,7 +164,7 @@ parseQuote(PEnv& penv, const AST* exp, void* arg) THROW_IF(texp->list_len() != 2, exp->loc, "`quote' requires exactly 1 argument"); const ALexeme* quotee = texp->list_ref(1)->to<const ALexeme*>(); THROW_IF(!quotee, exp->loc, "`quote' argument is not a lexeme"); - ACall* ret = tup<ACall>(texp->loc, penv.sym("quote"), quotee, NULL); + ATuple* ret = tup<ATuple>(texp->loc, penv.sym("quote"), quotee, NULL); return ret; } diff --git a/src/repl.cpp b/src/repl.cpp index 15e263f..4fdbb53 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -114,7 +114,7 @@ eval(CEnv& cenv, Cursor& cursor, istream& is, bool execute) // Compile top-level (lifted) functions Code exprs; for (Code::const_iterator i = lifted.begin(); i != lifted.end(); ++i) { - const ACall* call = (*i)->to<const ACall*>(); + const ATuple* call = (*i)->to<const ATuple*>(); if (call && is_form(call, "def") && is_form(call->list_ref(2), "fn")) { val = resp_compile(cenv, call); } else { diff --git a/src/resp.cpp b/src/resp.cpp index 478c738..611de0d 100644 --- a/src/resp.cpp +++ b/src/resp.cpp @@ -31,7 +31,7 @@ GC Object::pool(8 * 1024 * 1024); bool is_form(const AST* ast, const std::string& form) { - const ACall* call = ast->to<const ACall*>(); + const ATuple* call = ast->to<const ATuple*>(); if (!call) return false; @@ -45,7 +45,7 @@ is_form(const AST* ast, const std::string& form) bool is_primitive(const PEnv& penv, const AST* ast) { - const ACall* call = ast->to<const ACall*>(); + const ATuple* call = ast->to<const ATuple*>(); if (!call) return false; diff --git a/src/resp.hpp b/src/resp.hpp index 0f372a1..724ed5d 100644 --- a/src/resp.hpp +++ b/src/resp.hpp @@ -525,15 +525,6 @@ struct List { typedef List<AType, AType> TList; -/// Function call/application, e.g. "(func arg1 arg2)" -struct ACall : public ATuple { - ACall(const ATuple* exp) : ATuple(*exp) {} - ACall(Cursor c, AST* ast, va_list args) : ATuple(c, ast, args) {} - ACall(AST* first, AST* rest, Cursor c) : ATuple(first, rest, c) {} - void constrain(TEnv& tenv, Constraints& c) const throw(Error); -}; - - /*************************************************************************** * Parser: S-Expressions (SExp) -> AST Nodes (AST) * ***************************************************************************/ @@ -718,7 +709,7 @@ struct Engine { const ATuple* args, const AType* type) = 0; - virtual void pushFunctionArgs(CEnv& cenv, const ACall* fn, const AType* type, CFunc f) = 0; + virtual void pushFunctionArgs(CEnv& cenv, const ATuple* fn, const AType* type, CFunc f) = 0; virtual void finishFunction(CEnv& cenv, CFunc f, CVal ret) = 0; virtual void eraseFunction(CEnv& cenv, CFunc f) = 0; @@ -727,9 +718,9 @@ struct Engine { virtual CVal compileLiteral(CEnv& cenv, const AST* lit) = 0; virtual CVal compileString(CEnv& cenv, const char* str) = 0; virtual CVal compileCall(CEnv& cenv, CFunc f, const AType* fT, ValVec& args) = 0; - virtual CVal compilePrimitive(CEnv& cenv, const ACall* prim) = 0; - virtual CVal compileIf(CEnv& cenv, const ACall* aif) = 0; - virtual CVal compileMatch(CEnv& cenv, const ACall* match) = 0; + virtual CVal compilePrimitive(CEnv& cenv, const ATuple* prim) = 0; + virtual CVal compileIf(CEnv& cenv, const ATuple* aif) = 0; + virtual CVal compileMatch(CEnv& cenv, const ATuple* match) = 0; virtual CVal compileGlobal(CEnv& cenv, const AType* t, const string& sym, CVal val) = 0; virtual CVal getGlobal(CEnv& cenv, const string& sym, CVal val) = 0; virtual void writeModule(CEnv& cenv, std::ostream& os) = 0; @@ -800,15 +791,15 @@ struct CEnv { Env<const ASymbol*, const AST*> code; - typedef map<const ACall*, CFunc> Impls; + typedef map<const ATuple*, CFunc> Impls; Impls impls; - CFunc findImpl(const ACall* fn, const AType* type) { + CFunc findImpl(const ATuple* fn, const AType* type) { Impls::const_iterator i = impls.find(fn); return (i != impls.end()) ? i->second : NULL; } - void addImpl(const ACall* fn, CFunc impl) { + void addImpl(const ATuple* fn, CFunc impl) { impls.insert(make_pair(fn, impl)); } @@ -817,8 +808,8 @@ struct CEnv { CFunc currentFn; ///< Currently compiling function struct FreeVars : public std::vector<ASymbol*> { - FreeVars(ACall* f, const std::string& n) : fn(f), implName(n) {} - ACall* const fn; + FreeVars(ATuple* f, const std::string& n) : fn(f), implName(n) {} + ATuple* const fn; const std::string implName; int32_t index(ASymbol* sym) { const_iterator i = find(begin(), end(), sym); @@ -833,15 +824,15 @@ struct CEnv { typedef std::stack<FreeVars> LiftStack; LiftStack liftStack; - typedef map<const ACall*, std::string> Names; + typedef map<const ATuple*, std::string> Names; Names names; - const std::string name(const ACall* fn) const { + const std::string name(const ATuple* fn) const { Names::const_iterator i = names.find(fn); return (i != names.end()) ? i->second : ""; } - void setName(const ACall* fn, const std::string& name) { + void setName(const ATuple* fn, const std::string& name) { names.insert(make_pair(fn, name)); } private: |