From: Armin R. <ar...@us...> - 2002-02-11 19:14:17
|
Update of /cvsroot/psyco/psyco/c/Python In directory usw-pr-cvs1:/tmp/cvs-serv28105/c/Python Modified Files: pycompiler.c Log Message: more bug fixes and support for a few new operations (in-place operators, sequence ops, some bytecode instr) Index: pycompiler.c =================================================================== RCS file: /cvsroot/psyco/psyco/c/Python/pycompiler.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** pycompiler.c 11 Feb 2002 14:27:24 -0000 1.14 --- pycompiler.c 11 Feb 2002 19:14:14 -0000 1.15 *************** *** 1064,1067 **** --- 1064,1087 ---- /* the code of the following functions is "copy-pasted" from ceval.c */ + static int cimpl_print_expr(PyObject* v) + { + PyObject* x; + PyObject* w = PySys_GetObject("displayhook"); + if (w == NULL) { + PyErr_SetString(PyExc_RuntimeError, + "lost sys.displayhook"); + return -1; + } + x = Py_BuildValue("(O)", v); + if (x == NULL) + return -1; + w = PyEval_CallObject(w, x); + Py_XDECREF(w); + Py_DECREF(x); + if (w == NULL) + return -1; + return 0; + } + static int cimpl_print_item_to(PyObject* v, PyObject* stream) { *************** *** 1277,1280 **** --- 1297,1332 ---- } + /* copied from ceval.c where it is private */ + static PyObject* + build_class(PyObject *methods, PyObject *bases, PyObject *name) + { + PyObject *metaclass = NULL, *result, *base; + + if (PyDict_Check(methods)) + metaclass = PyDict_GetItemString(methods, "__metaclass__"); + if (metaclass != NULL) + Py_INCREF(metaclass); + else if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) { + base = PyTuple_GET_ITEM(bases, 0); + metaclass = PyObject_GetAttrString(base, "__class__"); + if (metaclass == NULL) { + PyErr_Clear(); + metaclass = (PyObject *)base->ob_type; + Py_INCREF(metaclass); + } + } + else { + PyObject *g = PyEval_GetGlobals(); + if (g != NULL && PyDict_Check(g)) + metaclass = PyDict_GetItemString(g, "__metaclass__"); + if (metaclass == NULL) + metaclass = (PyObject *) &PyClass_Type; + Py_INCREF(metaclass); + } + result = PyObject_CallFunction(metaclass, "OOO", name, bases, methods); + Py_DECREF(metaclass); + return result; + } + /***************************************************************/ *************** *** 1305,1308 **** --- 1357,1364 ---- psyco_incref_v(po, retval); } + if (retval->array->count > 0) { + array_delete(retval->array, po); + retval->array = NullArray; + } } else { *************** *** 1511,1522 **** BINARY_OPCODE(BINARY_MULTIPLY, PsycoNumber_Multiply); BINARY_OPCODE(BINARY_DIVIDE, PsycoNumber_Divide); - - /*#ifdef BINARY_FLOOR_DIVIDE - MISSING_OPCODE(BINARY_FLOOR_DIVIDE); - MISSING_OPCODE(BINARY_TRUE_DIVIDE); - MISSING_OPCODE(INPLACE_FLOOR_DIVIDE); - MISSING_OPCODE(INPLACE_TRUE_DIVIDE); - #endif*/ - BINARY_OPCODE(BINARY_MODULO, PsycoNumber_Remainder); BINARY_OPCODE(BINARY_ADD, PsycoNumber_Add); --- 1567,1570 ---- *************** *** 1528,1532 **** BINARY_OPCODE(BINARY_XOR, PsycoNumber_Xor); BINARY_OPCODE(BINARY_OR, PsycoNumber_Or); ! case INPLACE_POWER: u = psyco_vi_None(); --- 1576,1587 ---- BINARY_OPCODE(BINARY_XOR, PsycoNumber_Xor); BINARY_OPCODE(BINARY_OR, PsycoNumber_Or); ! ! #ifdef BINARY_FLOOR_DIVIDE ! BINARY_OPCODE(BINARY_FLOOR_DIVIDE, PsycoNumber_FloorDivide); ! BINARY_OPCODE(BINARY_TRUE_DIVIDE, PsycoNumber_TrueDivide); ! BINARY_OPCODE(INPLACE_FLOOR_DIVIDE, PsycoNumber_InPlaceFloorDivide); ! BINARY_OPCODE(INPLACE_TRUE_DIVIDE, PsycoNumber_InPlaceTrueDivide); ! #endif ! case INPLACE_POWER: u = psyco_vi_None(); *************** *** 1656,1661 **** POP_DECREF(); goto fine; ! ! /*MISSING_OPCODE(PRINT_EXPR);*/ case PRINT_ITEM: --- 1711,1722 ---- POP_DECREF(); goto fine; ! ! case PRINT_EXPR: ! if (!psyco_generic_call(po, cimpl_print_expr, ! CfNoReturnValue|CfPyErrIfNonNull, ! "v", TOP())) ! break; ! POP_DECREF(); ! goto fine; case PRINT_ITEM: *************** *** 1783,1788 **** } ! /*MISSING_OPCODE(BUILD_CLASS); ! MISSING_OPCODE(STORE_NAME); MISSING_OPCODE(DELETE_NAME);*/ --- 1844,1860 ---- } ! case BUILD_CLASS: ! x = psyco_generic_call(po, build_class, ! CfReturnRef|CfPyErrIfNull, ! "vvv", NTOP(1), NTOP(2), NTOP(3)); ! if (x == NULL) ! break; ! POP_DECREF(); ! POP_DECREF(); ! POP_DECREF(); ! PUSH(x); ! goto fine; ! ! /*MISSING_OPCODE(STORE_NAME); -- only used in module's code objects? MISSING_OPCODE(DELETE_NAME);*/ |