]> granicus.if.org Git - python/commitdiff
SF patch 1547796 by Georg Brandl -- set literals.
authorGuido van Rossum <guido@python.org>
Mon, 28 Aug 2006 15:27:34 +0000 (15:27 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 28 Aug 2006 15:27:34 +0000 (15:27 +0000)
22 files changed:
Doc/lib/libdis.tex
Grammar/Grammar
Include/Python-ast.h
Include/graminit.h
Include/opcode.h
Lib/compiler/ast.py
Lib/compiler/pyassem.py
Lib/compiler/pycodegen.py
Lib/compiler/transformer.py
Lib/opcode.py
Lib/test/test_grammar.py
Lib/test/test_set.py
Objects/setobject.c
Parser/Python.asdl
Python/Python-ast.c
Python/ast.c
Python/ceval.c
Python/compile.c
Python/graminit.c
Python/import.c
Tools/compiler/ast.txt
Tools/compiler/astgen.py

index fc723220586c1a4c69b2b21d13511f1ccd1c0de5..5c53490666bc7a08a9b78d840503fd044d59d706 100644 (file)
@@ -501,6 +501,10 @@ the resulting tuple onto the stack.
 Works as \code{BUILD_TUPLE}, but creates a list.
 \end{opcodedesc}
 
+\begin{opcodedesc}{BUILD_SET}{count}
+Works as \code{BUILD_TUPLE}, but creates a set.
+\end{opcodedesc}
+
 \begin{opcodedesc}{BUILD_MAP}{zero}
 Pushes a new empty dictionary object onto the stack.  The argument is
 ignored and set to zero by the compiler.
index 31551f646e6d2eed2f5df042b09633dd86109886..2e964f22551967517a04a1050d49dc7e30cbed75 100644 (file)
@@ -101,7 +101,7 @@ factor: ('+'|'-'|'~') factor | power
 power: atom trailer* ['**' factor]
 atom: ('(' [yield_expr|testlist_gexp] ')' |
        '[' [listmaker] ']' |
-       '{' [dictmaker] '}' |
+       '{' [dictsetmaker] '}' |
        NAME | NUMBER | STRING+)
 listmaker: test ( list_for | (',' test)* [','] )
 testlist_gexp: test ( gen_for | (',' test)* [','] )
@@ -112,7 +112,7 @@ subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]
 sliceop: ':' [test]
 exprlist: expr (',' expr)* [',']
 testlist: test (',' test)* [',']
-dictmaker: test ':' test (',' test ':' test)* [',']
+dictsetmaker: (test ':' test (',' test ':' test)* [',']) | (test (',' test)* [','])
 
 classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
 
index 8fd8ceb26196d3cd1b1478ace364882841d79b5e..390b8eae4c60f16ae26ccac96b59dd4ec91ed1e1 100644 (file)
@@ -184,10 +184,10 @@ struct _stmt {
 };
 
 enum _expr_kind {BoolOp_kind=1, BinOp_kind=2, UnaryOp_kind=3, Lambda_kind=4,
-                  IfExp_kind=5, Dict_kind=6, ListComp_kind=7,
-                  GeneratorExp_kind=8, Yield_kind=9, Compare_kind=10,
-                  Call_kind=11, Num_kind=12, Str_kind=13, Attribute_kind=14,
-                  Subscript_kind=15, Name_kind=16, List_kind=17, Tuple_kind=18};
+                  IfExp_kind=5, Dict_kind=6, Set_kind=7, ListComp_kind=8,
+                  GeneratorExp_kind=9, Yield_kind=10, Compare_kind=11,
+                  Call_kind=12, Num_kind=13, Str_kind=14, Attribute_kind=15,
+                  Subscript_kind=16, Name_kind=17, List_kind=18, Tuple_kind=19};
 struct _expr {
         enum _expr_kind kind;
         union {
@@ -223,6 +223,10 @@ struct _expr {
                         asdl_seq *values;
                 } Dict;
                 
+                struct {
+                        asdl_seq *elts;
+                } Set;
+                
                 struct {
                         expr_ty elt;
                         asdl_seq *generators;
@@ -399,6 +403,7 @@ expr_ty IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
               col_offset, PyArena *arena);
 expr_ty Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset,
              PyArena *arena);
+expr_ty Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena);
 expr_ty ListComp(expr_ty elt, asdl_seq * generators, int lineno, int
                  col_offset, PyArena *arena);
 expr_ty GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int
