Source

hotpy_2 / Include / atomic_ops.inc

Full commit

        TARGET(NOP)
            FAST_DISPATCH();

        TARGET(POP_TOP)
            v = POP();
            Py_DECREF(v);
            FAST_DISPATCH();

        TARGET(ROT_TWO)
            v = TOP();
            w = SECOND();
            SET_TOP(w);
            SET_SECOND(v);
            FAST_DISPATCH();

        TARGET(ROT_THREE)
            v = TOP();
            w = SECOND();
            x = THIRD();
            SET_TOP(w);
            SET_SECOND(x);
            SET_THIRD(v);
            FAST_DISPATCH();

        TARGET(DUP_TOP)
            v = TOP();
            Py_INCREF(v);
            PUSH(v);
            FAST_DISPATCH();

        TARGET(DUP_TOP_TWO)
            x = TOP();
            Py_INCREF(x);
            w = SECOND();
            Py_INCREF(w);
            STACKADJ(2);
            SET_TOP(x);
            SET_SECOND(w);
            FAST_DISPATCH();

        TARGET(STORE_LOCALS)
            x = POP();
            v = f->f_locals;
            Py_XDECREF(v);
            f->f_locals = x;
            DISPATCH();

        TARGET(DELETE_DEREF)
            x = freevars[oparg];
            if (PyCell_GET(x) != NULL) {
                PyCell_Set(x, NULL);
                DISPATCH();
            }
            err = -1;
            format_exc_unbound(co, oparg);
            break;

        TARGET(LOAD_DEREF)
            x = freevars[oparg];
            w = PyCell_Get(x);
            if (w != NULL) {
                PUSH(w);
                DISPATCH();
            }
            err = -1;
            format_exc_unbound(co, oparg);
            break;

        TARGET(STORE_DEREF)
            w = POP();
            x = freevars[oparg];
            PyCell_Set(x, w);
            Py_DECREF(w);
            DISPATCH();

        TARGET(BUILD_TUPLE)
            x = PyTuple_New(oparg);
            if (x != NULL) {
                for (; --oparg >= 0;) {
                    w = POP();
                    PyTuple_SET_ITEM(x, oparg, w);
                }
                PUSH(x);
                DISPATCH();
            }
            break;

        TARGET(BUILD_LIST)
            x =  PyList_New(oparg);
            if (x != NULL) {
                for (; --oparg >= 0;) {
                    w = POP();
                    PyList_SET_ITEM(x, oparg, w);
                }
                PUSH(x);
                DISPATCH();
            }
            break;

        TARGET(BUILD_SET)
            x = PySet_New(NULL);
            if (x != NULL) {
                for (; --oparg >= 0;) {
                    w = POP();
                    if (err == 0)
                        err = PySet_Add(x, w);
                    Py_DECREF(w);
                }
                if (err != 0) {
                    Py_DECREF(x);
                    break;
                }
                PUSH(x);
                DISPATCH();
            }
            break;

        TARGET(BUILD_MAP)
            x = _PyDict_NewPresized((Py_ssize_t)oparg);
            PUSH(x);
            if (x != NULL) DISPATCH();
            break;

        TARGET(BUILD_SLICE)
            if (oparg == 3)
                w = POP();
            else
                w = NULL;
            v = POP();
            u = TOP();
            x = PySlice_New(u, v, w);
            Py_DECREF(u);
            Py_DECREF(v);
            Py_XDECREF(w);
            SET_TOP(x);
            if (x != NULL) DISPATCH();
            break;

        TARGET(LOAD_CLOSURE)
            x = freevars[oparg];
            Py_INCREF(x);
            PUSH(x);
            if (x != NULL) DISPATCH();
            break;

        TARGET(EXTENDED_ARG)
            opcode = NEXTOP();
            oparg = oparg << 16 | NEXTARG();
            goto dispatch_opcode;

        TARGET(UNPACK_SEQUENCE)
            v = POP();
            if (PyTuple_CheckExact(v) &&
                PyTuple_GET_SIZE(v) == oparg) {
                PyObject **items = \
                    ((PyTupleObject *)v)->ob_item;
                while (oparg--) {
                    w = items[oparg];
                    Py_INCREF(w);
                    PUSH(w);
                }
                Py_DECREF(v);
                DISPATCH();
            } else if (PyList_CheckExact(v) &&
                       PyList_GET_SIZE(v) == oparg) {
                PyObject **items = \
                    ((PyListObject *)v)->ob_item;
                while (oparg--) {
                    w = items[oparg];
                    Py_INCREF(w);
                    PUSH(w);
                }
            } else if (unpack_iterable(v, oparg, -1,
                                       f->f_stacktop + oparg)) {
                STACKADJ(oparg);
            } else {
                /* unpack_iterable() raised an exception */
                why = WHY_EXCEPTION;
            }
            Py_DECREF(v);
            break;

        /* HotPy byecodes */

        TARGET(GEN_EXIT)
            {
                PyGenObject *gen;
                w = POP();
                if (Py_TYPE(w) != &PyGen_Type) {
                    Py_DECREF(w);
                    PyErr_SetString(PyExc_SystemError,
                        "generator required");
                    x = NULL;
                    break;
                }
                gen = (PyGenObject *)w;
                Py_CLEAR(gen->gi_frame->f_back);
                gen->gi_running = 0;
                Py_DECREF(w);
            }
            FAST_DISPATCH();

        TARGET(GEN_CLEAR)
            w = TOP();
            if (Py_TYPE(w) != &PyGen_Type) {
                Py_DECREF(w);
                PyErr_SetString(PyExc_SystemError,
                    "generator required");
                x = NULL;
                break;
            }
            PyGen_Clear((PyGenObject *)w);
            DISPATCH();

        TARGET(GEN_STARTED)
            {
                PyGenObject *gen;
                w = TOP();
                if (Py_TYPE(w) != &PyGen_Type) {
                    PyErr_SetString(PyExc_SystemError,
                        "generator required");
                    x = NULL;
                    break;
                }
                gen = (PyGenObject *)w;
                x = (gen->gi_frame->f_lasti >= 0) ? Py_True : Py_False;
                Py_INCREF(x);
                SET_TOP(x);
                Py_DECREF(w);
            }
            FAST_DISPATCH();

        TARGET(HAS_DICT)
            w = TOP();
            if (_PyObject_GetDictPtr(w)) {
                Py_INCREF(Py_True);
                SET_TOP(Py_True);
            }
            else {
                Py_INCREF(Py_False);
                SET_TOP(Py_False);
            }
            Py_DECREF(w);
            DISPATCH();

        TARGET(GET_CLASS_ATTR)
            w = POP();
            v = TOP();
            if (PyType_Check(v) &&  PyUnicode_Check(w)) {
                if (((PyTypeObject *)v)->tp_dict == NULL &&
                     PyType_Ready((PyTypeObject *)v) < 0)
                    x = NULL;
                else
                    x = _PyType_Lookup((PyTypeObject *)v, w);
            }
            else {
                PyErr_SetString(PyExc_SystemError, "type & str required");
                x = NULL;
            }
            Py_XINCREF(x);
            Py_DECREF(v);
            SET_TOP(x);
            if (x != NULL) {
                Py_DECREF(w);
                DISPATCH();
            }
            if (!PyErr_Occurred())
                PyErr_SetObject(PyExc_AttributeError, w);
            Py_DECREF(w);
            break;

        TARGET(HAS_CLASS_ATTR)
            w = POP();
            v = TOP();
            if (PyType_Check(v) &&  PyUnicode_Check(w)) {
                if (((PyTypeObject *)v)->tp_dict == NULL &&
                     PyType_Ready((PyTypeObject *)v) < 0)
                    x = NULL;
                else
                    x = _PyType_Lookup((PyTypeObject *)v, w);
            }
            else {
                PyErr_SetString(PyExc_SystemError, "type & str required");
                x = NULL;
                Py_DECREF(w);
                break;
            }
            x = (x != NULL) ? Py_True : Py_False;
            Py_INCREF(x);
            SET_TOP(x);
            Py_DECREF(w);
            Py_DECREF(v);
            DISPATCH();

        TARGET(OVERRIDES)
            w = TOP();
            v = SECOND();
            u = THIRD();
            STACKADJ(-2);
            if (u->ob_type != v->ob_type &&
                PyType_IsSubtype(v->ob_type, u->ob_type) &&
                _PyType_Lookup(Py_TYPE(u), w) !=
                _PyType_Lookup(Py_TYPE(v), w)) {
                Py_INCREF(Py_True);
                SET_TOP(Py_True);
            }
            else {
                Py_INCREF(Py_False);
                SET_TOP(Py_False);
            }
            Py_DECREF(u);
            Py_DECREF(v);
            Py_DECREF(w);
            DISPATCH();

        TARGET(SET_IN_OBJECT_DICT)
        {
            PyObject *dict;
            w = TOP();
            v = SECOND();
            u = THIRD();
            dict = PyObject_GenericGetDict(w, NULL);
            if (dict == NULL) {
                PyErr_SetString(PyExc_SystemError, "object has no dictionary");
                break;
            }
            if ((err = PyDict_SetItem(dict, v, u)) != 0) {
                Py_DECREF(dict);
                break;
            }
            STACKADJ(-3);
            Py_DECREF(dict);
            Py_DECREF(w);
            Py_DECREF(v);
            Py_DECREF(u);
            DISPATCH();
        }

        TARGET(OVERRIDES_GENERIC_GETATTRIBUTE)
            w = TOP();
            if (w->ob_type->tp_getattro != PyObject_GenericGetAttr) {
                Py_INCREF(Py_True);
                SET_TOP(Py_True);
            }
            else {
                Py_INCREF(Py_False);
                SET_TOP(Py_False);
            }
            Py_DECREF(w);
            FAST_DISPATCH();

        TARGET(OVERRIDES_GENERIC_SETATTR)
            w = TOP();
            if (w->ob_type->tp_setattro != PyObject_GenericSetAttr) {
                Py_INCREF(Py_True);
                SET_TOP(Py_True);
            }
            else {
                Py_INCREF(Py_False);
                SET_TOP(Py_False);
            }
            Py_DECREF(w);
            FAST_DISPATCH();

        TARGET(ALLOCATE)
            w = TOP();
            if (!PyType_Check(w)) {
                PyErr_SetString(PyExc_SystemError,
                    "generator required");
                x = NULL;
                break;
            }
            assert(((PyTypeObject *)w)->tp_alloc == PyType_GenericAlloc);
            x = PyType_GenericAlloc((PyTypeObject *)w, 0);
            SET_TOP(x);
            Py_DECREF(w);
            if (x != NULL) DISPATCH();
            break;

        TARGET(SIZE)
            w = TOP();
            x = PyLong_FromSsize_t(Py_SIZE(w));
            SET_TOP(x);
            Py_DECREF(w);
            if (x != NULL) DISPATCH();
            break;