From 127b1171132062664c9b1ec6641d4fa48f1f27b2 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 15 Jan 2016 16:35:12 +0000 Subject: [PATCH] Add @host_only function decorator (#172). --- artiq/compiler/embedding.py | 6 ++++++ artiq/frontend/artiq_run.py | 1 + artiq/language/core.py | 22 +++++++++++++++++----- artiq/master/worker_impl.py | 1 + 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/artiq/compiler/embedding.py b/artiq/compiler/embedding.py index 4adb38814..fb185a39b 100644 --- a/artiq/compiler/embedding.py +++ b/artiq/compiler/embedding.py @@ -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: diff --git a/artiq/frontend/artiq_run.py b/artiq/frontend/artiq_run.py index 4bb33c606..a51b8083e 100755 --- a/artiq/frontend/artiq_run.py +++ b/artiq/frontend/artiq_run.py @@ -60,6 +60,7 @@ class DummyScheduler: def get_status(self): return dict() + @host_only def pause(self): pass diff --git a/artiq/language/core.py b/artiq/language/core.py index f32b598ee..a374562a9 100644 --- a/artiq/language/core.py +++ b/artiq/language/core.py @@ -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): diff --git a/artiq/master/worker_impl.py b/artiq/master/worker_impl.py index db3f33c20..13ecf9b61 100644 --- a/artiq/master/worker_impl.py +++ b/artiq/master/worker_impl.py @@ -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