mirror of https://github.com/m-labs/artiq.git
sync exception names and ids
This commit is contained in:
parent
e82cf94cae
commit
9591549b37
|
@ -57,7 +57,10 @@ class EmbeddingMap:
|
|||
self.str_forward_map = {}
|
||||
self.str_reverse_map = {}
|
||||
|
||||
self.preallocate_runtime_exception_names(["RuntimeError",
|
||||
# Keep this list of exceptions in sync with `EXCEPTION_ID_LOOKUP` in `artiq.firmware.ksupport.eh_artiq``
|
||||
# The exceptions declared here should be defined in `artiq.coredeive.exceptions``
|
||||
# Without sync, test cases in artiq.test.coredevice.test_exceptions would fail
|
||||
self.preallocate_runtime_exception_names([
|
||||
"RTIOUnderflow",
|
||||
"RTIOOverflow",
|
||||
"RTIODestinationUnreachable",
|
||||
|
@ -65,8 +68,20 @@ class EmbeddingMap:
|
|||
"I2CError",
|
||||
"CacheError",
|
||||
"SPIError",
|
||||
"0:ZeroDivisionError",
|
||||
"0:IndexError"])
|
||||
|
||||
"0:AssertionError",
|
||||
"0:AttributeError",
|
||||
"0:IndexError",
|
||||
"0:IOError",
|
||||
"0:KeyError",
|
||||
"0:NotImplementedError",
|
||||
"0:OverflowError",
|
||||
"0:RuntimeError",
|
||||
"0:TimeoutError",
|
||||
"0:TypeError",
|
||||
"0:ValueError",
|
||||
"0:ZeroDivisionError"
|
||||
])
|
||||
|
||||
def preallocate_runtime_exception_names(self, names):
|
||||
for i, name in enumerate(names):
|
||||
|
|
|
@ -6,12 +6,26 @@ import os
|
|||
from artiq import __artiq_dir__ as artiq_dir
|
||||
from artiq.coredevice.runtime import source_loader
|
||||
|
||||
"""
|
||||
This file should provide class definition for all the exceptions declared in `EmbeddingMap` in artiq.compiler.embedding
|
||||
|
||||
For python builtin exceptions, use the `builtins` module
|
||||
For artiq specific exceptions, inherit from `Exception` class
|
||||
"""
|
||||
|
||||
ZeroDivisionError = builtins.ZeroDivisionError
|
||||
ValueError = builtins.ValueError
|
||||
IndexError = builtins.IndexError
|
||||
RuntimeError = builtins.RuntimeError
|
||||
AssertionError = builtins.AssertionError
|
||||
AttributeError = builtins.AttributeError
|
||||
IndexError = builtins.IndexError
|
||||
IOError = builtins.IOError
|
||||
KeyError = builtins.KeyError
|
||||
NotImplementedError = builtins.NotImplementedError
|
||||
OverflowError = builtins.OverflowError
|
||||
RuntimeError = builtins.RuntimeError
|
||||
TimeoutError = builtins.TimeoutError
|
||||
TypeError = builtins.TypeError
|
||||
ValueError = builtins.ValueError
|
||||
ZeroDivisionError = builtins.ZeroDivisionError
|
||||
OSError = builtins.OSError
|
||||
|
||||
|
||||
class CoreException:
|
||||
|
@ -150,13 +164,13 @@ class DMAError(Exception):
|
|||
|
||||
class ClockFailure(Exception):
|
||||
"""Raised when RTIO PLL has lost lock."""
|
||||
|
||||
artiq_builtin = True
|
||||
|
||||
class I2CError(Exception):
|
||||
"""Raised when a I2C transaction fails."""
|
||||
pass
|
||||
artiq_builtin = True
|
||||
|
||||
|
||||
class SPIError(Exception):
|
||||
"""Raised when a SPI transaction fails."""
|
||||
pass
|
||||
artiq_builtin = True
|
||||
|
|
|
@ -333,18 +333,27 @@ extern fn stop_fn(_version: c_int,
|
|||
}
|
||||
}
|
||||
|
||||
static EXCEPTION_ID_LOOKUP: [(&str, u32); 11] = [
|
||||
("RuntimeError", 0),
|
||||
("RTIOUnderflow", 1),
|
||||
("RTIOOverflow", 2),
|
||||
("RTIODestinationUnreachable", 3),
|
||||
("DMAError", 4),
|
||||
("I2CError", 5),
|
||||
("CacheError", 6),
|
||||
("SPIError", 7),
|
||||
("ZeroDivisionError", 8),
|
||||
// Must be kept in sync with `artq.compiler.embedding`
|
||||
static EXCEPTION_ID_LOOKUP: [(&str, u32); 19] = [
|
||||
("RTIOUnderflow", 0),
|
||||
("RTIOOverflow", 1),
|
||||
("RTIODestinationUnreachable", 2),
|
||||
("DMAError", 3),
|
||||
("I2CError", 4),
|
||||
("CacheError", 5),
|
||||
("SPIError", 6),
|
||||
("AssertionError", 7),
|
||||
("AttributeError", 8),
|
||||
("IndexError", 9),
|
||||
("UnwrapNoneError", 10),
|
||||
("IOError", 10),
|
||||
("KeyError", 11),
|
||||
("NotImplementedError", 12),
|
||||
("OverflowError", 13),
|
||||
("RuntimeError", 14),
|
||||
("TimeoutError", 15),
|
||||
("TypeError", 16),
|
||||
("ValueError", 17),
|
||||
("ZeroDivisionError", 18),
|
||||
];
|
||||
|
||||
pub fn get_exception_id(name: &str) -> u32 {
|
||||
|
|
|
@ -8,7 +8,7 @@ def catch(f):
|
|||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
# CHECK-L: 8(0, 0, 0)
|
||||
# CHECK-L: 18(0, 0, 0)
|
||||
catch(lambda: 1/0)
|
||||
# CHECK-L: 9(10, 1, 0)
|
||||
catch(lambda: [1.0][10])
|
||||
|
|
|
@ -10,7 +10,7 @@ def catch(f):
|
|||
except IndexError as ie:
|
||||
print(ie)
|
||||
|
||||
# CHECK-L: 8(0, 0, 0)
|
||||
# CHECK-L: 18(0, 0, 0)
|
||||
catch(lambda: 1/0)
|
||||
# CHECK-L: 9(10, 1, 0)
|
||||
catch(lambda: [1.0][10])
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# REQUIRES: exceptions
|
||||
|
||||
def f():
|
||||
# CHECK-L: Uncaught 8
|
||||
# CHECK-L: Uncaught 18
|
||||
# CHECK-L: at input.py:${LINE:+1}:
|
||||
1/0
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ def g():
|
|||
try:
|
||||
f()
|
||||
except Exception as e:
|
||||
# CHECK-L: Uncaught 8
|
||||
# CHECK-L: Uncaught 18
|
||||
# CHECK-L: at input.py:${LINE:+1}:
|
||||
raise e
|
||||
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
# RUN: OutputCheck %s --file-to-check=%t
|
||||
# REQUIRES: exceptions
|
||||
|
||||
# CHECK-L: Uncaught 8: cannot divide by zero (0, 0, 0)
|
||||
# CHECK-L: Uncaught 18: cannot divide by zero (0, 0, 0)
|
||||
# CHECK-L: at input.py:${LINE:+1}:
|
||||
1/0
|
||||
|
|
Loading…
Reference in New Issue