Mercurial > cpython-lru_cache-weakref
annotate Python/peephole.c @ 58689:514b56efd89a 3.1
Merged revisions 77962 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r77962 | r.david.murray | 2010-02-04 11:41:57 -0500 (Thu, 04 Feb 2010) | 17 lines
Merged revisions 77943,77959-77960 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77943 | r.david.murray | 2010-02-03 08:36:23 -0500 (Wed, 03 Feb 2010) | 2 lines
Explicitly mention the default value for formatdate's usegmt parameter.
........
r77959 | nick.coghlan | 2010-02-04 07:43:58 -0500 (Thu, 04 Feb 2010) | 1 line
Issue 6760: Clarify args handling for subprocess.Popen. Patch by Chris Rebert
........
r77960 | r.david.murray | 2010-02-04 11:33:31 -0500 (Thu, 04 Feb 2010) | 2 lines
Add Chris Rebert to ACKS for issue 6760 Popen doc improvements.
........
................
| author | R. David Murray <rdmurray@bitdance.com> |
|---|---|
| date | Thu, 04 Feb 2010 16:44:31 +0000 |
| parents | 9d40586a6afc |
| children | f197407bdba2 |
| rev | line source |
|---|---|
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40943
diff
changeset
|
1 /* Peephole optimizations for bytecode compiler. */ |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
2 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
3 #include "Python.h" |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
4 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
5 #include "Python-ast.h" |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
6 #include "node.h" |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
7 #include "pyarena.h" |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
8 #include "ast.h" |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
9 #include "code.h" |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
10 #include "compile.h" |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
11 #include "symtable.h" |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
12 #include "opcode.h" |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
13 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
14 #define GETARG(arr, i) ((int)((arr[i+2]<<8) + arr[i+1])) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
15 #define UNCONDITIONAL_JUMP(op) (op==JUMP_ABSOLUTE || op==JUMP_FORWARD) |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
16 #define CONDITIONAL_JUMP(op) (op==POP_JUMP_IF_FALSE || op==POP_JUMP_IF_TRUE \ |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
17 || op==JUMP_IF_FALSE_OR_POP || op==JUMP_IF_TRUE_OR_POP) |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
18 #define ABSOLUTE_JUMP(op) (op==JUMP_ABSOLUTE || op==CONTINUE_LOOP \ |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
19 || op==POP_JUMP_IF_FALSE || op==POP_JUMP_IF_TRUE \ |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
20 || op==JUMP_IF_FALSE_OR_POP || op==JUMP_IF_TRUE_OR_POP) |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
21 #define JUMPS_ON_TRUE(op) (op==POP_JUMP_IF_TRUE || op==JUMP_IF_TRUE_OR_POP) |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
22 #define GETJUMPTGT(arr, i) (GETARG(arr,i) + (ABSOLUTE_JUMP(arr[i]) ? 0 : i+3)) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
23 #define SETARG(arr, i, val) arr[i+2] = val>>8; arr[i+1] = val & 255 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
24 #define CODESIZE(op) (HAS_ARG(op) ? 3 : 1) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
25 #define ISBASICBLOCK(blocks, start, bytes) \ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
26 (blocks[start]==blocks[start+bytes-1]) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
27 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
28 /* Replace LOAD_CONST c1. LOAD_CONST c2 ... LOAD_CONST cn BUILD_TUPLE n |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
29 with LOAD_CONST (c1, c2, ... cn). |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
30 The consts table must still be in list form so that the |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
31 new constant (c1, c2, ... cn) can be appended. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
32 Called with codestr pointing to the first LOAD_CONST. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
33 Bails out with no change if one or more of the LOAD_CONSTs is missing. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
34 Also works for BUILD_LIST when followed by an "in" or "not in" test. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
35 */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
36 static int |
|
46084
6bea2f1351b1
Merged revisions 61834,61841-61842,61851-61853,61863-61864,61869-61870,61874,61889 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45515
diff
changeset
|
37 tuple_of_constants(unsigned char *codestr, Py_ssize_t n, PyObject *consts) |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
38 { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
39 PyObject *newconst, *constant; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
40 Py_ssize_t i, arg, len_consts; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
41 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
42 /* Pre-conditions */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
43 assert(PyList_CheckExact(consts)); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
44 assert(codestr[n*3] == BUILD_TUPLE || codestr[n*3] == BUILD_LIST); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
45 assert(GETARG(codestr, (n*3)) == n); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
46 for (i=0 ; i<n ; i++) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
47 assert(codestr[i*3] == LOAD_CONST); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
48 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
49 /* Buildup new tuple of constants */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
50 newconst = PyTuple_New(n); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
51 if (newconst == NULL) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
52 return 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
53 len_consts = PyList_GET_SIZE(consts); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
54 for (i=0 ; i<n ; i++) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
55 arg = GETARG(codestr, (i*3)); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
56 assert(arg < len_consts); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
57 constant = PyList_GET_ITEM(consts, arg); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
58 Py_INCREF(constant); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
59 PyTuple_SET_ITEM(newconst, i, constant); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
60 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
61 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
62 /* Append folded constant onto consts */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
63 if (PyList_Append(consts, newconst)) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
64 Py_DECREF(newconst); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
65 return 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
66 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
67 Py_DECREF(newconst); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
68 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
69 /* Write NOPs over old LOAD_CONSTS and |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
70 add a new LOAD_CONST newconst on top of the BUILD_TUPLE n */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
71 memset(codestr, NOP, n*3); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
72 codestr[n*3] = LOAD_CONST; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
73 SETARG(codestr, (n*3), len_consts); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
74 return 1; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
75 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
76 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
77 /* Replace LOAD_CONST c1. LOAD_CONST c2 BINOP |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
78 with LOAD_CONST binop(c1,c2) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
79 The consts table must still be in list form so that the |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
80 new constant can be appended. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
81 Called with codestr pointing to the first LOAD_CONST. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
82 Abandons the transformation if the folding fails (i.e. 1+'a'). |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
83 If the new constant is a sequence, only folds when the size |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
84 is below a threshold value. That keeps pyc files from |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
85 becoming large in the presence of code like: (None,)*1000. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
86 */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
87 static int |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
88 fold_binops_on_constants(unsigned char *codestr, PyObject *consts) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
89 { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
90 PyObject *newconst, *v, *w; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
91 Py_ssize_t len_consts, size; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
92 int opcode; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
93 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
94 /* Pre-conditions */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
95 assert(PyList_CheckExact(consts)); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
96 assert(codestr[0] == LOAD_CONST); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
97 assert(codestr[3] == LOAD_CONST); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
98 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
99 /* Create new constant */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
100 v = PyList_GET_ITEM(consts, GETARG(codestr, 0)); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
101 w = PyList_GET_ITEM(consts, GETARG(codestr, 3)); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
102 opcode = codestr[6]; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
103 switch (opcode) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
104 case BINARY_POWER: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
105 newconst = PyNumber_Power(v, w, Py_None); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
106 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
107 case BINARY_MULTIPLY: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
108 newconst = PyNumber_Multiply(v, w); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
109 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
110 case BINARY_TRUE_DIVIDE: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
111 newconst = PyNumber_TrueDivide(v, w); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
112 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
113 case BINARY_FLOOR_DIVIDE: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
114 newconst = PyNumber_FloorDivide(v, w); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
115 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
116 case BINARY_MODULO: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
117 newconst = PyNumber_Remainder(v, w); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
118 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
119 case BINARY_ADD: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
120 newconst = PyNumber_Add(v, w); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
121 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
122 case BINARY_SUBTRACT: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
123 newconst = PyNumber_Subtract(v, w); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
124 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
125 case BINARY_SUBSCR: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
126 newconst = PyObject_GetItem(v, w); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
127 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
128 case BINARY_LSHIFT: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
129 newconst = PyNumber_Lshift(v, w); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
130 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
131 case BINARY_RSHIFT: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
132 newconst = PyNumber_Rshift(v, w); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
133 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
134 case BINARY_AND: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
135 newconst = PyNumber_And(v, w); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
136 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
137 case BINARY_XOR: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
138 newconst = PyNumber_Xor(v, w); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
139 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
140 case BINARY_OR: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
141 newconst = PyNumber_Or(v, w); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
142 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
143 default: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
144 /* Called with an unknown opcode */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
145 PyErr_Format(PyExc_SystemError, |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
146 "unexpected binary operation %d on a constant", |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
147 opcode); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
148 return 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
149 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
150 if (newconst == NULL) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
151 PyErr_Clear(); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
152 return 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
153 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
154 size = PyObject_Size(newconst); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
155 if (size == -1) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
156 PyErr_Clear(); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
157 else if (size > 20) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
158 Py_DECREF(newconst); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
159 return 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
160 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
161 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
162 /* Append folded constant into consts table */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
163 len_consts = PyList_GET_SIZE(consts); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
164 if (PyList_Append(consts, newconst)) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
165 Py_DECREF(newconst); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
166 return 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
167 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
168 Py_DECREF(newconst); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
169 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
170 /* Write NOP NOP NOP NOP LOAD_CONST newconst */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
171 memset(codestr, NOP, 4); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
172 codestr[4] = LOAD_CONST; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
173 SETARG(codestr, 4, len_consts); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
174 return 1; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
175 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
176 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
177 static int |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
178 fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
179 { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
180 PyObject *newconst=NULL, *v; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
181 Py_ssize_t len_consts; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
182 int opcode; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
183 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
184 /* Pre-conditions */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
185 assert(PyList_CheckExact(consts)); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
186 assert(codestr[0] == LOAD_CONST); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
187 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
188 /* Create new constant */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
189 v = PyList_GET_ITEM(consts, GETARG(codestr, 0)); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
190 opcode = codestr[3]; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
191 switch (opcode) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
192 case UNARY_NEGATIVE: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
193 /* Preserve the sign of -0.0 */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
194 if (PyObject_IsTrue(v) == 1) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
195 newconst = PyNumber_Negative(v); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
196 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
197 case UNARY_INVERT: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
198 newconst = PyNumber_Invert(v); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
199 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
200 default: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
201 /* Called with an unknown opcode */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
202 PyErr_Format(PyExc_SystemError, |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
203 "unexpected unary operation %d on a constant", |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
204 opcode); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
205 return 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
206 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
207 if (newconst == NULL) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
208 PyErr_Clear(); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
209 return 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
210 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
211 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
212 /* Append folded constant into consts table */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
213 len_consts = PyList_GET_SIZE(consts); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
214 if (PyList_Append(consts, newconst)) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
215 Py_DECREF(newconst); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
216 return 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
217 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
218 Py_DECREF(newconst); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
219 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
220 /* Write NOP LOAD_CONST newconst */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
221 codestr[0] = NOP; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
222 codestr[1] = LOAD_CONST; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
223 SETARG(codestr, 1, len_consts); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
224 return 1; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
225 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
226 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
227 static unsigned int * |
|
46084
6bea2f1351b1
Merged revisions 61834,61841-61842,61851-61853,61863-61864,61869-61870,61874,61889 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45515
diff
changeset
|
228 markblocks(unsigned char *code, Py_ssize_t len) |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
229 { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
230 unsigned int *blocks = (unsigned int *)PyMem_Malloc(len*sizeof(int)); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
231 int i,j, opcode, blockcnt = 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
232 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
233 if (blocks == NULL) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
234 PyErr_NoMemory(); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
235 return NULL; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
236 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
237 memset(blocks, 0, len*sizeof(int)); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
238 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
239 /* Mark labels in the first pass */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
240 for (i=0 ; i<len ; i+=CODESIZE(opcode)) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
241 opcode = code[i]; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
242 switch (opcode) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
243 case FOR_ITER: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
244 case JUMP_FORWARD: |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
245 case JUMP_IF_FALSE_OR_POP: |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
246 case JUMP_IF_TRUE_OR_POP: |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
247 case POP_JUMP_IF_FALSE: |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
248 case POP_JUMP_IF_TRUE: |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
249 case JUMP_ABSOLUTE: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
250 case CONTINUE_LOOP: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
251 case SETUP_LOOP: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
252 case SETUP_EXCEPT: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
253 case SETUP_FINALLY: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
254 j = GETJUMPTGT(code, i); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
255 blocks[j] = 1; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
256 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
257 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
258 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
259 /* Build block numbers in the second pass */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
260 for (i=0 ; i<len ; i++) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
261 blockcnt += blocks[i]; /* increment blockcnt over labels */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
262 blocks[i] = blockcnt; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
263 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
264 return blocks; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
265 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
266 |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
267 /* Helper to replace LOAD_NAME None/True/False with LOAD_CONST |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
268 Returns: 0 if no change, 1 if change, -1 if error */ |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
269 static int |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
270 load_global(unsigned char *codestr, Py_ssize_t i, char *name, PyObject *consts) |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
271 { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
272 Py_ssize_t j; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
273 PyObject *obj; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
274 if (name == NULL) |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
275 return 0; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
276 if (strcmp(name, "None") == 0) |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
277 obj = Py_None; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
278 else if (strcmp(name, "True") == 0) |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
279 obj = Py_True; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
280 else if (strcmp(name, "False") == 0) |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
281 obj = Py_False; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
282 else |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
283 return 0; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
284 for (j = 0; j < PyList_GET_SIZE(consts); j++) { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
285 if (PyList_GET_ITEM(consts, j) == obj) |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
286 break; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
287 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
288 if (j == PyList_GET_SIZE(consts)) { |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
289 if (PyList_Append(consts, obj) < 0) |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
290 return -1; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
291 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
292 assert(PyList_GET_ITEM(consts, j) == obj); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
293 codestr[i] = LOAD_CONST; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
294 SETARG(codestr, i, j); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
295 return 1; |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
296 } |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
297 |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
298 /* Perform basic peephole optimizations to components of a code object. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
299 The consts object should still be in list form to allow new constants |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
300 to be appended. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
301 |
|
40943
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
302 To keep the optimizer simple, it bails out (does nothing) for code that |
|
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
303 has a length over 32,700, and does not calculate extended arguments. |
|
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
304 That allows us to avoid overflow and sign issues. Likewise, it bails when |
|
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
305 the lineno table has complex encoding for gaps >= 255. EXTENDED_ARG can |
|
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
306 appear before MAKE_FUNCTION; in this case both opcodes are skipped. |
|
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
307 EXTENDED_ARG preceding any other opcode causes the optimizer to bail. |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
308 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
309 Optimizations are restricted to simple transformations occuring within a |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
310 single basic block. All transformations keep the code size the same or |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
311 smaller. For those that reduce size, the gaps are initially filled with |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
312 NOPs. Later those NOPs are removed and the jump addresses retargeted in |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
313 a single pass. Line numbering is adjusted accordingly. */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
314 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
315 PyObject * |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
316 PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
317 PyObject *lineno_obj) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
318 { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
319 Py_ssize_t i, j, codelen; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
320 int nops, h, adj; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
321 int tgt, tgttgt, opcode; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
322 unsigned char *codestr = NULL; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
323 unsigned char *lineno; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
324 int *addrmap = NULL; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
325 int new_line, cum_orig_line, last_line, tabsiz; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
326 int cumlc=0, lastlc=0; /* Count runs of consecutive LOAD_CONSTs */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
327 unsigned int *blocks = NULL; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
328 char *name; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
329 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
330 /* Bail out if an exception is set */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
331 if (PyErr_Occurred()) |
|
55609
9d40586a6afc
Merged revisions 74126,74130-74131,74149,74155,74157,74180-74183,74398 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51923
diff
changeset
|
332 goto exitError; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
333 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
334 /* Bypass optimization when the lineno table is too complex */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46084
diff
changeset
|
335 assert(PyBytes_Check(lineno_obj)); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46084
diff
changeset
|
336 lineno = (unsigned char*)PyBytes_AS_STRING(lineno_obj); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46084
diff
changeset
|
337 tabsiz = PyBytes_GET_SIZE(lineno_obj); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
338 if (memchr(lineno, 255, tabsiz) != NULL) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
339 goto exitUnchanged; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
340 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
341 /* Avoid situations where jump retargeting could overflow */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46084
diff
changeset
|
342 assert(PyBytes_Check(code)); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46084
diff
changeset
|
343 codelen = PyBytes_GET_SIZE(code); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
344 if (codelen > 32700) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
345 goto exitUnchanged; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
346 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
347 /* Make a modifiable copy of the code string */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
348 codestr = (unsigned char *)PyMem_Malloc(codelen); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
349 if (codestr == NULL) |
|
55609
9d40586a6afc
Merged revisions 74126,74130-74131,74149,74155,74157,74180-74183,74398 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51923
diff
changeset
|
350 goto exitError; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
351 codestr = (unsigned char *)memcpy(codestr, |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46084
diff
changeset
|
352 PyBytes_AS_STRING(code), codelen); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
353 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
354 /* Verify that RETURN_VALUE terminates the codestring. This allows |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
355 the various transformation patterns to look ahead several |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
356 instructions without additional checks to make sure they are not |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
357 looking beyond the end of the code string. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
358 */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
359 if (codestr[codelen-1] != RETURN_VALUE) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
360 goto exitUnchanged; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
361 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
362 /* Mapping to new jump targets after NOPs are removed */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
363 addrmap = (int *)PyMem_Malloc(codelen * sizeof(int)); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
364 if (addrmap == NULL) |
|
55609
9d40586a6afc
Merged revisions 74126,74130-74131,74149,74155,74157,74180-74183,74398 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51923
diff
changeset
|
365 goto exitError; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
366 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
367 blocks = markblocks(codestr, codelen); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
368 if (blocks == NULL) |
|
55609
9d40586a6afc
Merged revisions 74126,74130-74131,74149,74155,74157,74180-74183,74398 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51923
diff
changeset
|
369 goto exitError; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
370 assert(PyList_Check(consts)); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
371 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
372 for (i=0 ; i<codelen ; i += CODESIZE(codestr[i])) { |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
373 reoptimize_current: |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
374 opcode = codestr[i]; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
375 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
376 lastlc = cumlc; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
377 cumlc = 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
378 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
379 switch (opcode) { |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
380 /* Replace UNARY_NOT POP_JUMP_IF_FALSE |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
381 with POP_JUMP_IF_TRUE */ |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
382 case UNARY_NOT: |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
383 if (codestr[i+1] != POP_JUMP_IF_FALSE |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
384 || !ISBASICBLOCK(blocks,i,4)) |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
385 continue; |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
386 j = GETARG(codestr, i+1); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
387 codestr[i] = POP_JUMP_IF_TRUE; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
388 SETARG(codestr, i, j); |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
389 codestr[i+3] = NOP; |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
390 goto reoptimize_current; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
391 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
392 /* not a is b --> a is not b |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
393 not a in b --> a not in b |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
394 not a is not b --> a is b |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
395 not a not in b --> a in b |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
396 */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
397 case COMPARE_OP: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
398 j = GETARG(codestr, i); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
399 if (j < 6 || j > 9 || |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
400 codestr[i+3] != UNARY_NOT || |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
401 !ISBASICBLOCK(blocks,i,4)) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
402 continue; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
403 SETARG(codestr, i, (j^1)); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
404 codestr[i+3] = NOP; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
405 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
406 |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
407 /* Replace LOAD_GLOBAL/LOAD_NAME None/True/False |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
408 with LOAD_CONST None/True/False */ |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
409 case LOAD_NAME: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
410 case LOAD_GLOBAL: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
411 j = GETARG(codestr, i); |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
47301
diff
changeset
|
412 name = _PyUnicode_AsString(PyTuple_GET_ITEM(names, j)); |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
413 h = load_global(codestr, i, name, consts); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
414 if (h < 0) |
|
55609
9d40586a6afc
Merged revisions 74126,74130-74131,74149,74155,74157,74180-74183,74398 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51923
diff
changeset
|
415 goto exitError; |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
416 else if (h == 0) |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
417 continue; |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40943
diff
changeset
|
418 cumlc = lastlc + 1; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
419 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
420 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
421 /* Skip over LOAD_CONST trueconst |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
422 POP_JUMP_IF_FALSE xx. This improves |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
423 "while 1" performance. */ |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
424 case LOAD_CONST: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
425 cumlc = lastlc + 1; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
426 j = GETARG(codestr, i); |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
427 if (codestr[i+3] != POP_JUMP_IF_FALSE || |
|
51923
e1ce666d7405
Fix 2 oversights from r69961.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51853
diff
changeset
|
428 !ISBASICBLOCK(blocks,i,6) || |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
429 !PyObject_IsTrue(PyList_GET_ITEM(consts, j))) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
430 continue; |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
431 memset(codestr+i, NOP, 6); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
432 cumlc = 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
433 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
434 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
435 /* Try to fold tuples of constants (includes a case for lists |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
436 which are only used for "in" and "not in" tests). |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
437 Skip over BUILD_SEQN 1 UNPACK_SEQN 1. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
438 Replace BUILD_SEQN 2 UNPACK_SEQN 2 with ROT2. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
439 Replace BUILD_SEQN 3 UNPACK_SEQN 3 with ROT3 ROT2. */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
440 case BUILD_TUPLE: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
441 case BUILD_LIST: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
442 j = GETARG(codestr, i); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
443 h = i - 3 * j; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
444 if (h >= 0 && |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
445 j <= lastlc && |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
446 ((opcode == BUILD_TUPLE && |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
447 ISBASICBLOCK(blocks, h, 3*(j+1))) || |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
448 (opcode == BUILD_LIST && |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
449 codestr[i+3]==COMPARE_OP && |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
450 ISBASICBLOCK(blocks, h, 3*(j+2)) && |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
451 (GETARG(codestr,i+3)==6 || |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
452 GETARG(codestr,i+3)==7))) && |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
453 tuple_of_constants(&codestr[h], j, consts)) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
454 assert(codestr[i] == LOAD_CONST); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
455 cumlc = 1; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
456 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
457 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
458 if (codestr[i+3] != UNPACK_SEQUENCE || |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
459 !ISBASICBLOCK(blocks,i,6) || |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
460 j != GETARG(codestr, i+3)) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
461 continue; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
462 if (j == 1) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
463 memset(codestr+i, NOP, 6); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
464 } else if (j == 2) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
465 codestr[i] = ROT_TWO; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
466 memset(codestr+i+1, NOP, 5); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
467 } else if (j == 3) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
468 codestr[i] = ROT_THREE; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
469 codestr[i+1] = ROT_TWO; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
470 memset(codestr+i+2, NOP, 4); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
471 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
472 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
473 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
474 /* Fold binary ops on constants. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
475 LOAD_CONST c1 LOAD_CONST c2 BINOP --> LOAD_CONST binop(c1,c2) */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
476 case BINARY_POWER: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
477 case BINARY_MULTIPLY: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
478 case BINARY_TRUE_DIVIDE: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
479 case BINARY_FLOOR_DIVIDE: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
480 case BINARY_MODULO: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
481 case BINARY_ADD: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
482 case BINARY_SUBTRACT: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
483 case BINARY_SUBSCR: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
484 case BINARY_LSHIFT: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
485 case BINARY_RSHIFT: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
486 case BINARY_AND: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
487 case BINARY_XOR: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
488 case BINARY_OR: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
489 if (lastlc >= 2 && |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
490 ISBASICBLOCK(blocks, i-6, 7) && |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
491 fold_binops_on_constants(&codestr[i-6], consts)) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
492 i -= 2; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
493 assert(codestr[i] == LOAD_CONST); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
494 cumlc = 1; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
495 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
496 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
497 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
498 /* Fold unary ops on constants. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
499 LOAD_CONST c1 UNARY_OP --> LOAD_CONST unary_op(c) */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
500 case UNARY_NEGATIVE: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
501 case UNARY_INVERT: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
502 if (lastlc >= 1 && |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
503 ISBASICBLOCK(blocks, i-3, 4) && |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
504 fold_unaryops_on_constants(&codestr[i-3], consts)) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
505 i -= 2; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
506 assert(codestr[i] == LOAD_CONST); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
507 cumlc = 1; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
508 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
509 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
510 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
511 /* Simplify conditional jump to conditional jump where the |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
512 result of the first test implies the success of a similar |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
513 test or the failure of the opposite test. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
514 Arises in code like: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
515 "if a and b:" |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
516 "if a or b:" |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
517 "a and b or c" |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
518 "(a and b) and c" |
|
51923
e1ce666d7405
Fix 2 oversights from r69961.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51853
diff
changeset
|
519 x:JUMP_IF_FALSE_OR_POP y y:JUMP_IF_FALSE_OR_POP z |
|
e1ce666d7405
Fix 2 oversights from r69961.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51853
diff
changeset
|
520 --> x:JUMP_IF_FALSE_OR_POP z |
|
e1ce666d7405
Fix 2 oversights from r69961.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51853
diff
changeset
|
521 x:JUMP_IF_FALSE_OR_POP y y:JUMP_IF_TRUE_OR_POP z |
|
e1ce666d7405
Fix 2 oversights from r69961.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
51853
diff
changeset
|
522 --> x:POP_JUMP_IF_FALSE y+3 |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
523 where y+3 is the instruction following the second test. |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
524 */ |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
525 case JUMP_IF_FALSE_OR_POP: |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
526 case JUMP_IF_TRUE_OR_POP: |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
527 tgt = GETJUMPTGT(codestr, i); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
528 j = codestr[tgt]; |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
529 if (CONDITIONAL_JUMP(j)) { |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
530 /* NOTE: all possible jumps here are |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
531 absolute! */ |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
532 if (JUMPS_ON_TRUE(j) == JUMPS_ON_TRUE(opcode)) { |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
533 /* The second jump will be |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
534 taken iff the first is. */ |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
535 tgttgt = GETJUMPTGT(codestr, tgt); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
536 /* The current opcode inherits |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
537 its target's stack behaviour */ |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
538 codestr[i] = j; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
539 SETARG(codestr, i, tgttgt); |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
540 goto reoptimize_current; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
541 } else { |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
542 /* The second jump is not taken |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
543 if the first is (so jump past |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
544 it), and all conditional |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
545 jumps pop their argument when |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
546 they're not taken (so change |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
547 the first jump to pop its |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
548 argument when it's taken). */ |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
549 if (JUMPS_ON_TRUE(opcode)) |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
550 codestr[i] = POP_JUMP_IF_TRUE; |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
551 else |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
552 codestr[i] = POP_JUMP_IF_FALSE; |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
553 SETARG(codestr, i, (tgt + 3)); |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
554 goto reoptimize_current; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
555 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
556 } |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
557 /* Intentional fallthrough */ |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
558 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
559 /* Replace jumps to unconditional jumps */ |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
560 case POP_JUMP_IF_FALSE: |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
561 case POP_JUMP_IF_TRUE: |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
562 case FOR_ITER: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
563 case JUMP_FORWARD: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
564 case JUMP_ABSOLUTE: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
565 case CONTINUE_LOOP: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
566 case SETUP_LOOP: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
567 case SETUP_EXCEPT: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
568 case SETUP_FINALLY: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
569 tgt = GETJUMPTGT(codestr, i); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
570 /* Replace JUMP_* to a RETURN into just a RETURN */ |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
571 if (UNCONDITIONAL_JUMP(opcode) && |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
572 codestr[tgt] == RETURN_VALUE) { |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
573 codestr[i] = RETURN_VALUE; |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
574 memset(codestr+i+1, NOP, 2); |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
575 continue; |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
576 } |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
577 if (!UNCONDITIONAL_JUMP(codestr[tgt])) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
578 continue; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
579 tgttgt = GETJUMPTGT(codestr, tgt); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
580 if (opcode == JUMP_FORWARD) /* JMP_ABS can go backwards */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
581 opcode = JUMP_ABSOLUTE; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
582 if (!ABSOLUTE_JUMP(opcode)) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
583 tgttgt -= i + 3; /* Calc relative jump addr */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
584 if (tgttgt < 0) /* No backward relative jumps */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
585 continue; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
586 codestr[i] = opcode; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
587 SETARG(codestr, i, tgttgt); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
588 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
589 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
590 case EXTENDED_ARG: |
|
40943
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
591 if (codestr[i+3] != MAKE_FUNCTION) |
|
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
592 goto exitUnchanged; |
|
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
593 /* don't visit MAKE_FUNCTION as GETARG will be wrong */ |
|
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
594 i += 3; |
|
c79e6234fb19
Two more patches by Tony Lownds (SF# 1607548).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
595 break; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
596 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
597 /* Replace RETURN LOAD_CONST None RETURN with just RETURN */ |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
598 /* Remove unreachable JUMPs after RETURN */ |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
599 case RETURN_VALUE: |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
600 if (i+4 >= codelen) |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
601 continue; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
602 if (codestr[i+4] == RETURN_VALUE && |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
603 ISBASICBLOCK(blocks,i,5)) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
604 memset(codestr+i+1, NOP, 4); |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
605 else if (UNCONDITIONAL_JUMP(codestr[i+1]) && |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
606 ISBASICBLOCK(blocks,i,4)) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39678
diff
changeset
|
607 memset(codestr+i+1, NOP, 3); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
608 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
609 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
610 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
611 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
612 /* Fixup linenotab */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
613 for (i=0, nops=0 ; i<codelen ; i += CODESIZE(codestr[i])) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
614 addrmap[i] = i - nops; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
615 if (codestr[i] == NOP) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
616 nops++; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
617 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
618 cum_orig_line = 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
619 last_line = 0; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
620 for (i=0 ; i < tabsiz ; i+=2) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
621 cum_orig_line += lineno[i]; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
622 new_line = addrmap[cum_orig_line]; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
623 assert (new_line - last_line < 255); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
624 lineno[i] =((unsigned char)(new_line - last_line)); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
625 last_line = new_line; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
626 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
627 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
628 /* Remove NOPs and fixup jump targets */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
629 for (i=0, h=0 ; i<codelen ; ) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
630 opcode = codestr[i]; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
631 switch (opcode) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
632 case NOP: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
633 i++; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
634 continue; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
635 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
636 case JUMP_ABSOLUTE: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
637 case CONTINUE_LOOP: |
|
51853
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
638 case POP_JUMP_IF_FALSE: |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
639 case POP_JUMP_IF_TRUE: |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
640 case JUMP_IF_FALSE_OR_POP: |
|
643d8d4fc8eb
http://bugs.python.org/issue4715
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
49747
diff
changeset
|
641 case JUMP_IF_TRUE_OR_POP: |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
642 j = addrmap[GETARG(codestr, i)]; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
643 SETARG(codestr, i, j); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
644 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
645 |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
646 case FOR_ITER: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
647 case JUMP_FORWARD: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
648 case SETUP_LOOP: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
649 case SETUP_EXCEPT: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
650 case SETUP_FINALLY: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
651 j = addrmap[GETARG(codestr, i) + i + 3] - addrmap[i] - 3; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
652 SETARG(codestr, i, j); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
653 break; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
654 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
655 adj = CODESIZE(opcode); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
656 while (adj--) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
657 codestr[h++] = codestr[i++]; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
658 } |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
659 assert(h + nops == codelen); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
660 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
46084
diff
changeset
|
661 code = PyBytes_FromStringAndSize((char *)codestr, h); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
662 PyMem_Free(addrmap); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
663 PyMem_Free(codestr); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
664 PyMem_Free(blocks); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
665 return code; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
666 |
|
55609
9d40586a6afc
Merged revisions 74126,74130-74131,74149,74155,74157,74180-74183,74398 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51923
diff
changeset
|
667 exitError: |
|
9d40586a6afc
Merged revisions 74126,74130-74131,74149,74155,74157,74180-74183,74398 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51923
diff
changeset
|
668 code = NULL; |
|
9d40586a6afc
Merged revisions 74126,74130-74131,74149,74155,74157,74180-74183,74398 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51923
diff
changeset
|
669 |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
670 exitUnchanged: |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
671 if (blocks != NULL) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
672 PyMem_Free(blocks); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
673 if (addrmap != NULL) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
674 PyMem_Free(addrmap); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
675 if (codestr != NULL) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
676 PyMem_Free(codestr); |
|
55609
9d40586a6afc
Merged revisions 74126,74130-74131,74149,74155,74157,74180-74183,74398 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51923
diff
changeset
|
677 Py_XINCREF(code); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
678 return code; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
679 } |
