forked from M-Labs/nac3
1
0
Fork 0

nac3embedded: RTIO syscalls

This commit is contained in:
Sebastien Bourdeauducq 2021-09-24 11:39:26 +08:00
parent 13bd18bfcb
commit ac17bf50f8
4 changed files with 43 additions and 10 deletions

View File

@ -1,11 +1,37 @@
from language import * 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 @kernel
class Demo: class Demo:
@kernel @kernel
def run(self): def run(self):
pass rtio_init()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -4,26 +4,32 @@ from functools import wraps
import nac3embedded import nac3embedded
__all__ = ["kernel"] __all__ = ["syscall", "kernel"]
nac3 = nac3embedded.NAC3() 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): def kernel(function_or_class):
global allow_class_registration global allow_object_registration
if isclass(function_or_class): if isclass(function_or_class):
assert allow_class_registration assert allow_object_registration
nac3.register_class(function_or_class) nac3.register_object(function_or_class)
return function_or_class return function_or_class
else: else:
@wraps(function_or_class) @wraps(function_or_class)
def run_on_core(self, *args, **kwargs): def run_on_core(self, *args, **kwargs):
global allow_class_registration global allow_object_registration
if allow_class_registration: if allow_object_registration:
nac3.analyze() nac3.analyze()
allow_class_registration = False allow_object_registration = False
nac3.compile_method(self.__class__.__name__, function_or_class.__name__) nac3.compile_method(self.__class__.__name__, function_or_class.__name__)
return run_on_core return run_on_core

View File

@ -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<()> { Python::with_gil(|py| -> PyResult<()> {
let obj: &PyAny = obj.extract(py)?; let obj: &PyAny = obj.extract(py)?;

View File

@ -12,5 +12,6 @@ in
libffi libffi
libxml2 libxml2
clippy clippy
python3.withPackages(ps: [ps.numpy])
]; ];
} }