[Python-checkins] CVS: python/dist/src/Python ceval.c,2.193,2.194 compile.c,2.132,2.133

Fred L. Drake python-dev@python.org
Wed, 23 Aug 2000 17:32:12 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory slayer.i.sourceforge.net:/tmp/cvs-serv19656/Python

Modified Files:
	ceval.c compile.c 
Log Message:

Charles G. Waldman <cgw@fnal.gov>:
Add the EXTENDED_ARG opcode to the virtual machine, allowing 32-bit
arguments to opcodes instead of being forced to stick to the 16-bit
limit.  This is especially useful for machine-generated code, which
can be too long for the SET_LINENO parameter to fit into 16 bits.

This closes the implementation portion of SourceForge patch #100893.


Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.193
retrieving revision 2.194
diff -C2 -r2.193 -r2.194
*** ceval.c	2000/08/21 15:44:01	2.193
--- ceval.c	2000/08/24 00:32:09	2.194
***************
*** 614,617 ****
--- 614,618 ----
  		if (HAS_ARG(opcode))
  			oparg = NEXTARG();
+ 	  dispatch_opcode:
  #ifdef DYNAMIC_EXECUTION_PROFILE
  #ifdef DXPAIRS
***************
*** 1751,1754 ****
--- 1752,1760 ----
  			break;
  
+ 		case EXTENDED_ARG:
+ 			opcode = NEXTOP();
+ 			oparg = oparg<<16 | NEXTARG();
+ 			goto dispatch_opcode;
+ 			break;
  
  		default:

Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.132
retrieving revision 2.133
diff -C2 -r2.132 -r2.133
*** compile.c	2000/08/22 02:43:07	2.132
--- compile.c	2000/08/24 00:32:09	2.133
***************
*** 37,40 ****
--- 37,43 ----
  #include <limits.h>
  #endif
+ #ifndef INT_MAX
+ #define INT_MAX 2147483647
+ #endif
  
  /* Three symbols from graminit.h are also defined in Python.h, with
***************
*** 573,576 ****
--- 576,580 ----
  com_addoparg(struct compiling *c, int op, int arg)
  {
+ 	int extended_arg = arg >> 16;
  	if (op == SET_LINENO) {
  		com_set_lineno(c, arg);
***************
*** 578,581 ****
--- 582,590 ----
  			return;
  	}
+ 	if (extended_arg){
+ 		com_addbyte(c, EXTENDED_ARG);
+ 		com_addint(c, extended_arg);
+ 		arg &= 0xffff;
+ 	}
  	com_addbyte(c, op);
  	com_addint(c, arg);
***************
*** 607,611 ****
  		dist = target - (anchor+2);
  		code[anchor] = dist & 0xff;
! 		code[anchor+1] = dist >> 8;
  		if (!prev)
  			break;
--- 616,627 ----
  		dist = target - (anchor+2);
  		code[anchor] = dist & 0xff;
! 		dist >>= 8;
! 		code[anchor+1] = dist;
! 		dist >>= 8;
! 		if (dist) {
! 			com_error(c, PyExc_SystemError,
! 				  "com_backpatch: offset too large");
! 			break;
! 		}
  		if (!prev)
  			break;
***************
*** 3365,3368 ****
--- 3381,3385 ----
  		if (HAS_ARG(opcode))
  			oparg = NEXTARG();
+ 	  dispatch_opcode1:
  		switch (opcode) {
  		case STORE_NAME:
***************
*** 3375,3378 ****
--- 3392,3400 ----
  			c->c_flags &= ~CO_OPTIMIZED;
  			break;
+ 		case EXTENDED_ARG:
+ 			opcode = NEXTOP();
+ 			oparg = oparg<<16 | NEXTARG();
+ 			goto dispatch_opcode1;
+ 			break;
  		}
  	}
***************
*** 3390,3393 ****
--- 3412,3416 ----
  		if (HAS_ARG(opcode))
  			oparg = NEXTARG();
+ 	  dispatch_opcode2:
  		if (opcode == LOAD_NAME ||
  		    opcode == STORE_NAME ||
***************
*** 3404,3407 ****
--- 3427,3432 ----
  			}
  			i = PyInt_AsLong(v);
+ 			if (i >> 16) /* too big for 2 bytes */
+ 				continue;
  			switch (opcode) {
  			case LOAD_NAME: cur_instr[0] = LOAD_FAST; break;
***************
*** 3410,3414 ****
  			}
  			cur_instr[1] = i & 0xff;
! 			cur_instr[2] = (i>>8) & 0xff;
  		}
  	}
--- 3435,3444 ----
  			}
  			cur_instr[1] = i & 0xff;
! 			cur_instr[2] = i >> 8;
! 		}
! 		if (opcode == EXTENDED_ARG) {
! 			opcode = NEXTOP();
! 			oparg = oparg<<16 | NEXTARG();
! 			goto dispatch_opcode2;
  		}
  	}