index 9af182a56003570425b2780f99174640e8f91256..f4701a623ea021ff8218c4af408e02f6c677d174 100644 (file)
@@ -69,7 +69,7 @@
 #define sliceop 324
 #define exprlist 325
 #define testlist 326
-#define dictmaker 327
+#define dictsetmaker 327
 #define classdef 328
 #define arglist 329
 #define argument 330
index 1b9cb5cc573f4eff071ba31dbbb9f21c9010cf44..4c823d9fdc4f0f917ff6c3c1c8b159592c2ade29 100644 (file)
@@ -97,11 +97,12 @@ extern "C" {
 #define LOAD_NAME      101     /* Index in name list */
 #define BUILD_TUPLE    102     /* Number of tuple items */
 #define BUILD_LIST     103     /* Number of list items */
-#define BUILD_MAP      104     /* Always zero for now */
-#define LOAD_ATTR      105     /* Index in name list */
-#define COMPARE_OP     106     /* Comparison operator */
-#define IMPORT_NAME    107     /* Index in name list */
-#define IMPORT_FROM    108     /* Index in name list */
+#define BUILD_SET      104     /* Number of set items */
+#define BUILD_MAP      105     /* Always zero for now */
+#define LOAD_ATTR      106     /* Index in name list */
+#define COMPARE_OP     107     /* Comparison operator */
+#define IMPORT_NAME    108     /* Index in name list */
+#define IMPORT_FROM    109     /* Index in name list */
 
 #define JUMP_FORWARD   110     /* Number of bytes to skip */
 #define JUMP_IF_FALSE  111     /* "" */
index 94a6262d6844faa0a99ba109c2b3224566036b10..69533255d77eeb7c6ec7ce7993d743feda1b9c0b 100644 (file)
@@ -542,7 +542,6 @@ class Function(Node):
             self.kwargs = 1
 
 
-
     def getChildren(self):
         children = []
         children.append(self.decorators)
@@ -572,6 +571,7 @@ class GenExpr(Node):
         self.argnames = ['.0']
         self.varargs = self.kwargs = None
 
+
     def getChildren(self):
         return self.code,
 
@@ -589,7 +589,6 @@ class GenExprFor(Node):
         self.lineno = lineno
         self.is_outmost = False
 
-
     def getChildren(self):
         children = []
         children.append(self.assign)
@@ -766,7 +765,6 @@ class Lambda(Node):
             self.kwargs = 1
 
 
-
     def getChildren(self):
         children = []
         children.append(self.argnames)
@@ -1091,6 +1089,22 @@ class RightShift(Node):
     def __repr__(self):
         return "RightShift((%s, %s))" % (repr(self.left), repr(self.right))
 
+class Set(Node):
+    def __init__(self, items, lineno=None):
+        self.items = items
+        self.lineno = lineno
+
+    def getChildren(self):
+        return tuple(flatten(self.items))
+
+    def getChildNodes(self):
+        nodelist = []
+        nodelist.extend(flatten_nodes(self.items))
+        return tuple(nodelist)
+
+    def __repr__(self):
+        return "Set(%s)" % (repr(self.items),)
+
 class Slice(Node):
     def __init__(self, expr, flags, lower, upper, lineno=None):
         self.expr = expr
index 95f5c3e4097ed312799f08ca0973ed94074f697d..542d704b98ce219474a37614299929d51af4a003 100644 (file)
@@ -793,6 +793,8 @@ class StackDepthTracker:
         return -count+1
     def BUILD_LIST(self, count):
         return -count+1
+    def BUILD_SET(self, count):
+        return -count+1
     def CALL_FUNCTION(self, argc):
         hi, lo = divmod(argc, 256)
         return -(lo + hi * 2)
index cc197e307bab76387d99f43a1cb5f9a44510cd4a..af9904517ab94709131e445fc059c1651ca6f462 100644 (file)
@@ -1241,6 +1241,12 @@ class CodeGenerator:
             self.visit(elt)
         self.emit('BUILD_LIST', len(node.nodes))
 
+    def visitSet(self, node):
+        self.set_lineno(node)
+        for elt in node.items:
+            self.visit(elt)
+        self.emit('BUILD_SET', len(node.items))
+
     def visitSliceobj(self, node):
         for child in node.nodes:
             self.visit(child)
index b564300c01c7b23db68efa56e89f763b042bd34e..42640e81919b08987db727eb82e14cdd81a91f39 100644 (file)
@@ -738,7 +738,7 @@ class Transformer:
     def atom_lbrace(self, nodelist):
         if nodelist[1][0] == token.RBRACE:
             return Dict((), lineno=nodelist[0][2])
-        return self.com_dictmaker(nodelist[1])
+        return self.com_dictsetmaker(nodelist[1])
 
     def atom_backquote(self, nodelist):
         return Backquote(self.com_node(nodelist[1]))
@@ -1182,13 +1182,20 @@ class Transformer:
             assert node[0] == symbol.gen_iter
             return node[1]
 
-    def com_dictmaker(self, nodelist):
-        # dictmaker: test ':' test (',' test ':' value)* [',']
+    def com_dictsetmaker(self, nodelist):
+        # dictsetmaker: (test ':' test (',' test ':' value)* [',']) | (test (',' test)* [','])
         items = []
-        for i in range(1, len(nodelist), 4):
-            items.append((self.com_node(nodelist[i]),
-                          self.com_node(nodelist[i+2])))
-        return Dict(items, lineno=items[0][0].lineno)
+        if nodelist[2] != ':':
+            # it's a set
+            for i in range(1, len(nodelist), 2):
+                items.append(self.com_node(nodelist[i]))
+            return Set(items, lineno=items[0].lineno)
+        else:
+            # it's a dict
+            for i in range(1, len(nodelist), 4):
+                items.append((self.com_node(nodelist[i]),
+                              self.com_node(nodelist[i+2])))
+            return Dict(items, lineno=items[0][0].lineno)
 
     def com_apply_trailer(self, primaryNode, nodelist):
         t = nodelist[1][0]
index c2d7a59dc5d2c8f47da7bced4f868bb58f61a0e8..cf8d90941346c9d358c4610fb8cdba0de4d99ed4 100644 (file)
@@ -137,12 +137,13 @@ hasconst.append(100)
 name_op('LOAD_NAME', 101)       # Index in name list
 def_op('BUILD_TUPLE', 102)      # Number of tuple items
 def_op('BUILD_LIST', 103)       # Number of list items
-def_op('BUILD_MAP', 104)        # Always zero for now
-name_op('LOAD_ATTR', 105)       # Index in name list
-def_op('COMPARE_OP', 106)       # Comparison operator
-hascompare.append(106)
-name_op('IMPORT_NAME', 107)     # Index in name list
-name_op('IMPORT_FROM', 108)     # Index in name list
+def_op('BUILD_SET', 104)        # Number of set items
+def_op('BUILD_MAP', 105)        # Always zero for now
+name_op('LOAD_ATTR', 106)       # Index in name list
+def_op('COMPARE_OP', 107)       # Comparison operator
+hascompare.append(107)
+name_op('IMPORT_NAME', 108)     # Index in name list
+name_op('IMPORT_FROM', 109)     # Index in name list
 
 jrel_op('JUMP_FORWARD', 110)    # Number of bytes to skip
 jrel_op('JUMP_IF_FALSE', 111)   # ""
index 331d52762f63ae4734fdc669f651146c85d4cb28..93dc9ec83433ad85cb13140b1f248332ecfbd918 100644 (file)
@@ -685,8 +685,8 @@ print L
 
 
 print 'atoms'
-### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictmaker] '}' | NAME | NUMBER | STRING
-### dictmaker: test ':' test (',' test ':' test)* [',']
+### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictsetmaker] '}' | NAME | NUMBER | STRING
+### dictsetmaker: (test ':' test (',' test ':' test)* [',']) | (test (',' test)* [','])
 
 x = (1)
 x = (1 or 2 or 3)
@@ -706,6 +706,11 @@ x = {'one': 1, 'two': 2}
 x = {'one': 1, 'two': 2,}
 x = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6}
 
