Skip to content
Snippets Groups Projects

WIP: Hyteg

Closed Dominik Thoennes requested to merge hyteg into master
1 file
+ 23
2
Compare changes
  • Side-by-side
  • Inline
@@ -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
Loading