Пример #1
0
def _INPLACE_ADD(arg0, arg1):
    ret_val = llpy_null
    if (arg0 != llpy_null) and (arg1 != llpy_null):
        if _PyInt_CheckExact(arg0) and _PyInt_CheckExact(arg1):
            arg0_i = PyInt_AsLong(arg0)
            arg1_i = PyInt_AsLong(arg1)
            result_i = arg0_i + arg1_i
            if ((result_i ^ arg0_i) < 0) and ((result_i ^ arg1_i) < 0):
                ret_val = PyNumber_InPlaceAdd(arg0, arg1)
            else:
                ret_val = PyInt_FromLong(result_i)
        elif li1(PyString_CheckExact(arg0)) and li1(PyString_CheckExact(arg1)):
            # XXX FIXME: implement string_concatenate
            ret_val = llpy_null
        else:
            ret_val = PyNumber_InPlaceAdd(arg0, arg1)
    _DECREF(arg0)
    _DECREF(arg1)
    return ret_val
Пример #2
0
def _cmp_outcome(op, arg0, arg1):
    result = llfalse
    result_i = lc_int(0)
    if op == PyCmp_IS:
        result = arg0 == arg1
    elif op == PyCmp_IS_NOT:
        result = arg0 != arg1
    elif op == PyCmp_IN:
        result_i = PySequence_Contains(arg1, arg0)
        if result_i < 0:
            return llpy_null
        result = li1(result_i)
    elif op == PyCmp_NOT_IN:
        result_i = PySequence_Contains(arg1, arg0)
        if result_i < 0:
            return llpy_null
        result = ~li1(result_i)
    elif op == PyCmp_EXC_MATCH:
        # XXX: Generate warnings
        result = li1(PyErr_GivenExceptionMatches(arg0, arg1))
    else:
        return PyObject_RichCompare(arg0, arg1, op)
    return PyBool_FromLong(lc_long(result))