[Python-checkins] python/dist/src/Python newcompile.c, 1.1.2.84, 1.1.2.85

nnorwitz at users.sourceforge.net nnorwitz at users.sourceforge.net
Sun Mar 21 16:19:36 EST 2004


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

Modified Files:
      Tag: ast-branch
	newcompile.c 
Log Message:
fix yield/returns outside of functions

Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.84
retrieving revision 1.1.2.85
diff -C2 -d -r1.1.2.84 -r1.1.2.85
*** newcompile.c	21 Mar 2004 20:48:05 -0000	1.1.2.84
--- newcompile.c	21 Mar 2004 21:19:33 -0000	1.1.2.85
***************
*** 36,40 ****
       #: co_names doesn't contain locals, only globals, co_varnames may work
       #: ref leaks in interpreter when press return on empty line
-      #: yield or return outside a function don't raise a SyntaxError
       #: line numbers are off a bit (may just need to add calls to set lineno)
          In some cases, the line numbers for generated code aren't strictly
--- 36,39 ----
***************
*** 108,111 ****
--- 107,111 ----
  
  	int c_interactive;
+         int c_nestlevel;
  
  	struct compiler_unit *u;
***************
*** 234,237 ****
--- 234,238 ----
          flags->cf_flags = merged;
          c.c_flags = flags;
+         c.c_nestlevel = 0;
  
  	/* Trivial test of marshal code for now. */
***************
*** 427,430 ****
--- 428,432 ----
  	c->u = u;
  
+         c->c_nestlevel++;
  	if (compiler_use_new_block(c) < 0)
  		return 0;
***************
*** 475,478 ****
--- 477,481 ----
  	PyObject *wrapper;
  
+         c->c_nestlevel--;
  	compiler_unit_free(c->u);
  	/* Restore c->u to the parent unit. */
***************
*** 1515,1518 ****
--- 1518,1523 ----
  		return compiler_class(c, s);
          case Return_kind:
+                 if (c->c_nestlevel <= 1)
+                         return compiler_error(c, "'return' outside function");
  		if (s->v.Return.value)
  			VISIT(c, expr, s->v.Return.value)
***************
*** 1522,1525 ****
--- 1527,1532 ----
  		break;
          case Yield_kind:
+                 if (c->c_nestlevel <= 1)
+                         return compiler_error(c, "'yield' outside function");
  		VISIT(c, expr, s->v.Yield.value);
  		ADDOP(c, YIELD_VALUE);




More information about the Python-checkins mailing list