type checking / symbol table stuff
This commit is contained in:
parent
e412fb9a89
commit
62edc7c996
@ -1,11 +1,17 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use schala_lang::parsing::{AST, Statement, Declaration, Expression, ExpressionType, Operation, TypeAnno};
|
use schala_lang::parsing::{AST, Statement, Declaration, Expression, ExpressionType, Operation, TypeAnno};
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||||
|
struct PathSpecifier(String);
|
||||||
|
|
||||||
struct SymbolTable {
|
struct SymbolTable {
|
||||||
|
map: HashMap<PathSpecifier, Expression>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SymbolTable {
|
impl SymbolTable {
|
||||||
fn new() -> SymbolTable {
|
fn new() -> SymbolTable {
|
||||||
SymbolTable { }
|
SymbolTable { map: HashMap::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_symbols(&mut self, ast: &AST) {
|
fn add_symbols(&mut self, ast: &AST) {
|
||||||
@ -51,6 +57,16 @@ impl TypeContext {
|
|||||||
return Err(format!("Declarations not supported"));
|
return Err(format!("Declarations not supported"));
|
||||||
},
|
},
|
||||||
&Statement::ExpressionStatement(ref expr) => {
|
&Statement::ExpressionStatement(ref expr) => {
|
||||||
|
self.expr_type_check(expr)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(SchalaType { })
|
||||||
|
}
|
||||||
|
|
||||||
|
fn expr_type_check(&mut self, expr: &Expression) -> TypeCheckResult {
|
||||||
|
use self::ExpressionType::*;
|
||||||
|
|
||||||
match (&expr.0, &expr.1) {
|
match (&expr.0, &expr.1) {
|
||||||
(&IntLiteral(_), &Some(ref t)) => {
|
(&IntLiteral(_), &Some(ref t)) => {
|
||||||
match t {
|
match t {
|
||||||
@ -60,9 +76,6 @@ impl TypeContext {
|
|||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(SchalaType { })
|
Ok(SchalaType { })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user