[Python-checkins] CVS: python/dist/src/Python ceval.c,2.264,2.265 compile.c,2.212,2.213 future.c,2.9,2.10 pythonrun.c,2.142,2.143

Jeremy Hylton jhylton@users.sourceforge.net
Fri, 10 Aug 2001 14:41:35 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv16520

Modified Files:
	ceval.c compile.c future.c pythonrun.c 
Log Message:
Refactor future feature handling

Replace uses of PyCF_xxx with CO_xxx.

Replace individual feature slots in PyFutureFeatures with single
bitmask ff_features.

When flags must be transfered among the three parts of the interpreter
that care about them -- the pythonrun layer, the compiler, and the
future feature parser -- can simply or (|) the definitions.



Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.264
retrieving revision 2.265
diff -C2 -d -r2.264 -r2.265
*** ceval.c	2001/08/08 05:00:18	2.264
--- ceval.c	2001/08/10 21:41:33	2.265
***************
*** 2938,2946 ****
  		if (codeflags & CO_NESTED) {
  			result = 1;
! 			cf->cf_flags |= PyCF_NESTED_SCOPES;
  		}
  		if (codeflags & CO_GENERATOR_ALLOWED) {
  			result = 1;
! 			cf->cf_flags |= PyCF_GENERATORS;
  		}
  	}
--- 2938,2946 ----
  		if (codeflags & CO_NESTED) {
  			result = 1;
! 			cf->cf_flags |= CO_NESTED;
  		}
  		if (codeflags & CO_GENERATOR_ALLOWED) {
  			result = 1;
! 			cf->cf_flags |= CO_GENERATOR_ALLOWED;
  		}
  	}

Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.212
retrieving revision 2.213
diff -C2 -d -r2.212 -r2.213
*** compile.c	2001/08/08 05:00:18	2.212
--- compile.c	2001/08/10 21:41:33	2.213
***************
*** 3968,3987 ****
  			return NULL;
  		}
! 		if (flags) {
! 			if (flags->cf_flags & PyCF_NESTED_SCOPES)
! 				sc.c_future->ff_nested_scopes = 1;
! 			else if (sc.c_future->ff_nested_scopes)
! 				flags->cf_flags |= PyCF_NESTED_SCOPES;
! 
! 			if (flags->cf_flags & PyCF_GENERATORS)
! 				sc.c_future->ff_generators = 1;
! 			else if (sc.c_future->ff_generators)
! 				flags->cf_flags |= PyCF_GENERATORS;
! 
! 			if (flags->cf_flags & PyCF_DIVISION)
! 				sc.c_future->ff_division = 1;
! 			else if (sc.c_future->ff_division)
! 				flags->cf_flags |= PyCF_DIVISION;
! 		}
  		if (symtable_build(&sc, n) < 0) {
  			com_free(&sc);
--- 3968,3973 ----
  			return NULL;
  		}
