[Python-checkins] python/dist/src/Python newcompile.c, 1.1.2.89,
1.1.2.90
jhylton at users.sourceforge.net
jhylton at users.sourceforge.net
Tue Apr 20 22:16:06 EDT 2004
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18328
Modified Files:
Tag: ast-branch
newcompile.c
Log Message:
Generate code for module docstrings.
Extract the common code for modules and classes into compiler_body().
Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.89
retrieving revision 1.1.2.90
diff -C2 -d -r1.1.2.89 -r1.1.2.90
*** newcompile.c 13 Apr 2004 15:04:51 -0000 1.1.2.89
--- newcompile.c 21 Apr 2004 02:16:01 -0000 1.1.2.90
***************
*** 1071,1074 ****
--- 1071,1103 ----
}
+ static int
+ compiler_isdocstring(stmt_ty s)
+ {
+ if (s->kind != Expr_kind)
+ return 0;
+ return s->v.Expr.value->kind == Str_kind;
+ }
+
+ /* Compile a sequence of statements, checking for a docstring. */
+
+ static int
+ compiler_body(struct compiler *c, asdl_seq *stmts)
+ {
+ int i = 0;
+ stmt_ty st;
+
+ st = asdl_seq_GET(stmts, 0);
+ printf("is_docstring? %d\n", compiler_isdocstring(st));
+ if (compiler_isdocstring(st)) {
+ i = 1;
+ VISIT(c, expr, st->v.Expr.value);
+ if (!compiler_nameop(c, __doc__, Store))
+ return 0;
+ }
+ for (; i < asdl_seq_LEN(stmts); i++)
+ VISIT(c, stmt, asdl_seq_GET(stmts, i));
+ return 1;
+ }
+
static PyCodeObject *
compiler_mod(struct compiler *c, mod_ty mod)
***************
*** 1085,1090 ****
return NULL;
switch (mod->kind) {
! case Module_kind:
! VISIT_SEQ(c, stmt, mod->v.Module.body);
break;
case Interactive_kind:
--- 1114,1120 ----
return NULL;
switch (mod->kind) {
! case Module_kind:
! if (!compiler_body(c, mod->v.Module.body))
! return 0;
break;
case Interactive_kind:
***************
*** 1195,1206 ****
static int
- compiler_isdocstring(stmt_ty s)
- {
- if (s->kind != Expr_kind)
- return 0;
- return s->v.Expr.value->kind == Str_kind;
- }
-
- static int
compiler_function(struct compiler *c, stmt_ty s)
{
--- 1225,1228 ----
***************
*** 1257,1261 ****
compiler_class(struct compiler *c, stmt_ty s)
{
! int n, i;
PyCodeObject *co;
PyObject *str;
--- 1279,1283 ----
compiler_class(struct compiler *c, stmt_ty s)
{
! int n;
PyCodeObject *co;
PyObject *str;
***************
*** 1285,1299 ****
Py_DECREF(str);
! stmt_ty st = asdl_seq_GET(s->v.ClassDef.body, 0);
! i = 0;
! if (compiler_isdocstring(st)) {
! i = 1;
! VISIT(c, expr, st->v.Expr.value);
! if (!compiler_nameop(c, __doc__, Store))
! return 0;
! }
!
! for (; i < asdl_seq_LEN(s->v.ClassDef.body); i++)
! VISIT(c, stmt, asdl_seq_GET(s->v.ClassDef.body, i));
ADDOP(c, LOAD_LOCALS);
--- 1307,1312 ----
Py_DECREF(str);
! if (!compiler_body(c, s->v.ClassDef.body))
! return 0;
ADDOP(c, LOAD_LOCALS);
More information about the Python-checkins
mailing list