diff --git a/schala-lang/src/ast.rs b/schala-lang/src/ast.rs index 73ec35e..17fe965 100644 --- a/schala-lang/src/ast.rs +++ b/schala-lang/src/ast.rs @@ -157,7 +157,7 @@ pub enum Pattern { #[derive(Debug, PartialEq, Clone)] pub enum PatternLiteral { - NumPattern(ExpressionType), + NumPattern(ExpressionType), //TODO fix StringPattern(Rc), BoolPattern(bool), VarPattern(Rc) diff --git a/schala-lang/src/reduced_ast.rs b/schala-lang/src/reduced_ast.rs index ebd8c8a..5eaab7e 100644 --- a/schala-lang/src/reduced_ast.rs +++ b/schala-lang/src/reduced_ast.rs @@ -57,8 +57,8 @@ pub enum Expr { #[derive(Debug, Clone)] pub struct Alternative { - tag: usize, - bound_vars: (), + tag: Option, + bound_vars: Vec>, item: Vec, } @@ -158,20 +158,34 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody, None => vec![], Some(stmts) => stmts.iter().map(|expr| expr.reduce(symbol_table)).collect(), }; - Expr::Match { //TODO this still doesn't work right - cond, - alternatives: vec![ + + /* + let alternatives = match pat { + Pattern::TupleStruct(name, subpatterns) => { + let symbol = symbol_table.values.get(name).unwrap(); + + unimplemented!() + }, + _ => panic!() + }; + */ + + let alternatives = vec![ Alternative { - tag: 0, - bound_vars: (), + tag: Some(0), + bound_vars: vec![], item: then_clause, }, Alternative { - tag: 1, - bound_vars: (), + tag: None, + bound_vars: vec![], item: else_clause, }, - ], + ]; + + Expr::Match { + cond, + alternatives, } }, IfExpressionBody::GuardList(ref _guard_arms) => panic!(), diff --git a/schala-lang/src/symbol_table.rs b/schala-lang/src/symbol_table.rs index db2211a..01589c2 100644 --- a/schala-lang/src/symbol_table.rs +++ b/schala-lang/src/symbol_table.rs @@ -11,6 +11,8 @@ pub struct SymbolTable { pub values: HashMap, Symbol> //TODO this will eventually have real type information } +//TODO add various types of lookups here, maybe multiple hash tables internally? also make values +//non-public impl SymbolTable { pub fn new() -> SymbolTable { SymbolTable { values: HashMap::new() }