forked from M-Labs/artiq
Add exception constructor types.
This commit is contained in:
parent
9044e88983
commit
a4a9cd884e
|
@ -37,6 +37,10 @@ class TRange(types.TMono):
|
||||||
elt = types.TVar()
|
elt = types.TVar()
|
||||||
super().__init__("range", {"elt": elt})
|
super().__init__("range", {"elt": elt})
|
||||||
|
|
||||||
|
class TException(types.TMono):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__("Exception")
|
||||||
|
|
||||||
def fn_bool():
|
def fn_bool():
|
||||||
return types.TConstructor("bool")
|
return types.TConstructor("bool")
|
||||||
|
|
||||||
|
@ -49,6 +53,9 @@ def fn_float():
|
||||||
def fn_list():
|
def fn_list():
|
||||||
return types.TConstructor("list")
|
return types.TConstructor("list")
|
||||||
|
|
||||||
|
def fn_Exception():
|
||||||
|
return types.TExceptionConstructor("Exception")
|
||||||
|
|
||||||
def fn_range():
|
def fn_range():
|
||||||
return types.TBuiltinFunction("range")
|
return types.TBuiltinFunction("range")
|
||||||
|
|
||||||
|
@ -70,7 +77,7 @@ def is_bool(typ):
|
||||||
return types.is_mono(typ, "bool")
|
return types.is_mono(typ, "bool")
|
||||||
|
|
||||||
def is_int(typ, width=None):
|
def is_int(typ, width=None):
|
||||||
if width:
|
if width is not None:
|
||||||
return types.is_mono(typ, "int", {"width": width})
|
return types.is_mono(typ, "int", {"width": width})
|
||||||
else:
|
else:
|
||||||
return types.is_mono(typ, "int")
|
return types.is_mono(typ, "int")
|
||||||
|
@ -88,13 +95,13 @@ def is_numeric(typ):
|
||||||
typ.name in ('int', 'float')
|
typ.name in ('int', 'float')
|
||||||
|
|
||||||
def is_list(typ, elt=None):
|
def is_list(typ, elt=None):
|
||||||
if elt:
|
if elt is not None:
|
||||||
return types.is_mono(typ, "list", {"elt": elt})
|
return types.is_mono(typ, "list", {"elt": elt})
|
||||||
else:
|
else:
|
||||||
return types.is_mono(typ, "list")
|
return types.is_mono(typ, "list")
|
||||||
|
|
||||||
def is_range(typ, elt=None):
|
def is_range(typ, elt=None):
|
||||||
if elt:
|
if elt is not None:
|
||||||
return types.is_mono(typ, "range", {"elt": elt})
|
return types.is_mono(typ, "range", {"elt": elt})
|
||||||
else:
|
else:
|
||||||
return types.is_mono(typ, "range")
|
return types.is_mono(typ, "range")
|
||||||
|
@ -117,3 +124,11 @@ def is_builtin(typ, name):
|
||||||
typ = typ.find()
|
typ = typ.find()
|
||||||
return isinstance(typ, types.TBuiltin) and \
|
return isinstance(typ, types.TBuiltin) and \
|
||||||
typ.name == name
|
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)
|
||||||
|
|
|
@ -12,6 +12,7 @@ def globals():
|
||||||
"float": builtins.fn_float(),
|
"float": builtins.fn_float(),
|
||||||
"list": builtins.fn_list(),
|
"list": builtins.fn_list(),
|
||||||
"range": builtins.fn_range(),
|
"range": builtins.fn_range(),
|
||||||
|
"Exception": builtins.fn_Exception(),
|
||||||
"len": builtins.fn_len(),
|
"len": builtins.fn_len(),
|
||||||
"round": builtins.fn_round(),
|
"round": builtins.fn_round(),
|
||||||
"syscall": builtins.fn_syscall(),
|
"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