nac3embedded: basic source extraction
This commit is contained in:
parent
703059adab
commit
b79d8ad640
|
@ -1 +1,2 @@
|
||||||
|
__pycache__
|
||||||
/target
|
/target
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
from language import *
|
||||||
|
|
||||||
|
|
||||||
|
class Demo:
|
||||||
|
@kernel
|
||||||
|
def run(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
Demo().run()
|
|
@ -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
|
|
@ -2,13 +2,20 @@ use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
use pyo3::wrap_pyfunction;
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
|
fn add_host_object(obj: PyObject) -> PyResult<()> {
|
||||||
Ok((a + b).to_string())
|
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]
|
#[pymodule]
|
||||||
fn nac3embedded(py: Python, m: &PyModule) -> PyResult<()> {
|
fn nac3embedded(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||||
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
|
m.add_function(wrap_pyfunction!(add_host_object, m)?)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue