From 276662d98a3eb65b1b62d321728052c88373477c Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 15 May 2018 21:47:08 -0700 Subject: [PATCH] Some code rearrangements --- schala-lang/src/builtin.rs | 18 +++++++-------- schala-lang/src/typechecking.rs | 41 ++++++++++++++++----------------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/schala-lang/src/builtin.rs b/schala-lang/src/builtin.rs index e78eb7f..00a9d8e 100644 --- a/schala-lang/src/builtin.rs +++ b/schala-lang/src/builtin.rs @@ -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), }; } diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index ab2a164..07d113a 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -34,15 +34,33 @@ pub struct Symbol { #[derive(Debug, PartialEq, Clone)] pub enum Type { Const(TConst), - Sum(Vec), + Var(TVar), Func(Box, Box), //UVar(String), //EVar(u64), + Sum(Vec), 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 { @@ -274,15 +282,6 @@ impl TypeContext { } Ok(Sum(types)) }, - /* - Index { - indexee: Box, - indexers: Vec, - }, - IfExpression(Box, Vec, Option>), - MatchExpression(Box, Vec), - ForExpression - */ _ => Err(format!("Type not yet implemented")) } }