[Python-checkins] python/dist/src/Python Python-ast.c, 1.1.2.14, 1.1.2.15 ast.c, 1.1.2.69, 1.1.2.70 symtable.c, 2.10.8.38, 2.10.8.39 newcompile.c, 1.1.2.121, 1.1.2.122

jhylton@users.sourceforge.net jhylton at users.sourceforge.net
Sun Oct 16 07:19:48 CEST 2005


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27139/Python

Modified Files:
      Tag: ast-branch
	Python-ast.c ast.c symtable.c newcompile.c 
Log Message:
Track chance of yield from stmt to expr.

Somehwat crude integration of various (yield_expr|testlist) choices in
ast.  Perhaps add a helper function to hide the test for testlist.
The grammar is sure a mess.



Index: Python-ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/Python-ast.c,v
retrieving revision 1.1.2.14
retrieving revision 1.1.2.15
diff -u -d -r1.1.2.14 -r1.1.2.15
--- Python-ast.c	15 Oct 2005 19:19:21 -0000	1.1.2.14
+++ Python-ast.c	16 Oct 2005 05:19:44 -0000	1.1.2.15
@@ -1,4 +1,4 @@
-/* File automatically generated by ./Parser/asdl_c.py */
+/* File automatically generated by ../Parser/asdl_c.py */
 
 #include "Python.h"
 #include "Python-ast.h"
@@ -131,26 +131,6 @@
 }
 
 stmt_ty
-Yield(expr_ty value, int lineno)
-{
-        stmt_ty p;
-        if (!value) {
-                PyErr_SetString(PyExc_ValueError,
-                                "field value is required for Yield");
-                return NULL;
-        }
-        p = (stmt_ty)malloc(sizeof(*p));
-        if (!p) {
-                PyErr_SetString(PyExc_MemoryError, "no memory");
-                return NULL;
-        }
-        p->kind = Yield_kind;
-        p->v.Yield.value = value;
-        p->lineno = lineno;
-        return p;
-}
-
-stmt_ty
 Delete(asdl_seq * targets, int lineno)
 {
         stmt_ty p;
@@ -678,6 +658,21 @@
 }
 
 expr_ty
+Yield(expr_ty value, int lineno)
+{
+        expr_ty p;
+        p = (expr_ty)malloc(sizeof(*p));
+        if (!p) {
+                PyErr_SetString(PyExc_MemoryError, "no memory");
+                return NULL;
+        }
+        p->kind = Yield_kind;
+        p->v.Yield.value = value;
+        p->lineno = lineno;
+        return p;
+}
+
+expr_ty
 Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators, int lineno)
 {
         expr_ty p;
@@ -1148,9 +1143,6 @@
                         free_expr((expr_ty)o->v.Return.value);
                 }
                 break;
-        case Yield_kind:
-                free_expr((expr_ty)o->v.Yield.value);
-                break;
         case Delete_kind:
                 free_seq_exprs(o->v.Delete.targets);
                 break;
@@ -1310,6 +1302,11 @@
                                            i));
                 asdl_seq_free(seq);
                 break;
+        case Yield_kind:
+                if (o->v.Yield.value) {
+                        free_expr((expr_ty)o->v.Yield.value);
+                }
+                break;
         case Compare_kind:
                 free_expr((expr_ty)o->v.Compare.left);
                 seq = o->v.Compare.ops;
@@ -1608,12 +1605,8 @@
                         marshal_write_int(buf, off, 0);
                 }
                 break;
-        case Yield_kind:
-                marshal_write_int(buf, off, 4);
-                marshal_write_expr(buf, off, o->v.Yield.value);
-                break;
         case Delete_kind:
-                marshal_write_int(buf, off, 5);
+                marshal_write_int(buf, off, 4);
                 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Delete.targets));
                 for (i = 0; i < asdl_seq_LEN(o->v.Delete.targets); i++) {
                         void *elt = asdl_seq_GET(o->v.Delete.targets, i);
@@ -1621,7 +1614,7 @@
                 }
                 break;
         case Assign_kind:
