Start eval-ing data constructors

This commit is contained in:
greg 2018-06-03 20:55:55 -07:00
parent 25790f8643
commit 3beabf4678
2 changed files with 14 additions and 6 deletions

View File

@ -1,7 +1,6 @@
use std::rc::Rc; use std::rc::Rc;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt; use std::fmt;
use std::fmt::Write;
use self::Type::*; use self::TConstOld::*; use self::Type::*; use self::TConstOld::*;

View File

@ -140,11 +140,20 @@ impl<'a> State<'a> {
match expr { match expr {
literal @ Lit(_) => Ok(literal), literal @ Lit(_) => Ok(literal),
Call { box f, args } => { Call { box f, args } => {
let f = match self.expression(f)? { if let Val(name) = f {
Func(f) => f, let symbol_table = self.symbol_table_handle.borrow();
other => return Err(format!("Tried to call {:?} which is not a function", other)), match symbol_table.values.get(&name) {
}; Some(Symbol { spec: SymbolSpec::DataConstructor { type_name, type_args }, .. }) => {
self.apply_function(f, args) Ok(Expr::Lit(self::Lit::Nat(99)))
},
_ => return Err(format!("Bad symbol {}", name))
}
} else {
match self.expression(f)? {
Func(f) => self.apply_function(f, args),
other => return Err(format!("Tried to call {:?} which is not a function or data constructor", other)),
}
}
}, },
Val(v) => self.value(v), Val(v) => self.value(v),
func @ Func(_) => Ok(func), func @ Func(_) => Ok(func),