TConst
This commit is contained in:
parent
69b7b9f528
commit
0d5ccd21fe
@ -16,10 +16,24 @@ struct TypeError { }
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum MonoType {
|
enum MonoType {
|
||||||
Var(Rc<String>),
|
Var(Rc<String>),
|
||||||
Const(Rc<String>),
|
Const(TConst),
|
||||||
Arrow(Rc<String>)
|
Arrow(Rc<String>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
enum TConst {
|
||||||
|
User(Rc<String>),
|
||||||
|
Unit,
|
||||||
|
Nat,
|
||||||
|
Int
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TConst {
|
||||||
|
fn user(name: &str) -> TConst {
|
||||||
|
TConst::User(Rc::new(name.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct PolyType {
|
struct PolyType {
|
||||||
vars: Vec<Rc<String>>,
|
vars: Vec<Rc<String>>,
|
||||||
@ -41,7 +55,7 @@ impl TypeContext {
|
|||||||
|
|
||||||
impl TypeContext {
|
impl TypeContext {
|
||||||
fn infer_ast(&mut self, ast: &AST) -> TypeResult<MonoType> {
|
fn infer_ast(&mut self, ast: &AST) -> TypeResult<MonoType> {
|
||||||
let mut output = MonoType::Const(Rc::new("Unit".to_string()));
|
let mut output = MonoType::Const(TConst::Unit);
|
||||||
for statement in ast.0.iter() {
|
for statement in ast.0.iter() {
|
||||||
output = match statement {
|
output = match statement {
|
||||||
Statement::ExpressionStatement(ref expr) => self.infer_expr(expr)?,
|
Statement::ExpressionStatement(ref expr) => self.infer_expr(expr)?,
|
||||||
@ -59,14 +73,14 @@ impl TypeContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn infer_decl(&mut self, expr: &Declaration) -> TypeResult<MonoType> {
|
fn infer_decl(&mut self, expr: &Declaration) -> TypeResult<MonoType> {
|
||||||
Ok(MonoType::Const(Rc::new("Unimplemented".to_string())))
|
Ok(MonoType::Const(TConst::user("unimplemented")))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn infer_expr_type(&mut self, expr_type: &ExpressionType) -> TypeResult<MonoType> {
|
fn infer_expr_type(&mut self, expr_type: &ExpressionType) -> TypeResult<MonoType> {
|
||||||
use self::ExpressionType::*;
|
use self::ExpressionType::*;
|
||||||
match expr_type {
|
match expr_type {
|
||||||
NatLiteral(_) => Ok(MonoType::Const(Rc::new("Nat".to_string()))),
|
NatLiteral(_) => Ok(MonoType::Const(TConst::Nat)),
|
||||||
_ => Ok(MonoType::Const(Rc::new("Unimplemented".to_string())))
|
_ => Ok(MonoType::Const(TConst::user("unimplemented")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user