Rigorously treat builtin core device exceptions.

This commit is contained in:
whitequark 2016-01-19 01:45:25 +00:00
parent 53b06a0b9b
commit 5c6b1517d0
4 changed files with 20 additions and 7 deletions

View File

@ -124,8 +124,13 @@ class ASTSynthesizer:
instance_type, constructor_type = self.type_map[typ] instance_type, constructor_type = self.type_map[typ]
else: else:
if issubclass(typ, BaseException): if issubclass(typ, BaseException):
instance_type = builtins.TException("{}.{}".format(typ.__module__, typ.__qualname__), if hasattr(typ, 'artiq_builtin'):
id=self.object_map.store(typ)) exception_id = 0
else:
exception_id = self.object_map.store(typ)
instance_type = builtins.TException("{}.{}".format(typ.__module__,
typ.__qualname__),
id=exception_id)
constructor_type = types.TExceptionConstructor(instance_type) constructor_type = types.TExceptionConstructor(instance_type)
else: else:
instance_type = types.TInstance("{}.{}".format(typ.__module__, typ.__qualname__), instance_type = types.TInstance("{}.{}".format(typ.__module__, typ.__qualname__),

View File

@ -472,7 +472,8 @@ class CommGeneric:
self._write_string(function) self._write_string(function)
else: else:
exn_type = type(exn) exn_type = type(exn)
if exn_type in (ZeroDivisionError, ValueError, IndexError): if exn_type in (ZeroDivisionError, ValueError, IndexError) or \
hasattr(exn, 'artiq_builtin'):
self._write_string("0:{}".format(exn_type.__name__)) self._write_string("0:{}".format(exn_type.__name__))
else: else:
exn_id = object_map.store(exn_type) exn_id = object_map.store(exn_type)
@ -506,10 +507,10 @@ class CommGeneric:
[(filename, line, column, function, None)] [(filename, line, column, function, None)]
exception = core_language.ARTIQException(name, message, params, traceback) exception = core_language.ARTIQException(name, message, params, traceback)
if hasattr(exceptions, exception.name): print(exception.id, exception.name)
python_exn_type = getattr(exceptions, exception.name) if exception.id == 0:
python_exn_type = getattr(exceptions, exception.name.split('.')[-1])
else: else:
assert exception.id != 0
python_exn_type = object_map.retrieve(exception.id) python_exn_type = object_map.retrieve(exception.id)
python_exn = python_exn_type(message.format(*params)) python_exn = python_exn_type(message.format(*params))

View File

@ -9,10 +9,12 @@ IndexError = builtins.IndexError
class InternalError(Exception): class InternalError(Exception):
"""Raised when the runtime encounters an internal error condition.""" """Raised when the runtime encounters an internal error condition."""
artiq_builtin = True
class CacheError(Exception): class CacheError(Exception):
"""Raised when putting a value into a cache row would violate memory safety.""" """Raised when putting a value into a cache row would violate memory safety."""
artiq_builtin = True
class RTIOUnderflow(Exception): class RTIOUnderflow(Exception):
@ -21,6 +23,7 @@ class RTIOUnderflow(Exception):
The offending event is discarded and the RTIO core keeps operating. The offending event is discarded and the RTIO core keeps operating.
""" """
artiq_builtin = True
class RTIOSequenceError(Exception): class RTIOSequenceError(Exception):
"""Raised when an event is submitted on a given channel with a timestamp """Raised when an event is submitted on a given channel with a timestamp
@ -28,6 +31,7 @@ class RTIOSequenceError(Exception):
The offending event is discarded and the RTIO core keeps operating. The offending event is discarded and the RTIO core keeps operating.
""" """
artiq_builtin = True
class RTIOCollisionError(Exception): class RTIOCollisionError(Exception):
"""Raised when an event is submitted on a given channel with the same """Raised when an event is submitted on a given channel with the same
@ -39,6 +43,7 @@ class RTIOCollisionError(Exception):
The offending event is discarded and the RTIO core keeps operating. The offending event is discarded and the RTIO core keeps operating.
""" """
artiq_builtin = True
class RTIOOverflow(Exception): class RTIOOverflow(Exception):
"""Raised when at least one event could not be registered into the RTIO """Raised when at least one event could not be registered into the RTIO
@ -48,8 +53,10 @@ class RTIOOverflow(Exception):
read attempt and discarding some events. Reading can be reattempted after read attempt and discarding some events. Reading can be reattempted after
the exception is caught, and events will be partially retrieved. the exception is caught, and events will be partially retrieved.
""" """
artiq_builtin = True
class DDSBatchError(Exception): class DDSBatchError(Exception):
"""Raised when attempting to start a DDS batch while already in a batch, """Raised when attempting to start a DDS batch while already in a batch,
or when too many commands are batched. or when too many commands are batched.
""" """
artiq_builtin = True

View File

@ -35,7 +35,7 @@ void __artiq_reraise(void)
#define artiq_raise_from_c(exnname, exnmsg, exnparam0, exnparam1, exnparam2) \ #define artiq_raise_from_c(exnname, exnmsg, exnparam0, exnparam1, exnparam2) \
do { \ do { \
struct artiq_exception exn = { \ struct artiq_exception exn = { \
.name = exnname, \ .name = "0:artiq.coredevice.exceptions." exnname, \
.message = exnmsg, \ .message = exnmsg, \
.param = { exnparam0, exnparam1, exnparam2 }, \ .param = { exnparam0, exnparam1, exnparam2 }, \
.file = __FILE__, \ .file = __FILE__, \