[Python-checkins] python/dist/src/Python newcompile.c, 1.1.2.76, 1.1.2.77

nnorwitz at users.sourceforge.net nnorwitz at users.sourceforge.net
Sat Mar 20 12:44:30 EST 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24327/Python

Modified Files:
      Tag: ast-branch
	newcompile.c 
Log Message:
get all docstrings working

Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.76
retrieving revision 1.1.2.77
diff -C2 -d -r1.1.2.76 -r1.1.2.77
*** newcompile.c	20 Mar 2004 17:10:46 -0000	1.1.2.76
--- newcompile.c	20 Mar 2004 17:44:21 -0000	1.1.2.77
***************
*** 37,42 ****
          doesn't output BINARY_TRUE_DIVISION
       #: co_names doesn't contain locals, only globals, co_varnames may work
-      #: doc strings at class scope are POPed, not stored
-         In interactive mode, they are printed. :-)
       #: ref leaks in interpreter when press return on empty line
       #: yield or return outside a function don't raise a SyntaxError
--- 37,40 ----
***************
*** 614,619 ****
  
  static int
! compiler_addop_o(struct compiler *c, int opcode, PyObject *dict,
! 		     PyObject *o)
  {
  	PyObject *t, *v;
--- 612,616 ----
  
  static int
! compiler_add_o(struct compiler *c, PyObject *dict, PyObject *o)
  {
  	PyObject *t, *v;
***************
*** 624,628 ****
          t = Py_BuildValue("(OO)", o, o->ob_type);
          if (t == NULL)
!             return 0;
  
  	v = PyDict_GetItem(dict, t);
--- 621,625 ----
          t = Py_BuildValue("(OO)", o, o->ob_type);
          if (t == NULL)
!             return -1;
  
  	v = PyDict_GetItem(dict, t);
***************
*** 632,641 ****
  		if (!v) {
  			Py_DECREF(t);
! 			return 0;
                  }
  		if (PyDict_SetItem(dict, t, v) < 0) {
  			Py_DECREF(t);
  			Py_DECREF(v);
! 			return 0;
  		}
  		Py_DECREF(v);
--- 629,638 ----
  		if (!v) {
  			Py_DECREF(t);
! 			return -1;
                  }
  		if (PyDict_SetItem(dict, t, v) < 0) {
  			Py_DECREF(t);
  			Py_DECREF(v);
! 			return -1;
  		}
  		Py_DECREF(v);
***************
*** 644,648 ****
  		arg = PyInt_AsLong(v);
  	Py_DECREF(t);
! 	return compiler_addop_i(c, opcode, arg);
  }
  
--- 641,655 ----
  		arg = PyInt_AsLong(v);
  	Py_DECREF(t);
!         return arg;
! }
! 
! static int
! compiler_addop_o(struct compiler *c, int opcode, PyObject *dict,
! 		     PyObject *o)
! {
!     int arg = compiler_add_o(c, dict, o);
!     if (arg < 0)
!         return 0;
!     return compiler_addop_i(c, opcode, arg);
  }
  
***************
*** 874,882 ****
  
  static int
  compiler_function(struct compiler *c, stmt_ty s)
  {
  	PyCodeObject *co;
  	arguments_ty args = s->v.FunctionDef.args;
! 	int i, n;
  	assert(s->kind == FunctionDef_kind);
  
--- 881,899 ----
  
  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)
  {
  	PyCodeObject *co;
+         PyObject *first_const = Py_None;
  	arguments_ty args = s->v.FunctionDef.args;
!         stmt_ty st;
! 	int i, n, docstring;
  	assert(s->kind == FunctionDef_kind);
  
***************
*** 885,888 ****
--- 902,913 ----
  	if (!compiler_enter_scope(c, s->v.FunctionDef.name, (void *)s))
  		return 0;
+ 
+         st = asdl_seq_GET(s->v.FunctionDef.body, 0);
+         docstring = compiler_isdocstring(st);
+         if (docstring)
+             first_const = st->v.Expr.value->v.Str.s;
+         if (compiler_add_o(c, c->u->u_consts, first_const) < 0)
+             return 0;
+ 
          /* unpack nested arguments */
          for (i = 0; i < asdl_seq_LEN(args->args); i++) {
***************
*** 898,902 ****
  	c->u->u_argcount = asdl_seq_LEN(args->args);
  	n = asdl_seq_LEN(s->v.FunctionDef.body);
! 	for (i = 0; i < n; i++) {
  		stmt_ty s2 = asdl_seq_GET(s->v.FunctionDef.body, i);
  		if (i == 0 && s2->kind == Expr_kind &&
--- 923,928 ----
  	c->u->u_argcount = asdl_seq_LEN(args->args);
  	n = asdl_seq_LEN(s->v.FunctionDef.body);
!         /* if there was a docstring, we need to skip the first statement */
! 	for (i = docstring; i < n; i++) {
  		stmt_ty s2 = asdl_seq_GET(s->v.FunctionDef.body, i);
  		if (i == 0 && s2->kind == Expr_kind &&
***************
*** 918,929 ****
  
  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_class(struct compiler *c, stmt_ty s)
  {
--- 944,947 ----
***************
*** 957,961 ****
          i = 0;
          if (compiler_isdocstring(st)) {
!             i++;
              VISIT(c, expr, st->v.Expr.value);
              if (!compiler_nameop(c, __doc__, Store))
--- 975,979 ----
          i = 0;
          if (compiler_isdocstring(st)) {
!             i = 1;
              VISIT(c, expr, st->v.Expr.value);
              if (!compiler_nameop(c, __doc__, Store))




More information about the Python-checkins mailing list