From 62edc7c996682d83169aff714fadf126f29f2e69 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 8 Oct 2017 12:22:04 -0700 Subject: [PATCH] type checking / symbol table stuff --- src/schala_lang/type_check.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/schala_lang/type_check.rs b/src/schala_lang/type_check.rs index 379d379..daf70db 100644 --- a/src/schala_lang/type_check.rs +++ b/src/schala_lang/type_check.rs @@ -1,11 +1,17 @@ +use std::collections::HashMap; + use schala_lang::parsing::{AST, Statement, Declaration, Expression, ExpressionType, Operation, TypeAnno}; +#[derive(Debug, PartialEq, Eq, Hash)] +struct PathSpecifier(String); + struct SymbolTable { + map: HashMap, } impl SymbolTable { fn new() -> SymbolTable { - SymbolTable { } + SymbolTable { map: HashMap::new() } } fn add_symbols(&mut self, ast: &AST) { @@ -51,18 +57,25 @@ impl TypeContext { return Err(format!("Declarations not supported")); }, &Statement::ExpressionStatement(ref expr) => { - match (&expr.0, &expr.1) { - (&IntLiteral(_), &Some(ref t)) => { - match t { - &TypeAnno::Singleton { ref name, ref params } if **name == "Int" && params.len() == 0 => (), - t => return Err(format!("Bad type {:?} for int literal", t)), - } - }, - _ => (), - } + self.expr_type_check(expr)?; } } } Ok(SchalaType { }) } + + fn expr_type_check(&mut self, expr: &Expression) -> TypeCheckResult { + use self::ExpressionType::*; + + match (&expr.0, &expr.1) { + (&IntLiteral(_), &Some(ref t)) => { + match t { + &TypeAnno::Singleton { ref name, ref params } if **name == "Int" && params.len() == 0 => (), + t => return Err(format!("Bad type {:?} for int literal", t)), + } + }, + _ => (), + } + Ok(SchalaType { }) + } }