From 66c7bbeb071e0469186b1d827f4a3ecaa60ab128 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 9 Oct 2017 04:02:50 -0700 Subject: [PATCH] Floats, pathspec changes --- src/schala_lang/type_check.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/schala_lang/type_check.rs b/src/schala_lang/type_check.rs index bf7de29..6ba73b1 100644 --- a/src/schala_lang/type_check.rs +++ b/src/schala_lang/type_check.rs @@ -4,9 +4,7 @@ use std::rc::Rc; use schala_lang::parsing::{AST, Statement, Declaration, Signature, Expression, ExpressionType, Operation, TypeName}; #[derive(Debug, PartialEq, Eq, Hash)] -struct PathSpecifier { - name: Rc, -} +struct PathSpecifier(Rc); #[derive(Debug, PartialEq, Clone)] struct TypeContextEntry { @@ -39,9 +37,7 @@ impl TypeContext { TypeDecl { .. } => (), TypeAlias { .. } => (), Binding {ref name, ref constant, ref expr} => { - let spec = PathSpecifier { - name: name.clone(), - }; + let spec = PathSpecifier(name.clone()); let type_var = expr.1.as_ref() .map(|ty| self.from_anno(ty)) .unwrap_or_else(|| { self.get_existential_type() }); @@ -49,10 +45,7 @@ impl TypeContext { self.symbol_table.insert(spec, entry); }, FuncDecl(ref signature, _) => { - let spec = PathSpecifier { - name: signature.name.clone(), - }; - + let spec = PathSpecifier(signature.name.clone()); let type_var = self.from_signature(signature); let entry = TypeContextEntry { type_var, constant: true }; self.symbol_table.insert(spec, entry); @@ -63,10 +56,7 @@ impl TypeContext { } } fn lookup(&mut self, binding: &Rc) -> Option { - let key = PathSpecifier { - name: binding.clone(), - }; - + let key = PathSpecifier(binding.clone()); self.symbol_table.get(&key).map(|entry| entry.clone()) } pub fn debug_symbol_table(&self) -> String { @@ -120,6 +110,7 @@ pub enum TypeVariable { #[derive(Debug, PartialEq, Clone)] pub enum UVar { Integer, + Float, Boolean, Unit, Function(Box, Box), @@ -171,6 +162,7 @@ impl TypeContext { self.from_anno(anno) }, (&IntLiteral(_), _) => Univ(UVar::Integer), + (&FloatLiteral(_), _) => Univ(UVar::Float), (&BoolLiteral(_), _) => Univ(UVar::Boolean), (&Variable(ref name), _) => self.lookup(name).map(|entry| entry.type_var) .ok_or(format!("Couldn't find {}", name))?,