-                marshal_write_int(buf, off, 6);
+                marshal_write_int(buf, off, 5);
                 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Assign.targets));
                 for (i = 0; i < asdl_seq_LEN(o->v.Assign.targets); i++) {
                         void *elt = asdl_seq_GET(o->v.Assign.targets, i);
@@ -1630,13 +1623,13 @@
                 marshal_write_expr(buf, off, o->v.Assign.value);
                 break;
         case AugAssign_kind:
-                marshal_write_int(buf, off, 7);
+                marshal_write_int(buf, off, 6);
                 marshal_write_expr(buf, off, o->v.AugAssign.target);
                 marshal_write_operator(buf, off, o->v.AugAssign.op);
                 marshal_write_expr(buf, off, o->v.AugAssign.value);
                 break;
         case Print_kind:
-                marshal_write_int(buf, off, 8);
+                marshal_write_int(buf, off, 7);
                 if (o->v.Print.dest) {
                         marshal_write_int(buf, off, 1);
                         marshal_write_expr(buf, off, o->v.Print.dest);
@@ -1652,7 +1645,7 @@
                 marshal_write_bool(buf, off, o->v.Print.nl);
                 break;
         case For_kind:
-                marshal_write_int(buf, off, 9);
+                marshal_write_int(buf, off, 8);
                 marshal_write_expr(buf, off, o->v.For.target);
                 marshal_write_expr(buf, off, o->v.For.iter);
                 marshal_write_int(buf, off, asdl_seq_LEN(o->v.For.body));
@@ -1667,7 +1660,7 @@
                 }
                 break;
         case While_kind:
-                marshal_write_int(buf, off, 10);
+                marshal_write_int(buf, off, 9);
                 marshal_write_expr(buf, off, o->v.While.test);
                 marshal_write_int(buf, off, asdl_seq_LEN(o->v.While.body));
                 for (i = 0; i < asdl_seq_LEN(o->v.While.body); i++) {
@@ -1681,7 +1674,7 @@
                 }
                 break;
         case If_kind:
-                marshal_write_int(buf, off, 11);
+                marshal_write_int(buf, off, 10);
                 marshal_write_expr(buf, off, o->v.If.test);
                 marshal_write_int(buf, off, asdl_seq_LEN(o->v.If.body));
                 for (i = 0; i < asdl_seq_LEN(o->v.If.body); i++) {
@@ -1695,7 +1688,7 @@
                 }
                 break;
         case Raise_kind:
-                marshal_write_int(buf, off, 12);
+                marshal_write_int(buf, off, 11);
                 if (o->v.Raise.type) {
                         marshal_write_int(buf, off, 1);
                         marshal_write_expr(buf, off, o->v.Raise.type);
@@ -1719,7 +1712,7 @@
                 }
                 break;
         case TryExcept_kind:
-                marshal_write_int(buf, off, 13);
+                marshal_write_int(buf, off, 12);
                 marshal_write_int(buf, off, asdl_seq_LEN(o->v.TryExcept.body));
                 for (i = 0; i < asdl_seq_LEN(o->v.TryExcept.body); i++) {
                         void *elt = asdl_seq_GET(o->v.TryExcept.body, i);
@@ -1740,7 +1733,7 @@
                 }
                 break;
         case TryFinally_kind:
-                marshal_write_int(buf, off, 14);
+                marshal_write_int(buf, off, 13);
                 marshal_write_int(buf, off, asdl_seq_LEN(o->v.TryFinally.body));
                 for (i = 0; i < asdl_seq_LEN(o->v.TryFinally.body); i++) {
                         void *elt = asdl_seq_GET(o->v.TryFinally.body, i);
@@ -1754,7 +1747,7 @@
                 }
                 break;
         case Assert_kind:
-                marshal_write_int(buf, off, 15);
+                marshal_write_int(buf, off, 14);
                 marshal_write_expr(buf, off, o->v.Assert.test);
                 if (o->v.Assert.msg) {
                         marshal_write_int(buf, off, 1);
@@ -1765,7 +1758,7 @@
                 }
                 break;
         case Import_kind:
-                marshal_write_int(buf, off, 16);
+                marshal_write_int(buf, off, 15);
                 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Import.names));
                 for (i = 0; i < asdl_seq_LEN(o->v.Import.names); i++) {
                         void *elt = asdl_seq_GET(o->v.Import.names, i);
@@ -1773,7 +1766,7 @@
                 }
                 break;
         case ImportFrom_kind:
-                marshal_write_int(buf, off, 17);
+                marshal_write_int(buf, off, 16);
                 marshal_write_identifier(buf, off, o->v.ImportFrom.module);
                 marshal_write_int(buf, off,
                                   asdl_seq_LEN(o->v.ImportFrom.names));
