forked from M-Labs/nac3
subkernels: get destination from decorator
This commit is contained in:
parent
a35219396b
commit
0cbea962b2
@ -501,9 +501,22 @@ impl Nac3 {
|
|||||||
.iter()
|
.iter()
|
||||||
.any(|decorator| decorator_id_string(decorator) == Some("subkernel".to_string()))
|
.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();
|
if let Constant::Int(destination) = decorator_get_destination(decorator) {
|
||||||
let dest = decorator_list.SOMETHING;
|
if destination < 0 || destination > 255 {
|
||||||
subkernel_rpc_ids.push((None, def_id, dest));
|
return Err(CompileError::new_err(format!(
|
||||||
|
"compilation failed\n----------\nSubkernel destination must be between 0 and 255 (at {})",
|
||||||
|
stmt.location
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
subkernel_ids.push((None, def_id, destination));
|
||||||
|
} else {
|
||||||
|
return Err(CompileError::new_err(format!(
|
||||||
|
"compilation failed\n----------\nDestination must be provided for subkernels (at {})",
|
||||||
|
stmt.location
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
// store_fun.call1(py, (def_id.0.into_py(py), module.getattr(py, name.to_string().as_str()).unwrap())).unwrap();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StmtKind::ClassDef { name, body, .. } => {
|
StmtKind::ClassDef { name, body, .. } => {
|
||||||
@ -527,14 +540,28 @@ impl Nac3 {
|
|||||||
}
|
}
|
||||||
rpc_ids.push((Some((class_obj.clone(), *name)), def_id, is_async));
|
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())) {
|
} else if decorator_list.iter().any(|decorator| matches!(decorator.node, ExprKind::Name { id, .. } if id == "subkernel".into())) {
|
||||||
if name == &"__init__".into() {
|
if let Constant::Int(destination) = decorator_get_destination(decorator) {
|
||||||
|
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
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if destination < 0 || destination > 255 {
|
||||||
|
return Err(CompileError::new_err(format!(
|
||||||
|
"compilation failed\n----------\nSubkernel destination must be between 0 and 255 (at {})",
|
||||||
|
stmt.location
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
subkernel_ids.push((Some((class_obj.clone(), *name)), def_id, destination));
|
||||||
|
} else {
|
||||||
return Err(CompileError::new_err(format!(
|
return Err(CompileError::new_err(format!(
|
||||||
"compilation failed\n----------\nThe constructor of class {} should not be decorated with subkernel decorator (at {})",
|
"compilation failed\n----------\nDestination must be provided for subkernels (at {})",
|
||||||
class_name, stmt.location
|
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -922,6 +949,20 @@ fn decorator_get_flags(decorator: &Located<ExprKind>) -> Vec<Constant> {
|
|||||||
flags
|
flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn decorator_get_destination(decorator: &Located<ExprKind>) -> Option<Constant> {
|
||||||
|
if let ExprKind::Call { keywords, .. } = &decorator.node {
|
||||||
|
for keyword in keywords {
|
||||||
|
if keyword.node.arg != Some("destination".into()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let ExprKind::Constant { value, .. } = &keyword.node.value.node {
|
||||||
|
return Some(value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
fn link_with_lld(elf_filename: String, obj_filename: String) -> PyResult<()> {
|
fn link_with_lld(elf_filename: String, obj_filename: String) -> PyResult<()> {
|
||||||
let linker_args = vec![
|
let linker_args = vec![
|
||||||
"-shared".to_string(),
|
"-shared".to_string(),
|
||||||
|
Loading…
Reference in New Issue
Block a user