diff --git a/artiq/py2llvm/builtins.py b/artiq/py2llvm/builtins.py index 8875f64d7..7e4e71d76 100644 --- a/artiq/py2llvm/builtins.py +++ b/artiq/py2llvm/builtins.py @@ -38,28 +38,28 @@ class TRange(types.TMono): super().__init__("range", {"elt": elt}) def fn_bool(): - return types.TBuiltin("class bool") + return types.TConstructor("bool") def fn_int(): - return types.TBuiltin("class int") + return types.TConstructor("int") def fn_float(): - return types.TBuiltin("class float") + return types.TConstructor("float") def fn_list(): - return types.TBuiltin("class list") + return types.TConstructor("list") def fn_range(): - return types.TBuiltin("function range") + return types.TBuiltinFunction("range") def fn_len(): - return types.TBuiltin("function len") + return types.TBuiltinFunction("len") def fn_round(): - return types.TBuiltin("function round") + return types.TBuiltinFunction("round") def fn_syscall(): - return types.TBuiltin("function syscall") + return types.TBuiltinFunction("syscall") # Accessors diff --git a/artiq/py2llvm/types.py b/artiq/py2llvm/types.py index 60e09f2e3..4f1bc4dfc 100644 --- a/artiq/py2llvm/types.py +++ b/artiq/py2llvm/types.py @@ -209,6 +209,24 @@ class TBuiltin(Type): def __ne__(self, other): return not (self == other) +class TBuiltinFunction(TBuiltin): + """ + A type of a builtin function. + """ + +class TConstructor(TBuiltin): + """ + A type of a constructor of a builtin class, e.g. ``list``. + Note that this is not the same as the type of an instance of + the class, which is ``TMono("list", ...)``. + """ + +class TExceptionConstructor(TBuiltin): + """ + A type of a constructor of a builtin exception, e.g. ``Exception``. + Note that this is not the same as the type of an instance of + the class, which is ``TMono("Exception", ...)``. + """ class TValue(Type): """ @@ -306,8 +324,10 @@ class TypePrinter(object): args += [ "%s:%s" % (arg, self.name(typ.args[arg])) for arg in typ.args] args += ["?%s:%s" % (arg, self.name(typ.optargs[arg])) for arg in typ.optargs] return "(%s)->%s" % (", ".join(args), self.name(typ.ret)) - elif isinstance(typ, TBuiltin): - return "" % typ.name + elif isinstance(typ, TBuiltinFunction): + return "" % typ.name + elif isinstance(typ, (TConstructor, TExceptionConstructor)): + return "" % typ.name elif isinstance(typ, TValue): return repr(typ.value) else: diff --git a/artiq/py2llvm/typing.py b/artiq/py2llvm/typing.py index 775b0d1f2..f16191fd8 100644 --- a/artiq/py2llvm/typing.py +++ b/artiq/py2llvm/typing.py @@ -739,7 +739,7 @@ class Inferencer(algorithm.Visitor): node.func.loc, notes=valid_forms) self.engine.process(diag) - if builtins.is_builtin(typ, "class bool"): + if builtins.is_builtin(typ, "bool"): valid_forms = lambda: [ valid_form("bool() -> bool"), valid_form("bool(x:'a) -> bool") @@ -755,7 +755,7 @@ class Inferencer(algorithm.Visitor): self._unify(node.type, builtins.TBool(), node.loc, None) - elif builtins.is_builtin(typ, "class int"): + elif builtins.is_builtin(typ, "int"): valid_forms = lambda: [ valid_form("int() -> int(width='a)"), valid_form("int(x:'a) -> int(width='b) where 'a is numeric"), @@ -785,7 +785,7 @@ class Inferencer(algorithm.Visitor): node.loc, None) else: diagnose(valid_forms()) - elif builtins.is_builtin(typ, "class float"): + elif builtins.is_builtin(typ, "float"): valid_forms = lambda: [ valid_form("float() -> float"), valid_form("float(x:'a) -> float where 'a is numeric") @@ -801,7 +801,7 @@ class Inferencer(algorithm.Visitor): pass else: diagnose(valid_forms()) - elif builtins.is_builtin(typ, "class list"): + elif builtins.is_builtin(typ, "list"): valid_forms = lambda: [ valid_form("list() -> list(elt='a)"), valid_form("list(x:'a) -> list(elt='b) where 'a is iterable") @@ -828,7 +828,7 @@ class Inferencer(algorithm.Visitor): self.engine.process(diag) else: diagnose(valid_forms()) - elif builtins.is_builtin(typ, "function range"): + elif builtins.is_builtin(typ, "range"): valid_forms = lambda: [ valid_form("range(max:'a) -> range(elt='a)"), valid_form("range(min:'a, max:'a) -> range(elt='a)"), @@ -855,7 +855,7 @@ class Inferencer(algorithm.Visitor): self.engine.process(diag) else: diagnose(valid_forms()) - elif builtins.is_builtin(typ, "function len"): + elif builtins.is_builtin(typ, "len"): valid_forms = lambda: [ valid_form("len(x:'a) -> int(width='b) where 'a is iterable"), ] @@ -880,7 +880,7 @@ class Inferencer(algorithm.Visitor): self.engine.process(diag) else: diagnose(valid_forms()) - elif builtins.is_builtin(typ, "function round"): + elif builtins.is_builtin(typ, "round"): valid_forms = lambda: [ valid_form("round(x:float) -> int(width='a)"), ] @@ -896,7 +896,7 @@ class Inferencer(algorithm.Visitor): else: diagnose(valid_forms()) # TODO: add when it is clear what interface syscall() has - # elif builtins.is_builtin(typ, "function syscall"): + # elif builtins.is_builtin(typ, "syscall"): # valid_Forms = lambda: [ # ] diff --git a/lit-test/py2llvm/typing/builtin_calls.py b/lit-test/py2llvm/typing/builtin_calls.py index 8405391f9..7d72895e6 100644 --- a/lit-test/py2llvm/typing/builtin_calls.py +++ b/lit-test/py2llvm/typing/builtin_calls.py @@ -1,32 +1,32 @@ # RUN: %python -m artiq.py2llvm.typing %s >%t # RUN: OutputCheck %s --file-to-check=%t -# CHECK-L: bool:():bool +# CHECK-L: bool:():bool bool() -# CHECK-L: bool:([]:list(elt='a)):bool +# CHECK-L: bool:([]:list(elt='a)):bool bool([]) -# CHECK-L: int:():int(width='b) +# CHECK-L: int:():int(width='b) int() -# CHECK-L: int:(1.0:float):int(width='c) +# CHECK-L: int:(1.0:float):int(width='c) int(1.0) -# CHECK-L: int:(1.0:float, width=64:int(width='d)):int(width=64) +# CHECK-L: int:(1.0:float, width=64:int(width='d)):int(width=64) int(1.0, width=64) -# CHECK-L: float:():float +# CHECK-L: float:():float float() -# CHECK-L: float:(1:int(width='e)):float +# CHECK-L: float:(1:int(width='e)):float float(1) -# CHECK-L: list:():list(elt='f) +# CHECK-L: list:():list(elt='f) list() -# CHECK-L: len:([]:list(elt='g)):int(width=32) +# CHECK-L: len:([]:list(elt='g)):int(width=32) len([]) -# CHECK-L: round:(1.0:float):int(width='h) +# CHECK-L: round:(1.0:float):int(width='h) round(1.0) diff --git a/lit-test/py2llvm/typing/prelude.py b/lit-test/py2llvm/typing/prelude.py index d1229f66c..007c8d3a4 100644 --- a/lit-test/py2llvm/typing/prelude.py +++ b/lit-test/py2llvm/typing/prelude.py @@ -1,7 +1,7 @@ # RUN: %python -m artiq.py2llvm.typing %s >%t # RUN: OutputCheck %s --file-to-check=%t -# CHECK-L: x: +# CHECK-L: x: x = len def f():