forked from M-Labs/nac3
nac3embedded: basic source extraction
This commit is contained in:
parent
703059adab
commit
b79d8ad640
|
@ -1 +1,2 @@
|
|||
__pycache__
|
||||
/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;
|
||||
|
||||
#[pyfunction]
|
||||
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
|
||||
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(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue