Commit 5e4f44b0 authored by Marius Wachtler's avatar Marius Wachtler

Generator: implement basic review comments

parent 4c9e23d2
......@@ -1817,8 +1817,7 @@ private:
llvm::BasicBlock* target = entry_blocks[node->target];
if (ENABLE_OSR && node->target->idx < myblock->idx && irstate->getEffortLevel() < EffortLevel::MAXIMAL
&& !irstate->getScopeInfo()->takesGenerator()) {
if (ENABLE_OSR && node->target->idx < myblock->idx && irstate->getEffortLevel() < EffortLevel::MAXIMAL) {
assert(node->target->predecessors.size() > 1);
doOSRExit(target, node);
} else {
......
......@@ -32,7 +32,7 @@ struct GlobalFuncs {
llvm::Value* boxInt, *unboxInt, *boxFloat, *unboxFloat, *boxStringPtr, *boxCLFunction, *unboxCLFunction,
*boxInstanceMethod, *boxBool, *unboxBool, *createTuple, *createDict, *createList, *createSlice,
*createUserClass, *createClosure, *createGenerator, *insideGenerator;
*createUserClass, *createClosure, *createGenerator;
llvm::Value* getattr, *setattr, *delattr, *delitem, *delGlobal, *print, *nonzero, *binop, *compare, *augbinop,
*unboxedLen, *getitem, *getclsattr, *getGlobal, *setitem, *unaryop, *import, *importFrom, *importStar, *repr,
*isinstance, *yield;
......
......@@ -858,8 +858,6 @@ Box* getattr_internal(Box* obj, const std::string& attr, bool check_cls, bool al
raiseExcHelper(NameError, "free variable '%s' referenced before assignment in enclosing scope", attr.c_str());
}
if (obj->cls == generator_cls) {
}
if (allow_custom) {
// Don't need to pass icentry args, since we special-case __getattribtue__ and __getattr__ to use
......@@ -1758,7 +1756,7 @@ Box* callFunc(BoxedFunction* func, CallRewriteArgs* rewrite_args, ArgPassSpec ar
BoxedClosure* closure = func->closure;
if (argspec.has_starargs || argspec.has_kwargs || f->takes_kwargs)
if (argspec.has_starargs || argspec.has_kwargs || f->takes_kwargs || func->isGenerator)
rewrite_args = NULL;
// These could be handled:
......@@ -1793,26 +1791,21 @@ Box* callFunc(BoxedFunction* func, CallRewriteArgs* rewrite_args, ArgPassSpec ar
if (rewrite_args) {
int closure_indicator = closure ? 1 : 0;
int generator_indicator = func->isGenerator ? 1 : 0;
int arg_offset = closure_indicator + generator_indicator;
if (num_passed_args >= 1)
rewrite_args->arg1 = rewrite_args->arg1.move(0 + arg_offset);
rewrite_args->arg1 = rewrite_args->arg1.move(0 + closure_indicator);
if (num_passed_args >= 2)
rewrite_args->arg2 = rewrite_args->arg2.move(1 + arg_offset);
rewrite_args->arg2 = rewrite_args->arg2.move(1 + closure_indicator);
if (num_passed_args >= 3)
rewrite_args->arg3 = rewrite_args->arg3.move(2 + arg_offset);
rewrite_args->arg3 = rewrite_args->arg3.move(2 + closure_indicator);
if (num_passed_args >= 4)
rewrite_args->args = rewrite_args->args.move(3 + arg_offset);
rewrite_args->args = rewrite_args->args.move(3 + closure_indicator);
// TODO this kind of embedded reference needs to be tracked by the GC somehow?
// Or maybe it's ok, since we've guarded on the function object?
if (closure)
rewrite_args->rewriter->loadConst(0, (intptr_t)closure);
if (func->isGenerator)
rewrite_args->rewriter->loadConst(0, (intptr_t)func->isGenerator);
// We might have trouble if we have more output args than input args,
// such as if we need more space to pass defaults.
if (num_output_args > 3 && num_output_args > argspec.totalPassed()) {
......@@ -2002,8 +1995,7 @@ Box* callFunc(BoxedFunction* func, CallRewriteArgs* rewrite_args, ArgPassSpec ar
return createGenerator(func, oarg1, oarg2, oarg3, oargs);
}
return callCLFunc(f, rewrite_args, num_output_args, closure, (BoxedGenerator*)func->isGenerator, oarg1, oarg2,
oarg3, oargs);
return callCLFunc(f, rewrite_args, num_output_args, closure, NULL, oarg1, oarg2, oarg3, oargs);
}
Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure,
......@@ -2035,7 +2027,6 @@ Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_arg
}
Box* runtimeCallInternal(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2, Box* arg3,
Box** args, const std::vector<const std::string*>* keyword_names) {
int npassed_args = argspec.totalPassed();
......
......@@ -285,11 +285,8 @@ extern "C" void generatorGCHandler(GCVisitor* v, void* p) {
BoxedGenerator* g = (BoxedGenerator*)p;
if (g->function) {
v->visit(g->function);
if (g->function->f) {
int num_args = g->function->f->num_args;
if (num_args >= 1)
v->visit(g->arg1);
if (num_args >= 2)
......@@ -299,15 +296,11 @@ extern "C" void generatorGCHandler(GCVisitor* v, void* p) {
if (num_args > 3)
v->visitPotentialRange(reinterpret_cast<void* const*>(&g->args->elts[0]),
reinterpret_cast<void* const*>(&g->args->elts[num_args - 3]));
}
}
if (g->returnValue)
v->visit(g->returnValue);
if (g->exception)
v->visit(g->exception);
v->visitPotentialRange((void**)&g->context, ((void**)&g->context) + sizeof(g->context) / sizeof(void*));
v->visitPotentialRange((void**)&g->returnContext,
((void**)&g->returnContext) + sizeof(g->returnContext) / sizeof(void*));
......
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