diff --git a/artiq/compiler/embedding.py b/artiq/compiler/embedding.py index fb185a39b..571023349 100644 --- a/artiq/compiler/embedding.py +++ b/artiq/compiler/embedding.py @@ -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__), diff --git a/artiq/coredevice/comm_generic.py b/artiq/coredevice/comm_generic.py index 8d8dccf87..b97d13a4d 100644 --- a/artiq/coredevice/comm_generic.py +++ b/artiq/coredevice/comm_generic.py @@ -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)) diff --git a/artiq/coredevice/exceptions.py b/artiq/coredevice/exceptions.py index 46402a31f..b0dbf740f 100644 --- a/artiq/coredevice/exceptions.py +++ b/artiq/coredevice/exceptions.py @@ -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 diff --git a/artiq/runtime/artiq_personality.h b/artiq/runtime/artiq_personality.h index 9e7ddce3e..0ddf9e88f 100644 --- a/artiq/runtime/artiq_personality.h +++ b/artiq/runtime/artiq_personality.h @@ -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__, \