mirror of https://github.com/m-labs/artiq.git
Add exception constructor types.
This commit is contained in:
parent
9044e88983
commit
a4a9cd884e
|
@ -37,6 +37,10 @@ class TRange(types.TMono):
|
|||
elt = types.TVar()
|
||||
super().__init__("range", {"elt": elt})
|
||||
|
||||
class TException(types.TMono):
|
||||
def __init__(self):
|
||||
super().__init__("Exception")
|
||||
|
||||
def fn_bool():
|
||||
return types.TConstructor("bool")
|
||||
|
||||
|
@ -49,6 +53,9 @@ def fn_float():
|
|||
def fn_list():
|
||||
return types.TConstructor("list")
|
||||
|
||||
def fn_Exception():
|
||||
return types.TExceptionConstructor("Exception")
|
||||
|
||||
def fn_range():
|
||||
return types.TBuiltinFunction("range")
|
||||
|
||||
|
@ -70,7 +77,7 @@ def is_bool(typ):
|
|||
return types.is_mono(typ, "bool")
|
||||
|
||||
def is_int(typ, width=None):
|
||||
if width:
|
||||
if width is not None:
|
||||
return types.is_mono(typ, "int", {"width": width})
|
||||
else:
|
||||
return types.is_mono(typ, "int")
|
||||
|
@ -88,13 +95,13 @@ def is_numeric(typ):
|
|||
typ.name in ('int', 'float')
|
||||
|
||||
def is_list(typ, elt=None):
|
||||
if elt:
|
||||
if elt is not None:
|
||||
return types.is_mono(typ, "list", {"elt": elt})
|
||||
else:
|
||||
return types.is_mono(typ, "list")
|
||||
|
||||
def is_range(typ, elt=None):
|
||||
if elt:
|
||||
if elt is not None:
|
||||
return types.is_mono(typ, "range", {"elt": elt})
|
||||
else:
|
||||
return types.is_mono(typ, "range")
|
||||
|
@ -117,3 +124,11 @@ def is_builtin(typ, name):
|
|||
typ = typ.find()
|
||||
return isinstance(typ, types.TBuiltin) and \
|
||||
typ.name == name
|
||||
|
||||
def is_exception(typ, name=None):
|
||||
typ = typ.find()
|
||||
if name is not None:
|
||||
return isinstance(typ, types.TExceptionConstructor) and \
|
||||
typ.name == name
|
||||
else:
|
||||
return isinstance(typ, types.TExceptionConstructor)
|
||||
|
|
|
@ -7,12 +7,13 @@ from . import builtins
|
|||
|
||||
def globals():
|
||||
return {
|
||||
"bool": builtins.fn_bool(),
|
||||
"int": builtins.fn_int(),
|
||||
"float": builtins.fn_float(),
|
||||
"list": builtins.fn_list(),
|
||||
"range": builtins.fn_range(),
|
||||
"len": builtins.fn_len(),
|
||||
"round": builtins.fn_round(),
|
||||
"syscall": builtins.fn_syscall(),
|
||||
"bool": builtins.fn_bool(),
|
||||
"int": builtins.fn_int(),
|
||||
"float": builtins.fn_float(),
|
||||
"list": builtins.fn_list(),
|
||||
"range": builtins.fn_range(),
|
||||
"Exception": builtins.fn_Exception(),
|
||||
"len": builtins.fn_len(),
|
||||
"round": builtins.fn_round(),
|
||||
"syscall": builtins.fn_syscall(),
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# RUN: %python -m artiq.py2llvm.typing %s >%t
|
||||
# RUN: OutputCheck %s --file-to-check=%t
|
||||
|
||||
# CHECK-L: Exception:<constructor Exception>
|
||||
Exception
|
Loading…
Reference in New Issue