Commit 0fdabf35 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Support passing up to 6 elements in varargs

parent 443a4720
...@@ -2878,7 +2878,7 @@ Box* callattrInternal(Box* obj, BoxedString* attr, LookupScope scope, CallRewrit ...@@ -2878,7 +2878,7 @@ Box* callattrInternal(Box* obj, BoxedString* attr, LookupScope scope, CallRewrit
rewrite_args->out_rtn = rewrite_args->rewriter->call(true, (void*)Helper::call, arg_vec); rewrite_args->out_rtn = rewrite_args->rewriter->call(true, (void*)Helper::call, arg_vec);
rewrite_args->out_success = true; rewrite_args->out_success = true;
void* _args[2] = {args, const_cast<std::vector<BoxedString*>*>(keyword_names)}; void* _args[2] = { args, const_cast<std::vector<BoxedString*>*>(keyword_names) };
return Helper::call(val, argspec, arg1, arg2, arg3, _args); return Helper::call(val, argspec, arg1, arg2, arg3, _args);
} }
...@@ -3243,8 +3243,8 @@ void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_name ...@@ -3243,8 +3243,8 @@ void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_name
rewrite_args = NULL; rewrite_args = NULL;
} }
if (paramspec.takes_varargs && argspec.num_args > paramspec.num_args + 3) { if (paramspec.takes_varargs && argspec.num_args > paramspec.num_args + 6) {
// We currently only handle up to 3 arguments into the varargs tuple // We currently only handle up to 6 arguments into the varargs tuple
rewrite_args = NULL; rewrite_args = NULL;
} }
...@@ -3338,19 +3338,18 @@ void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_name ...@@ -3338,19 +3338,18 @@ void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_name
if (varargs_size == 0) { if (varargs_size == 0) {
varargs_val = rewrite_args->rewriter->loadConst( varargs_val = rewrite_args->rewriter->loadConst(
(intptr_t)EmptyTuple, varargs_idx < 3 ? Location::forArg(varargs_idx) : Location::any()); (intptr_t)EmptyTuple, varargs_idx < 3 ? Location::forArg(varargs_idx) : Location::any());
} else if (varargs_size == 1) {
varargs_val
= rewrite_args->rewriter->call(false, (void*)BoxedTuple::create1, unused_positional_rvars[0]);
} else if (varargs_size == 2) {
varargs_val = rewrite_args->rewriter->call(false, (void*)BoxedTuple::create2,
unused_positional_rvars[0], unused_positional_rvars[1]);
} else if (varargs_size == 3) {
varargs_val
= rewrite_args->rewriter->call(false, (void*)BoxedTuple::create3, unused_positional_rvars[0],
unused_positional_rvars[1], unused_positional_rvars[2]);
} else { } else {
// This is too late to abort the rewrite (we should have checked this earlier) assert(varargs_size <= 6);
abort(); void* create_ptrs[] = {
NULL, //
(void*)BoxedTuple::create1, //
(void*)BoxedTuple::create2, //
(void*)BoxedTuple::create3, //
(void*)BoxedTuple::create4, //
(void*)BoxedTuple::create5, //
(void*)BoxedTuple::create6, //
};
varargs_val = rewrite_args->rewriter->call(false, create_ptrs[varargs_size], unused_positional_rvars);
} }
if (varargs_val) { if (varargs_val) {
......
...@@ -557,6 +557,18 @@ public: ...@@ -557,6 +557,18 @@ public:
assert(gc::isValidGCObject(rtn->elts[i])); assert(gc::isValidGCObject(rtn->elts[i]));
return rtn; return rtn;
} }
static BoxedTuple* create6(Box* elt0, Box* elt1, Box* elt2, Box* elt3, Box* elt4, Box* elt5) {
BoxedTuple* rtn = new (6) BoxedTuple();
rtn->elts[0] = elt0;
rtn->elts[1] = elt1;
rtn->elts[2] = elt2;
rtn->elts[3] = elt3;
rtn->elts[4] = elt4;
rtn->elts[5] = elt5;
for (int i = 0; i < rtn->size(); i++)
assert(gc::isValidGCObject(rtn->elts[i]));
return rtn;
}
static BoxedTuple* create(std::initializer_list<Box*> members) { static BoxedTuple* create(std::initializer_list<Box*> members) {
auto rtn = new (members.size()) BoxedTuple(members); auto rtn = new (members.size()) BoxedTuple(members);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment