Index: Include/opcode.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Include/opcode.h,v retrieving revision 2.43 diff -c -r2.43 opcode.h *** Include/opcode.h 24 Apr 2003 05:45:16 -0000 2.43 --- Include/opcode.h 21 Dec 2003 18:09:05 -0000 *************** *** 14,19 **** --- 14,22 ---- #define DUP_TOP 4 #define ROT_FOUR 5 + #define CALL_FUNCTION_0 7 /* #args == 0, no kw args */ + #define CALL_FUNCTION_1 8 /* #args == 1, no kw args */ + #define UNARY_POSITIVE 10 #define UNARY_NEGATIVE 11 #define UNARY_NOT 12 Index: Lib/opcode.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/opcode.py,v retrieving revision 1.3 diff -c -r1.3 opcode.py *** Lib/opcode.py 24 Apr 2003 05:45:17 -0000 1.3 --- Lib/opcode.py 21 Dec 2003 18:09:05 -0000 *************** *** 49,54 **** --- 49,57 ---- def_op('DUP_TOP', 4) def_op('ROT_FOUR', 5) + def_op('CALL_FUNCTION_0', 7) + def_op('CALL_FUNCTION_1', 8) + def_op('UNARY_POSITIVE', 10) def_op('UNARY_NEGATIVE', 11) def_op('UNARY_NOT', 12) Index: Python/ceval.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v retrieving revision 2.373 diff -c -r2.373 ceval.c *** Python/ceval.c 20 Nov 2003 01:44:58 -0000 2.373 --- Python/ceval.c 21 Dec 2003 18:09:10 -0000 *************** *** 580,596 **** #endif PyObject **stack_pointer; /* Next free slot in value stack */ register unsigned char *next_instr; ! register int opcode=0; /* Current opcode */ register int oparg=0; /* Current opcode argument, if any */ ! register enum why_code why; /* Reason for block stack unwind */ ! register int err; /* Error status -- nonzero if error */ register PyObject *x; /* Result object -- NULL if error */ register PyObject *v; /* Temporary objects popped off stack */ register PyObject *w; ! register PyObject *u; ! register PyObject *t; ! register PyObject *stream = NULL; /* for PRINT opcodes */ ! register PyObject **fastlocals, **freevars; PyObject *retval = NULL; /* Return value */ PyThreadState *tstate = PyThreadState_GET(); PyCodeObject *co; --- 580,596 ---- #endif PyObject **stack_pointer; /* Next free slot in value stack */ register unsigned char *next_instr; ! int opcode; /* Current opcode */ register int oparg=0; /* Current opcode argument, if any */ ! enum why_code why; /* Reason for block stack unwind */ ! int err; /* Error status -- nonzero if error */ register PyObject *x; /* Result object -- NULL if error */ register PyObject *v; /* Temporary objects popped off stack */ register PyObject *w; ! PyObject *u; ! PyObject *t; ! PyObject *stream = NULL; /* for PRINT opcodes */ ! register PyObject **fastlocals; PyObject *retval = NULL; /* Return value */ PyThreadState *tstate = PyThreadState_GET(); PyCodeObject *co; *************** *** 685,690 **** --- 685,691 ---- /* Local variable macros */ #define GETLOCAL(i) (fastlocals[i]) + #define FREEVARS(f) ((f)->f_localsplus + (f)->f_nlocals) /* The SETLOCAL() macro must not DECREF the local variable in-place and then store the new value; it must copy the old value to a temporary *************** *** 744,750 **** names = co->co_names; consts = co->co_consts; fastlocals = f->f_localsplus; - freevars = f->f_localsplus + f->f_nlocals; _PyCode_GETCODEPTR(co, &first_instr); /* An explanation is in order for the next line. --- 745,750 ---- *************** *** 1578,1589 **** #endif case BREAK_LOOP: why = WHY_BREAK; ! break; case CONTINUE_LOOP: retval = PyInt_FromLong(oparg); why = WHY_CONTINUE; ! break; case RAISE_VARARGS: u = v = w = NULL; --- 1578,1589 ---- #endif case BREAK_LOOP: why = WHY_BREAK; ! goto fast_block_end; case CONTINUE_LOOP: retval = PyInt_FromLong(oparg); why = WHY_CONTINUE; ! goto fast_block_end; case RAISE_VARARGS: u = v = w = NULL; *************** *** 1620,1633 **** case RETURN_VALUE: retval = POP(); why = WHY_RETURN; ! break; case YIELD_VALUE: retval = POP(); f->f_stacktop = stack_pointer; why = WHY_YIELD; ! break; ! case EXEC_STMT: w = TOP(); --- 1620,1634 ---- case RETURN_VALUE: retval = POP(); why = WHY_RETURN; ! if (f->f_iblock > 0) ! goto fast_block_end; ! goto fast_return; case YIELD_VALUE: retval = POP(); f->f_stacktop = stack_pointer; why = WHY_YIELD; ! goto fast_yield; case EXEC_STMT: w = TOP(); *************** *** 1729,1748 **** } } } - else if (PyList_CheckExact(v)) { - if (PyList_Size(v) != oparg) { - PyErr_SetString(PyExc_ValueError, - "unpack list of wrong size"); - why = WHY_EXCEPTION; - } - else { - for (; --oparg >= 0; ) { - w = PyList_GET_ITEM(v, oparg); - Py_INCREF(w); - PUSH(w); - } - } - } else if (unpack_iterable(v, oparg, stack_pointer + oparg)) stack_pointer += oparg; --- 1730,1735 ---- *************** *** 1868,1880 **** continue; case LOAD_CLOSURE: ! x = freevars[oparg]; Py_INCREF(x); PUSH(x); break; case LOAD_DEREF: ! x = freevars[oparg]; w = PyCell_Get(x); if (w == NULL) { err = -1; --- 1855,1867 ---- continue; case LOAD_CLOSURE: ! x = FREEVARS(f)[oparg]; Py_INCREF(x); PUSH(x); break; case LOAD_DEREF: ! x = FREEVARS(f)[oparg]; w = PyCell_Get(x); if (w == NULL) { err = -1; *************** *** 1904,1910 **** case STORE_DEREF: w = POP(); ! x = freevars[oparg]; PyCell_Set(x, w); Py_DECREF(w); continue; --- 1891,1897 ---- case STORE_DEREF: w = POP(); ! x = FREEVARS(f)[oparg]; PyCell_Set(x, w); Py_DECREF(w); continue; *************** *** 1980,1986 **** SET_TOP(x); if (x == NULL) break; PREDICT(JUMP_IF_FALSE); - PREDICT(JUMP_IF_TRUE); continue; case IMPORT_NAME: --- 1967,1972 ---- *************** *** 2056,2062 **** break; continue; - PREDICTED_WITH_ARG(JUMP_IF_TRUE); case JUMP_IF_TRUE: w = TOP(); if (w == Py_False) { --- 2042,2047 ---- *************** *** 2122,2127 **** --- 2107,2161 ---- STACK_LEVEL()); continue; + case CALL_FUNCTION_0: + PCALL(PCALL_ALL); + { + PyObject *func = TOP(); + if (PyCFunction_Check(func)) { + PyCFunction meth = PyCFunction_GET_FUNCTION(func); + PCALL(PCALL_CFUNCTION); + if (PyCFunction_GET_FLAGS(func) == METH_NOARGS) { + x = (*meth)(PyCFunction_GET_SELF(func), NULL); + } else { + PyObject *callargs = PyTuple_New(0); + x = PyCFunction_Call(func, callargs, NULL); + Py_XDECREF(callargs); + } + + w = POP(); + Py_DECREF(w); + } else + x = call_function(&stack_pointer, 0); + } + + PUSH(x); + if (x != NULL) + continue; + break; + + case CALL_FUNCTION_1: + PCALL(PCALL_ALL); + { + PyObject *func = SECOND(); + if (PyCFunction_Check(func) && + PyCFunction_GET_FLAGS(func) == METH_O) { + PyCFunction meth = PyCFunction_GET_FUNCTION(func); + PyObject *self = PyCFunction_GET_SELF(func); + PyObject *arg = TOP(); + PCALL(PCALL_CFUNCTION); + x = (*meth)(self, arg); + Py_DECREF(arg); + Py_DECREF(func); + STACKADJ(-2); + } else + x = call_function(&stack_pointer, 1); + } + + PUSH(x); + if (x != NULL) + continue; + break; + case CALL_FUNCTION: PCALL(PCALL_ALL); x = call_function(&stack_pointer, oparg); *************** *** 2327,2332 **** --- 2361,2367 ---- /* Unwind stacks if a (pseudo) exception occurred */ + fast_block_end: while (why != WHY_NOT && why != WHY_YIELD && f->f_iblock > 0) { PyTryBlock *b = PyFrame_BlockPop(f); *************** *** 2400,2405 **** --- 2435,2444 ---- } /* main loop */ if (why != WHY_YIELD) { + if (why != WHY_RETURN) + retval = NULL; + + fast_return: /* Pop remaining stack entries -- but when yielding */ while (!EMPTY()) { v = POP(); *************** *** 2407,2415 **** } } ! if (why != WHY_RETURN && why != WHY_YIELD) ! retval = NULL; ! if (tstate->use_tracing) { if (tstate->c_tracefunc && (why == WHY_RETURN || why == WHY_YIELD)) { --- 2446,2452 ---- } } ! fast_yield: if (tstate->use_tracing) { if (tstate->c_tracefunc && (why == WHY_RETURN || why == WHY_YIELD)) { *************** *** 2452,2459 **** PyObject **defs, int defcount, PyObject *closure) { register PyFrameObject *f; ! register PyObject *retval = NULL; ! register PyObject **fastlocals, **freevars; PyThreadState *tstate = PyThreadState_GET(); PyObject *x, *u; --- 2489,2496 ---- PyObject **defs, int defcount, PyObject *closure) { register PyFrameObject *f; ! PyObject *retval = NULL; ! PyObject **fastlocals; PyThreadState *tstate = PyThreadState_GET(); PyObject *x, *u; *************** *** 2469,2475 **** return NULL; fastlocals = f->f_localsplus; - freevars = f->f_localsplus + f->f_nlocals; if (co->co_argcount > 0 || co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) { --- 2506,2511 ---- *************** *** 2655,2661 **** for (i = 0; i < f->f_nfreevars; ++i) { PyObject *o = PyTuple_GET_ITEM(closure, i); Py_INCREF(o); ! freevars[f->f_ncells + i] = o; } } --- 2691,2697 ---- for (i = 0; i < f->f_nfreevars; ++i) { PyObject *o = PyTuple_GET_ITEM(closure, i); Py_INCREF(o); ! FREEVARS(f)[f->f_ncells + i] = o; } } *************** *** 3399,3419 **** #define EXT_POP(STACK_POINTER) (*--(STACK_POINTER)) - static void - err_args(PyObject *func, int flags, int nargs) - { - if (flags & METH_NOARGS) - PyErr_Format(PyExc_TypeError, - "%.200s() takes no arguments (%d given)", - ((PyCFunctionObject *)func)->m_ml->ml_name, - nargs); - else - PyErr_Format(PyExc_TypeError, - "%.200s() takes exactly one argument (%d given)", - ((PyCFunctionObject *)func)->m_ml->ml_name, - nargs); - } - static PyObject * call_function(PyObject ***pp_stack, int oparg) { --- 3435,3440 ---- *************** *** 3428,3456 **** presumed to be the most frequent callable object. */ if (PyCFunction_Check(func) && nk == 0) { - int flags = PyCFunction_GET_FLAGS(func); PCALL(PCALL_CFUNCTION); ! if (flags & (METH_NOARGS | METH_O)) { ! PyCFunction meth = PyCFunction_GET_FUNCTION(func); ! PyObject *self = PyCFunction_GET_SELF(func); ! if (flags & METH_NOARGS && na == 0) ! x = (*meth)(self, NULL); ! else if (flags & METH_O && na == 1) { ! PyObject *arg = EXT_POP(*pp_stack); ! x = (*meth)(self, arg); ! Py_DECREF(arg); ! } ! else { ! err_args(func, flags, na); ! x = NULL; ! } ! } ! else { ! PyObject *callargs; ! callargs = load_args(pp_stack, na); ! x = PyCFunction_Call(func, callargs, NULL); ! Py_XDECREF(callargs); ! } } else { if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) { /* optimize access to bound methods */ --- 3449,3458 ---- presumed to be the most frequent callable object. */ if (PyCFunction_Check(func) && nk == 0) { PCALL(PCALL_CFUNCTION); ! PyObject *callargs = load_args(pp_stack, na); ! x = PyCFunction_Call(func, callargs, NULL); ! Py_XDECREF(callargs); } else { if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) { /* optimize access to bound methods */ Index: Python/compile.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v retrieving revision 2.298 diff -c -r2.298 compile.c *** Python/compile.c 29 Nov 2003 23:52:13 -0000 2.298 --- Python/compile.c 21 Dec 2003 18:09:11 -0000 *************** *** 1552,1558 **** com_addop_varname(c, VAR_LOAD, t); com_push(c, 1); com_node(c, e); ! com_addoparg(c, CALL_FUNCTION, 1); com_addbyte(c, POP_TOP); com_pop(c, 2); } --- 1552,1558 ---- com_addop_varname(c, VAR_LOAD, t); com_push(c, 1); com_node(c, e); ! com_addbyte(c, CALL_FUNCTION_1); com_addbyte(c, POP_TOP); com_pop(c, 2); } *************** *** 1817,1823 **** com_call_function(struct compiling *c, node *n) { if (TYPE(n) == RPAR) { ! com_addoparg(c, CALL_FUNCTION, 0); } else { PyObject *keywords = NULL; --- 1817,1823 ---- com_call_function(struct compiling *c, node *n) { if (TYPE(n) == RPAR) { ! com_addbyte(c, CALL_FUNCTION_0); } else { PyObject *keywords = NULL; *************** *** 1864,1870 **** star_flag + (starstar_flag << 1); else opcode = CALL_FUNCTION; ! com_addoparg(c, opcode, na | (nk << 8)); com_pop(c, na + 2*nk + star_flag + starstar_flag); } } --- 1864,1873 ---- star_flag + (starstar_flag << 1); else opcode = CALL_FUNCTION; ! if (opcode == CALL_FUNCTION && na == 1 && nk == 0) ! com_addbyte(c, CALL_FUNCTION_1); ! else ! com_addoparg(c, opcode, na | (nk << 8)); com_pop(c, na + 2*nk + star_flag + starstar_flag); } } *************** *** 3799,3805 **** com_pop(c, PyCode_GetNumFree(co)); } else com_addoparg(c, MAKE_FUNCTION, 0); ! com_addoparg(c, CALL_FUNCTION, 0); com_addbyte(c, BUILD_CLASS); com_pop(c, 2); com_addop_varname(c, VAR_STORE, STR(CHILD(n, 1))); --- 3802,3808 ---- com_pop(c, PyCode_GetNumFree(co)); } else com_addoparg(c, MAKE_FUNCTION, 0); ! com_addbyte(c, CALL_FUNCTION_0); com_addbyte(c, BUILD_CLASS); com_pop(c, 2); com_addop_varname(c, VAR_STORE, STR(CHILD(n, 1))); Index: Python/import.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/import.c,v retrieving revision 2.225 diff -c -r2.225 import.c *** Python/import.c 20 Nov 2003 01:44:58 -0000 2.225 --- Python/import.c 21 Dec 2003 18:09:11 -0000 *************** *** 66,73 **** Python 2.3a0: 62011 Python 2.3a0: 62021 Python 2.3a0: 62011 (!) */ ! #define MAGIC (62011 | ((long)'\r'<<16) | ((long)'\n'<<24)) /* Magic word as global; note that _PyImport_Init() can change the value of this global to accommodate for alterations of how the --- 66,74 ---- Python 2.3a0: 62011 Python 2.3a0: 62021 Python 2.3a0: 62011 (!) + Python 2.4a0: 62021 */ ! #define MAGIC (62021 | ((long)'\r'<<16) | ((long)'\n'<<24)) /* Magic word as global; note that _PyImport_Init() can change the value of this global to accommodate for alterations of how the