[Python-checkins] python/dist/src/Python Python-ast.c, 1.1.2.8,
1.1.2.9 ast.c, 1.1.2.54, 1.1.2.55 newcompile.c, 1.1.2.100,
1.1.2.101 symtable.c, 2.10.8.29, 2.10.8.30
nnorwitz at users.sourceforge.net
nnorwitz at users.sourceforge.net
Sun Jan 16 18:09:15 CET 2005
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14168/Python
Modified Files:
Tag: ast-branch
Python-ast.c ast.c newcompile.c symtable.c
Log Message:
Handle generator comps a little, lots more to do to get working
Index: Python-ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/Python-ast.c,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -u -d -r1.1.2.8 -r1.1.2.9
--- Python-ast.c 13 Apr 2004 14:58:35 -0000 1.1.2.8
+++ Python-ast.c 16 Jan 2005 17:09:11 -0000 1.1.2.9
@@ -650,6 +650,26 @@
}
expr_ty
+GeneratorComp(expr_ty elt, asdl_seq * generators)
+{
+ expr_ty p;
+ if (!elt) {
+ PyErr_SetString(PyExc_ValueError,
+ "field elt is required for GeneratorComp");
+ return NULL;
+ }
+ p = (expr_ty)malloc(sizeof(*p));
+ if (!p) {
+ PyErr_SetString(PyExc_MemoryError, "no memory");
+ return NULL;
+ }
+ p->kind = GeneratorComp_kind;
+ p->v.GeneratorComp.elt = elt;
+ p->v.GeneratorComp.generators = generators;
+ return p;
+}
+
+expr_ty
Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators)
{
expr_ty p;
@@ -940,21 +960,21 @@
return p;
}
-listcomp_ty
-listcomp(expr_ty target, expr_ty iter, asdl_seq * ifs)
+comprehension_ty
+comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs)
{
- listcomp_ty p;
+ comprehension_ty p;
if (!target) {
PyErr_SetString(PyExc_ValueError,
- "field target is required for listcomp");
+ "field target is required for comprehension");
return NULL;
}
if (!iter) {
PyErr_SetString(PyExc_ValueError,
- "field iter is required for listcomp");
+ "field iter is required for comprehension");
return NULL;
}
- p = (listcomp_ty)malloc(sizeof(*p));
+ p = (comprehension_ty)malloc(sizeof(*p));
if (!p) {
PyErr_SetString(PyExc_MemoryError, "no memory");
return NULL;
@@ -1278,7 +1298,14 @@
seq = o->v.ListComp.generators;
n = asdl_seq_LEN(seq);
for (i = 0; i < n; i++)
- free_listcomp(asdl_seq_GET(seq, i));
+ free_comprehension(asdl_seq_GET(seq, i));
+ break;
+ case GeneratorComp_kind:
+ free_expr(o->v.GeneratorComp.elt);
+ seq = o->v.GeneratorComp.generators;
+ n = asdl_seq_LEN(seq);
+ for (i = 0; i < n; i++)
+ free_comprehension(asdl_seq_GET(seq, i));
break;
case Compare_kind:
free_expr(o->v.Compare.left);
@@ -1400,7 +1427,7 @@
}
void
-free_listcomp(listcomp_ty o)
+free_comprehension(comprehension_ty o)
{
int i, n;
asdl_seq *seq;
@@ -1817,11 +1844,24 @@
i++) {
void *elt = asdl_seq_GET(o->v.ListComp.generators,
i);
- marshal_write_listcomp(buf, off, elt);
+ marshal_write_comprehension(buf, off, elt);
}
break;
- case Compare_kind:
+ case GeneratorComp_kind:
marshal_write_int(buf, off, 7);
+ marshal_write_expr(buf, off, o->v.GeneratorComp.elt);
+ marshal_write_int(buf, off,
+ asdl_seq_LEN(o->v.GeneratorComp.generators));
+
+ for (i = 0; i <
+ asdl_seq_LEN(o->v.GeneratorComp.generators); i++) {
+ void *elt =
+ asdl_seq_GET(o->v.GeneratorComp.generators, i);
+ marshal_write_comprehension(buf, off, elt);
+ }
+ break;
+ case Compare_kind:
+ marshal_write_int(buf, off, 8);
marshal_write_expr(buf, off, o->v.Compare.left);
marshal_write_int(buf, off, asdl_seq_LEN(o->v.Compare.ops));
for (i = 0; i < asdl_seq_LEN(o->v.Compare.ops); i++) {
@@ -1838,7 +1878,7 @@
}
break;
case Call_kind:
- marshal_write_int(buf, off, 8);
+ marshal_write_int(buf, off, 9);
marshal_write_expr(buf, off, o->v.Call.func);
marshal_write_int(buf, off, asdl_seq_LEN(o->v.Call.args));
for (i = 0; i < asdl_seq_LEN(o->v.Call.args); i++) {
@@ -1865,36 +1905,36 @@
marshal_write_int(buf, off, 0);
break;
case Repr_kind:
- marshal_write_int(buf, off, 9);
+ marshal_write_int(buf, off, 10);
marshal_write_expr(buf, off, o->v.Repr.value);
break;
case Num_kind:
- marshal_write_int(buf, off, 10);
+ marshal_write_int(buf, off, 11);
marshal_write_object(buf, off, o->v.Num.n);
break;
case Str_kind:
- marshal_write_int(buf, off, 11);
+ marshal_write_int(buf, off, 12);
marshal_write_string(buf, off, o->v.Str.s);
break;
case Attribute_kind:
- marshal_write_int(buf, off, 12);
+ marshal_write_int(buf, off, 13);
marshal_write_expr(buf, off, o->v.Attribute.value);
marshal_write_identifier(buf, off, o->v.Attribute.attr);
marshal_write_expr_context(buf, off, o->v.Attribute.ctx);
break;
case Subscript_kind:
- marshal_write_int(buf, off, 13);
+ marshal_write_int(buf, off, 14);
marshal_write_expr(buf, off, o->v.Subscript.value);
marshal_write_slice(buf, off, o->v.Subscript.slice);
marshal_write_expr_context(buf, off, o->v.Subscript.ctx);
break;
case Name_kind:
- marshal_write_int(buf, off, 14);
+ marshal_write_int(buf, off, 15);
marshal_write_identifier(buf, off, o->v.Name.id);
marshal_write_expr_context(buf, off, o->v.Name.ctx);
break;
case List_kind:
- marshal_write_int(buf, off, 15);
+ marshal_write_int(buf, off, 16);
marshal_write_int(buf, off, asdl_seq_LEN(o->v.List.elts));
for (i = 0; i < asdl_seq_LEN(o->v.List.elts); i++) {
void *elt = asdl_seq_GET(o->v.List.elts, i);
@@ -1903,7 +1943,7 @@
marshal_write_expr_context(buf, off, o->v.List.ctx);
break;
case Tuple_kind:
- marshal_write_int(buf, off, 16);
+ marshal_write_int(buf, off, 17);
marshal_write_int(buf, off, asdl_seq_LEN(o->v.Tuple.elts));
for (i = 0; i < asdl_seq_LEN(o->v.Tuple.elts); i++) {
void *elt = asdl_seq_GET(o->v.Tuple.elts, i);
@@ -2104,7 +2144,7 @@
}
int
-marshal_write_listcomp(PyObject **buf, int *off, listcomp_ty o)
+marshal_write_comprehension(PyObject **buf, int *off, comprehension_ty o)
{
int i;
marshal_write_expr(buf, off, o->target);
Index: ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v
retrieving revision 1.1.2.54
retrieving revision 1.1.2.55
diff -u -d -r1.1.2.54 -r1.1.2.55
--- ast.c 16 Jan 2005 15:14:57 -0000 1.1.2.54
+++ ast.c 16 Jan 2005 17:09:11 -0000 1.1.2.55
@@ -757,7 +757,7 @@
ch = CHILD(n, 1);
for (i = 0; i < n_fors; i++) {
- listcomp_ty lc;
+ comprehension_ty lc;
asdl_seq *t;
expr_ty expression;
@@ -777,9 +777,9 @@
}
if (asdl_seq_LEN(t) == 1)
- lc = listcomp(asdl_seq_GET(t, 0), expression, NULL);
+ lc = comprehension(asdl_seq_GET(t, 0), expression, NULL);
else
- lc = listcomp(Tuple(t, Store), expression, NULL);
+ lc = comprehension(Tuple(t, Store), expression, NULL);
if (!lc) {
asdl_seq_free(listcomps);
@@ -1279,10 +1279,10 @@
/*
arglist: (argument ',')* (argument [',']| '*' test [',' '**' test]
| '**' test)
- argument: [test '='] test # Really [keyword '='] test
+ argument: [test '='] test [gen_for] # Really [keyword '='] test
*/
- int i, nargs, nkeywords;
+ int i, nargs, nkeywords, ngens;
asdl_seq *args = NULL;
asdl_seq *keywords = NULL;
expr_ty vararg = NULL, kwarg = NULL;
@@ -1291,11 +1291,14 @@
nargs = 0;
nkeywords = 0;
+ ngens = 0;
for (i = 0; i < NCH(n); i++)
if (TYPE(CHILD(n, i)) == argument) {
if (NCH(CHILD(n, i)) == 1)
nargs++;
- else
+ else if (TYPE(CHILD(CHILD(n, i), 1)) == gen_for)
+ ngens++;
+ else
nkeywords++;
}
@@ -1317,6 +1320,9 @@
goto error;
asdl_seq_SET(args, nargs++, e);
}
+ else if (TYPE(CHILD(CHILD(n, 0), 1)) == gen_for) {
+ /* XXX handle generator comp */
+ }
else {
keyword_ty kw;
identifier key;
Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.100
retrieving revision 1.1.2.101
diff -u -d -r1.1.2.100 -r1.1.2.101
--- newcompile.c 24 Apr 2004 03:54:02 -0000 1.1.2.100
+++ newcompile.c 16 Jan 2005 17:09:12 -0000 1.1.2.101
@@ -2303,7 +2303,7 @@
/* generate code for the iterator, then each of the ifs,
and then write to the element */
- listcomp_ty l;
+ comprehension_ty l;
int start, anchor, skip, if_cleanup, i, n;
start = compiler_new_block(c);
@@ -2393,6 +2393,13 @@
}
static int
+compiler_generatorcomp(struct compiler *c, expr_ty e)
+{
+ /* XXX handle */
+ return 0;
+}
+
+static int
compiler_visit_keyword(struct compiler *c, keyword_ty k)
{
ADDOP_O(c, LOAD_CONST, k->arg, consts);
@@ -2454,6 +2461,8 @@
break;
case ListComp_kind:
return compiler_listcomp(c, e);
+ case GeneratorComp_kind:
+ return compiler_generatorcomp(c, e);
case Compare_kind:
return compiler_compare(c, e);
case Call_kind:
Index: symtable.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/symtable.c,v
retrieving revision 2.10.8.29
retrieving revision 2.10.8.30
diff -u -d -r2.10.8.29 -r2.10.8.30
--- symtable.c 7 Jan 2005 07:04:59 -0000 2.10.8.29
+++ symtable.c 16 Jan 2005 17:09:12 -0000 2.10.8.30
@@ -160,7 +160,7 @@
static int symtable_visit_arguments(struct symtable *st, arguments_ty);
static int symtable_visit_excepthandler(struct symtable *st, excepthandler_ty);
static int symtable_visit_alias(struct symtable *st, alias_ty);
-static int symtable_visit_listcomp(struct symtable *st, listcomp_ty);
+static int symtable_visit_comprehension(struct symtable *st, comprehension_ty);
static int symtable_visit_keyword(struct symtable *st, keyword_ty);
static int symtable_visit_slice(struct symtable *st, slice_ty);
static int symtable_visit_params(struct symtable *st, asdl_seq *args, int top);
@@ -919,8 +919,9 @@
if (e->v.Lambda.args->defaults)
VISIT_SEQ(st, expr, e->v.Lambda.args->defaults);
/* XXX how to get line numbers for expressions */
- symtable_enter_block(st, GET_IDENTIFIER(lambda),
- FunctionBlock, (void *)e, 0);
+ if (!symtable_enter_block(st, GET_IDENTIFIER(lambda),
+ FunctionBlock, (void *)e, 0))
+ return 0;
VISIT(st, arguments, e->v.Lambda.args);
VISIT(st, expr, e->v.Lambda.body);
symtable_exit_block(st, (void *)e);
@@ -940,7 +941,21 @@
if (!symtable_add_def(st, tmp, DEF_LOCAL))
return 0;
VISIT(st, expr, e->v.ListComp.elt);
- VISIT_SEQ(st, listcomp, e->v.ListComp.generators);
+ VISIT_SEQ(st, comprehension, e->v.ListComp.generators);
+ break;
+ }
+ case GeneratorComp_kind: {
+ char tmpname[256];
+ identifier tmp;
+
+ /* XXX this is correct/complete */
+ tmp = PyString_FromString("<genexpr>");
+ if (!symtable_enter_block(st, tmp, FunctionBlock,
+ (void *)e, 0))
+ return 0;
+ VISIT(st, expr, e->v.GeneratorComp.elt);
+ VISIT_SEQ(st, comprehension, e->v.GeneratorComp.generators);
+ symtable_exit_block(st, (void *)e);
break;
}
case Compare_kind:
@@ -1102,7 +1117,7 @@
static int
-symtable_visit_listcomp(struct symtable *st, listcomp_ty lc)
+symtable_visit_comprehension(struct symtable *st, comprehension_ty lc)
{
VISIT(st, expr, lc->target);
VISIT(st, expr, lc->iter);
More information about the Python-checkins
mailing list