mirror of https://github.com/m-labs/artiq.git
update NAC3, define option type
This commit is contained in:
parent
a4c1f8a079
commit
d2add0a683
|
@ -1,6 +1,7 @@
|
||||||
from artiq.language.core import nac3
|
from artiq.language.core import nac3, UnwrapNoneError
|
||||||
from builtins import ZeroDivisionError, ValueError, IndexError, RuntimeError, AssertionError
|
from builtins import ZeroDivisionError, ValueError, IndexError, RuntimeError, AssertionError
|
||||||
|
|
||||||
|
|
||||||
@nac3
|
@nac3
|
||||||
class RTIOUnderflow(Exception):
|
class RTIOUnderflow(Exception):
|
||||||
"""Raised when the CPU or DMA core fails to submit a RTIO event early
|
"""Raised when the CPU or DMA core fails to submit a RTIO event early
|
||||||
|
|
|
@ -6,7 +6,6 @@ from typing import Generic, TypeVar
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from inspect import getfullargspec, getmodule
|
from inspect import getfullargspec, getmodule
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
from typing import TypeVar
|
|
||||||
from math import floor, ceil
|
from math import floor, ceil
|
||||||
|
|
||||||
from artiq.language import import_cache
|
from artiq.language import import_cache
|
||||||
|
@ -16,9 +15,10 @@ __all__ = [
|
||||||
"Kernel", "KernelInvariant", "virtual",
|
"Kernel", "KernelInvariant", "virtual",
|
||||||
"round64", "floor64", "ceil64",
|
"round64", "floor64", "ceil64",
|
||||||
"extern", "kernel", "portable", "nac3", "rpc",
|
"extern", "kernel", "portable", "nac3", "rpc",
|
||||||
|
"print_rpc",
|
||||||
|
"Option", "Some", "none", "UnwrapNoneError",
|
||||||
"parallel", "sequential",
|
"parallel", "sequential",
|
||||||
"set_watchdog_factory", "watchdog", "TerminationRequested",
|
"set_watchdog_factory", "watchdog", "TerminationRequested",
|
||||||
"print_rpc"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -109,13 +109,51 @@ def rpc(arg=None, flags={}):
|
||||||
return arg
|
return arg
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar('T')
|
|
||||||
|
|
||||||
@rpc
|
@rpc
|
||||||
def print_rpc(a: T):
|
def print_rpc(a: T):
|
||||||
print(a)
|
print(a)
|
||||||
|
|
||||||
|
|
||||||
|
@nac3
|
||||||
|
class UnwrapNoneError(Exception):
|
||||||
|
"""Raised when unwrapping a none Option."""
|
||||||
|
artiq_builtin = True
|
||||||
|
|
||||||
|
class Option(Generic[T]):
|
||||||
|
_nac3_option: T
|
||||||
|
|
||||||
|
def __init__(self, v: T):
|
||||||
|
self._nac3_option = v
|
||||||
|
|
||||||
|
def is_none(self):
|
||||||
|
return self._nac3_option is None
|
||||||
|
|
||||||
|
def is_some(self):
|
||||||
|
return self._nac3_option is not None
|
||||||
|
|
||||||
|
def unwrap(self):
|
||||||
|
if self.is_none():
|
||||||
|
raise UnwrapNoneError()
|
||||||
|
return self._nac3_option
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
if self.is_none():
|
||||||
|
return "none"
|
||||||
|
else:
|
||||||
|
return "Some({})".format(repr(self._nac3_option))
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
if self.is_none():
|
||||||
|
return "none"
|
||||||
|
else:
|
||||||
|
return "Some({})".format(str(self._nac3_option))
|
||||||
|
|
||||||
|
def Some(v: T) -> Option[T]:
|
||||||
|
return Option(v)
|
||||||
|
|
||||||
|
none = Option(None)
|
||||||
|
|
||||||
|
|
||||||
@nac3
|
@nac3
|
||||||
class KernelContextManager:
|
class KernelContextManager:
|
||||||
@kernel
|
@kernel
|
||||||
|
|
|
@ -23,7 +23,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):
|
||||||
|
|
|
@ -45,11 +45,11 @@
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1648132215,
|
"lastModified": 1648280781,
|
||||||
"narHash": "sha256-Sts6AGduDi4jsD6YSYR2bwHW35TByGgHAfVPrenrCxg=",
|
"narHash": "sha256-HSelJSl7Q4LNI1cCApsUULidDCnRcXRocT+/e31iHL8=",
|
||||||
"ref": "master",
|
"ref": "master",
|
||||||
"rev": "55db05fdbb2ee35a907d32de778887716f71f5fe",
|
"rev": "1ad4b0227c87736beec62d94161291b7e27de6cc",
|
||||||
"revCount": 680,
|
"revCount": 685,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.m-labs.hk/m-labs/nac3.git"
|
"url": "https://git.m-labs.hk/m-labs/nac3.git"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue