1
0
forked from M-Labs/nac3

make note of subkernel id, and destination at some point

This commit is contained in:
mwojcik 2024-09-05 17:20:28 +08:00
parent 52d6121a84
commit 47cb3ebddf
2 changed files with 19 additions and 1 deletions

View File

@ -415,6 +415,7 @@ impl Nac3 {
let mut module_to_resolver_cache: HashMap<u64, _> = HashMap::new(); let mut module_to_resolver_cache: HashMap<u64, _> = HashMap::new();
let mut rpc_ids = vec![]; let mut rpc_ids = vec![];
let mut subkernel_ids = vec![];
for (stmt, path, module) in &self.top_levels { for (stmt, path, module) in &self.top_levels {
let py_module: &PyAny = module.extract(py)?; let py_module: &PyAny = module.extract(py)?;
let module_id: u64 = id_fn.call1((py_module,))?.extract()?; let module_id: u64 = id_fn.call1((py_module,))?.extract()?;
@ -484,7 +485,8 @@ impl Nac3 {
rpc_ids.push((None, def_id)); rpc_ids.push((None, def_id));
} else if decorator_list.iter().any(|decorator| matches!(decorator.node, ExprKind::Name { id, .. } if id == "subkernel".into())) { } else if decorator_list.iter().any(|decorator| matches!(decorator.node, ExprKind::Name { id, .. } if id == "subkernel".into())) {
store_fun.call1(py, (def_id.0.into_py(py), module.getattr(py, name.to_string().as_str()).unwrap())).unwrap(); store_fun.call1(py, (def_id.0.into_py(py), module.getattr(py, name.to_string().as_str()).unwrap())).unwrap();
//rpc_ids.push((None, def_id)); let dest = decorator_list.SOMETHING
subkernel_rpc_ids.push((None, def_id, dest));
} }
} }
StmtKind::ClassDef { name, body, .. } => { StmtKind::ClassDef { name, body, .. } => {
@ -500,6 +502,15 @@ impl Nac3 {
))); )));
} }
rpc_ids.push((Some((class_obj.clone(), *name)), def_id)); rpc_ids.push((Some((class_obj.clone(), *name)), def_id));
} 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));
} }
} }
} }

View File

@ -2057,6 +2057,13 @@ impl TopLevelComposer {
instance_to_symbol.insert(String::new(), simple_name.to_string()); instance_to_symbol.insert(String::new(), simple_name.to_string());
continue; 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;
}
let fun_body = body let fun_body = body
.into_iter() .into_iter()