[Python-checkins] python/dist/src/Python newcompile.c, 1.1.2.60,
1.1.2.61 ast.c, 1.1.2.39, 1.1.2.40
nnorwitz at users.sourceforge.net
nnorwitz at users.sourceforge.net
Wed Dec 31 15:26:39 EST 2003
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv26003/Python
Modified Files:
Tag: ast-branch
newcompile.c ast.c
Log Message:
get nested list comps and list comps with ifs to work
Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.60
retrieving revision 1.1.2.61
diff -C2 -d -r1.1.2.60 -r1.1.2.61
*** newcompile.c 29 Dec 2003 22:10:41 -0000 1.1.2.60
--- newcompile.c 31 Dec 2003 20:26:36 -0000 1.1.2.61
***************
*** 26,33 ****
4:
! typing Ctrl-C seg faults
5:
! line numbers are off
*/
--- 26,37 ----
4:
! line numbers are off a bit (may just need to add calls to set lineno
5:
! Modules/parsermodule.c:496: warning: implicit declaration
! of function `PyParser_SimpleParseString'
!
! 6:
! while loops with try/except in them don't work
*/
***************
*** 935,938 ****
--- 939,946 ----
if there is no else clause ?
*/
+
+ /* sometimes this needs to be compiler_use_next_block
+ (e.g., nested loops), but if the code is
+ while XXX: try: ... this is correct */
compiler_use_block(c, anchor);
ADDOP(c, POP_TOP);
***************
*** 1228,1233 ****
int i, n;
! fprintf(stderr, "compile stmt %d lineno %d\n",
! s->kind, s->lineno);
c->u->u_lineno = s->lineno;
c->u->u_lineno_set = false;
--- 1236,1240 ----
int i, n;
! fprintf(stderr, "compile stmt %d lineno %d\n", s->kind, s->lineno);
c->u->u_lineno = s->lineno;
c->u->u_lineno_set = false;
***************
*** 1677,1691 ****
static int
! compiler_listcomp_generator(struct compiler *c, listcomp_ty l, expr_ty elt)
{
/* generate code for the iterator, then each of the ifs,
and then write to the element */
! int start, anchor, skip, i, n;
start = compiler_new_block(c);
skip = compiler_new_block(c);
anchor = compiler_new_block(c);
VISIT(c, expr, l->iter);
ADDOP(c, GET_ITER);
--- 1684,1703 ----
static int
! compiler_listcomp_generator(struct compiler *c,
! asdl_seq *generators, int gen_index,
! expr_ty elt)
{
/* generate code for the iterator, then each of the ifs,
and then write to the element */
! listcomp_ty l;
! int start, anchor, skip, if_cleanup, i, n;
start = compiler_new_block(c);
skip = compiler_new_block(c);
+ if_cleanup = compiler_new_block(c);
anchor = compiler_new_block(c);
+ l = asdl_seq_GET(generators, gen_index);
VISIT(c, expr, l->iter);
ADDOP(c, GET_ITER);
***************
*** 1694,1718 ****
NEXT_BLOCK(c);
VISIT(c, expr, l->target);
!
n = asdl_seq_LEN(l->ifs);
for (i = 0; i < n; i++) {
expr_ty e = asdl_seq_GET(l->ifs, i);
VISIT(c, expr, e);
! /* XXX not anchor? */
! ADDOP_JREL(c, JUMP_IF_FALSE, skip);
NEXT_BLOCK(c);
! ADDOP(c, DUP_TOP);
}
! if (!compiler_nameop(c, c->u->u_tmp, Load))
return 0;
! VISIT(c, expr, elt);
! ADDOP_I(c, CALL_FUNCTION, 1);
! ADDOP(c, POP_TOP);
! compiler_use_next_block(c, skip);
ADDOP_JABS(c, JUMP_ABSOLUTE, start);
compiler_use_next_block(c, anchor);
! if (!compiler_nameop(c, c->u->u_tmp, Del))
return 0;
--- 1706,1745 ----
NEXT_BLOCK(c);
VISIT(c, expr, l->target);
!
! /* XXX this needs to be cleaned up...a lot! */
n = asdl_seq_LEN(l->ifs);
for (i = 0; i < n; i++) {
expr_ty e = asdl_seq_GET(l->ifs, i);
VISIT(c, expr, e);
! ADDOP_JREL(c, JUMP_IF_FALSE, if_cleanup);
NEXT_BLOCK(c);
! ADDOP(c, POP_TOP);
}
! if (++gen_index < asdl_seq_LEN(generators))
! if (!compiler_listcomp_generator(c, generators, gen_index, elt))
! return 0;
!
! /* only append after the last for generator */
! if (gen_index >= asdl_seq_LEN(generators)) {
! if (!compiler_nameop(c, c->u->u_tmp, Load))
return 0;
! VISIT(c, expr, elt);
! ADDOP_I(c, CALL_FUNCTION, 1);
! ADDOP(c, POP_TOP);
! compiler_use_next_block(c, skip);
! }
! for (i = 0; i < n; i++) {
! ADDOP_I(c, JUMP_FORWARD, 1);
! if (i == 0)
! compiler_use_next_block(c, if_cleanup);
! ADDOP(c, POP_TOP);
! }
ADDOP_JABS(c, JUMP_ABSOLUTE, start);
compiler_use_next_block(c, anchor);
! /* delete the append method added to locals */
! if (gen_index == 1)
! if (!compiler_nameop(c, c->u->u_tmp, Del))
return 0;
***************
*** 1723,1727 ****
compiler_listcomp(struct compiler *c, expr_ty e)
{
- int i;
char tmpname[256];
identifier tmp;
--- 1750,1753 ----
***************
*** 1746,1755 ****
return 0;
c->u->u_tmp = tmp;
! for (i = 0; i < asdl_seq_LEN(generators); i++) {
! if (!compiler_listcomp_generator(c,
! asdl_seq_GET(generators, i),
! e->v.ListComp.elt))
! return 0;
! }
c->u->u_tmp = NULL;
return 1;
--- 1772,1777 ----
return 0;
c->u->u_tmp = tmp;
! if (!compiler_listcomp_generator(c, generators, 0, e->v.ListComp.elt))
! return 0;
c->u->u_tmp = NULL;
return 1;
***************
*** 2476,2480 ****
struct basicblock *b = c->u->u_blocks[a.a_postorder[i]];
fprintf(stderr,
! "\nblock %d: order=%d used=%d alloc=%d next=%d\n",
i, a.a_postorder[i], b->b_iused, b->b_ialloc,
b->b_next);
--- 2498,2502 ----
struct basicblock *b = c->u->u_blocks[a.a_postorder[i]];
fprintf(stderr,
! "\nblock %d: order=%d used=%d alloc=%d next=%d\n",
i, a.a_postorder[i], b->b_iused, b->b_ialloc,
b->b_next);
Index: ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v
retrieving revision 1.1.2.39
retrieving revision 1.1.2.40
diff -C2 -d -r1.1.2.39 -r1.1.2.40
*** ast.c 29 Dec 2003 22:11:32 -0000 1.1.2.39
--- ast.c 31 Dec 2003 20:26:36 -0000 1.1.2.40
***************
*** 287,290 ****
--- 287,297 ----
/* XXX It's not clear why were't getting into this code,
although list comps seem like one possibility.
+
+ This occurs in at least 2 cases:
+ [x(i) for i in range(3)] # Call_kind (8)
+ [i*2 for i in range(3)] # BinOp_kind (2)
+
+ The byte code generated seems to work fine.
+ Maybe there's a problem with nested list comps?
*/
fprintf(stderr, "can't set context for %d\n", e->kind);
***************
*** 713,724 ****
REQ(ch, list_if);
! asdl_seq_APPEND(ifs, CHILD(ch, 1));
if (NCH(ch) == 3)
ch = CHILD(ch, 2);
}
- /* XXX ifs is leaked, we surely have to do something with it */
/* on exit, must guarantee that ch is a list_for */
if (TYPE(ch) == list_iter)
ch = CHILD(ch, 0);
}
asdl_seq_APPEND(listcomps, c);
--- 720,731 ----
REQ(ch, list_if);
! asdl_seq_APPEND(ifs, ast_for_expr(CHILD(ch, 1)));
if (NCH(ch) == 3)
ch = CHILD(ch, 2);
}
/* on exit, must guarantee that ch is a list_for */
if (TYPE(ch) == list_iter)
ch = CHILD(ch, 0);
+ c->ifs = ifs;
}
asdl_seq_APPEND(listcomps, c);
More information about the Python-checkins
mailing list