@@ -1783,7 +1776,7 @@
                 }
                 break;
         case Exec_kind:
-                marshal_write_int(buf, off, 18);
+                marshal_write_int(buf, off, 17);
                 marshal_write_expr(buf, off, o->v.Exec.body);
                 if (o->v.Exec.globals) {
                         marshal_write_int(buf, off, 1);
@@ -1801,7 +1794,7 @@
                 }
                 break;
         case Global_kind:
-                marshal_write_int(buf, off, 19);
+                marshal_write_int(buf, off, 18);
                 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Global.names));
                 for (i = 0; i < asdl_seq_LEN(o->v.Global.names); i++) {
                         void *elt = asdl_seq_GET(o->v.Global.names, i);
@@ -1809,17 +1802,17 @@
                 }
                 break;
         case Expr_kind:
-                marshal_write_int(buf, off, 20);
+                marshal_write_int(buf, off, 19);
                 marshal_write_expr(buf, off, o->v.Expr.value);
                 break;
         case Pass_kind:
-                marshal_write_int(buf, off, 21);
+                marshal_write_int(buf, off, 20);
                 break;
         case Break_kind:
-                marshal_write_int(buf, off, 22);
+                marshal_write_int(buf, off, 21);
                 break;
         case Continue_kind:
-                marshal_write_int(buf, off, 23);
+                marshal_write_int(buf, off, 22);
                 break;
         }
         return 1;
@@ -1892,8 +1885,18 @@
                                                     (comprehension_ty)elt);
                 }
                 break;
-        case Compare_kind:
+        case Yield_kind:
                 marshal_write_int(buf, off, 8);
+                if (o->v.Yield.value) {
+                        marshal_write_int(buf, off, 1);
+                        marshal_write_expr(buf, off, o->v.Yield.value);
+                }
+                else {
+                        marshal_write_int(buf, off, 0);
+                }
+                break;
+        case Compare_kind:
+                marshal_write_int(buf, off, 9);
                 marshal_write_expr(buf, off, o->v.Compare.left);
                 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Compare.ops));
                 for (i = 0; i < asdl_seq_LEN(o->v.Compare.ops); i++) {
@@ -1908,7 +1911,7 @@
                 }
                 break;
         case Call_kind:
-                marshal_write_int(buf, off, 9);
+                marshal_write_int(buf, off, 10);
                 marshal_write_expr(buf, off, o->v.Call.func);
                 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Call.args));
                 for (i = 0; i < asdl_seq_LEN(o->v.Call.args); i++) {
@@ -1936,36 +1939,36 @@
                 }
                 break;
         case Repr_kind:
-                marshal_write_int(buf, off, 10);
+                marshal_write_int(buf, off, 11);
                 marshal_write_expr(buf, off, o->v.Repr.value);
                 break;
         case Num_kind:
-                marshal_write_int(buf, off, 11);
+                marshal_write_int(buf, off, 12);
                 marshal_write_object(buf, off, o->v.Num.n);
                 break;
         case Str_kind:
-                marshal_write_int(buf, off, 12);
+                marshal_write_int(buf, off, 13);
                 marshal_write_string(buf, off, o->v.Str.s);
                 break;
         case Attribute_kind:
-                marshal_write_int(buf, off, 13);
+                marshal_write_int(buf, off, 14);
                 marshal_write_expr(buf, off, o->v.Attribute.value);
                 marshal_write_identifier(buf, off, o->v.Attribute.attr);
                 marshal_write_expr_context(buf, off, o->v.Attribute.ctx);
                 break;
         case Subscript_kind:
-                marshal_write_int(buf, off, 14);
+                marshal_write_int(buf, off, 15);
                 marshal_write_expr(buf, off, o->v.Subscript.value);
                 marshal_write_slice(buf, off, o->v.Subscript.slice);
                 marshal_write_expr_context(buf, off, o->v.Subscript.ctx);
                 break;
         case Name_kind:
-                marshal_write_int(buf, off, 15);
+                marshal_write_int(buf, off, 16);
                 marshal_write_identifier(buf, off, o->v.Name.id);
                 marshal_write_expr_context(buf, off, o->v.Name.ctx);
                 break;
         case List_kind:
