diff options
author | David Robillard <d@drobilla.net> | 2009-01-26 07:53:15 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-01-26 07:53:15 +0000 |
commit | 109ef1d1aa6a7982b1e6ffa874ac1145afed7574 (patch) | |
tree | 42b439acc231d1e92126acf0fc3ce82fbb6ca4ed /ll.cpp | |
parent | 6671a54283fc7d9323fc14c9feee525f01b2821d (diff) | |
download | resp-109ef1d1aa6a7982b1e6ffa874ac1145afed7574.tar.gz resp-109ef1d1aa6a7982b1e6ffa874ac1145afed7574.tar.bz2 resp-109ef1d1aa6a7982b1e6ffa874ac1145afed7574.zip |
Clean up / shrink primitive code generation.
git-svn-id: http://svn.drobilla.net/resp/llvm-lisp@17 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'll.cpp')
-rw-r--r-- | ll.cpp | 22 |
1 files changed, 7 insertions, 15 deletions
@@ -845,26 +845,18 @@ ASTClosure::compile(CEnv& cenv) Value* ASTPrimitive::compile(CEnv& cenv) { - vector<Value*> params(tup.size() - 1); - for (size_t i = 1; i < tup.size(); ++i) - params[i-1] = tup[i]->compile(cenv); - + if (tup.size() < 3) throw SyntaxError("Too few arguments"); Value* a = tup[1]->compile(cenv); Value* b = tup[2]->compile(cenv); if (OP_IS_A(op, Instruction::BinaryOps)) { const Instruction::BinaryOps bo = (Instruction::BinaryOps)op; - switch (params.size()) { - case 0: - throw SyntaxError("Primitive expects at least 1 argument"); - case 1: - return params[0]; - default: - Value* val = cenv.builder.CreateBinOp(bo, a, b); - for (size_t i = 2; i < params.size(); ++i) - val = cenv.builder.CreateBinOp(bo, val, params[i]); - return val; - } + if (tup.size() == 2) + return tup[1]->compile(cenv); + Value* val = cenv.builder.CreateBinOp(bo, a, b); + for (size_t i = 3; i < tup.size(); ++i) + val = cenv.builder.CreateBinOp(bo, val, tup[i]->compile(cenv)); + return val; } else if (op == Instruction::ICmp) { bool isInt = cenv.tenv.type(tup[1])->str() == "(Int)"; if (isInt) { |