+x = {'one'}
+x = {'one', 1,}
+x = {'one', 'two', 'three'}
+x = {2, 3, 4,}
+
 x = x
 x = 'x'
 x = 123
index 23926bef727b8c3b3fef1adaa880b16b85152c5d..556e390259aa3cc0757d67e63eb1c6ccc96a266f 100644 (file)
@@ -261,6 +261,11 @@ class TestSet(TestJointOps):
         t = self.thetype(s)
         self.assertNotEqual(id(s), id(t))
 
+    def test_set_literal(self):
+        s = set([1,2,3])
+        t = {1,2,3}
+        self.assertEqual(s, t)
+
     def test_hash(self):
         self.assertRaises(TypeError, hash, self.s)
 
@@ -626,7 +631,7 @@ class TestBasicOpsEmpty(TestBasicOps):
         self.set    = set(self.values)
         self.dup    = set(self.values)
         self.length = 0
-        self.repr   = "set([])"
+        self.repr   = "{}"
 
 #------------------------------------------------------------------------------
 
@@ -637,7 +642,7 @@ class TestBasicOpsSingleton(TestBasicOps):
         self.set    = set(self.values)
         self.dup    = set(self.values)
         self.length = 1
-        self.repr   = "set([3])"
+        self.repr   = "{3}"
 
     def test_in(self):
         self.failUnless(3 in self.set)
