diff -urw cpython-8122deb904e1-old/Include/opcode.h cpython-8122deb904e1/Include/opcode.h --- cpython-8122deb904e1-old/Include/opcode.h 2010-07-04 13:07:10.668582342 +0000 +++ cpython-8122deb904e1/Include/opcode.h 2010-07-05 00:49:02.199038120 +0000 @@ -11,20 +11,24 @@ #define POP_TOP 1 #define ROT_TWO 2 #define ROT_THREE 3 -#define DUP_TOP 4 -#define ROT_FOUR 5 +#define ROT_THREE_TWO 4 +#define DUP_TOP 5 +#define DUP_TOP_TWO 6 +#define DUP_ROT_THREE 7 #define NOP 9 #define UNARY_POSITIVE 10 #define UNARY_NEGATIVE 11 #define UNARY_NOT 12 - -#define UNARY_INVERT 15 - -#define BINARY_POWER 19 - -#define BINARY_MULTIPLY 20 - +#define UNARY_INVERT 13 +#define BINARY_IN 14 /* peephole relies on NOT x == x^1 */ +#define BINARY_NOT_IN 15 /* "" */ +#define BINARY_IS 16 /* "" */ +#define BINARY_IS_NOT 17 /* "" */ + +#define BINARY_EXC_MATCH 19 +#define BINARY_POWER 20 +#define BINARY_MULTIPLY 21 #define BINARY_MODULO 22 #define BINARY_ADD 23 #define BINARY_SUBTRACT 24 @@ -42,7 +46,6 @@ #define INPLACE_MODULO 59 #define STORE_SUBSCR 60 #define DELETE_SUBSCR 61 - #define BINARY_LSHIFT 62 #define BINARY_RSHIFT 63 #define BINARY_AND 64 @@ -78,7 +81,6 @@ #define FOR_ITER 93 #define UNPACK_EX 94 /* Num items before variable part + (Num items after variable part << 8) */ - #define STORE_ATTR 95 /* Index in name list */ #define DELETE_ATTR 96 /* "" */ #define STORE_GLOBAL 97 /* "" */ @@ -147,8 +149,7 @@ #define EXCEPT_HANDLER 257 -enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, PyCmp_GT=Py_GT, PyCmp_GE=Py_GE, - PyCmp_IN, PyCmp_NOT_IN, PyCmp_IS, PyCmp_IS_NOT, PyCmp_EXC_MATCH, PyCmp_BAD}; +enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, PyCmp_GT=Py_GT, PyCmp_GE=Py_GE, PyCmp_BAD}; #define HAS_ARG(op) ((op) >= HAVE_ARGUMENT) diff -urw cpython-8122deb904e1-old/Lib/opcode.py cpython-8122deb904e1/Lib/opcode.py --- cpython-8122deb904e1-old/Lib/opcode.py 2010-07-04 13:07:10.947457526 +0000 +++ cpython-8122deb904e1/Lib/opcode.py 2010-07-05 00:49:11.737334731 +0000 @@ -8,8 +8,7 @@ "haslocal", "hascompare", "hasfree", "opname", "opmap", "HAVE_ARGUMENT", "EXTENDED_ARG"] -cmp_op = ('<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is', - 'is not', 'exception match', 'BAD') +cmp_op = ('<', '<=', '==', '!=', '>', '>=', 'BAD') hasconst = [] hasname = [] @@ -47,19 +46,24 @@ def_op('POP_TOP', 1) def_op('ROT_TWO', 2) def_op('ROT_THREE', 3) -def_op('DUP_TOP', 4) -def_op('ROT_FOUR', 5) +def_op('ROT_THREE_TWO', 4) +def_op('DUP_TOP', 5) +def_op('DUP_TOP_TWO', 6) +def_op('DUP_ROT_THREE', 7) def_op('NOP', 9) def_op('UNARY_POSITIVE', 10) def_op('UNARY_NEGATIVE', 11) def_op('UNARY_NOT', 12) - -def_op('UNARY_INVERT', 15) - -def_op('BINARY_POWER', 19) -def_op('BINARY_MULTIPLY', 20) - +def_op('UNARY_INVERT', 13) +def_op('BINARY_IN', 14) # peephole relies on NOT x == x^1 +def_op('BINARY_NOT_IN', 15) # "" +def_op('BINARY_IS', 16) # "" +def_op('BINARY_IS_NOT', 17) # "" + +def_op('BINARY_EXC_MATCH', 19) +def_op('BINARY_POWER', 20) +def_op('BINARY_MULTIPLY', 21) def_op('BINARY_MODULO', 22) def_op('BINARY_ADD', 23) def_op('BINARY_SUBTRACT', 24) Seulement dans cpython-8122deb904e1/Lib/__pycache__: inspect.cpython-32.pyc Seulement dans cpython-8122deb904e1/Lib/__pycache__: pkgutil.cpython-32.pyc Seulement dans cpython-8122deb904e1/Lib/__pycache__: pydoc.cpython-32.pyc Seulement dans cpython-8122deb904e1/Lib/__pycache__: reprlib.cpython-32.pyc Seulement dans cpython-8122deb904e1-old/Parser: asdl.pyc Seulement dans cpython-8122deb904e1-old/Parser: spark.pyc diff -urw cpython-8122deb904e1-old/Python/ceval.c cpython-8122deb904e1/Python/ceval.c --- cpython-8122deb904e1-old/Python/ceval.c 2010-07-04 13:07:10.989840439 +0000 +++ cpython-8122deb904e1/Python/ceval.c 2010-07-05 00:49:39.247334015 +0000 @@ -131,7 +131,6 @@ static int maybe_call_line_trace(Py_tracefunc, PyObject *, PyFrameObject *, int *, int *, int *); -static PyObject * cmp_outcome(int, PyObject *, PyObject *); static PyObject * import_from(PyObject *, PyObject *); static int import_all_from(PyObject *, PyObject *); static void format_exc_check_arg(PyObject *, const char *, PyObject *); @@ -1286,6 +1285,7 @@ fast_next_opcode: f->f_lasti = INSTR_OFFSET(); + f->f_lasti = INSTR_OFFSET(); /* line-by-line tracing support */ @@ -1402,15 +1402,13 @@ SET_THIRD(v); FAST_DISPATCH(); - TARGET(ROT_FOUR) - u = TOP(); - v = SECOND(); - w = THIRD(); - x = FOURTH(); - SET_TOP(v); - SET_SECOND(w); - SET_THIRD(x); - SET_FOURTH(u); + TARGET(ROT_THREE_TWO) + v = TOP(); + w = SECOND(); + x = THIRD(); + SET_TOP(x); + SET_SECOND(v); + SET_THIRD(w); FAST_DISPATCH(); TARGET(DUP_TOP) @@ -1419,8 +1417,7 @@ PUSH(v); FAST_DISPATCH(); - TARGET(DUP_TOPX) - if (oparg == 2) { + TARGET(DUP_TOP_TWO) x = TOP(); Py_INCREF(x); w = SECOND(); @@ -1428,24 +1425,17 @@ STACKADJ(2); SET_TOP(x); SET_SECOND(w); + PREDICT(BINARY_SUBSCR); FAST_DISPATCH(); - } else if (oparg == 3) { - x = TOP(); - Py_INCREF(x); - w = SECOND(); - Py_INCREF(w); - v = THIRD(); + + TARGET(DUP_ROT_THREE) + v = TOP(); Py_INCREF(v); - STACKADJ(3); - SET_TOP(x); - SET_SECOND(w); - SET_THIRD(v); + w = SECOND(); + SET_TOP(w); + SET_SECOND(v); + PUSH(v); FAST_DISPATCH(); - } - Py_FatalError("invalid argument to DUP_TOPX" - " (bytecode corruption?)"); - /* Never returns, so don't bother to set why. */ - break; TARGET(UNARY_POSITIVE) v = TOP(); @@ -1489,6 +1479,108 @@ if (x != NULL) DISPATCH(); break; + TARGET(BINARY_IN) + { + w = POP(); + v = TOP(); + int res = PySequence_Contains(w, v); + if (res < 0){ + Py_DECREF(v); + Py_DECREF(w); + SET_TOP(NULL); + break; + } + x = res ? Py_True : Py_False; + Py_DECREF(v); + Py_DECREF(w); + Py_INCREF(x); + SET_TOP(x); + PREDICT(POP_JUMP_IF_FALSE); + PREDICT(POP_JUMP_IF_TRUE); + DISPATCH(); + } + + TARGET(BINARY_NOT_IN) + { + w = POP(); + v = TOP(); + int res = PySequence_Contains(w, v); + if (res < 0){ + Py_DECREF(v); + Py_DECREF(w); + SET_TOP(NULL); + break; + } + x = res ? Py_False : Py_True; + Py_DECREF(v); + Py_DECREF(w); + Py_INCREF(x); + SET_TOP(x); + PREDICT(POP_JUMP_IF_FALSE); + PREDICT(POP_JUMP_IF_TRUE); + DISPATCH(); + } + + TARGET(BINARY_IS) + w = POP(); + v = TOP(); + x = v == w ? Py_True : Py_False; + Py_DECREF(v); + Py_DECREF(w); + Py_INCREF(x); + SET_TOP(x); + PREDICT(POP_JUMP_IF_FALSE); + PREDICT(POP_JUMP_IF_TRUE); + FAST_DISPATCH(); + + TARGET(BINARY_IS_NOT) + w = POP(); + v = TOP(); + x = v != w ? Py_True : Py_False; + Py_DECREF(v); + Py_DECREF(w); + Py_INCREF(x); + SET_TOP(x); + PREDICT(POP_JUMP_IF_FALSE); + PREDICT(POP_JUMP_IF_TRUE); + FAST_DISPATCH(); + + TARGET(BINARY_EXC_MATCH) + w = POP(); + v = TOP(); + if (PyTuple_Check(w)) { + Py_ssize_t i, length; + length = PyTuple_Size(w); + for (i = 0; i < length; i += 1) { + PyObject *exc = PyTuple_GET_ITEM(w, i); + if (!PyExceptionClass_Check(exc)) { + PyErr_SetString(PyExc_TypeError, + "catching classes that do not inherit from BaseException is not allowed"); + Py_DECREF(v); + Py_DECREF(w); + SET_TOP(NULL); + break; + } + } + } + else { + if (!PyExceptionClass_Check(w)) { + PyErr_SetString(PyExc_TypeError, + "catching classes that do not inherit from BaseException is not allowed"); + Py_DECREF(v); + Py_DECREF(w); + SET_TOP(NULL); + break; + } + } + x = PyErr_GivenExceptionMatches(v, w)? Py_True : Py_False; + Py_DECREF(v); + Py_DECREF(w); + Py_INCREF(x); + SET_TOP(x); + PREDICT(POP_JUMP_IF_FALSE); + DISPATCH(); + TARGET(BINARY_POWER) w = POP(); v = TOP(); @@ -1571,6 +1663,7 @@ if (x != NULL) DISPATCH(); break; + PREDICTED(BINARY_SUBSCR); TARGET(BINARY_SUBSCR) w = POP(); v = TOP(); @@ -2281,7 +2374,7 @@ TARGET(COMPARE_OP) w = POP(); v = TOP(); - x = cmp_outcome(oparg, v, w); + x = PyObject_RichCompare(v, w, oparg); Py_DECREF(v); Py_DECREF(w); SET_TOP(x); @@ -4221,61 +4314,6 @@ return 1; } -#define CANNOT_CATCH_MSG "catching classes that do not inherit from "\ - "BaseException is not allowed" - -static PyObject * -cmp_outcome(int op, register PyObject *v, register PyObject *w) -{ - int res = 0; - switch (op) { - case PyCmp_IS: - res = (v == w); - break; - case PyCmp_IS_NOT: - res = (v != w); - break; - case PyCmp_IN: - res = PySequence_Contains(w, v); - if (res < 0) - return NULL; - break; - case PyCmp_NOT_IN: - res = PySequence_Contains(w, v); - if (res < 0) - return NULL; - res = !res; - break; - case PyCmp_EXC_MATCH: - if (PyTuple_Check(w)) { - Py_ssize_t i, length; - length = PyTuple_Size(w); - for (i = 0; i < length; i += 1) { - PyObject *exc = PyTuple_GET_ITEM(w, i); - if (!PyExceptionClass_Check(exc)) { - PyErr_SetString(PyExc_TypeError, - CANNOT_CATCH_MSG); - return NULL; - } - } - } - else { - if (!PyExceptionClass_Check(w)) { - PyErr_SetString(PyExc_TypeError, - CANNOT_CATCH_MSG); - return NULL; - } - } - res = PyErr_GivenExceptionMatches(v, w); - break; - default: - return PyObject_RichCompare(v, w, op); - } - v = res ? Py_True : Py_False; - Py_INCREF(v); - return v; -} - static PyObject * import_from(PyObject *v, PyObject *name) { diff -urw cpython-8122deb904e1-old/Python/compile.c cpython-8122deb904e1/Python/compile.c --- cpython-8122deb904e1-old/Python/compile.c 2010-07-04 13:07:10.979840451 +0000 +++ cpython-8122deb904e1/Python/compile.c 2010-07-05 00:47:02.128597850 +0000 @@ -677,11 +677,14 @@ return -1; case ROT_TWO: case ROT_THREE: + case ROT_THREE_TWO: return 0; case DUP_TOP: return 1; - case ROT_FOUR: - return 0; + case DUP_TOP2: + return 2; + case DUP_ROT_THREE: + return 1; case UNARY_POSITIVE: case UNARY_NEGATIVE: @@ -694,7 +697,11 @@ return -1; case MAP_ADD: return -2; - + case BINARY_IN: + case BINARY_NOT_IN: + case BINARY_IS: + case BINARY_IS_NOT: + case BINARY_EXC_MATCH: case BINARY_POWER: case BINARY_MULTIPLY: case BINARY_MODULO: @@ -782,8 +789,6 @@ return -1; case DELETE_GLOBAL: return 0; - case DUP_TOPX: - return oparg; case LOAD_CONST: return 1; case LOAD_NAME: @@ -1919,7 +1924,7 @@ [tb, val, exc] L1: DUP ) [tb, val, exc, exc] ) - [tb, val, exc, exc, E1] COMPARE_OP EXC_MATCH ) only if E1 + [tb, val, exc, exc, E1] BINARY_EXC_MATCH ) only if E1 [tb, val, exc, 1-or-0] POP_JUMP_IF_FALSE L2 ) [tb, val, exc] POP [tb, val] (or POP if no V1) @@ -1971,7 +1976,7 @@ if (handler->v.ExceptHandler.type) { ADDOP(c, DUP_TOP); VISIT(c, expr, handler->v.ExceptHandler.type); - ADDOP_I(c, COMPARE_OP, PyCmp_EXC_MATCH); + ADDOP(c, BINARY_EXC_MATCH); ADDOP_JABS(c, POP_JUMP_IF_FALSE, except); } ADDOP(c, POP_TOP); @@ -2407,13 +2412,13 @@ case GtE: return PyCmp_GE; case Is: - return PyCmp_IS; + return -BINARY_IS; case IsNot: - return PyCmp_IS_NOT; + return -BINARY_IS_NOT; case In: - return PyCmp_IN; + return -BINARY_IN; case NotIn: - return PyCmp_NOT_IN; + return -BINARY_NOT_IN; default: return PyCmp_BAD; } @@ -2675,7 +2680,7 @@ static int compiler_compare(struct compiler *c, expr_ty e) { - int i, n; + int i, n, t; basicblock *cleanup = NULL; /* XXX the logic can be cleaned up for 1 or multiple comparisons */ @@ -2690,11 +2695,13 @@ (expr_ty)asdl_seq_GET(e->v.Compare.comparators, 0)); } for (i = 1; i < n; i++) { - ADDOP(c, DUP_TOP); - ADDOP(c, ROT_THREE); - ADDOP_I(c, COMPARE_OP, - cmpop((cmpop_ty)(asdl_seq_GET( - e->v.Compare.ops, i - 1)))); + ADDOP(c, DUP_ROT_THREE); + t = cmpop((cmpop_ty)(asdl_seq_GET(e->v.Compare.ops, i - 1))); + if (t >= 0) { + ADDOP_I(c, COMPARE_OP, t); + } else { + ADDOP(c, -t); + } ADDOP_JABS(c, JUMP_IF_FALSE_OR_POP, cleanup); NEXT_BLOCK(c); if (i < (n - 1)) @@ -2702,8 +2709,12 @@ (expr_ty)asdl_seq_GET(e->v.Compare.comparators, i)); } VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Compare.comparators, n - 1)); - ADDOP_I(c, COMPARE_OP, - cmpop((cmpop_ty)(asdl_seq_GET(e->v.Compare.ops, n - 1)))); + t = cmpop((cmpop_ty)(asdl_seq_GET(e->v.Compare.ops, n - 1))); + if(t >= 0) { + ADDOP_I(c, COMPARE_OP, t); + } else { + ADDOP(c, -t); + } if (n > 1) { basicblock *end = compiler_new_block(c); if (end == NULL) @@ -3404,7 +3415,7 @@ return 0; } if (ctx == AugLoad) { - ADDOP_I(c, DUP_TOPX, 2); + ADDOP(c, DUP_TOP_TWO); } else if (ctx == AugStore) { ADDOP(c, ROT_THREE); diff -urw cpython-8122deb904e1-old/Python/opcode_targets.h cpython-8122deb904e1/Python/opcode_targets.h --- cpython-8122deb904e1-old/Python/opcode_targets.h 2010-07-04 15:29:09.429845926 +0000 +++ cpython-8122deb904e1/Python/opcode_targets.h 2010-07-05 00:52:59.759845214 +0000 @@ -3,24 +3,24 @@ &&TARGET_POP_TOP, &&TARGET_ROT_TWO, &&TARGET_ROT_THREE, + &&TARGET_ROT_THREE_TWO, &&TARGET_DUP_TOP, - &&TARGET_ROT_FOUR, - &&_unknown_opcode, - &&_unknown_opcode, + &&TARGET_DUP_TOP_TWO, + &&TARGET_DUP_ROT_THREE, &&_unknown_opcode, &&TARGET_NOP, &&TARGET_UNARY_POSITIVE, &&TARGET_UNARY_NEGATIVE, &&TARGET_UNARY_NOT, - &&_unknown_opcode, - &&_unknown_opcode, &&TARGET_UNARY_INVERT, + &&TARGET_BINARY_IN, + &&TARGET_BINARY_NOT_IN, + &&TARGET_BINARY_IS, + &&TARGET_BINARY_IS_NOT, &&_unknown_opcode, - &&_unknown_opcode, - &&_unknown_opcode, + &&TARGET_BINARY_EXC_MATCH, &&TARGET_BINARY_POWER, &&TARGET_BINARY_MULTIPLY, - &&_unknown_opcode, &&TARGET_BINARY_MODULO, &&TARGET_BINARY_ADD, &&TARGET_BINARY_SUBTRACT, diff -urw cpython-8122deb904e1-old/Python/peephole.c cpython-8122deb904e1/Python/peephole.c --- cpython-8122deb904e1-old/Python/peephole.c 2010-07-04 13:07:10.989840439 +0000 +++ cpython-8122deb904e1/Python/peephole.c 2010-07-05 00:48:29.991082438 +0000 @@ -315,7 +315,7 @@ to be appended. To keep the optimizer simple, it bails out (does nothing) for code that - has a length over 32,700, and does not calculate extended arguments. + has a length over 32,767, and does not calculate extended arguments. That allows us to avoid overflow and sign issues. Likewise, it bails when the lineno table has complex encoding for gaps >= 255. EXTENDED_ARG can appear before MAKE_FUNCTION; in this case both opcodes are skipped. @@ -356,7 +356,7 @@ /* Avoid situations where jump retargeting could overflow */ assert(PyBytes_Check(code)); codelen = PyBytes_GET_SIZE(code); - if (codelen > 32700) + if (codelen&~0x7FFF) goto exitUnchanged; /* Make a modifiable copy of the code string */ @@ -409,14 +409,15 @@ not a is not b --> a is b not a not in b --> a in b */ - case COMPARE_OP: - j = GETARG(codestr, i); - if (j < 6 || j > 9 || - codestr[i+3] != UNARY_NOT || - !ISBASICBLOCK(blocks,i,4)) + case BINARY_IN: + case BINARY_NOT_IN: + case BINARY_IS: + case BINARY_IS_NOT: + if (!ISBASICBLOCK(blocks,i,2) || + codestr[i+1]!=UNARY_NOT) continue; - SETARG(codestr, i, (j^1)); - codestr[i+3] = NOP; + codestr[i] ^= 1; + codestr[i+1] = NOP; break; /* Replace LOAD_GLOBAL/LOAD_NAME None/True/False @@ -462,10 +463,8 @@ ((opcode == BUILD_TUPLE && ISBASICBLOCK(blocks, h, 3*(j+1))) || ((opcode == BUILD_LIST || opcode == BUILD_SET) && - codestr[i+3]==COMPARE_OP && - ISBASICBLOCK(blocks, h, 3*(j+2)) && - (GETARG(codestr,i+3)==6 || - GETARG(codestr,i+3)==7))) && + (codestr[i+3]==BINARY_IN || codestr[i+3]==BINARY_NOT_IN) && + ISBASICBLOCK(blocks, h, 3*j+4))) && tuple_of_constants(&codestr[h], j, consts)) { assert(codestr[i] == LOAD_CONST); cumlc = 1; @@ -481,9 +480,8 @@ codestr[i] = ROT_TWO; memset(codestr+i+1, NOP, 5); } else if (j == 3) { - codestr[i] = ROT_THREE; - codestr[i+1] = ROT_TWO; - memset(codestr+i+2, NOP, 4); + codestr[i] = ROT_THREE_TWO; + memset(codestr+i+1, NOP, 5); } break;