nac3core/artiq: raise dedicated UnwrapNoneError

This commit is contained in:
ychenfo 2022-03-26 13:39:09 +08:00
parent 8cdcb663f4
commit add536428e
3 changed files with 11 additions and 5 deletions

View File

@ -16,7 +16,8 @@ class EmbeddingMap:
"CacheError", "CacheError",
"SPIError", "SPIError",
"0:ZeroDivisionError", "0:ZeroDivisionError",
"0:IndexError"]) "0:IndexError",
"0:UnwrapNoneError"])
def preallocate_runtime_exception_names(self, names): def preallocate_runtime_exception_names(self, names):
for i, name in enumerate(names): for i, name in enumerate(names):

View File

@ -11,7 +11,7 @@ from embedding_map import EmbeddingMap
__all__ = [ __all__ = [
"Kernel", "KernelInvariant", "virtual", "Kernel", "KernelInvariant", "virtual",
"Option", "Some", "none", "Option", "Some", "none", "UnwrapNoneError",
"round64", "floor64", "ceil64", "round64", "floor64", "ceil64",
"extern", "kernel", "portable", "nac3", "extern", "kernel", "portable", "nac3",
"rpc", "ms", "us", "ns", "rpc", "ms", "us", "ns",
@ -47,7 +47,7 @@ class Option(Generic[T]):
def unwrap(self): def unwrap(self):
if self.is_none(): if self.is_none():
raise ValueError("unwrap on none") raise UnwrapNoneError()
return self._nac3_option return self._nac3_option
def __repr__(self) -> str: def __repr__(self) -> str:
@ -274,5 +274,10 @@ class KernelContextManager:
def __exit__(self): def __exit__(self):
pass pass
@nac3
class UnwrapNoneError(Exception):
"""raised when unwrapping a none value"""
artiq_builtin = True
parallel = KernelContextManager() parallel = KernelContextManager()
sequential = KernelContextManager() sequential = KernelContextManager()

View File

@ -1319,8 +1319,8 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
ctx.make_assert( ctx.make_assert(
generator, generator,
not_null, not_null,
"0:ValueError", "0:UnwrapNoneError",
"unwrap on none", "",
[None, None, None], [None, None, None],
expr.location, expr.location,
); );