Skip to content
Snippets Groups Projects
Commit 90239d2c authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Merge branch 'bauerd/long-int' into 'backend-rework'

Cast integer literals to target type

See merge request !387
parents 31884002 c78e6088
Branches
Tags
1 merge request!387Cast integer literals to target type
Pipeline #66121 passed with stages
in 3 minutes and 52 seconds
...@@ -483,8 +483,7 @@ class PsIntegerType(PsScalarType, ABC): ...@@ -483,8 +483,7 @@ class PsIntegerType(PsScalarType, ABC):
if not isinstance(value, np_dtype): if not isinstance(value, np_dtype):
raise PsTypeError(f"Given value {value} is not of required type {np_dtype}") raise PsTypeError(f"Given value {value} is not of required type {np_dtype}")
unsigned_suffix = "" if self.signed else "u" unsigned_suffix = "" if self.signed else "u"
# TODO: cast literal to correct type? return f"(({self._c_type_without_const()}) {value}{unsigned_suffix})"
return str(value) + unsigned_suffix
def create_constant(self, value: Any) -> Any: def create_constant(self, value: Any) -> Any:
np_type = self.NUMPY_TYPES[self._width] np_type = self.NUMPY_TYPES[self._width]
...@@ -499,9 +498,12 @@ class PsIntegerType(PsScalarType, ABC): ...@@ -499,9 +498,12 @@ class PsIntegerType(PsScalarType, ABC):
raise PsTypeError(f"Could not interpret {value} as {repr(self)}") raise PsTypeError(f"Could not interpret {value} as {repr(self)}")
def c_string(self) -> str: def _c_type_without_const(self) -> str:
prefix = "" if self._signed else "u" prefix = "" if self._signed else "u"
return f"{self._const_string()}{prefix}int{self._width}_t" return f"{prefix}int{self._width}_t"
def c_string(self) -> str:
return f"{self._const_string()}{self._c_type_without_const()}"
def __repr__(self) -> str: def __repr__(self) -> str:
return f"PsIntegerType( width={self.width}, signed={self.signed}, const={self.const} )" return f"PsIntegerType( width={self.width}, signed={self.signed}, const={self.const} )"
......
...@@ -54,6 +54,6 @@ def test_literals(): ...@@ -54,6 +54,6 @@ def test_literals():
print(code) print(code)
assert "const double x = C;" in code assert "const double x = C;" in code
assert "CELLS[0]" in code assert "CELLS[((int64_t) 0)]" in code
assert "CELLS[1]" in code assert "CELLS[((int64_t) 1)]" in code
assert "CELLS[2]" in code assert "CELLS[((int64_t) 2)]" in code
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment