diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index 0c580fb..e0ad609 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -36,7 +36,7 @@ mod eval; pub struct Schala { state: eval::State<'static>, symbol_table: Rc>, - type_context: typechecking::TypeContext, + type_context: typechecking::TypeContext<'static>, } impl Schala { diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index bdf89b1..d6c175c 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -9,6 +9,7 @@ use itertools::Itertools; */ use parsing; +use util::StateStack; pub type TypeName = Rc; type TypeResult = Result; @@ -28,11 +29,13 @@ enum TConst { Custom(String) } -pub struct TypeContext; +pub struct TypeContext<'a> { + values: StateStack<'a, TypeName, Type> +} -impl TypeContext { - pub fn new() -> TypeContext { - TypeContext { } +impl<'a> TypeContext<'a> { + pub fn new() -> TypeContext<'static> { + TypeContext { values: StateStack::new(None) } } pub fn debug_types(&self) -> String { @@ -45,7 +48,7 @@ impl TypeContext { } } -impl TypeContext { +impl<'a> TypeContext<'a> { fn infer_block(&mut self, block: &Vec) -> TypeResult { let mut output = Type::Const(TConst::Unit); for statement in block { @@ -60,6 +63,13 @@ impl TypeContext { } } fn infer_decl(&mut self, decl: &parsing::Declaration) -> TypeResult { + use parsing::Declaration::*; + match decl { + Binding { name, expr, .. } => { + + }, + _ => (), + } Ok(Type::Const(TConst::Unit)) } fn infer_expr(&mut self, expr: &parsing::Expression) -> TypeResult { @@ -79,6 +89,10 @@ impl TypeContext { Ok(match expr { NatLiteral(_) => Type::Const(Nat), StringLiteral(_) => Type::Const(StringT), + Call { f, arguments } => { + + return Err(format!("NOTDONE")) + }, _ => Type::Const(Unit) }) } diff --git a/schala-lang/src/util.rs b/schala-lang/src/util.rs index 33217f3..0e8cadf 100644 --- a/schala-lang/src/util.rs +++ b/schala-lang/src/util.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::hash::Hash; use std::cmp::Eq; +//TODO rename this ScopeStack #[derive(Default, Debug)] pub struct StateStack<'a, T: 'a, V: 'a> where T: Hash + Eq { parent: Option<&'a StateStack<'a, T, V>>, @@ -27,6 +28,7 @@ impl<'a, T, V> StateStack<'a, T, V> where T: Hash + Eq { (Some(value), _) => Some(value), } } + //TODO rename new_scope pub fn new_frame(&'a self, name: Option) -> StateStack<'a, T, V> where T: Hash + Eq { StateStack { parent: Some(self),