Semantics in check

This commit is contained in:
2026-04-15 09:18:56 +02:00
parent 6717be038f
commit deeb9350b4
3 changed files with 10 additions and 2 deletions
+1
View File
@@ -2,6 +2,7 @@ use std::sync::Arc;
use crate::top_level::TopLevelScope; use crate::top_level::TopLevelScope;
#[derive(Clone, Debug)]
pub enum Scope { pub enum Scope {
TopLevel(TopLevelScope), TopLevel(TopLevelScope),
} }
+5
View File
@@ -4,13 +4,16 @@ use parser::ast::TopLevel;
use parser::ast::{ParamList, TypeExpr}; use parser::ast::{ParamList, TypeExpr};
#[derive(Clone, Debug)]
pub struct TypeSymbol(pub String); pub struct TypeSymbol(pub String);
#[derive(Clone, Debug)]
pub struct VarSymbol { pub struct VarSymbol {
pub var_type: TypeSymbol, pub var_type: TypeSymbol,
pub name: String, pub name: String,
} }
#[derive(Clone, Debug)]
pub struct FunctionSymbol { pub struct FunctionSymbol {
pub export: bool, pub export: bool,
pub name: String, pub name: String,
@@ -18,6 +21,7 @@ pub struct FunctionSymbol {
pub return_type: Option<TypeSymbol>, pub return_type: Option<TypeSymbol>,
} }
#[derive(Clone, Debug)]
pub struct StructSymbol { pub struct StructSymbol {
pub export: bool, pub export: bool,
pub name: String, pub name: String,
@@ -71,6 +75,7 @@ impl StructSymbol {
} }
} }
#[derive(Clone, Debug)]
pub struct TopLevelScope { pub struct TopLevelScope {
pub structs: HashMap<String, StructSymbol>, pub structs: HashMap<String, StructSymbol>,
pub functions: HashMap<String, FunctionSymbol>, pub functions: HashMap<String, FunctionSymbol>,
+4 -2
View File
@@ -53,8 +53,10 @@ pub fn cmd_build() {
fn cmd_check(path: &str) { fn cmd_check(path: &str) {
let source = read_ms_file(path); let source = read_ms_file(path);
match parser::parse(&source) { match parser::parse(&source) {
Ok(_) => { Ok(ast) => {
println!("ok"); println!("parse: ok");
println!("{:#?}", semantic::scope::Scope::from_top(&ast))
} }
Err(e) => { Err(e) => {
eprintln!("parse error:\n{}", e); eprintln!("parse error:\n{}", e);