aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-08-22 19:16:28 +0000
committerDavid Robillard <d@drobilla.net>2010-08-22 19:16:28 +0000
commitb4dba561084b7ce60a8b1cfdb4e3b9de87de8d35 (patch)
tree4bdd431a1af0885a27c4c4c582bd721862629a84 /src
parent6f63ae0e3e9af059c7cac3d3a29e4fb34b0b0e28 (diff)
downloadresp-b4dba561084b7ce60a8b1cfdb4e3b9de87de8d35.tar.gz
resp-b4dba561084b7ce60a8b1cfdb4e3b9de87de8d35.tar.bz2
resp-b4dba561084b7ce60a8b1cfdb4e3b9de87de8d35.zip
Simplify Engine::startFunction.
git-svn-id: http://svn.drobilla.net/resp/resp@267 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src')
-rw-r--r--src/c.cpp15
-rw-r--r--src/compile.cpp11
-rw-r--r--src/llvm.cpp14
-rw-r--r--src/repl.cpp4
-rw-r--r--src/resp.hpp4
5 files changed, 19 insertions, 29 deletions
diff --git a/src/c.cpp b/src/c.cpp
index 66ab971..77c5fbe 100644
--- a/src/c.cpp
+++ b/src/c.cpp
@@ -101,8 +101,7 @@ struct CEngine : public Engine {
}
CFunc startFunction(CEnv& cenv,
- const std::string& name, const AType* retT, const ATuple& argsT,
- const vector<string> argNames)
+ const std::string& name, const ATuple* args, const AType* retT, const ATuple& argsT)
{
vector<const Type*> cprot;
FOREACH(ATuple::const_iterator, i, argsT) {
@@ -119,12 +118,12 @@ struct CEngine : public Engine {
f->returnType = *llType(retT);
f->name = name;
f->text += f->returnType + "\n" + f->name + "(";
- ATuple::const_iterator ai = argsT.begin();
- vector<string>::const_iterator ni = argNames.begin();
+ ATuple::const_iterator ai = argsT.begin();
+ ATuple::const_iterator ni = args->begin();
for (; ai != argsT.end(); ++ai, ++ni) {
if (ai != argsT.begin())
f->text += ", ";
- f->text += *llType((*ai)->as<const AType*>()) + " " + *ni;
+ f->text += *llType((*ai)->as<const AType*>()) + " " + (*ni)->as<const ASymbol*>()->cppstr;
}
f->text += ")\n{\n";
@@ -216,13 +215,9 @@ CEngine::compileFunction(CEnv& cenv, const AFn* fn, const AType* type)
const AType* retT = type->last()->as<const AType*>();
Subst argsSubst = cenv.tenv.buildSubst(type, *argsT);
- vector<string> argNames;
- for (ATuple::const_iterator i = fn->prot()->begin(); i != fn->prot()->end(); ++i)
- argNames.push_back((*i)->str());
-
// Write function declaration
const string name = (fn->name == "") ? cenv.penv.gensymstr("_fn") : fn->name;
- Function* f = llFunc(cenv.engine()->startFunction(cenv, name, retT, *argsT, argNames));
+ Function* f = llFunc(cenv.engine()->startFunction(cenv, name, fn->prot(), retT, *argsT));
cenv.push();
Subst oldSubst = cenv.tsubst;
diff --git a/src/compile.cpp b/src/compile.cpp
index 7a875f3..66c3abe 100644
--- a/src/compile.cpp
+++ b/src/compile.cpp
@@ -64,11 +64,12 @@ AFn::compile(CEnv& cenv) const throw()
{
const AType* type = cenv.type(this);
CFunc f = cenv.findImpl(this, type);
- if (!f) {
- f = cenv.engine()->compileFunction(cenv, this, type);
- cenv.vals.def(cenv.penv.sym(name), f);
- cenv.addImpl(this, f);
- }
+ if (f)
+ return f;
+
+ f = cenv.engine()->compileFunction(cenv, this, type);
+ cenv.vals.def(cenv.penv.sym(name), f);
+ cenv.addImpl(this, f);
return f;
}
diff --git a/src/llvm.cpp b/src/llvm.cpp
index 8e3ea50..7ba3d54 100644
--- a/src/llvm.cpp
+++ b/src/llvm.cpp
@@ -128,8 +128,7 @@ struct LLVMEngine : public Engine {
}
CFunc startFunction(CEnv& cenv,
- const std::string& name, const AType* retT, const ATuple& argsT,
- const vector<string> argNames)
+ const std::string& name, const ATuple* args, const AType* retT, const ATuple& argsT)
{
Function::LinkageTypes linkage = Function::ExternalLinkage;
@@ -152,9 +151,8 @@ struct LLVMEngine : public Engine {
// Set argument names in generated code
Function::arg_iterator a = f->arg_begin();
- if (!argNames.empty())
- for (vector<string>::const_iterator i = argNames.begin(); i != argNames.end(); ++a, ++i)
- a->setName(*i);
+ for (ATuple::const_iterator i = args->begin(); i != args->end(); ++a, ++i)
+ a->setName((*i)->as<const ASymbol*>()->cppstr);
BasicBlock* bb = BasicBlock::Create(context, "entry", f);
builder.SetInsertPoint(bb);
@@ -330,13 +328,9 @@ LLVMEngine::compileFunction(CEnv& cenv, const AFn* fn, const AType* type)
const AType* argsT = type->prot()->as<const AType*>();
const AType* retT = type->last()->as<const AType*>();
- vector<string> argNames;
- for (ATuple::const_iterator i = fn->prot()->begin(); i != fn->prot()->end(); ++i)
- argNames.push_back((*i)->str());
-
// Write function declaration
const string name = (fn->name == "") ? cenv.penv.gensymstr("_fn") : fn->name;
- Function* f = llFunc(cenv.engine()->startFunction(cenv, name, retT, *argsT, argNames));
+ Function* f = llFunc(cenv.engine()->startFunction(cenv, name, fn->prot(), retT, *argsT));
cenv.push();
diff --git a/src/repl.cpp b/src/repl.cpp
index 65f04ef..d2b8270 100644
--- a/src/repl.cpp
+++ b/src/repl.cpp
@@ -149,7 +149,7 @@ eval(CEnv& cenv, const string& name, istream& is, bool execute)
const AType* type = cenv.type(exprs.back());
// Create function for top-level of program
- f = cenv.engine()->startFunction(cenv, "main", type, ATuple(cursor));
+ f = cenv.engine()->startFunction(cenv, "main", new ATuple(cursor), type, ATuple(cursor));
// Compile expressions (other than function definitions) into it
for (list<AST*>::const_iterator i = exprs.begin(); i != exprs.end(); ++i)
@@ -191,7 +191,7 @@ repl(CEnv& cenv)
CFunc f = NULL;
try {
// Create function for this repl loop
- f = cenv.engine()->startFunction(cenv, replFnName, type, ATuple(cursor));
+ f = cenv.engine()->startFunction(cenv, replFnName, new ATuple(cursor), type, ATuple(cursor));
cenv.engine()->finishFunction(cenv, f, ast->compile(cenv));
callPrintCollect(cenv, f, ast, type, true);
if (cenv.args.find("-d") != cenv.args.end())
diff --git a/src/resp.hpp b/src/resp.hpp
index 1432b0f..5d3a93c 100644
--- a/src/resp.hpp
+++ b/src/resp.hpp
@@ -657,9 +657,9 @@ struct Engine {
virtual CFunc startFunction(
CEnv& cenv,
const std::string& name,
+ const ATuple* args,
const AType* retT,
- const ATuple& argsT,
- const vector<string> argNames=vector<string>()) = 0;
+ const ATuple& argsT) = 0;
typedef const vector<CVal> ValVec;