diff options
Diffstat (limited to 'Python/compile.c')
| -rw-r--r-- | Python/compile.c | 50 | 
1 files changed, 33 insertions, 17 deletions
| diff --git a/Python/compile.c b/Python/compile.c index dd4262c..1ecbae8 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -970,6 +970,7 @@ opcode_stack_effect(int opcode, int oparg)          case LOAD_CLOSURE:              return 1;          case LOAD_DEREF: +        case LOAD_CLASSDEREF:              return 1;          case STORE_DEREF:              return -1; @@ -1501,15 +1502,15 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args,      if (compiler_visit_argannotations(c, args->args, names))          goto error; -    if (args->varargannotation && -        compiler_visit_argannotation(c, args->vararg, -                                     args->varargannotation, names)) +    if (args->vararg && args->vararg->annotation && +        compiler_visit_argannotation(c, args->vararg->arg, +                                     args->vararg->annotation, names))          goto error;      if (compiler_visit_argannotations(c, args->kwonlyargs, names))          goto error; -    if (args->kwargannotation && -        compiler_visit_argannotation(c, args->kwarg, -                                     args->kwargannotation, names)) +    if (args->kwarg && args->kwarg->annotation && +        compiler_visit_argannotation(c, args->kwarg->arg, +                                     args->kwarg->annotation, names))          goto error;      if (!return_str) { @@ -1568,6 +1569,8 @@ compiler_function(struct compiler *c, stmt_ty s)      if (!compiler_decorators(c, decos))          return 0; +    if (args->defaults) +        VISIT_SEQ(c, expr, args->defaults);      if (args->kwonlyargs) {          int res = compiler_visit_kwonlydefaults(c, args->kwonlyargs,                                                  args->kw_defaults); @@ -1575,8 +1578,6 @@ compiler_function(struct compiler *c, stmt_ty s)              return 0;          kw_default_count = res;      } -    if (args->defaults) -        VISIT_SEQ(c, expr, args->defaults);      num_annotations = compiler_visit_annotations(c, args, returns);      if (num_annotations < 0)          return 0; @@ -1797,14 +1798,14 @@ compiler_lambda(struct compiler *c, expr_ty e)              return 0;      } +    if (args->defaults) +        VISIT_SEQ(c, expr, args->defaults);      if (args->kwonlyargs) {          int res = compiler_visit_kwonlydefaults(c, args->kwonlyargs,                                                  args->kw_defaults);          if (res < 0) return 0;          kw_default_count = res;      } -    if (args->defaults) -        VISIT_SEQ(c, expr, args->defaults);      if (!compiler_enter_scope(c, name, COMPILER_SCOPE_FUNCTION,                                (void *)e, e->lineno))          return 0; @@ -2638,6 +2639,10 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)      if (!mangled)          return 0; +    assert(PyUnicode_CompareWithASCIIString(name, "None") && +           PyUnicode_CompareWithASCIIString(name, "True") && +           PyUnicode_CompareWithASCIIString(name, "False")); +      op = 0;      optype = OP_NAME;      scope = PyST_GetScope(c->u->u_ste, mangled); @@ -2673,7 +2678,9 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)      switch (optype) {      case OP_DEREF:          switch (ctx) { -        case Load: op = LOAD_DEREF; break; +        case Load: +            op = (c->u->u_ste->ste_type == ClassBlock) ? LOAD_CLASSDEREF : LOAD_DEREF; +            break;          case Store: op = STORE_DEREF; break;          case AugLoad:          case AugStore: @@ -3197,12 +3204,18 @@ expr_constant(struct compiler *c, expr_ty e)      case Name_kind:          /* optimize away names that can't be reassigned */          id = PyUnicode_AsUTF8(e->v.Name.id); -        if (strcmp(id, "True") == 0) return 1; -        if (strcmp(id, "False") == 0) return 0; -        if (strcmp(id, "None") == 0) return 0; -        if (strcmp(id, "__debug__") == 0) -            return ! c->c_optimize; -        /* fall through */ +        if (id && strcmp(id, "__debug__") == 0) +            return !c->c_optimize; +        return -1; +    case NameConstant_kind: { +        PyObject *o = e->v.NameConstant.value; +        if (o == Py_None) +            return 0; +        else if (o == Py_True) +            return 1; +        else if (o == Py_False) +            return 0; +    }      default:          return -1;      } @@ -3378,6 +3391,9 @@ compiler_visit_expr(struct compiler *c, expr_ty e)      case Ellipsis_kind:          ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts);          break; +    case NameConstant_kind: +        ADDOP_O(c, LOAD_CONST, e->v.NameConstant.value, consts); +        break;      /* The following exprs can be assignment targets. */      case Attribute_kind:          if (e->v.Attribute.ctx != AugStore) | 
