Eval shouldn't be aware of types

This commit is contained in:
greg 2018-05-15 23:48:36 -07:00
parent b4c7ea3d02
commit 98cfcfc18d
2 changed files with 13 additions and 9 deletions

View File

@ -7,7 +7,7 @@ use itertools::Itertools;
use util::StateStack;
use ast_reducing::{ReducedAST, Stmt, Expr, Lit, Func};
use typechecking::{TypeContext, Symbol, Type, TConst};
use typechecking::{TypeContext, SymbolSpec, Symbol};
pub struct State<'a> {
values: StateStack<'a, Rc<String>, ValueEntry>,
@ -266,17 +266,16 @@ impl<'a> State<'a> {
let type_context = self.type_context_handle.borrow();
Ok(match type_context.symbol_table.values.get(&name) {
Some(Symbol { name, ty }) => match ty {
Type::Const(TConst::Custom(_typename)) => {
Some(Symbol { name, spec }) => match spec {
SymbolSpec::Custom(_typename) => {
Expr::Lit(Lit::Custom(name.clone()))
},
Type::Func(_,_) => match self.values.lookup(&name) {
SymbolSpec::Func => match self.values.lookup(&name) {
Some(Binding { val: Expr::Func(UserDefined { name, params, body }), .. }) => {
Expr::Func(UserDefined { name: name.clone(), params: params.clone(), body: body.clone() })
},
_ => unreachable!(),
},
e => return Err(format!("Bad type in symbol table {:?}", e))
},
/* see if it's an ordinary variable TODO make variables go in symbol table */
None => match self.values.lookup(&name) {

View File

@ -28,7 +28,12 @@ impl SymbolTable {
#[derive(Debug)]
pub struct Symbol {
pub name: Rc<String>,
pub ty: Type
pub spec: SymbolSpec,
}
#[derive(Debug)]
pub enum SymbolSpec {
Func, Custom(String)
}
#[derive(Debug, PartialEq, Clone)]
@ -159,7 +164,7 @@ impl TypeContext {
*/
self.symbol_table.values.insert(
signature.name.clone(),
Symbol { name: signature.name.clone(), ty: Func(Box::new(Void), Box::new(Void)) }
Symbol { name: signature.name.clone(), spec: SymbolSpec::Func }
);
},
TypeDecl(TypeSingletonName { name, ..}, TypeBody(variants)) => {
@ -167,8 +172,8 @@ impl TypeContext {
match var {
Variant::UnitStruct(variant_name) => {
//TODO will have to make this a function to this type eventually
let ty = Type::Const(TConst::Custom(format!("{}", name)));
self.symbol_table.values.insert(variant_name.clone(), Symbol { name: variant_name.clone(), ty });
let spec = SymbolSpec::Custom(format!("{}", name));
self.symbol_table.values.insert(variant_name.clone(), Symbol { name: variant_name.clone(), spec });
},
e => return Err(format!("{:?} not supported in typing yet", e)),
}