From ac17bf50f8fcf6d1d82eba54a50b0a7be644edd6 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 24 Sep 2021 11:39:26 +0800 Subject: [PATCH] nac3embedded: RTIO syscalls --- nac3embedded/demo.py | 28 +++++++++++++++++++++++++++- nac3embedded/language.py | 22 ++++++++++++++-------- nac3embedded/src/lib.rs | 2 +- shell.nix | 1 + 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/nac3embedded/demo.py b/nac3embedded/demo.py index 4160f325e..532c623de 100644 --- a/nac3embedded/demo.py +++ b/nac3embedded/demo.py @@ -1,11 +1,37 @@ from language import * +from numpy import int32, int64 + + +@syscall +def rtio_init(): + raise NotImplementedError("syscall not simulated") + + +@syscall +def rtio_get_counter() -> int64: + raise NotImplementedError("syscall not simulated") + + +@syscall +def rtio_output(target: int32, data: int32): + raise NotImplementedError("syscall not simulated") + + +@syscall +def rtio_input_timestamp(timeout_mu: int64, channel: int32) -> int64: + raise NotImplementedError("syscall not simulated") + + +@syscall +def rtio_input_data(channel: int32) -> int32: + raise NotImplementedError("syscall not simulated") @kernel class Demo: @kernel def run(self): - pass + rtio_init() if __name__ == "__main__": diff --git a/nac3embedded/language.py b/nac3embedded/language.py index a9ed614dc..3a767a212 100644 --- a/nac3embedded/language.py +++ b/nac3embedded/language.py @@ -4,26 +4,32 @@ from functools import wraps import nac3embedded -__all__ = ["kernel"] +__all__ = ["syscall", "kernel"] nac3 = nac3embedded.NAC3() -allow_class_registration = True +allow_object_registration = True + + +def syscall(function): + assert allow_object_registration + nac3.register_object(function) + return function def kernel(function_or_class): - global allow_class_registration + global allow_object_registration if isclass(function_or_class): - assert allow_class_registration - nac3.register_class(function_or_class) + assert allow_object_registration + nac3.register_object(function_or_class) return function_or_class else: @wraps(function_or_class) def run_on_core(self, *args, **kwargs): - global allow_class_registration - if allow_class_registration: + global allow_object_registration + if allow_object_registration: nac3.analyze() - allow_class_registration = False + allow_object_registration = False nac3.compile_method(self.__class__.__name__, function_or_class.__name__) return run_on_core diff --git a/nac3embedded/src/lib.rs b/nac3embedded/src/lib.rs index 94ce172ed..a7b31074f 100644 --- a/nac3embedded/src/lib.rs +++ b/nac3embedded/src/lib.rs @@ -67,7 +67,7 @@ impl Nac3 { } } - fn register_class(&mut self, obj: PyObject) -> PyResult<()> { + fn register_object(&mut self, obj: PyObject) -> PyResult<()> { Python::with_gil(|py| -> PyResult<()> { let obj: &PyAny = obj.extract(py)?; diff --git a/shell.nix b/shell.nix index 070196c7e..7a073d6ee 100644 --- a/shell.nix +++ b/shell.nix @@ -12,5 +12,6 @@ in libffi libxml2 clippy + python3.withPackages(ps: [ps.numpy]) ]; }