diff --git a/nac3artiq/demo/nac3artiq.so b/nac3artiq/demo/nac3artiq.so deleted file mode 120000 index d05f6c9b..00000000 --- a/nac3artiq/demo/nac3artiq.so +++ /dev/null @@ -1 +0,0 @@ -../../target/release/libnac3artiq.so \ No newline at end of file diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index 870713ba..8fa14153 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -43,7 +43,7 @@ use nac3core::{ OptimizationLevel, }, nac3parser::{ - ast::{Constant, ExprKind, Located, Stmt, StmtKind, StrRef}, + ast::{Constant, ExprKind, Located, Location, Stmt, StmtKind, StrRef}, parser::parse_program, }, symbol_resolver::SymbolResolver, @@ -168,9 +168,10 @@ impl Nac3 { Ok((module.getattr("__name__")?.extract()?, source_file.to_string(), source)) })?; - let parser_result = parse_program(&source, source_file.into()) + let parser_result = parse_program(&source, source_file.clone().into()) .map_err(|e| exceptions::PySyntaxError::new_err(format!("parse error: {e}")))?; + let mut module_content: Vec = Vec::default(); for mut stmt in parser_result { let include = match stmt.node { StmtKind::ClassDef { ref decorator_list, ref mut body, ref mut bases, .. } => { @@ -232,9 +233,28 @@ impl Nac3 { }; if include { - self.top_levels.push((stmt, module_name.clone(), module.clone())); + module_content.push(stmt.clone()); + // self.top_levels.push((stmt, module_name.clone(), module.clone())); } } + let mut module_body: Vec = Vec::default(); + for stmt in module_content.iter() { + match &stmt.node { + StmtKind::FunctionDef { .. } => module_body.push(stmt.clone()), + _ => {} + } + } + // let module_def = StmtKind::ModuleDef { + // name: module_name.clone().into(), + // body: module_body + // }; + // let module_stmt = Located::new(Location::new(1, 1, source_file.into()), module_def); + // self.top_levels.push((module_stmt, module_name, module.clone())); + + for stmt in module_content { + self.top_levels.push((stmt, module_name.clone().into(), module.clone())); + } + Ok(()) } @@ -1044,6 +1064,34 @@ impl Nac3 { ), ]; + // let mut def_idx: usize = 1; + // let mut builtin_methods = Vec::new(); + // let mut top_levels: Vec = Vec::new(); + // for (name, signature, callback) in builtins { + // let function_def = TopLevelDef::Function { + // name: format!("__builtins__.{name}").into(), + // simple_name: name, + // signature: signature.ret, + // var_id: Vec::new(), + // instance_to_symbol: HashMap::new(), + // instance_to_stmt: HashMap::new(), + // resolver: None, + // codegen_callback: Some(callback), + // loc: None + // }; + // top_levels.push(( + // Arc::new(RwLock::new(function_def)), + // "__builtins__", + // None + // )); + // builtin_methods.push(( + // name, + // signature.ret, + // DefinitionId(def_idx) + // )); + // def_idx += 1; + // } + let builtins_mod = PyModule::import(py, "builtins").unwrap(); let id_fn = builtins_mod.getattr("id").unwrap(); let numpy_mod = PyModule::import(py, "numpy").unwrap(); diff --git a/nac3ast/src/ast_gen.rs b/nac3ast/src/ast_gen.rs index d23717dc..107171cb 100644 --- a/nac3ast/src/ast_gen.rs +++ b/nac3ast/src/ast_gen.rs @@ -115,6 +115,10 @@ pub enum StmtKind { type_comment: Option, config_comment: Vec, }, + // ModuleDef { + // name: Ident, + // body: Vec>, + // }, ClassDef { name: Ident, bases: Vec>, @@ -626,6 +630,12 @@ pub mod fold { type_comment: Foldable::fold(type_comment, folder)?, config_comment: Foldable::fold(config_comment, folder)?, }), + // StmtKind::ModuleDef { name, body } => { + // Ok(StmtKind::ModuleDef { + // name: Foldable::fold(name, folder)?, + // body: Foldable::fold(body, folder)?, + // }) + // } StmtKind::ClassDef { name, bases, keywords, body, decorator_list, config_comment } => { Ok(StmtKind::ClassDef { name: Foldable::fold(name, folder)?, diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index 499fed79..0183a9e1 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -224,6 +224,12 @@ impl TopLevelComposer { let defined_names = &mut self.defined_names; match &ast.node { + // ast::StmtKind::ModuleDef { name: module_name, body } => { + // // Add any exclusions to module naming here + // // Module classes and functions are handled separately + // // Register module name and fields here if any + // Ok(()) + // } ast::StmtKind::ClassDef { name: class_name, bases, body, .. } => { if self.keyword_list.contains(class_name) { return Err(format!(