@@ -654,7 +659,7 @@ class TestBasicOpsTuple(TestBasicOps):
         self.set    = set(self.values)
         self.dup    = set(self.values)
         self.length = 1
-        self.repr   = "set([(0, 'zero')])"
+        self.repr   = "{(0, 'zero')}"
 
     def test_in(self):
         self.failUnless((0, "zero") in self.set)
index d65145730c0550b25e8e1246d369f757f7a165da..b4b58b7afaab0885d31a0b676fc986c17de2c5e9 100644 (file)
@@ -530,14 +530,20 @@ set_tp_print(PySetObject *so, FILE *fp, int flags)
        char *emit = "";        /* No separator emitted on first pass */
        char *separator = ", ";
 
-       fprintf(fp, "%s([", so->ob_type->tp_name);
+       if (so->ob_type == &PySet_Type)
+               fprintf(fp, "{");
+       else
+               fprintf(fp, "%s([", so->ob_type->tp_name);
        while (set_next(so, &pos, &entry)) {
                fputs(emit, fp);
                emit = separator;
                if (PyObject_Print(entry->key, fp, 0) != 0)
                        return -1;
        }
-       fputs("])", fp);
+       if (so->ob_type == &PySet_Type)
+               fputs("}", fp);
+       else
+               fputs("])", fp);
        return 0;
 }
 
@@ -554,8 +560,15 @@ set_repr(PySetObject *so)
        if (listrepr == NULL)
                return NULL;
 
-       result = PyString_FromFormat("%s(%s)", so->ob_type->tp_name,
-               PyString_AS_STRING(listrepr));
+       if (so->ob_type == &PySet_Type) {
+               char *s = PyString_AS_STRING(listrepr);
+               s += 1;
+               s[strlen(s)-1] = 0;
+               result = PyString_FromFormat("{%s}", s);
+       } else {
+               result = PyString_FromFormat("%s(%s)", so->ob_type->tp_name,
+                        PyString_AS_STRING(listrepr));
+       }
        Py_DECREF(listrepr);
        return result;
 }
index 5124e47616d60d54736b08452235b378625b9739..55b3bd37079f14a6393bbdf6feb4b90d3781304a 100644 (file)
@@ -56,6 +56,7 @@ module Python version "$Revision$"
             | Lambda(arguments args, expr body)
             | IfExp(expr test, expr body, expr orelse)
             | Dict(expr* keys, expr* values)
