[Python-checkins] CVS: python/dist/src/Python compile.c,2.145,2.146

Jeremy Hylton jhylton@users.sourceforge.net
Thu, 18 Jan 2001 19:21:32 -0800


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

Modified Files:
	compile.c 
Log Message:
This patch introduces an extra pass to the compiler that generates a
symbol table for each top-level compilation unit.  The information in
the symbol table allows the elimination of the later optimize() pass;
the bytecode generation emits the correct opcodes.

The current version passes the complete regression test, but may still
contain some bugs.  It's a fairly substantial revision.  The current
code adds an assert() and a test that may lead to a Py_FatalError().
I expect to remove these before 2.1 beta 1.

The symbol table (struct symtable) is described in comments in the
code.

The changes affects the several com_XXX() functions that were used to
emit LOAD_NAME and its ilk.  The primary interface for this bytecode
is now com_addop_varname() which takes a kind and a name, where kind
is one of VAR_LOAD, VAR_STORE, or VAR_DELETE.

There are many other smaller changes:

- The name mangling code is no longer contained in ifdefs.  There are
  two functions that expose the mangling logical: com_mangle() and
  symtable_mangle(). 

- The com_error() function can accept NULL for its first argument;
  this is useful with is_constant_false() is called during symbol
  table generation.

- The loop index names used by list comprehensions have been changed
  from __1__ to [1], so that they can not be accessed by Python code.

- in com_funcdef(), com_argdefs() is now called before the body of the
  function is compiled.  This provides consistency with com_lambdef()
  and symtable_funcdef().

- Helpers do_pad(), dump(), and DUMP() are added to aid in debugging
  the compiler.




Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.145
retrieving revision 2.146
diff -C2 -r2.145 -r2.146
*** compile.c	2001/01/19 00:24:06	2.145
--- compile.c	2001/01/19 03:21:30	2.146
***************
*** 11,18 ****
  */
  
- #ifndef NO_PRIVATE_NAME_MANGLING
- #define PRIVATE_NAME_MANGLING
- #endif
- 
  #include "Python.h"
  
--- 11,14 ----
***************
[...1868 lines suppressed...]
+ 				symtable_add_def(st,
+ 						 STR(CHILD(CHILD(n,
+ 								 0), 0)),
+ 						 DEF_LOCAL);
+ 			return;
+ 		case dotted_name:
+ 			symtable_add_def(st, STR(CHILD(n, 0)), DEF_LOCAL);
+ 			return;
+ 		case NAME:
+ 			symtable_add_def(st, STR(n), DEF_LOCAL);
+ 			return;
+ 		default:
+ 			if (NCH(n) == 0)
+ 				return;
+ 			assert(NCH(n) == 1);
+ 			n = CHILD(n, 0);
+ 			break;
+ 		}
+ 	}
  }