Пример #1
0
 def visit_BuiltinLiteral(self, node: BuiltinLiteral) -> gtir.Literal:  # type: ignore[return]
     # currently deals only with boolean literals
     if node.value in self.GT4PY_BUILTIN_TO_GTIR.keys():
         return gtir.Literal(
             value=self.GT4PY_BUILTIN_TO_GTIR[node.value], dtype=common.DataType.BOOL
         )
     raise NotImplementedError(f"BuiltIn.{node.value} not implemented in lowering")
Пример #2
0
def _make_literal(v: numbers.Number) -> gtir.Literal:
    value: Union[BuiltinLiteral, str]
    if isinstance(v, bool):
        dtype = common.DataType.BOOL
        value = common.BuiltInLiteral.TRUE if v else common.BuiltInLiteral.FALSE
    else:
        if isinstance(v, int):
            # note: could be extended to support 32 bit integers by checking the values magnitude
            dtype = common.DataType.INT64
        elif isinstance(v, float):
            dtype = common.DataType.FLOAT64
        else:
            print(
                f"Warning: Only INT64 and FLOAT64 literals are supported currently. Implicitly upcasting `{v}` to FLOAT64"
            )
            dtype = common.DataType.FLOAT64
        value = str(v)
    return gtir.Literal(dtype=dtype, value=value)
Пример #3
0
 def visit_ScalarLiteral(self, node: ScalarLiteral) -> gtir.Literal:
     return gtir.Literal(value=str(node.value), dtype=common.DataType(node.data_type.value))