2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 03:08:27 +08:00

Add @host_only function decorator (#172).

This commit is contained in:
whitequark 2016-01-15 16:35:12 +00:00
parent 15039e1d74
commit 127b117113
4 changed files with 25 additions and 5 deletions

View File

@ -739,6 +739,12 @@ class Stitcher:
# to perform a system call instead of a regular call.
result = self._quote_foreign_function(function, loc,
syscall=function.artiq_embedded.syscall)
elif function.artiq_embedded.forbidden is not None:
diag = diagnostic.Diagnostic("fatal",
"this function cannot be called as an RPC", {},
self._function_loc(function),
notes=self._call_site_note(loc, is_syscall=True))
self.engine.process(diag)
else:
assert False
else:

View File

@ -60,6 +60,7 @@ class DummyScheduler:
def get_status(self):
return dict()
@host_only
def pause(self):
pass

View File

@ -11,7 +11,7 @@ from artiq.coredevice.runtime import source_loader
__all__ = ["host_int", "int", "host_round", "round",
"kernel", "portable", "syscall",
"kernel", "portable", "syscall", "host_only",
"set_time_manager", "set_watchdog_factory",
"ARTIQException",
"TerminationRequested"]
@ -168,7 +168,7 @@ def round(value, width=32):
_ARTIQEmbeddedInfo = namedtuple("_ARTIQEmbeddedInfo",
"core_name function syscall")
"core_name function syscall forbidden")
def kernel(arg):
"""
@ -196,7 +196,8 @@ def kernel(arg):
def run_on_core(self, *k_args, **k_kwargs):
return getattr(self, arg).run(run_on_core, ((self,) + k_args), k_kwargs)
run_on_core.artiq_embedded = _ARTIQEmbeddedInfo(
core_name=arg, function=function, syscall=None)
core_name=arg, function=function, syscall=None,
forbidden=False)
return run_on_core
return inner_decorator
else:
@ -213,7 +214,8 @@ def portable(function):
on the core device (no RPC).
"""
function.artiq_embedded = \
_ARTIQEmbeddedInfo(core_name=None, function=function, syscall=None)
_ARTIQEmbeddedInfo(core_name=None, function=function, syscall=None,
forbidden=False)
return function
def syscall(arg):
@ -231,12 +233,22 @@ def syscall(arg):
def inner_decorator(function):
function.artiq_embedded = \
_ARTIQEmbeddedInfo(core_name=None, function=None,
syscall=function.__name__)
syscall=function.__name__, forbidden=False)
return function
return inner_decorator
else:
return syscall(arg.__name__)(arg)
def host_only(function):
"""
This decorator marks a function so that it can only be executed
in the host Python interpreter.
"""
function.artiq_embedded = \
_ARTIQEmbeddedInfo(core_name=None, function=None, syscall=None,
forbidden=True)
return function
class _DummyTimeManager:
def _not_implemented(self, *args, **kwargs):

View File

@ -93,6 +93,7 @@ set_watchdog_factory(Watchdog)
class Scheduler:
pause_noexc = staticmethod(make_parent_action("pause"))
@host_only
def pause(self):
if self.pause_noexc():
raise TerminationRequested