From add536428ef85c4a497e3a12a531489119e56fda Mon Sep 17 00:00:00 2001 From: ychenfo Date: Sat, 26 Mar 2022 13:39:09 +0800 Subject: [PATCH] nac3core/artiq: raise dedicated UnwrapNoneError --- nac3artiq/demo/embedding_map.py | 3 ++- nac3artiq/demo/min_artiq.py | 9 +++++++-- nac3core/src/codegen/expr.rs | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/nac3artiq/demo/embedding_map.py b/nac3artiq/demo/embedding_map.py index 74b9aa1a9..dc64d7df1 100644 --- a/nac3artiq/demo/embedding_map.py +++ b/nac3artiq/demo/embedding_map.py @@ -16,7 +16,8 @@ class EmbeddingMap: "CacheError", "SPIError", "0:ZeroDivisionError", - "0:IndexError"]) + "0:IndexError", + "0:UnwrapNoneError"]) def preallocate_runtime_exception_names(self, names): for i, name in enumerate(names): diff --git a/nac3artiq/demo/min_artiq.py b/nac3artiq/demo/min_artiq.py index c361d55b9..1dd5786ab 100644 --- a/nac3artiq/demo/min_artiq.py +++ b/nac3artiq/demo/min_artiq.py @@ -11,7 +11,7 @@ from embedding_map import EmbeddingMap __all__ = [ "Kernel", "KernelInvariant", "virtual", - "Option", "Some", "none", + "Option", "Some", "none", "UnwrapNoneError", "round64", "floor64", "ceil64", "extern", "kernel", "portable", "nac3", "rpc", "ms", "us", "ns", @@ -47,7 +47,7 @@ class Option(Generic[T]): def unwrap(self): if self.is_none(): - raise ValueError("unwrap on none") + raise UnwrapNoneError() return self._nac3_option def __repr__(self) -> str: @@ -274,5 +274,10 @@ class KernelContextManager: def __exit__(self): pass +@nac3 +class UnwrapNoneError(Exception): + """raised when unwrapping a none value""" + artiq_builtin = True + parallel = KernelContextManager() sequential = KernelContextManager() diff --git a/nac3core/src/codegen/expr.rs b/nac3core/src/codegen/expr.rs index 72bc2cd65..7991b55cf 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -1319,8 +1319,8 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>( ctx.make_assert( generator, not_null, - "0:ValueError", - "unwrap on none", + "0:UnwrapNoneError", + "", [None, None, None], expr.location, );