From 493d76da0bbcf3b391724dfd441bdb3e3e769c25 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 13 May 2018 15:17:25 -0700 Subject: [PATCH] Add symbol table data structure to typechecking --- schala-lang/src/typechecking.rs | 15 +++++++++++++-- source_files/schala/test.schala | 9 ++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index f0a19e0..4a867f1 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -11,12 +11,23 @@ use parsing; pub struct TypeContext { type_var_count: u64, bindings: HashMap, Type>, - //symbol_table: SymbolTable + symbol_table: SymbolTable } //cf. p. 150 or so of Language Implementation Patterns struct SymbolTable { + pub values: HashMap, Symbol> //TODO this will eventually have real type information +} +impl SymbolTable { + fn new() -> SymbolTable { + SymbolTable { values: HashMap::new() } + } +} + +struct Symbol { + name: Rc, + ty: Type } #[derive(Debug, PartialEq, Clone)] @@ -104,7 +115,7 @@ pub type TypeResult = Result; impl TypeContext { pub fn new() -> TypeContext { - TypeContext { bindings: HashMap::new(), type_var_count: 0 } + TypeContext { bindings: HashMap::new(), type_var_count: 0, symbol_table: SymbolTable::new() } } pub fn fresh(&mut self) -> Type { let ret = self.type_var_count; diff --git a/source_files/schala/test.schala b/source_files/schala/test.schala index 76c90ba..eab6109 100644 --- a/source_files/schala/test.schala +++ b/source_files/schala/test.schala @@ -1,5 +1,12 @@ -const a = getline() +println(a(4)) + +fn sua(x): Int { + x + 10 +} + + +//const a = getline() if a == "true" { println("You typed true")