diff Python/compile.c @ 80738:03f92a9f0875

create NameConstant AST class for None, True, and False literals (closes #16619)
author Benjamin Peterson <benjamin@python.org>
date Thu, 06 Dec 2012 17:41:04 -0500
parents ffb2fa900cb7
children 0238cc842805
line wrap: on
line diff
--- a/Python/compile.c	Thu Dec 06 12:21:22 2012 +0200
+++ b/Python/compile.c	Thu Dec 06 17:41:04 2012 -0500
@@ -3194,12 +3194,18 @@
     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;
     }
@@ -3375,6 +3381,9 @@
     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)