for op, funcname in [('-', 'PyNumber_Negative'), ('+', 'PyNumber_Positive'), ('~', 'PyNumber_Invert')]: unary_op(op=op, arg_type=object_rprimitive, result_type=object_rprimitive, error_kind=ERR_MAGIC, emit=call_emit(funcname), priority=0) unary_op(op='not', arg_type=object_rprimitive, result_type=bool_rprimitive, error_kind=ERR_MAGIC, format_str='{dest} = not {args[0]}', emit=call_negative_magic_emit('PyObject_Not'), priority=0) # obj1[obj2] method_op('__getitem__', arg_types=[object_rprimitive, object_rprimitive], result_type=object_rprimitive, error_kind=ERR_MAGIC, emit=call_emit('PyObject_GetItem'), priority=0) # obj1[obj2] = obj3 method_op('__setitem__', arg_types=[object_rprimitive, object_rprimitive, object_rprimitive], result_type=bool_rprimitive,
# Exact type check that doesn't consider subclasses: type(obj) is cls type_is_op = custom_op( name='type_is', arg_types=[object_rprimitive, object_rprimitive], result_type=bool_rprimitive, error_kind=ERR_NEVER, emit=simple_emit( '{dest} = Py_TYPE({args[0]}) == (PyTypeObject *){args[1]};')) # bool(obj) with unboxed result bool_op = func_op('builtins.bool', arg_types=[object_rprimitive], result_type=bool_rprimitive, error_kind=ERR_MAGIC, emit=call_negative_magic_emit('PyObject_IsTrue')) # slice(start, stop, step) new_slice_op = func_op( 'builtins.slice', arg_types=[object_rprimitive, object_rprimitive, object_rprimitive], result_type=object_rprimitive, error_kind=ERR_MAGIC, emit=call_emit('PySlice_New')) # type(obj) type_op = func_op('builtins.type', arg_types=[object_rprimitive], result_type=object_rprimitive, error_kind=ERR_NEVER, emit=call_emit('PyObject_Type'))
for op, funcname in [('-', 'PyNumber_Negative'), ('+', 'PyNumber_Positive'), ('~', 'PyNumber_Invert')]: unary_op(op=op, arg_type=object_rprimitive, result_type=object_rprimitive, error_kind=ERR_MAGIC, emit=call_emit(funcname), priority=0) unary_op(op='not', arg_type=object_rprimitive, result_type=bool_rprimitive, error_kind=ERR_MAGIC, format_str='{dest} = not {args[0]}', emit=call_negative_magic_emit('PyObject_Not'), priority=0) unary_op(op='not', arg_type=bool_rprimitive, result_type=bool_rprimitive, error_kind=ERR_NEVER, format_str='{dest} = !{args[0]}', emit=simple_emit('{dest} = !{args[0]};'), priority=1) method_op('__getitem__', arg_types=[object_rprimitive, object_rprimitive], result_type=object_rprimitive, error_kind=ERR_MAGIC, emit=call_emit('PyObject_GetItem'),