+            | Set(expr* elts)
             | ListComp(expr elt, comprehension* generators)
             | GeneratorExp(expr elt, comprehension* generators)
             -- the grammar constrains where yield expressions can occur
index 68523e4904bca215d6e70d9dc1abefc1da2c5652..86f09edbffd7226dcb0961916d68fd6e0ec98dc4 100644 (file)
@@ -178,6 +178,10 @@ static char *Dict_fields[]={
         "keys",
         "values",
 };
+static PyTypeObject *Set_type;
+static char *Set_fields[]={
+        "elts",
+};
 static PyTypeObject *ListComp_type;
 static char *ListComp_fields[]={
         "elt",
@@ -517,6 +521,8 @@ static int init_types(void)
         if (!IfExp_type) return 0;
         Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
         if (!Dict_type) return 0;
+        Set_type = make_type("Set", expr_type, Set_fields, 1);
+        if (!Set_type) return 0;
         ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
         if (!ListComp_type) return 0;
         GeneratorExp_type = make_type("GeneratorExp", expr_type,
@@ -1434,6 +1440,22 @@ Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
         return p;
 }
 
+expr_ty
+Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
+{
+        expr_ty p;
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
+        if (!p) {
+                PyErr_NoMemory();
+                return NULL;
+        }
+        p->kind = Set_kind;
+        p->v.Set.elts = elts;
+        p->lineno = lineno;
+        p->col_offset = col_offset;
+        return p;
+}
+
 expr_ty
 ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
          PyArena *arena)
@@ -2424,6 +2446,15 @@ ast2obj_expr(void* _o)
                         goto failed;
                 Py_DECREF(value);
                 break;
+        case Set_kind:
+                result = PyType_GenericNew(Set_type, NULL, NULL);
+                if (!result) goto failed;
+                value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
+                if (!value) goto failed;
+                if (PyObject_SetAttrString(result, "elts", value) == -1)
+                        goto failed;
+                Py_DECREF(value);
+                break;
         case ListComp_kind:
                 result = PyType_GenericNew(ListComp_type, NULL, NULL);
                 if (!result) goto failed;
@@ -3069,6 +3100,7 @@ init_ast(void)
             return;
         if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
         if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
