Add type data handle on Node

I think the way I want to handle this is a two-step process: first infer and
fill in variables, then unfiy in a separate step. Storing the data in
the AST is handy.
This commit is contained in:
greg 2019-02-21 01:46:27 -08:00
parent 9fa0576547
commit 9bb3a2be88
2 changed files with 16 additions and 3 deletions

View File

@ -2,16 +2,18 @@ use std::rc::Rc;
use std::convert::From;
use crate::builtin::{BinOp, PrefixOp};
use crate::typechecking::TypeData;
#[derive(Clone, Debug, PartialEq)]
pub struct Node<T> {
n: T,
source_map: SourceMap
source_map: SourceMap,
type_data: TypeData,
}
impl<T> Node<T> {
pub fn new(n: T) -> Node<T> {
Node { n, source_map: SourceMap::default() }
Node { n, source_map: SourceMap::default(), type_data: TypeData::new() }
}
pub fn node(&self) -> &T {
@ -26,7 +28,7 @@ struct SourceMap {
impl From<Expression> for Node<Expression> {
fn from(expr: Expression) -> Node<Expression> {
Node { n: expr, source_map: SourceMap::default() }
Node { n: expr, source_map: SourceMap::default(), type_data: TypeData::new() }
}
}

View File

@ -8,6 +8,17 @@ use crate::ast::*;
use crate::util::ScopeStack;
use crate::builtin::{PrefixOp, BinOp};
#[derive(Debug, Clone, PartialEq)]
pub struct TypeData {
ty: Option<Type>
}
impl TypeData {
pub fn new() -> TypeData {
TypeData { ty: None }
}
}
pub type TypeName = Rc<String>;
pub struct TypeContext<'a> {