[Python-checkins] python/dist/src/Python newcompile.c, 1.1.2.57, 1.1.2.58

nnorwitz at users.sourceforge.net nnorwitz at users.sourceforge.net
Sat Dec 27 11:20:26 EST 2003


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv12392/Python
Modified Files:
 Tag: ast-branch
	newcompile.c 
Log Message:
Fix several problems (some from #752911):
 * add known limitation that file encoding doesn't work
 * create lambdas with keyword arguments properly
 * fix nested for loops
 * fix while loops
 * fix chained comparisons (needs to be cleaned up)
 * fix calling functions with keyword args (like foo(a=1, b=2))
Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.57
retrieving revision 1.1.2.58
diff -C2 -d -r1.1.2.57 -r1.1.2.58
*** newcompile.c	2 Dec 2003 07:01:20 -0000	1.1.2.57
--- newcompile.c	27 Dec 2003 16:20:23 -0000	1.1.2.58
***************
*** 9,12 ****
--- 9,19 ----
 int Py_OptimizeFlag = 0;
 
+ /*
+ KNOWN BUGS:
+ using coding statement, such as in getopt:
+ 		# -*- coding: iso-8859-1 -*-
+ generates: SystemError
+ */
+ 
 /* fblockinfo tracks the current frame block.
 
***************
*** 95,98 ****
--- 102,106 ----
 static PyCodeObject *compiler_mod(struct compiler *, mod_ty);
 static int compiler_visit_stmt(struct compiler *, stmt_ty);
+ static int compiler_visit_keyword(struct compiler *, keyword_ty);
 static int compiler_visit_expr(struct compiler *, expr_ty);
 static int compiler_augassign(struct compiler *, stmt_ty);
***************
*** 780,784 ****
 	/* XXX closure */
 	ADDOP_O(c, LOAD_CONST, (PyObject *)co, consts);
! 	ADDOP_I(c, MAKE_FUNCTION, c->u->u_argcount);
 
 	Py_DECREF(name);
--- 788,792 ----
 	/* XXX closure */
 	ADDOP_O(c, LOAD_CONST, (PyObject *)co, consts);
! 	ADDOP_I(c, MAKE_FUNCTION, asdl_seq_LEN(args->defaults));
 
 	Py_DECREF(name);
***************
*** 882,886 ****
 	VISIT_SEQ(c, stmt, s->v.For.body);
 	ADDOP_JABS(c, JUMP_ABSOLUTE, start);
! 	compiler_use_block(c, cleanup);
 	ADDOP(c, POP_BLOCK);
 	compiler_pop_fblock(c, LOOP, start);
--- 890,894 ----
 	VISIT_SEQ(c, stmt, s->v.For.body);
 	ADDOP_JABS(c, JUMP_ABSOLUTE, start);
! 	compiler_use_next_block(c, cleanup);
 	ADDOP(c, POP_BLOCK);
 	compiler_pop_fblock(c, LOOP, start);
***************
*** 919,926 ****
 	 if there is no else clause ?
 	*/
- 	if (orelse == -1)
- 		compiler_use_block(c, end);
- 	else
- 		compiler_use_block(c, orelse);
 	ADDOP(c, POP_TOP);
 	ADDOP(c, POP_BLOCK);
--- 927,930 ----
***************
*** 1591,1599 ****
 	int i, n, cleanup = -1;
 
 	VISIT(c, expr, e->v.Compare.left);
 	n = asdl_seq_LEN(e->v.Compare.ops);
 	assert(n > 0);
! 	if (n > 1)
 		cleanup = compiler_new_block(c);
 	for (i = 1; i < n; i++) {
 		ADDOP(c, DUP_TOP);
--- 1595,1606 ----
 	int i, n, cleanup = -1;
 
+ 	/* XXX the logic can be cleaned up for 1 or multiple comparisons */
 	VISIT(c, expr, e->v.Compare.left);
 	n = asdl_seq_LEN(e->v.Compare.ops);
 	assert(n > 0);
! 	if (n > 1) {
 		cleanup = compiler_new_block(c);
+ 		VISIT(c, expr, asdl_seq_GET(e->v.Compare.comparators, 0));
+ 	}
 	for (i = 1; i < n; i++) {
 		ADDOP(c, DUP_TOP);
***************
*** 1605,1608 ****
--- 1612,1617 ----
 		NEXT_BLOCK(c);
 		ADDOP(c, POP_TOP);
+ 		if (i < (n - 1))
+ 		 VISIT(c, expr, asdl_seq_GET(e->v.Compare.comparators, i));
 	}
 	VISIT(c, expr, asdl_seq_GET(e->v.Compare.comparators, n - 1));
***************
*** 1628,1631 ****
--- 1637,1644 ----
 	VISIT(c, expr, e->v.Call.func);
 	n = asdl_seq_LEN(e->v.Call.args);
+ 	if (e->v.Call.keywords) {
+ 		VISIT_SEQ(c, keyword, e->v.Call.keywords);
+ 		n |= asdl_seq_LEN(e->v.Call.keywords) << 8;
+ 	}
 	if (e->v.Call.starargs) {
 		VISIT(c, expr, e->v.Call.starargs);
***************
*** 1731,1734 ****
--- 1744,1755 ----
 	}
 	c->u->u_tmp = NULL;
+ 	return 1;
+ }
+ 
+ static int
+ compiler_visit_keyword(struct compiler *c, keyword_ty k)
+ {
+ 	ADDOP_O(c, LOAD_CONST, k->arg, consts);
+ 	VISIT(c, expr, k->value);
 	return 1;
 }


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /