diff --git a/semantic/src/lib.rs b/semantic/src/lib.rs index b601db3..8dd6f97 100644 --- a/semantic/src/lib.rs +++ b/semantic/src/lib.rs @@ -1,3 +1,37 @@ +use std::sync::Arc; + +use crate::scope::{LocalScope, Scope}; + pub mod hir; pub mod scope; pub mod top_level; + +pub fn walk_ast(top_scope: Arc, tl: &mut Vec) { + for tl in tl { + match tl { + parser::ast::TopLevel::Import(_) => unimplemented!(), + + parser::ast::TopLevel::FunctionDecl { + export, + name, + params, + return_type, + body, + } => { + let scope = LocalScope::new(top_scope.clone()); + + scope.with_params(params); + + scope.with_block(body); + + println!("{:?}", scope); + } + + parser::ast::TopLevel::StructDecl { + export, + name, + fields, + } => {} + } + } +} diff --git a/semantic/src/scope.rs b/semantic/src/scope.rs index 34ce4b1..7dd42c8 100644 --- a/semantic/src/scope.rs +++ b/semantic/src/scope.rs @@ -61,6 +61,7 @@ impl LocalScope { for statement in &mut block.0 { match statement { Statement::Block(b) => self.clone().with_block(b), + Statement::VarDecl { kind, name, init } => unimplemented!(), _ => {} } } @@ -85,33 +86,3 @@ impl LocalScope { } } } - -pub fn walk_ast(top_scope: Arc, tl: &mut Vec) { - for tl in tl { - match tl { - parser::ast::TopLevel::Import(_) => unimplemented!(), - - parser::ast::TopLevel::FunctionDecl { - export, - name, - params, - return_type, - body, - } => { - let scope = LocalScope::new(top_scope.clone()); - - scope.with_params(params); - - scope.with_block(body); - - println!("{:?}", scope); - } - - parser::ast::TopLevel::StructDecl { - export, - name, - fields, - } => {} - } - } -} diff --git a/src/main.rs b/src/main.rs index fc20c5b..dec07c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use std::fs; use std::path::PathBuf; use std::process; -use semantic::scope::walk_ast; +use semantic::walk_ast; fn main() { let args: Vec = std::env::args().collect(); diff --git a/test/src/main.ms b/test/src/main.ms index bede08a..350881d 100644 --- a/test/src/main.ms +++ b/test/src/main.ms @@ -1,6 +1,3 @@ -struct AddParams { - x: int, - y: int, -} - -function add(p: AddParams) {} +function add(a: int, b: int) { + let a = 10; +} \ No newline at end of file