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]
else:
if issubclass(typ, BaseException):
instance_type = builtins.TException("{}.{}".format(typ.__module__, typ.__qualname__),
id=self.object_map.store(typ))
if hasattr(typ, 'artiq_builtin'):
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)
else:
instance_type = types.TInstance("{}.{}".format(typ.__module__, typ.__qualname__),

View File

@ -472,7 +472,8 @@ class CommGeneric:
self._write_string(function)
else:
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__))
else:
exn_id = object_map.store(exn_type)
@ -506,10 +507,10 @@ class CommGeneric:
[(filename, line, column, function, None)]
exception = core_language.ARTIQException(name, message, params, traceback)
if hasattr(exceptions, exception.name):
python_exn_type = getattr(exceptions, exception.name)
print(exception.id, exception.name)
if exception.id == 0:
python_exn_type = getattr(exceptions, exception.name.split('.')[-1])
else:
assert exception.id != 0
python_exn_type = object_map.retrieve(exception.id)
python_exn = python_exn_type(message.format(*params))

View File

@ -9,10 +9,12 @@ IndexError = builtins.IndexError
class InternalError(Exception):
"""Raised when the runtime encounters an internal error condition."""
artiq_builtin = True
class CacheError(Exception):
"""Raised when putting a value into a cache row would violate memory safety."""
artiq_builtin = True
class RTIOUnderflow(Exception):
@ -21,6 +23,7 @@ class RTIOUnderflow(Exception):
The offending event is discarded and the RTIO core keeps operating.
"""
artiq_builtin = True
class RTIOSequenceError(Exception):
"""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.
"""
artiq_builtin = True
class RTIOCollisionError(Exception):
"""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.
"""
artiq_builtin = True
class RTIOOverflow(Exception):
"""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
the exception is caught, and events will be partially retrieved.
"""
artiq_builtin = True
class DDSBatchError(Exception):
"""Raised when attempting to start a DDS batch while already in a batch,
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) \
do { \
struct artiq_exception exn = { \
.name = exnname, \
.name = "0:artiq.coredevice.exceptions." exnname, \
.message = exnmsg, \
.param = { exnparam0, exnparam1, exnparam2 }, \
.file = __FILE__, \