nac3core: fixes #32 and #57

escape-analysis
pca006132 2021-10-09 16:20:49 +08:00
parent a22552a012
commit a3ce5be10b
2 changed files with 12 additions and 2 deletions

View File

@ -7,7 +7,7 @@ class Demo:
core: Core
led: TTLOut
@portable # FIXME: why does it still compile if @portable is removed?
@portable
def __init__(self):
self.core = Core()
self.led = TTLOut(0)

View File

@ -419,8 +419,13 @@ impl TopLevelComposer {
// we do not push anything to the def list, so we keep track of the index
// and then push in the correct order after the for loop
let mut class_method_index_offset = 0;
let mut contains_constructor = false;
let init_id = "__init__".into();
for b in body {
if let ast::StmtKind::FunctionDef { name: method_name, .. } = &b.node {
if method_name == &init_id {
contains_constructor = true;
}
if self.keyword_list.contains(method_name) {
return Err("cannot use keyword as a method name".into());
}
@ -484,7 +489,12 @@ impl TopLevelComposer {
self.definition_ast_list.push((def, Some(ast)));
}
Ok((class_name, DefinitionId(class_def_id), Some(constructor_ty)))
let result_ty = if contains_constructor {
Some(constructor_ty)
} else {
None
};
Ok((class_name, DefinitionId(class_def_id), result_ty))
}
ast::StmtKind::FunctionDef { name, .. } => {