Skip to content
Snippets Groups Projects
Commit f76edf72 authored by Dominik Thoennes's avatar Dominik Thoennes
Browse files

add single argument integer functions

parent 26fce4ff
Branches
Tags
No related merge requests found
...@@ -27,6 +27,27 @@ class IntegerFunctionTwoArgsMixIn(sp.Function): ...@@ -27,6 +27,27 @@ class IntegerFunctionTwoArgsMixIn(sp.Function):
raise ValueError("Integer functions can only be constructed with typed expressions") raise ValueError("Integer functions can only be constructed with typed expressions")
return super().__new__(cls, *args) return super().__new__(cls, *args)
class IntegerFunctionOneArgMixIn(sp.Function):
is_integer = True
def __new__(cls, arg1):
args = []
if isinstance(arg1, sp.Number) or isinstance(arg1, int):
args.append(cast_func(arg1, create_type("int")))
elif isinstance(arg1, np.generic):
args.append(cast_func(arg1, arg1.dtype))
else:
args.append(arg1)
try:
type = get_type_of_expression(arg1)
if not type.is_int():
raise ValueError("Argument to integer function is not an int but " + str(type))
except NotImplementedError:
raise ValueError("Integer functions can only be constructed with typed expressions")
return super().__new__(cls, *args)
# noinspection PyPep8Naming # noinspection PyPep8Naming
class bitwise_xor(IntegerFunctionTwoArgsMixIn): class bitwise_xor(IntegerFunctionTwoArgsMixIn):
...@@ -59,11 +80,11 @@ class int_div(IntegerFunctionTwoArgsMixIn): ...@@ -59,11 +80,11 @@ class int_div(IntegerFunctionTwoArgsMixIn):
# noinspection PyPep8Naming # noinspection PyPep8Naming
class int_power_of_2(sp.Function): class int_power_of_2(IntegerFunctionOneArgMixIn):
pass pass
# noinspection PyPep8Naming # noinspection PyPep8Naming
class post_increment(sp.Function): class post_increment(IntegerFunctionOneArgMixIn):
pass pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment