Skip to content

Commit

Permalink
Merge pull request #1812 from certik/unsigned5
Browse files Browse the repository at this point in the history
lpython.py: handle unsigned integers everywhere
  • Loading branch information
certik authored May 15, 2023
2 parents 68024a0 + 159e646 commit 0407d30
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions src/runtime/lpython/lpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ def convert_type_to_ctype(arg):
return ctypes.c_int16
elif arg == i8:
return ctypes.c_int8
elif arg == u64:
return ctypes.c_uint64
elif arg == u32:
return ctypes.c_uint32
elif arg == u16:
return ctypes.c_uint16
elif arg == u8:
return ctypes.c_uint8
elif arg == CPtr:
return ctypes.c_void_p
elif arg == str:
Expand Down Expand Up @@ -264,11 +272,16 @@ def convert_numpy_dtype_to_ctype(arg):
return ctypes.c_int32
elif arg == np.int16:
return ctypes.c_int16
elif arg == np.uint16:
# TODO: once LPython supports unsigned, change this to unsigned:
return ctypes.c_int16
elif arg == np.int8:
return ctypes.c_int8
elif arg == np.uint64:
return ctypes.c_uint64
elif arg == np.uint32:
return ctypes.c_uint32
elif arg == np.uint16:
return ctypes.c_uint16
elif arg == np.uint8:
return ctypes.c_uint8
elif arg == np.void:
return ctypes.c_void_p
elif arg is None:
Expand Down Expand Up @@ -431,12 +444,30 @@ def pointer(x, type_=None):
if isinstance(x, ndarray):
return x.ctypes.data_as(ctypes.POINTER(convert_numpy_dtype_to_ctype(x.dtype)))
else:
if type_ == i32:
if type_ == i8:
return ctypes.cast(ctypes.pointer(ctypes.c_int8(x)),
ctypes.c_void_p)
elif type_ == i16:
return ctypes.cast(ctypes.pointer(ctypes.c_int16(x)),
ctypes.c_void_p)
elif type_ == i32:
return ctypes.cast(ctypes.pointer(ctypes.c_int32(x)),
ctypes.c_void_p)
elif type_ == i64:
return ctypes.cast(ctypes.pointer(ctypes.c_int64(x)),
ctypes.c_void_p)
elif type_ == u8:
return ctypes.cast(ctypes.pointer(ctypes.c_uint8(x)),
ctypes.c_void_p)
elif type_ == u16:
return ctypes.cast(ctypes.pointer(ctypes.c_uint16(x)),
ctypes.c_void_p)
elif type_ == u32:
return ctypes.cast(ctypes.pointer(ctypes.c_uint32(x)),
ctypes.c_void_p)
elif type_ == u64:
return ctypes.cast(ctypes.pointer(ctypes.c_uint64(x)),
ctypes.c_void_p)
elif type_ == f32:
return ctypes.cast(ctypes.pointer(ctypes.c_float(x)),
ctypes.c_void_p)
Expand Down

0 comments on commit 0407d30

Please sign in to comment.