aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ll.cpp22
1 files changed, 7 insertions, 15 deletions
diff --git a/ll.cpp b/ll.cpp
index 0dfa04e..d14ce53 100644
--- a/ll.cpp
+++ b/ll.cpp
@@ -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) {