[Python-checkins] python/dist/src/Python newcompile.c,1.1.2.52,1.1.2.53

jhylton@users.sourceforge.net jhylton@users.sourceforge.net
Mon, 28 Apr 2003 09:35:44 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv11746/Python

Modified Files:
      Tag: ast-branch
	newcompile.c 
Log Message:
Improve line number handling./

Set a_lineno on exit from assemble_lnotab()!  Otherwise the lnotab
entries are always line numbers relative to 0.

Set the first line number in a code object.

Handle bytecode offsets greater than 255.


Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.52
retrieving revision 1.1.2.53
diff -C2 -d -r1.1.2.52 -r1.1.2.53
*** newcompile.c	24 Apr 2003 17:39:24 -0000	1.1.2.52
--- newcompile.c	28 Apr 2003 16:35:40 -0000	1.1.2.53
***************
*** 77,80 ****
--- 77,81 ----
  	int a_lineno;          /* last lineno of emitted instruction */
  	int a_lineno_off;      /* bytecode offset of last lineno */
+ 	int a_firstlineno;     /* first line number in code */
  };
  
***************
*** 495,500 ****
  {
  	struct basicblock *b;
- 	fprintf(stderr, "set_lineno() set=%d lineno=%d\n",
- 		c->u->u_lineno_set, c->u->u_lineno);
  	if (c->u->u_lineno_set)
  		return;
--- 496,499 ----
***************
*** 2160,2176 ****
  		return 1;
  
! 	/* XXX for now */
! 	assert(d_bytecode < 256);
  	assert(d_lineno < 256);
! 
! 	len = PyString_GET_SIZE(a->a_lnotab);
! 	if (a->a_lnotab_off + 2 >= len) {
! 		if (_PyString_Resize(&a->a_lnotab, len * 2) < 0)
! 			return 0;
  	}
- 	lnotab = PyString_AS_STRING(a->a_lnotab) + a->a_lnotab_off;
  	*lnotab++ = d_bytecode;
  	*lnotab++ = d_lineno;
! 	a->a_lnotab_off += 2;
  	return 1;
  }
--- 2159,2196 ----
  		return 1;
  
! 	/* XXX Need logic for line number gaps greater than 255. */
  	assert(d_lineno < 256);
! 	if (d_bytecode > 255) {
! 		int i, nbytes, ncodes = d_bytecode / 255;
! 		nbytes = a->a_lnotab_off + 2 * ncodes;
! 		len = PyString_GET_SIZE(a->a_lnotab);
! 		if (nbytes >= len) {
! 			if (len * 2 < nbytes)
! 				len = nbytes;
! 			else
! 				len *= 2;
! 			if (_PyString_Resize(&a->a_lnotab, len) < 0)
! 				return 0;
! 		}
! 		lnotab = PyString_AS_STRING(a->a_lnotab) + a->a_lnotab_off;
! 		for (i = 0; i < ncodes; i++) {
! 			*lnotab++ = 255;
! 			*lnotab++ = 0;
! 		}
! 		d_bytecode -= ncodes * 255;
! 		a->a_lnotab_off += ncodes * 2;
! 	}
! 	else {
! 		len = PyString_GET_SIZE(a->a_lnotab);
! 		if (a->a_lnotab_off + 2 >= len) {
! 			if (_PyString_Resize(&a->a_lnotab, len * 2) < 0)
! 				return 0;
! 	    }
! 		lnotab = PyString_AS_STRING(a->a_lnotab) + a->a_lnotab_off;
! 		a->a_lnotab_off += 2;
  	}
  	*lnotab++ = d_bytecode;
  	*lnotab++ = d_lineno;
! 	a->a_lineno = i->i_lineno;
  	return 1;
  }
***************
*** 2331,2335 ****
  			nil, nil,
  			filename, c->u->u_name,
! 			0,
  			a->a_lnotab);
   error:
--- 2351,2355 ----
  			nil, nil,
  			filename, c->u->u_name,
! 			a->a_firstlineno,
  			a->a_lnotab);
   error:
***************
*** 2366,2369 ****
--- 2386,2390 ----
  		goto error;
  
+ 	a.a_firstlineno = -1;
  	/* Emit code in reverse postorder from dfs. */
  	for (i = a.a_nblocks - 1; i >= 0; i--) {
***************
*** 2374,2377 ****
--- 2395,2402 ----
  			b->b_next);
  		for (j = 0; j < b->b_iused; j++) {
+ 			if (a.a_firstlineno < 0) {
+ 				a.a_firstlineno = b->b_instr[0].i_lineno;
+ 				a.a_lineno = a.a_firstlineno;
+ 			}
  			if (!assemble_emit(&a, &b->b_instr[j]))
  				goto error;