Commit 4f95e1cc authored by Kevin Modzelewski's avatar Kevin Modzelewski

refactor out bindObjIntoArgs

parent c4ebf05f
...@@ -3012,6 +3012,34 @@ static Box* _callFuncHelper(BoxedFunctionBase* func, ArgPassSpec argspec, Box* a ...@@ -3012,6 +3012,34 @@ static Box* _callFuncHelper(BoxedFunctionBase* func, ArgPassSpec argspec, Box* a
typedef std::function<Box*(int, int, RewriterVar*&)> GetDefaultFunc; typedef std::function<Box*(int, int, RewriterVar*&)> GetDefaultFunc;
ArgPassSpec bindObjIntoArgs(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box*& arg1, Box*& arg2,
Box*& arg3, Box** args, Box** new_args) {
int npassed_args = argspec.totalPassed();
assert((new_args != NULL) == (npassed_args >= 3));
if (npassed_args >= 3) {
new_args[0] = arg3;
memcpy(new_args + 1, args, (npassed_args - 3) * sizeof(Box*));
}
arg3 = arg2;
arg2 = arg1;
arg1 = obj;
if (rewrite_args) {
if (npassed_args >= 3) {
rewrite_args->args = rewrite_args->rewriter->allocateAndCopyPlus1(
rewrite_args->arg3, npassed_args == 3 ? NULL : rewrite_args->args, npassed_args - 3);
}
rewrite_args->arg3 = rewrite_args->arg2;
rewrite_args->arg2 = rewrite_args->arg1;
rewrite_args->arg1 = rewrite_args->obj;
}
return ArgPassSpec(argspec.num_args + 1, argspec.num_keywords, argspec.has_starargs, argspec.has_kwargs);
}
void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_names, const char* func_name, void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_names, const char* func_name,
Box** defaults, CallRewriteArgs* rewrite_args, bool& rewrite_success, ArgPassSpec argspec, Box** defaults, CallRewriteArgs* rewrite_args, bool& rewrite_success, ArgPassSpec argspec,
Box* arg1, Box* arg2, Box* arg3, Box** args, const std::vector<BoxedString*>* keyword_names, Box* arg1, Box* arg2, Box* arg3, Box** args, const std::vector<BoxedString*>* keyword_names,
......
...@@ -130,6 +130,10 @@ void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_name ...@@ -130,6 +130,10 @@ void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_name
Box** defaults, CallRewriteArgs* rewrite_args, bool& rewrite_success, ArgPassSpec argspec, Box** defaults, CallRewriteArgs* rewrite_args, bool& rewrite_success, ArgPassSpec argspec,
Box* arg1, Box* arg2, Box* arg3, Box** args, const std::vector<BoxedString*>* keyword_names, Box* arg1, Box* arg2, Box* arg3, Box** args, const std::vector<BoxedString*>* keyword_names,
Box*& oarg1, Box*& oarg2, Box*& oarg3, Box** oargs); Box*& oarg1, Box*& oarg2, Box*& oarg3, Box** oargs);
// new_args should be allocated by the caller if at least three args get passed in
ArgPassSpec bindObjIntoArgs(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box*& arg1, Box*& arg2,
Box*& arg3, Box** args, Box** new_args);
} // namespace pyston } // namespace pyston
#endif #endif
...@@ -537,43 +537,18 @@ static Box* typeTppCall(Box* self, CallRewriteArgs* rewrite_args, ArgPassSpec ar ...@@ -537,43 +537,18 @@ static Box* typeTppCall(Box* self, CallRewriteArgs* rewrite_args, ArgPassSpec ar
Box** args, const std::vector<BoxedString*>* keyword_names) { Box** args, const std::vector<BoxedString*>* keyword_names) {
int npassed_args = argspec.totalPassed(); int npassed_args = argspec.totalPassed();
Box** new_args;
if (npassed_args >= 3) {
new_args = (Box**)alloca(sizeof(Box*) * (npassed_args + 1 - 3));
new_args[0] = arg3;
memcpy(new_args + 1, args, (npassed_args - 3) * sizeof(Box*));
}
if (argspec.has_starargs) { if (argspec.has_starargs) {
// This would fail in typeCallInner // This would fail in typeCallInner
rewrite_args = NULL; rewrite_args = NULL;
} }
if (rewrite_args) { Box** new_args = NULL;
CallRewriteArgs srewrite_args(rewrite_args->rewriter, NULL, rewrite_args->destination); if (npassed_args >= 3) {
srewrite_args.arg1 = rewrite_args->obj; new_args = (Box**)alloca(sizeof(Box*) * (npassed_args + 1 - 3));
srewrite_args.arg2 = rewrite_args->arg1;
srewrite_args.arg3 = rewrite_args->arg2;
if (npassed_args >= 3) {
srewrite_args.args = rewrite_args->rewriter->allocateAndCopyPlus1(
rewrite_args->arg3, npassed_args == 3 ? NULL : rewrite_args->args, npassed_args - 3);
}
srewrite_args.args_guarded = rewrite_args->args_guarded;
srewrite_args.func_guarded = rewrite_args->func_guarded;
Box* rtn = typeCallInner(&srewrite_args, ArgPassSpec(argspec.num_args + 1, argspec.num_keywords,
argspec.has_starargs, argspec.has_kwargs),
self, arg1, arg2, new_args, keyword_names);
rewrite_args->out_rtn = srewrite_args.out_rtn;
rewrite_args->out_success = srewrite_args.out_success;
return rtn;
} else {
return typeCallInner(
NULL, ArgPassSpec(argspec.num_args + 1, argspec.num_keywords, argspec.has_starargs, argspec.has_kwargs),
self, arg1, arg2, new_args, keyword_names);
} }
ArgPassSpec new_argspec = bindObjIntoArgs(self, rewrite_args, argspec, arg1, arg2, arg3, args, new_args);
return typeCallInner(rewrite_args, new_argspec, arg1, arg2, arg3, new_args, keyword_names);
} }
static Box* typeCallInternal(BoxedFunctionBase* f, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, static Box* typeCallInternal(BoxedFunctionBase* f, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1,
......
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