+        if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
         if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
             return;
         if (PyDict_SetItemString(d, "GeneratorExp",
index 1a438789434ad8ba96c315af933ec7a2ab215814..cd0a81dcfa4be5fd9b71cc97beba32bc5f60dc77 100644 (file)
@@ -394,6 +394,7 @@ set_context(expr_ty e, expr_context_ty ctx, const node *n)
             expr_name = "list comprehension";
             break;
         case Dict_kind:
+       case Set_kind:
         case Num_kind:
         case Str_kind:
             expr_name = "literal";
@@ -1187,7 +1188,7 @@ static expr_ty
 ast_for_atom(struct compiling *c, const node *n)
 {
     /* atom: '(' [yield_expr|testlist_gexp] ')' | '[' [listmaker] ']'
-       | '{' [dictmaker] '}' | NAME | NUMBER | STRING+
+       | '{' [dictsetmaker] '}' | NAME | NUMBER | STRING+
     */
     node *ch = CHILD(n, 0);
     
@@ -1242,36 +1243,55 @@ ast_for_atom(struct compiling *c, const node *n)
        else
            return ast_for_listcomp(c, ch);
     case LBRACE: {
-       /* dictmaker: test ':' test (',' test ':' test)* [','] */
+       /* dictsetmaker: test ':' test (',' test ':' test)* [','] |
+        *               test (',' test)* [',']  */
        int i, size;
        asdl_seq *keys, *values;
        
        ch = CHILD(n, 1);
-       size = (NCH(ch) + 1) / 4; /* +1 in case no trailing comma */
-       keys = asdl_seq_new(size, c->c_arena);
-       if (!keys)
-           return NULL;
-       
-       values = asdl_seq_new(size, c->c_arena);
-       if (!values)
-           return NULL;
-       
-       for (i = 0; i < NCH(ch); i += 4) {
-           expr_ty expression;
-           
-           expression = ast_for_expr(c, CHILD(ch, i));
-           if (!expression)
-               return NULL;
+       if (NCH(ch) == 1 || (NCH(ch) > 0 && STR(CHILD(ch, 1))[0] == ',')) {
+            /* it's a set */
+            size = (NCH(ch) + 1) / 2; /* +1 in case no trailing comma */
+            keys = asdl_seq_new(size, c->c_arena);
+            if (!keys)
+                return NULL;
+
+            for (i = 0; i < NCH(ch); i += 2) {
+                expr_ty expression;
+                expression = ast_for_expr(c, CHILD(ch, i));
+                if (!expression)
+                    return NULL;
+                asdl_seq_SET(keys, i / 2, expression);
+            }
+            return Set(keys, LINENO(n), n->n_col_offset, c->c_arena);
+        } else {
+            /* it's a dict */
+            size = (NCH(ch) + 1) / 4; /* +1 in case no trailing comma */
+            keys = asdl_seq_new(size, c->c_arena);
+            if (!keys)
+                return NULL;
+            
+            values = asdl_seq_new(size, c->c_arena);
+            if (!values)
+                return NULL;
+            
+            for (i = 0; i < NCH(ch); i += 4) {
+                expr_ty expression;
+                
+                expression = ast_for_expr(c, CHILD(ch, i));
+                if (!expression)
+                    return NULL;
 
-           asdl_seq_SET(keys, i / 4, expression);
+                asdl_seq_SET(keys, i / 4, expression);
 
-           expression = ast_for_expr(c, CHILD(ch, i + 2));
-           if (!expression)
-               return NULL;
+                expression = ast_for_expr(c, CHILD(ch, i + 2));
+                if (!expression)
+                    return NULL;
 
-           asdl_seq_SET(values, i / 4, expression);
-       }
-       return Dict(keys, values, LINENO(n), n->n_col_offset, c->c_arena);
+                asdl_seq_SET(values, i / 4, expression);
+            }
+            return Dict(keys, values, LINENO(n), n->n_col_offset, c->c_arena);
+        }
     }
     default:
        PyErr_Format(PyExc_SystemError, "unhandled atom %d", TYPE(ch));
index 95def9a95439f19ecffe0c0d0c886ebc7a2599c7..25e6a0b4cff1b65258604c960adb369f99bf6462 100644 (file)
@@ -1945,6 +1945,24 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
                        }
                        break;
 
+               case BUILD_SET:
+                       x = PySet_New(NULL);
+                       if (x != NULL) {
+                               for (; --oparg >= 0;) {
+                                       w = POP();
+                                       if (err == 0)
+                                               err = PySet_Add(x, w);
+                                       Py_DECREF(w);
+                               }
+                               if (err != 0) {
+                                       Py_DECREF(x);
+                                       break;
+                               }
+                               PUSH(x);
+                               continue;
+                       }
+                       break;
+
                case BUILD_MAP:
                        x = PyDict_New();
                        PUSH(x);
index 4601f2ca7ede51d458ab91e4ac64057b2ae6a014..945a281235869b9d41129402de85d5e764c03b21 100644 (file)
@@ -851,6 +851,7 @@ opcode_stack_effect(int opcode, int oparg)
                        return 1;
                case BUILD_TUPLE:
                case BUILD_LIST:
+               case BUILD_SET:
                        return 1-oparg;
                case BUILD_MAP:
                        return 1;
@@ -2955,6 +2956,11 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
                        ADDOP(c, STORE_SUBSCR);
                }
                break;
+       case Set_kind:
+               n = asdl_seq_LEN(e->v.Set.elts);
+               VISIT_SEQ(c, expr, e->v.Set.elts);
+               ADDOP_I(c, BUILD_SET, n);
+               break;
        case ListComp_kind:
                return compiler_listcomp(c, e);
        case GeneratorExp_kind:
index cfbd7a424ff41df3c919753139da764541455c76..aeaa429236bf2079a3a1d47e2ca9e165c59e2ad0 100644 (file)
@@ -1500,26 +1500,42 @@ static state states_70[3] = {
 static arc arcs_71_0[1] = {
        {26, 1},
 };
-static arc arcs_71_1[1] = {
+static arc arcs_71_1[3] = {
        {21, 2},
+       {27, 3},
+       {0, 1},
 };
 static arc arcs_71_2[1] = {
-       {26, 3},
+       {26, 4},
 };
 static arc arcs_71_3[2] = {
-       {27, 4},
+       {26, 5},
        {0, 3},
 };
 static arc arcs_71_4[2] = {
-       {26, 1},
+       {27, 6},
        {0, 4},
 };
-static state states_71[5] = {
+static arc arcs_71_5[2] = {
+       {27, 3},
+       {0, 5},
+};
+static arc arcs_71_6[2] = {
+       {26, 7},
+       {0, 6},
+};
+static arc arcs_71_7[1] = {
+       {21, 2},
+};
+static state states_71[8] = {
        {1, arcs_71_0},
-       {1, arcs_71_1},
+       {3, arcs_71_1},
        {1, arcs_71_2},
        {2, arcs_71_3},
        {2, arcs_71_4},
+       {2, arcs_71_5},
+       {2, arcs_71_6},
+       {1, arcs_71_7},
 };
 static arc arcs_72_0[1] = {
        {157, 1},
@@ -1911,7 +1927,7 @@ static dfa dfas[84] = {
         "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\140\010\311\000\000"},
        {326, "testlist", 0, 3, states_70,
         "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"},
-       {327, "dictmaker", 0, 5, states_71,
+       {327, "dictsetmaker", 0, 8, states_71,
         "\000\040\010\000\000\000\000\000\000\000\000\000\000\020\004\000\140\010\311\000\000"},
        {328, "classdef", 0, 8, states_72,
         "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\040\000"},
index d80611effb9e366c67b190d1967c692105092d16..49e844a9f841775fd00f5303de49731d5b88efb7 100644 (file)
@@ -66,9 +66,10 @@ extern time_t PyOS_GetLastModificationTime(char *, FILE *);
                                    storing constants that should have been removed)
        Python 3000:   3000
                              3010 (removed UNARY_CONVERT)
+                     3020 (added BUILD_SET)
 .
 */
-#define MAGIC (3010 | ((long)'\r'<<16) | ((long)'\n'<<24))
+#define MAGIC (3020 | ((long)'\r'<<16) | ((long)'\n'<<24))
 
 /* Magic word as global; note that _PyImport_Init() can change the
    value of this global to accommodate for alterations of how the
index 7968a52228cba437ec033a454dfa1805ecd0fc28..0db14d7f1e6295cd768a5101e1803a41ece39792 100644 (file)
@@ -50,11 +50,11 @@ GenExprFor: assign, iter, ifs!
 GenExprIf: test
 List: nodes!
 Dict: items!
+Set: items!
 Not: expr
 Compare: expr, ops!
 Name: name*
 Global: names*
-Backquote: expr
 Getattr: expr, attrname*
 CallFunc: node, args!, star_args& = None, dstar_args& = None
 Keyword: name*, expr
@@ -97,7 +97,7 @@ init(Lambda):
         self.kwargs = 1
 
 init(GenExpr):
-    self.argnames = ['[outmost-iterable]']
+    self.argnames = ['.0']
     self.varargs = self.kwargs = None
 
 init(GenExprFor):
index 59b98f2b0a186f562fbe729ea9b35d19dc3ac6d4..26a185be79a20ea3b9dc2df008eddfe88efb1838 100644 (file)
@@ -235,7 +235,7 @@ if __name__ == "__main__":
 
 This file is automatically generated by Tools/compiler/astgen.py
 """
-from consts import CO_VARARGS, CO_VARKEYWORDS
+from compiler.consts import CO_VARARGS, CO_VARKEYWORDS
 
 def flatten(seq):
     l = []