-                marshal_write_int(buf, off, 16);
+                marshal_write_int(buf, off, 17);
                 marshal_write_int(buf, off, asdl_seq_LEN(o->v.List.elts));
                 for (i = 0; i < asdl_seq_LEN(o->v.List.elts); i++) {
                         void *elt = asdl_seq_GET(o->v.List.elts, i);
@@ -1974,7 +1977,7 @@
                 marshal_write_expr_context(buf, off, o->v.List.ctx);
                 break;
         case Tuple_kind:
-                marshal_write_int(buf, off, 17);
+                marshal_write_int(buf, off, 18);
                 marshal_write_int(buf, off, asdl_seq_LEN(o->v.Tuple.elts));
                 for (i = 0; i < asdl_seq_LEN(o->v.Tuple.elts); i++) {
                         void *elt = asdl_seq_GET(o->v.Tuple.elts, i);

Index: ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v
retrieving revision 1.1.2.69
retrieving revision 1.1.2.70
diff -u -d -r1.1.2.69 -r1.1.2.70
--- ast.c	15 Oct 2005 19:01:36 -0000	1.1.2.69
+++ ast.c	16 Oct 2005 05:19:44 -0000	1.1.2.70
@@ -512,6 +512,7 @@
 seq_for_testlist(struct compiling *c, const node *n)
 {
     /* testlist: test (',' test)* [','] */
+    REQ(n, testlist);
     asdl_seq *seq;
     expr_ty expression;
     int i;
@@ -521,12 +522,15 @@
         return NULL;
 
     for (i = 0; i < NCH(n); i += 2) {
+        REQ(CHILD(n, i), test);
+
         expression = ast_for_expr(c, CHILD(n, i));
         if (!expression) {
             asdl_seq_free(seq);
             return NULL;
         }
-        
+
+        assert(i / 2 < seq->size);
         asdl_seq_SET(seq, i / 2, expression);
     }
     return seq;
@@ -1193,7 +1197,8 @@
 static expr_ty
 ast_for_atom(struct compiling *c, const node *n)
 {
-	/* atom: '(' [testlist_gexp] ')' | '[' [listmaker] ']'
+    /* XXX yield_expr */
+	/* atom: '(' [yield_expr|testlist_gexp] ')' | '[' [listmaker] ']'
 	   | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING+
 	*/
 	node *ch = CHILD(n, 0);
@@ -1225,6 +1230,9 @@
 			if (TYPE(ch) == RPAR)
 				return Tuple(NULL, Load, LINENO(n));
 
+			if (TYPE(ch) == yield_expr)
+				return ast_for_expr(c, ch);
+
 			if ((NCH(ch) > 1) && (TYPE(CHILD(ch, 1)) == gen_for))
 				return ast_for_genexp(c, ch);
 
@@ -1533,6 +1541,15 @@
                 goto loop;
             }
             return ast_for_binop(c, n);
+        case yield_expr: {
+	    expr_ty exp = NULL;
+	    if (NCH(n) == 2) {
+		exp = ast_for_testlist(c, CHILD(n, 1));
+		if (!exp)
+		    return NULL;
+	    }
+	    return Yield(exp, LINENO(n));
+	}
         case factor: {
             expr_ty expression;
             
@@ -1647,6 +1664,7 @@
             return e;
         }
         default:
+	    abort();
             PyErr_Format(PyExc_Exception, "unhandled expr: %d", TYPE(n));
             return NULL;
     }
@@ -1791,6 +1809,7 @@
 ast_for_expr_stmt(struct compiling *c, const node *n)
 {
     REQ(n, expr_stmt);
+    /* XXX yield_expr */
     /* expr_stmt: testlist (augassign testlist | ('=' testlist)*)
        testlist: test (',' test)* [',']
        augassign: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^='
@@ -1808,24 +1827,33 @@
     else if (TYPE(CHILD(n, 1)) == augassign) {
         expr_ty expr1, expr2;
         operator_ty operator;
+	node *ch = CHILD(n, 0);
+
+	if (TYPE(ch) == testlist)
+	    expr1 = ast_for_testlist(c, ch);
+	else
+	    expr1 = Yield(ast_for_expr(c, CHILD(ch, 0)), LINENO(ch));
 
-        expr1 = ast_for_testlist(c, CHILD(n, 0));
         if (!expr1)
             return NULL;
         if (expr1->kind == GeneratorExp_kind) {
-          ast_error(CHILD(n, 0), "augmented assignment to generator "
-                                 "expression not possible");
-          return NULL;
+	    ast_error(ch, "augmented assignment to generator "
+		      "expression not possible");
+	    return NULL;
         }
 	if (expr1->kind == Name_kind) {
 		char *var_name = PyString_AS_STRING(expr1->v.Name.id);
 		if (var_name[0] == 'N' && !strcmp(var_name, "None")) {
-			ast_error(CHILD(n, 0), "assignment to None");
+			ast_error(ch, "assignment to None");
 			return NULL;
 		}
 	}
 
-        expr2 = ast_for_testlist(c, CHILD(n, 2));
+	ch = CHILD(n, 2);
+	if (TYPE(ch) == testlist)
+	    expr2 = ast_for_testlist(c, ch);
+	else
+	    expr2 = Yield(ast_for_expr(c, ch), LINENO(ch));
         if (!expr2)
             return NULL;
 
@@ -1838,6 +1866,7 @@
     else {
 	int i;
 	asdl_seq *targets;
+	node *value;
         expr_ty expression;
 
 	/* a normal assignment */
@@ -1846,7 +1875,12 @@
 	if (!targets)
 	    return NULL;
 	for (i = 0; i < NCH(n) - 2; i += 2) {
-	    expr_ty e = ast_for_testlist(c, CHILD(n, i));
+	    node *ch = CHILD(n, i);
+	    if (TYPE(ch) == yield_expr) {
+		ast_error(ch, "assignment to yield expression not possible");
+		goto error;
+	    }
+	    expr_ty e = ast_for_testlist(c, ch);
 
 	    /* set context to assign */
 	    if (!e) 
@@ -1859,7 +1893,13 @@
 
 	    asdl_seq_SET(targets, i / 2, e);
 	}
-        expression = ast_for_testlist(c, CHILD(n, NCH(n) - 1));
+	value = CHILD(n, NCH(n) - 1);
+	if (TYPE(value) == testlist)
+	    expression = ast_for_testlist(c, value);
+	else
+	    expression = ast_for_expr(c, value);
+	if (!expression)
+	    return NULL;
 	return Assign(targets, expression, LINENO(n));
     error:
         for (i = i / 2; i >= 0; i--)
@@ -1954,7 +1994,8 @@
       break_stmt: 'break'
       continue_stmt: 'continue'
       return_stmt: 'return' [testlist]
-      yield_stmt: 'yield' testlist
+      yield_stmt: yield_expr
+      yield_expr: 'yield' testlist
       raise_stmt: 'raise' [test [',' test [',' test]]]
     */
     node *ch;
@@ -1966,11 +2007,11 @@
             return Break(LINENO(n));
         case continue_stmt:
             return Continue(LINENO(n));
-        case yield_stmt: {
-            expr_ty expression = ast_for_testlist(c, CHILD(ch, 1));
-            if (!expression)
-                return NULL;
-            return Yield(expression, LINENO(n));
+        case yield_stmt: { /* will reduce to yield_expr */
+	    expr_ty exp = ast_for_expr(c, CHILD(ch, 0));
+	    if (!exp)
+		return NULL;
+            return Expr(exp, LINENO(n));
         }
         case return_stmt:
             if (NCH(ch) == 1)
@@ -2679,7 +2720,7 @@
 	s = ast_for_suite(c, CHILD(n,5));
 	if (!s)
 		return NULL;
-	return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)),NULL,s,LINENO(n));
+	return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, LINENO(n));
     }
 
     /* else handle the base class list */

