More work

This commit is contained in:
greg 2018-05-29 00:09:12 -07:00
parent c4666b82ec
commit 07af54b78a
3 changed files with 22 additions and 6 deletions

View File

@ -36,7 +36,7 @@ mod eval;
pub struct Schala {
state: eval::State<'static>,
symbol_table: Rc<RefCell<symbol_table::SymbolTable>>,
type_context: typechecking::TypeContext,
type_context: typechecking::TypeContext<'static>,
}
impl Schala {

View File

@ -9,6 +9,7 @@ use itertools::Itertools;
*/
use parsing;
use util::StateStack;
pub type TypeName = Rc<String>;
type TypeResult<T> = Result<T, String>;
@ -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<parsing::Statement>) -> TypeResult<Type> {
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<Type> {
use parsing::Declaration::*;
match decl {
Binding { name, expr, .. } => {
},
_ => (),
}
Ok(Type::Const(TConst::Unit))
}
fn infer_expr(&mut self, expr: &parsing::Expression) -> TypeResult<Type> {
@ -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)
})
}

View File

@ -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<String>) -> StateStack<'a, T, V> where T: Hash + Eq {
StateStack {
parent: Some(self),