Exemplo n.º 1
0
def add_binop(cls, name, restype=None, pykitname=None):
    if not pykitname:
        pykitname = name
    special_name = "__%s__" % name
    impl = lambda b, _, x, y: b.ret(getattr(b, pykitname)(x, y))
    add_impl_cls(cls, special_name, impl, restype)
Exemplo n.º 2
0
def restype_to_int(argtypes):
    (bits, ), count = argtypes[0]
    i_t = ptypes.Int(targetBits, True)
    return i_t


def implement_to_int(builder, argtypes, vector):
    i_t = restype_to_int(argtypes)
    i = builder.bitcast(i_t, vector)
    return builder.ret(i)


# implementations

add_impl_cls(Vector, "__len__", implement_len, restype=ptypes.UInt64)
add_impl_cls(Vector, "to_array", implement_to_array, restype=ptypes.Void)
add_impl_cls(Vector, "to_int", implement_to_int, restype_func=restype_to_int)

#===------------------------------------------------------------------===
# Utils
#===------------------------------------------------------------------===


def make_ctypes_vector(items, type):
    # TODO:
    from flypy.support.cffi_support import is_cffi, ffi
    from flypy.support.ctypes_support import is_ctypes_pointer_type

    cty = ctype(type)
    if is_cffi(ptr):
Exemplo n.º 3
0
    pvector = builder.bitcast(pvector_t, parray)
    builder.ptrstore(vector, pvector)

def restype_to_int(argtypes):
    (bits,), count = argtypes[0]
    i_t = ptypes.Int(targetBits, True)
    return i_t

def implement_to_int(builder, argtypes, vector):
    i_t = restype_to_int(argtypes)
    i = builder.bitcast(i_t, vector)
    return builder.ret(i)

# implementations

add_impl_cls(Vector, "__len__", implement_len, restype=ptypes.UInt64)
add_impl_cls(Vector, "to_array", implement_to_array, restype=ptypes.Void)
add_impl_cls(Vector, "to_int", implement_to_int, restype_func=restype_to_int)

#===------------------------------------------------------------------===
# Utils
#===------------------------------------------------------------------===

def make_ctypes_vector(items, type):
    # TODO:
    from flypy.support.cffi_support import is_cffi, ffi
    from flypy.support.ctypes_support import is_ctypes_pointer_type

    cty = ctype(type)
    if is_cffi(ptr):
        addr = ffi.cast('uintptr_t', ptr)
Exemplo n.º 4
0
#===------------------------------------------------------------------===
# Low-level Implementations
#===------------------------------------------------------------------===

# Methods

def implement_getitem(builder, argtypes, arr, idx):
    e = builder.get(arr, idx)
    return builder.ret(e)

def implement_set(builder, argtypes, arr, idx, item):
    e = builder.set(arr, item, idx)
    return builder.ret(e)

def implement_len(builder, argtypes, arr):
    count = argtypes[0].parameters[1]
    return builder.ret(ir.Const(count, ptypes.Int64))

add_impl_cls(Array, "__getitem__", implement_getitem)
add_impl_cls(Array, "set", implement_set)
add_impl_cls(Array, "__len__", implement_len)

#===------------------------------------------------------------------===
# Utils
#===------------------------------------------------------------------===

def make_ctypes_array(arr, type):
    cty = ctype(type)
    arr = ctypes.cast(arr, cty)
    return arr