Index: symtable.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/symtable.c,v
retrieving revision 2.10.8.38
retrieving revision 2.10.8.39
diff -u -d -r2.10.8.38 -r2.10.8.39
--- symtable.c	14 Oct 2005 20:06:13 -0000	2.10.8.38
+++ symtable.c	16 Oct 2005 05:19:44 -0000	2.10.8.39
@@ -863,10 +863,6 @@
 		if (s->v.Return.value)
 			VISIT(st, expr, s->v.Return.value);
 		break;
-        case Yield_kind:
-		VISIT(st, expr, s->v.Yield.value);
-                st->st_cur->ste_generator = 1;
-		break;
         case Delete_kind:
 		VISIT_SEQ(st, expr, s->v.Delete.targets);
 		break;
@@ -1047,6 +1043,11 @@
 		}
 		break;
 	}
+        case Yield_kind:
+		if (e->v.Yield.value)
+			VISIT(st, expr, e->v.Yield.value);
+                st->st_cur->ste_generator = 1;
+		break;
         case Compare_kind:
 		VISIT(st, expr, e->v.Compare.left);
 		VISIT_SEQ(st, expr, e->v.Compare.comparators);

Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.121
retrieving revision 1.1.2.122
diff -u -d -r1.1.2.121 -r1.1.2.122
--- newcompile.c	14 Oct 2005 20:06:13 -0000	1.1.2.121
+++ newcompile.c	16 Oct 2005 05:19:44 -0000	1.1.2.122
@@ -2270,7 +2270,7 @@
 static int
 compiler_while(struct compiler *c, stmt_ty s)
 {
-	basicblock *loop, *orelse, *end, *anchor;
+	basicblock *loop, *orelse, *end, *anchor = NULL;
 	int constant = expr_constant(s->v.While.test);
 
 	if (constant == 0)
@@ -2685,18 +2685,6 @@
 			ADDOP_O(c, LOAD_CONST, Py_None, consts);
 		ADDOP(c, RETURN_VALUE);
 		break;
-        case Yield_kind:
-		if (c->u->u_ste->ste_type != FunctionBlock)
-                        return compiler_error(c, "'yield' outside function");
-		for (i = 0; i < c->u->u_nfblocks; i++) {
-			if (c->u->u_fblock[i].fb_type == FINALLY_TRY)
-				return compiler_error(
-					c, "'yield' not allowed in a 'try' "
-					"block with a 'finally' clause");
-		}
-		VISIT(c, expr, s->v.Yield.value);
-		ADDOP(c, YIELD_VALUE);
-		break;
         case Delete_kind:
 		VISIT_SEQ(c, expr, s->v.Delete.targets)
 		break;
@@ -3306,6 +3294,7 @@
         if (gen_index >= asdl_seq_LEN(generators)) {
 		VISIT(c, expr, elt);
 		ADDOP(c, YIELD_VALUE);
+		ADDOP(c, POP_TOP);
 
 		compiler_use_next_block(c, skip);
         }
@@ -3336,12 +3325,12 @@
 
 	name = PyString_FromString("<generator expression>");
 	if (!name)
-	  return 0;
+		return 0;
 
 	if (!compiler_enter_scope(c, name, (void *)e, e->lineno))
 		return 0;
 	compiler_genexp_generator(c, e->v.GeneratorExp.generators, 0,
-					e->v.GeneratorExp.elt);
+				  e->v.GeneratorExp.elt);
 	co = assemble(c, 1);
 	if (co == NULL)
 		return 0;
