[Python-checkins] python/dist/src/Python newcompile.c,1.1.2.13,1.1.2.14

jhylton@users.sourceforge.net jhylton@users.sourceforge.net
Mon, 21 Oct 2002 14:33:34 -0700


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

Modified Files:
      Tag: ast-branch
	newcompile.c 
Log Message:
Several small fixes that get simple function definitions working.

Determine the number of locals from the symtable and pass it to
PyCode_New().

Add missing breaks in compiler_nameop().

Determine the number of function arguments directly from the AST.

Make basic blocks that have a return statement.  The flow graph should
stop right there.  XXX Nothing uses that information yet.



Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.13
retrieving revision 1.1.2.14
diff -C2 -d -r1.1.2.13 -r1.1.2.14
*** newcompile.c	2 Oct 2002 11:58:53 -0000	1.1.2.13
--- newcompile.c	21 Oct 2002 21:33:31 -0000	1.1.2.14
***************
*** 376,379 ****
--- 376,380 ----
  compiler_addop(struct compiler *c, int opcode)
  {
+ 	struct basicblock *b;
  	struct instr *i;
  	int off;
***************
*** 381,387 ****
  	if (off < 0)
  		return 0;
! 	i = &c->u->u_blocks[c->u->u_curblock]->b_instr[off];
  	i->i_opcode = opcode;
  	i->i_hasarg = 0;
  	return 1;
  }
--- 382,391 ----
  	if (off < 0)
  		return 0;
! 	b = c->u->u_blocks[c->u->u_curblock];
! 	i = &b->b_instr[off];
  	i->i_opcode = opcode;
  	i->i_hasarg = 0;
+ 	if (opcode == RETURN_VALUE)
+ 		b->b_return = 1;
  	return 1;
  }
***************
*** 547,551 ****
  {
  	PyCodeObject *co;
- 	int ndefs = 0;
  	arguments_ty args = s->v.FunctionDef.args;
  	assert(s->kind == FunctionDef_kind);
--- 551,554 ----
***************
*** 558,562 ****
  	if (!compiler_enter_scope(c, s->v.FunctionDef.name, (void *)s))
  		return 0;
! 	c->u->u_argcount = ndefs;
  	VISIT_SEQ(c, stmt, s->v.FunctionDef.body);
  	co = assemble(c);
--- 561,565 ----
  	if (!compiler_enter_scope(c, s->v.FunctionDef.name, (void *)s))
  		return 0;
! 	c->u->u_argcount = asdl_seq_LEN(s->v.FunctionDef.args->args);
  	VISIT_SEQ(c, stmt, s->v.FunctionDef.body);
  	co = assemble(c);
***************
*** 567,571 ****
  	/* XXX closure */
  	ADDOP_O(c, LOAD_CONST, (PyObject *)co, consts);
! 	ADDOP_I(c, MAKE_FUNCTION, ndefs);
  	if (!compiler_nameop(c, s->v.FunctionDef.name, Store))
  		return 0;
--- 570,574 ----
  	/* XXX closure */
  	ADDOP_O(c, LOAD_CONST, (PyObject *)co, consts);
! 	ADDOP_I(c, MAKE_FUNCTION, c->u->u_argcount);
  	if (!compiler_nameop(c, s->v.FunctionDef.name, Store))
  		return 0;
***************
*** 945,948 ****
--- 948,953 ----
  		optype = OP_GLOBAL;
  		break;
+ 	default:
+ 		assert(0);
  	}
  
***************
*** 958,961 ****
--- 963,967 ----
  			assert(0); /* impossible */
  		}
+ 		break;
  	case OP_FAST:
  		switch (ctx) {
***************
*** 968,971 ****
--- 974,978 ----
  			assert(0); /* impossible */
  		}
+ 		break;
  	case OP_GLOBAL:
  		switch (ctx) {
***************
*** 978,981 ****
--- 985,989 ----
  			assert(0); /* impossible */
  		}
+ 		break;
  	case OP_NAME:
  		switch (ctx) {
***************
*** 988,991 ****
--- 996,1000 ----
  			assert(0); /* impossible */
  		}
+ 		break;
  	}
  	
***************
*** 1371,1374 ****
--- 1380,1384 ----
  	PyObject *name = NULL;
  	PyObject *nil = PyTuple_New(0);
+ 	int nlocals;
  
  	consts = dict_keys_inorder(c->u->u_consts, 0);
***************
*** 1385,1389 ****
  		goto error;
  	
! 	co = PyCode_New(c->u->u_argcount, 0, stackdepth(c), 0,
  			a->a_bytecode, consts, names, varnames,
  			nil, nil,
--- 1395,1400 ----
  		goto error;
  	
! 	nlocals = PyList_GET_SIZE(c->u->u_ste->ste_varnames);
! 	co = PyCode_New(c->u->u_argcount, nlocals, stackdepth(c), 0,
  			a->a_bytecode, consts, names, varnames,
  			nil, nil,