diff --git a/.gitignore b/.gitignore index ea8c4bf..691f494 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +__pycache__ /target diff --git a/nac3embedded/demo.py b/nac3embedded/demo.py new file mode 100644 index 0000000..9264b96 --- /dev/null +++ b/nac3embedded/demo.py @@ -0,0 +1,11 @@ +from language import * + + +class Demo: + @kernel + def run(self): + pass + + +if __name__ == "__main__": + Demo().run() diff --git a/nac3embedded/language.py b/nac3embedded/language.py new file mode 100644 index 0000000..57e10d9 --- /dev/null +++ b/nac3embedded/language.py @@ -0,0 +1,17 @@ +from functools import wraps + +import nac3embedded + + +__all__ = ["kernel", "portable"] + + +def kernel(function): + @wraps(function) + def run_on_core(self, *args, **kwargs): + nac3embedded.add_host_object(self) + return run_on_core + + +def portable(function): + return fn diff --git a/nac3embedded/src/lib.rs b/nac3embedded/src/lib.rs index c0e864d..213f15e 100644 --- a/nac3embedded/src/lib.rs +++ b/nac3embedded/src/lib.rs @@ -2,13 +2,20 @@ use pyo3::prelude::*; use pyo3::wrap_pyfunction; #[pyfunction] -fn sum_as_string(a: usize, b: usize) -> PyResult { - Ok((a + b).to_string()) +fn add_host_object(obj: PyObject) -> PyResult<()> { + Python::with_gil(|py| -> PyResult<()> { + let obj: &PyAny = obj.extract(py)?; + let inspect = PyModule::import(py, "inspect")?; + let source = inspect.call1("getsource", (obj.get_type(), ))?; + println!("source:\n{}", source); + Ok(()) + })?; + Ok(()) } #[pymodule] -fn nac3embedded(py: Python, m: &PyModule) -> PyResult<()> { - m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; +fn nac3embedded(_py: Python, m: &PyModule) -> PyResult<()> { + m.add_function(wrap_pyfunction!(add_host_object, m)?)?; Ok(()) }