@@ -3426,6 +3415,25 @@
 		return compiler_listcomp(c, e);
         case GeneratorExp_kind:
 		return compiler_genexp(c, e);
+	case Yield_kind:
+		if (c->u->u_ste->ste_type != FunctionBlock)
+                        return compiler_error(c, "'yield' outside function");
+		/*
+		for (i = 0; i < c->u->u_nfblocks; i++) {
+			if (c->u->u_fblock[i].fb_type == FINALLY_TRY)
+				return compiler_error(
+					c, "'yield' not allowed in a 'try' "
+					"block with a 'finally' clause");
+		}
+		*/
+		if (e->v.Yield.value) {
+			VISIT(c, expr, e->v.Yield.value);
+		}
+		else {
+			ADDOP_O(c, LOAD_CONST, Py_None, consts);
+		}
+		ADDOP(c, YIELD_VALUE);
+		break;
         case Compare_kind:
 		return compiler_compare(c, e);
         case Call_kind:
@@ -3602,7 +3610,7 @@
 static int
 compiler_handle_subscr(struct compiler *c, const char *kind, 
                        expr_context_ty ctx) {
-    int op;
+    int op = 0;
 
     /* XXX this code is duplicated */
     switch (ctx) {
@@ -3658,7 +3666,7 @@
 static int
 compiler_simple_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
 {
-	int op, slice_offset = 0, stack_count = 0;
+	int op = 0, slice_offset = 0, stack_count = 0;
 
 	assert(s->v.Slice.step == NULL);
 	if (s->v.Slice.lower) {



More information about the Python-checkins mailing list