Some code rearrangements

This commit is contained in:
greg 2018-05-15 21:47:08 -07:00
parent e8e9265b26
commit 276662d98a
2 changed files with 29 additions and 30 deletions

View File

@ -63,15 +63,15 @@ lazy_static! {
lazy_static! {
static ref BINOPS: HashMap<&'static str, (Type, (), i32)> =
hashmap! {
"+" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 10),
"-" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 10),
"*" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 20),
"/" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Float))))), (), 20),
"//" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 20), //TODO change this to `quot`
"%" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 20),
"+" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 10),
"-" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 10),
"*" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20),
"/" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Float))))), (), 20),
"//" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20), //TODO change this to `quot`
"%" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20),
"++" => (Func(bx!(Const(StringT)), bx!(Func(bx!(Const(StringT)), bx!(Const(StringT))))), (), 30),
"^" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 20),
"&" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 20),
"|" => (Func(bx!(Const(Int)), bx!(Func(bx!(Const(Int)), bx!(Const(Int))))), (), 20),
"^" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20),
"&" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20),
"|" => (Func(bx!(Const(Nat)), bx!(Func(bx!(Const(Nat)), bx!(Const(Nat))))), (), 20),
};
}

View File

@ -34,15 +34,33 @@ pub struct Symbol {
#[derive(Debug, PartialEq, Clone)]
pub enum Type {
Const(TConst),
Sum(Vec<Type>),
Var(TVar),
Func(Box<Type>, Box<Type>),
//UVar(String),
//EVar(u64),
Sum(Vec<Type>),
Void
}
#[derive(Debug, PartialEq, Clone)]
pub struct TVar(String);
#[derive(Debug, PartialEq, Clone)]
pub enum TConst {
Unit,
Nat,
Int,
Float,
StringT,
Bool,
Custom(String),
}
impl fmt::Display for Type {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
/*
use self::Type::*;
match self {
&Const(ref c) => write!(f, "{:?}", c),
@ -61,6 +79,7 @@ impl fmt::Display for Type {
//&EVar(ref n) => write!(f, "{}_e", n),
&Void => write!(f, "Void")
}
*/
}
}
@ -82,17 +101,6 @@ impl UVarGenerator {
}
*/
#[derive(Debug, PartialEq, Clone)]
pub enum TConst {
Unit,
Nat,
Int,
Float,
StringT,
Bool,
Custom(String),
}
//TODO get rid of this, just instantiate builtin types to the environment
impl parsing::TypeName {
fn to_type(&self) -> TypeResult<Type> {
@ -274,15 +282,6 @@ impl TypeContext {
}
Ok(Sum(types))
},
/*
Index {
indexee: Box<Expression>,
indexers: Vec<Expression>,
},
IfExpression(Box<Expression>, Vec<Statement>, Option<Vec<Statement>>),
MatchExpression(Box<Expression>, Vec<MatchArm>),
ForExpression
*/
_ => Err(format!("Type not yet implemented"))
}
}