diff --git a/Cargo.lock b/Cargo.lock index 857ba230..f16dee50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -459,6 +459,8 @@ dependencies = [ name = "nac3embedded" version = "0.1.0" dependencies = [ + "inkwell", + "nac3core", "pyo3", "rustpython-parser", ] diff --git a/nac3embedded/Cargo.toml b/nac3embedded/Cargo.toml index e2b466f0..c7f9c0b6 100644 --- a/nac3embedded/Cargo.toml +++ b/nac3embedded/Cargo.toml @@ -10,4 +10,6 @@ crate-type = ["cdylib"] [dependencies] pyo3 = { version = "0.12.4", features = ["extension-module"] } +inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm10-0"] } rustpython-parser = { git = "https://github.com/RustPython/RustPython", branch = "master" } +nac3core = { path = "../nac3core" } diff --git a/nac3embedded/demo.py b/nac3embedded/demo.py index 9264b960..58f91d27 100644 --- a/nac3embedded/demo.py +++ b/nac3embedded/demo.py @@ -3,8 +3,8 @@ from language import * class Demo: @kernel - def run(self): - pass + def run(self: bool) -> bool: + return False if __name__ == "__main__": diff --git a/nac3embedded/src/lib.rs b/nac3embedded/src/lib.rs index 91165859..270b9e8b 100644 --- a/nac3embedded/src/lib.rs +++ b/nac3embedded/src/lib.rs @@ -4,6 +4,10 @@ use std::collections::hash_map::Entry; use pyo3::prelude::*; use pyo3::exceptions; use rustpython_parser::{ast, parser}; +use inkwell::context::Context; +use inkwell::targets::*; + +use nac3core::CodeGen; fn runs_on_core(decorator_list: &[ast::Expression]) -> bool { for decorator in decorator_list.iter() { @@ -87,7 +91,11 @@ impl Nac3 { decorator_list, returns: _ } = &statement.node { if runs_on_core(decorator_list) && funcdef_name == &name { - println!("found: {:?}", &statement.node); + let context = Context::create(); + let mut codegen = CodeGen::new(&context); + codegen.compile_toplevel(&body[0]).map_err(|e| + exceptions::PyRuntimeError::new_err(format!("compilation failed: {}", e)))?; + codegen.print_ir(); } } } @@ -102,6 +110,7 @@ impl Nac3 { #[pymodule] fn nac3embedded(_py: Python, m: &PyModule) -> PyResult<()> { + Target::initialize_all(&InitializationConfig::default()); m.add_class::()?; Ok(()) }