! 		if (flags)
! 			sc.c_future->ff_features |= flags->cf_flags;
  		if (symtable_build(&sc, n) < 0) {
  			com_free(&sc);
***************
*** 4151,4156 ****
  		return -1;
  	c->c_symtable->st_future = c->c_future;
- 	if (c->c_future->ff_nested_scopes)
- 		c->c_symtable->st_nested_scopes = 1;
  	c->c_symtable->st_filename = c->c_filename;
  	symtable_enter_scope(c->c_symtable, TOP, TYPE(n), n->n_lineno);
--- 4137,4140 ----
***************
*** 4452,4463 ****
  		      struct symbol_info *si)
  {
! 	if (c->c_future) {
! 		if (c->c_future->ff_nested_scopes)
! 			c->c_flags |= CO_NESTED;
! 		if (c->c_future->ff_generators)
! 			c->c_flags |= CO_GENERATOR_ALLOWED;
! 		if (c->c_future->ff_division)
! 			c->c_flags |= CO_FUTURE_DIVISION;
! 	}
  	if (ste->ste_generator)
  		c->c_flags |= CO_GENERATOR;
--- 4436,4441 ----
  		      struct symbol_info *si)
  {
! 	if (c->c_future)
! 		c->c_flags |= c->c_future->ff_features;
  	if (ste->ste_generator)
  		c->c_flags |= CO_GENERATOR;
***************
*** 4618,4622 ****
  		return NULL;
  	st->st_pass = 1;
- 	st->st_nested_scopes = NESTED_SCOPES_DEFAULT;
  	st->st_filename = NULL;
  	if ((st->st_stack = PyList_New(0)) == NULL)
--- 4596,4599 ----

Index: future.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/future.c,v
retrieving revision 2.9
retrieving revision 2.10
diff -C2 -d -r2.9 -r2.10
*** future.c	2001/08/08 05:00:18	2.9
--- future.c	2001/08/10 21:41:33	2.10
***************
*** 31,39 ****
  		feature = STR(CHILD(ch, 0));
  		if (strcmp(feature, FUTURE_NESTED_SCOPES) == 0) {
! 			ff->ff_nested_scopes = 1;
  		} else if (strcmp(feature, FUTURE_GENERATORS) == 0) {
! 			ff->ff_generators = 1;
  		} else if (strcmp(feature, FUTURE_DIVISION) == 0) {
! 			ff->ff_division = 1;
  		} else if (strcmp(feature, "braces") == 0) {
  			PyErr_SetString(PyExc_SyntaxError,
--- 31,39 ----
  		feature = STR(CHILD(ch, 0));
  		if (strcmp(feature, FUTURE_NESTED_SCOPES) == 0) {
! 			continue;
  		} else if (strcmp(feature, FUTURE_GENERATORS) == 0) {
! 			ff->ff_features |= CO_GENERATOR_ALLOWED;
  		} else if (strcmp(feature, FUTURE_DIVISION) == 0) {
! 			ff->ff_features |= CO_FUTURE_DIVISION;
  		} else if (strcmp(feature, "braces") == 0) {
  			PyErr_SetString(PyExc_SyntaxError,
***************
*** 235,241 ****
  	ff->ff_found_docstring = 0;
  	ff->ff_last_lineno = -1;
! 	ff->ff_nested_scopes = 0;
! 	ff->ff_generators = 0;
! 	ff->ff_division = 0;
  
  	if (future_parse(ff, n, filename) < 0) {
--- 235,239 ----
  	ff->ff_found_docstring = 0;
  	ff->ff_last_lineno = -1;
! 	ff->ff_features = 0;
  
  	if (future_parse(ff, n, filename) < 0) {

Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.142
retrieving revision 2.143
diff -C2 -d -r2.142 -r2.143
*** pythonrun.c	2001/08/09 16:37:16	2.142
--- pythonrun.c	2001/08/10 21:41:33	2.143
***************
*** 557,561 ****
  			    	    Py_single_input, ps1, ps2, &err,
  			    	    (flags &&
! 			    	     flags->cf_flags & PyCF_GENERATORS) ?
  			    	    	PyPARSE_YIELD_IS_KEYWORD : 0);
  	Py_XDECREF(v);
--- 557,561 ----
  			    	    Py_single_input, ps1, ps2, &err,
  			    	    (flags &&
! 			    	     flags->cf_flags & CO_GENERATOR_ALLOWED) ?
  			    	    	PyPARSE_YIELD_IS_KEYWORD : 0);
  	Py_XDECREF(v);
***************
*** 1010,1015 ****
  {
  	return run_err_node(PyParser_SimpleParseStringFlags(
! 				str, start,
! 				(flags && flags->cf_flags & PyCF_GENERATORS) ?
  				PyPARSE_YIELD_IS_KEYWORD : 0),
  			    "<string>", globals, locals, flags);
--- 1010,1015 ----
  {
  	return run_err_node(PyParser_SimpleParseStringFlags(
! 			str, start,
! 			(flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ?
  				PyPARSE_YIELD_IS_KEYWORD : 0),
  			    "<string>", globals, locals, flags);
***************
*** 1029,1033 ****
  {
  	node *n = PyParser_SimpleParseFileFlags(fp, filename, start,
! 			(flags && flags->cf_flags & PyCF_GENERATORS) ?
  				PyPARSE_YIELD_IS_KEYWORD : 0);
  	if (closeit)
--- 1029,1033 ----
  {
  	node *n = PyParser_SimpleParseFileFlags(fp, filename, start,
! 			(flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ?
  				PyPARSE_YIELD_IS_KEYWORD : 0);
  	if (closeit)
***************
*** 1086,1101 ****
  	co = (PyCodeObject *)v;
  	v = PyEval_EvalCode(co, globals, locals);
! 	if (v && flags) {
! 		if (co->co_flags & CO_NESTED)
! 			flags->cf_flags |= PyCF_NESTED_SCOPES;
! 		if (co->co_flags & CO_GENERATOR_ALLOWED)
! 			flags->cf_flags |= PyCF_GENERATORS;
! #if 0
! 		fprintf(stderr, "run_pyc_file: nested_scopes: %d\n",
! 			flags->cf_flags & PyCF_NESTED_SCOPES);
! 		fprintf(stderr, "run_pyc_file: generators: %d\n",
! 			flags->cf_flags & PyCF_GENERATORS);
! #endif
! 	}
  	Py_DECREF(co);
  	return v;
--- 1086,1091 ----
  	co = (PyCodeObject *)v;
  	v = PyEval_EvalCode(co, globals, locals);
! 	if (v && flags)
! 		flags->cf_flags |= (co->co_flags & PyCF_MASK);
  	Py_DECREF(co);
  	return v;
***************
*** 1115,1119 ****
  	PyCodeObject *co;
  	n = PyParser_SimpleParseStringFlags(str, start,
! 		(flags && flags->cf_flags & PyCF_GENERATORS) ?
  			PyPARSE_YIELD_IS_KEYWORD : 0);
  	if (n == NULL)
--- 1105,1109 ----
  	PyCodeObject *co;
  	n = PyParser_SimpleParseStringFlags(str, start,
! 		(flags && flags->cf_flags & CO_GENERATOR_ALLOWED) ?
  			PyPARSE_YIELD_IS_KEYWORD : 0);
  	if (n == NULL)