From a35219396bb04ace84f4d6822de5460d0198b7d4 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Thu, 5 Sep 2024 17:20:28 +0800 Subject: [PATCH] make note of subkernel id, and destination at some point --- nac3artiq/src/lib.rs | 12 ++++++++++++ nac3core/src/toplevel/composer.rs | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index 369f2d6c..ea624c20 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -412,6 +412,7 @@ impl Nac3 { let mut module_to_resolver_cache: HashMap = HashMap::new(); let mut rpc_ids = vec![]; + let mut subkernel_ids = vec![]; for (stmt, path, module) in &self.top_levels { let py_module: &PyAny = module.extract(py)?; let module_id: u64 = id_fn.call1((py_module,))?.extract()?; @@ -501,6 +502,8 @@ impl Nac3 { .any(|decorator| decorator_id_string(decorator) == Some("subkernel".to_string())) { store_fun.call1(py, (def_id.0.into_py(py), module.getattr(py, name.to_string().as_str()).unwrap())).unwrap(); + let dest = decorator_list.SOMETHING; + subkernel_rpc_ids.push((None, def_id, dest)); } } StmtKind::ClassDef { name, body, .. } => { @@ -523,6 +526,15 @@ impl Nac3 { ))); } rpc_ids.push((Some((class_obj.clone(), *name)), def_id, is_async)); + } else if decorator_list.iter().any(|decorator| matches!(decorator.node, ExprKind::Name { id, .. } if id == "subkernel".into())) { + if name == &"__init__".into() { + return Err(CompileError::new_err(format!( + "compilation failed\n----------\nThe constructor of class {} should not be decorated with subkernel decorator (at {})", + class_name, stmt.location + ))); + } + let dest = decorator_list.iter(). // figure out what's in the decorator list + subkernel_ids.push((Some((class_obj.clone(), *name)), def_id, dest)); } } } diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index b93e1b36..5e456888 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -2134,6 +2134,13 @@ impl TopLevelComposer { instance_to_symbol.insert(String::new(), simple_name.to_string()); continue; } + if !decorator_list.is_empty() + && matches!(&decorator_list[0].node, + ast::ExprKind::Name{ id, .. } if id == &"subkernel".into()) + { + instance_to_symbol.insert(String::new(), simple_name.to_string()); + continue; + } if matches!(&decorator_list[0].node, ExprKind::Name { id, .. } if id == &"rpc".into()) {