* Improve readability and remove data dependencies by converting

pre-increment forms to post-increment forms.  Post-incrementing
also eliminates the need for negative array indices for oparg fetches.

* In exception handling code, check for class based exceptions before
  the older string based exceptions.
This commit is contained in:
Raymond Hettinger 2004-04-07 13:17:27 +00:00
parent 467a698bd2
commit d3b836d202
1 changed files with 18 additions and 14 deletions

View File

@ -625,7 +625,8 @@ eval_frame(PyFrameObject *f)
#define INSTR_OFFSET() (next_instr - first_instr) #define INSTR_OFFSET() (next_instr - first_instr)
#define NEXTOP() (*next_instr++) #define NEXTOP() (*next_instr++)
#define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2]) #define OPARG() (next_instr[0] + (next_instr[1]<<8))
#define SKIPARG() (next_instr += 2)
#define JUMPTO(x) (next_instr = first_instr + (x)) #define JUMPTO(x) (next_instr = first_instr + (x))
#define JUMPBY(x) (next_instr += (x)) #define JUMPBY(x) (next_instr += (x))
@ -861,8 +862,10 @@ eval_frame(PyFrameObject *f)
/* Extract opcode and argument */ /* Extract opcode and argument */
opcode = NEXTOP(); opcode = NEXTOP();
if (HAS_ARG(opcode)) if (HAS_ARG(opcode)) {
oparg = NEXTARG(); oparg = OPARG();
SKIPARG();
}
dispatch_opcode: dispatch_opcode:
#ifdef DYNAMIC_EXECUTION_PROFILE #ifdef DYNAMIC_EXECUTION_PROFILE
#ifdef DXPAIRS #ifdef DXPAIRS
@ -1653,7 +1656,7 @@ eval_frame(PyFrameObject *f)
if (why & (WHY_RETURN | WHY_CONTINUE)) if (why & (WHY_RETURN | WHY_CONTINUE))
retval = POP(); retval = POP();
} }
else if (PyString_Check(v) || PyClass_Check(v)) { else if (PyClass_Check(v) || PyString_Check(v)) {
w = POP(); w = POP();
u = POP(); u = POP();
PyErr_Restore(v, w, u); PyErr_Restore(v, w, u);
@ -1892,7 +1895,7 @@ eval_frame(PyFrameObject *f)
case BUILD_TUPLE: case BUILD_TUPLE:
x = PyTuple_New(oparg); x = PyTuple_New(oparg);
if (x != NULL) { if (x != NULL) {
for (; --oparg >= 0;) { while (oparg--) {
w = POP(); w = POP();
PyTuple_SET_ITEM(x, oparg, w); PyTuple_SET_ITEM(x, oparg, w);
} }
@ -1904,7 +1907,7 @@ eval_frame(PyFrameObject *f)
case BUILD_LIST: case BUILD_LIST:
x = PyList_New(oparg); x = PyList_New(oparg);
if (x != NULL) { if (x != NULL) {
for (; --oparg >= 0;) { while (oparg--) {
w = POP(); w = POP();
PyList_SET_ITEM(x, oparg, w); PyList_SET_ITEM(x, oparg, w);
} }
@ -2176,7 +2179,7 @@ eval_frame(PyFrameObject *f)
x = NULL; x = NULL;
break; break;
} }
while (--oparg >= 0) { while (oparg--) {
w = POP(); w = POP();
PyTuple_SET_ITEM(v, oparg, w); PyTuple_SET_ITEM(v, oparg, w);
} }
@ -2201,7 +2204,7 @@ eval_frame(PyFrameObject *f)
x = NULL; x = NULL;
break; break;
} }
while (--nfree >= 0) { while (nfree--) {
w = POP(); w = POP();
PyTuple_SET_ITEM(v, nfree, w); PyTuple_SET_ITEM(v, nfree, w);
} }
@ -2215,7 +2218,7 @@ eval_frame(PyFrameObject *f)
x = NULL; x = NULL;
break; break;
} }
while (--oparg >= 0) { while (oparg--) {
w = POP(); w = POP();
PyTuple_SET_ITEM(v, oparg, w); PyTuple_SET_ITEM(v, oparg, w);
} }
@ -2243,7 +2246,8 @@ eval_frame(PyFrameObject *f)
case EXTENDED_ARG: case EXTENDED_ARG:
opcode = NEXTOP(); opcode = NEXTOP();
oparg = oparg<<16 | NEXTARG(); oparg = oparg<<16 | OPARG();
SKIPARG();
goto dispatch_opcode; goto dispatch_opcode;
default: default:
@ -3192,7 +3196,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
} }
if (size > 0) { if (size > 0) {
while (--size >= 0) { while (size--) {
addr += *p++; addr += *p++;
if (*p++) if (*p++)
break; break;
@ -3607,7 +3611,7 @@ update_keyword_args(PyObject *orig_kwdict, int nk, PyObject ***pp_stack,
} }
if (kwdict == NULL) if (kwdict == NULL)
return NULL; return NULL;
while (--nk >= 0) { while (nk--) {
int err; int err;
PyObject *value = EXT_POP(*pp_stack); PyObject *value = EXT_POP(*pp_stack);
PyObject *key = EXT_POP(*pp_stack); PyObject *key = EXT_POP(*pp_stack);
@ -3652,7 +3656,7 @@ update_star_args(int nstack, int nstar, PyObject *stararg,
PyTuple_SET_ITEM(callargs, nstack + i, a); PyTuple_SET_ITEM(callargs, nstack + i, a);
} }
} }
while (--nstack >= 0) { while (nstack--) {
w = EXT_POP(*pp_stack); w = EXT_POP(*pp_stack);
PyTuple_SET_ITEM(callargs, nstack, w); PyTuple_SET_ITEM(callargs, nstack, w);
} }
@ -3667,7 +3671,7 @@ load_args(PyObject ***pp_stack, int na)
if (args == NULL) if (args == NULL)
return NULL; return NULL;
while (--na >= 0) { while (na--) {
w = EXT_POP(*pp_stack); w = EXT_POP(*pp_stack);
PyTuple_SET_ITEM(args, na, w); PyTuple_SET_ITEM(args, na, w);
} }