diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 5aa09bd..9a3096b 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -392,7 +392,7 @@ macro_rules! expect { #[derive(Debug, PartialEq)] pub struct AST(pub Vec); -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub enum Statement { ExpressionStatement(Expression), Declaration(Declaration), @@ -403,7 +403,7 @@ type TypeName = Rc; type TraitName = Rc; type FormalParamList = Vec<(ParamName, Option)>; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub enum Declaration { FuncDecl { name: Rc, @@ -423,20 +423,20 @@ pub enum Declaration { }, } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub struct TypeBody(pub Vec); -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub enum Variant { Singleton(Rc), //ArgumentConstructor, //Record } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub struct Expression(pub ExpressionType, pub Option); -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub enum TypeAnno { Tuple(Vec), Singleton { @@ -445,7 +445,7 @@ pub enum TypeAnno { } } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub enum ExpressionType { IntLiteral(u64), FloatLiteral(f64), @@ -467,16 +467,16 @@ pub enum ExpressionType { MatchExpression(Box, Vec) } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub struct MatchArm { pat: Pattern, expr: Expression, } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub struct Pattern(Rc); -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub struct Operation(pub Rc); impl Operation { diff --git a/src/schala_lang/type_check.rs b/src/schala_lang/type_check.rs index daf70db..39cfeb8 100644 --- a/src/schala_lang/type_check.rs +++ b/src/schala_lang/type_check.rs @@ -1,9 +1,14 @@ use std::collections::HashMap; +use std::rc::Rc; use schala_lang::parsing::{AST, Statement, Declaration, Expression, ExpressionType, Operation, TypeAnno}; #[derive(Debug, PartialEq, Eq, Hash)] -struct PathSpecifier(String); +struct PathSpecifier { + name: Rc, + kind: &'static str, + constant: bool, +} struct SymbolTable { map: HashMap, @@ -15,6 +20,30 @@ impl SymbolTable { } fn add_symbols(&mut self, ast: &AST) { + use self::Declaration::*; + + for statement in ast.0.iter() { + match statement { + &Statement::ExpressionStatement(_) => (), + &Statement::Declaration(ref d) => { + match d { + &FuncDecl { .. } => (), + &TypeDecl { .. } => (), + &TypeAlias { .. } => (), + &Binding {ref name, ref constant, ref expr} => { + let spec = PathSpecifier { + name: name.clone(), + kind: "binding", + constant: *constant + }; + let binding_contents = (*expr).clone(); + self.map.insert(spec, binding_contents); + }, + &Impl { .. } => (), + } + } + } + } } }