[Python-checkins] python/dist/src/Python newcompile.c,1.1.2.16,1.1.2.17

jhylton@users.sourceforge.net jhylton@users.sourceforge.net
Sun, 16 Feb 2003 20:31:30 -0800


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

Modified Files:
      Tag: ast-branch
	newcompile.c 
Log Message:
Add code generation for Compare().


Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.16
retrieving revision 1.1.2.17
diff -C2 -d -r1.1.2.16 -r1.1.2.17
*** newcompile.c	21 Oct 2002 22:36:16 -0000	1.1.2.16
--- newcompile.c	17 Feb 2003 04:31:27 -0000	1.1.2.17
***************
*** 38,42 ****
  	int u_nalloc;
  	int u_curblock;
- 	struct basicblock u_entry;
  	struct basicblock u_exit;
  	struct basicblock **u_blocks;
--- 38,41 ----
***************
*** 1061,1064 ****
--- 1060,1099 ----
  	return 1;
  }
+ 
+ static int
+ compiler_compare(struct compiler *c, expr_ty e)
+ {
+ 	int i, n, cleanup;
+ 
+ 	VISIT(c, expr, e->v.Compare.left);
+ 	n = asdl_seq_LEN(e->v.Compare.ops);
+ 	if (n > 1)
+ 		cleanup = compiler_new_block(c);
+ 	for (i = 1; i < n; i++) {
+ 		ADDOP(c, DUP_TOP);
+ 		ADDOP(c, ROT_THREE);
+ 		ADDOP_I(c, COMPARE_OP, 
+ 			asdl_seq_GET(e->v.Compare.ops, i - 1));
+ 		ADDOP_JREL(c, JUMP_IF_FALSE, cleanup);
+ 		NEXT_BLOCK(c);
+ 		ADDOP(c, POP_TOP);
+ 	} 
+ 	if (n) {
+ 		VISIT(c, expr, asdl_seq_GET(e->v.Compare.comparators, n - 1));
+ 		ADDOP_I(c, COMPARE_OP,
+ 		       (cmpop_ty)asdl_seq_GET(e->v.Compare.ops, n - 1));
+ 	}
+ 	if (n > 1) {
+ 		int end = compiler_new_block(c);
+ 		ADDOP_JREL(c, JUMP_FORWARD, end);
+ 		compiler_use_block(c, cleanup);
+ 		ADDOP(c, ROT_TWO);
+ 		ADDOP(c, POP_TOP);
+ 		compiler_use_block(c, end);
+ 	}
+ 	return 1;
+ }	
+ 
+ 
  	
  static int 
***************
*** 1099,1102 ****
--- 1134,1138 ----
  		break;
          case Compare_kind:
+ 		return compiler_compare(c, e);
  		break;
          case Call_kind:
***************
*** 1627,1629 ****
  	"CALL_FUNCTION_VAR_KW",
  	"EXTENDED_ARG",
! };    
--- 1663,1666 ----
  	"CALL_FUNCTION_VAR_KW",
  	"EXTENDED_ARG",
! };
!