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::collections::HashMap;
use std::fmt;
use std::fmt::Write;
use self::Type::*; use self::TConstOld::*;

View File

@ -140,11 +140,20 @@ impl<'a> State<'a> {
match expr {
literal @ Lit(_) => Ok(literal),
Call { box f, args } => {
let f = match self.expression(f)? {
Func(f) => f,
other => return Err(format!("Tried to call {:?} which is not a function", other)),
};
self.apply_function(f, args)
if let Val(name) = f {
let symbol_table = self.symbol_table_handle.borrow();
match symbol_table.values.get(&name) {
Some(Symbol { spec: SymbolSpec::DataConstructor { type_name, type_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),
func @ Func(_) => Ok(func),