From 9121a0b782d2cd6551a393f1d3a79c7b092e4873 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sat, 2 Aug 2025 17:53:09 +0300 Subject: Added tests for type_check. Implemented std::fmt::Display for many enums. Added type variants List(Type), and UndefinedType for use in error messages. Implemented type utility arr(a, b). --- src/type/mod.rs | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'src/type/mod.rs') diff --git a/src/type/mod.rs b/src/type/mod.rs index 623edc9..12d1132 100644 --- a/src/type/mod.rs +++ b/src/type/mod.rs @@ -1,34 +1,43 @@ -use crate::sexp::{SExp, SExp::*}; +pub mod util; +pub mod display; +pub mod check; + + +use crate::sexp::SExp; + + +#[derive(Debug,PartialEq)] pub enum Type { + Integer, + Arrow(Box, Box), + + List(Vec), + + UndefinedType, // only for errors + } + +#[derive(Debug,PartialEq)] pub enum TypeError { + UndefinedVariable(String), + InvalidOperator { operator: SExp, expected: Type, found: Type, }, + InvalidArgList { arglist: SExp, expected: Type, found: Type, }, - OtherError -} -impl SExp { - /// ```rust - /// use melisp::{ - /// r#type::{*, Type::*, TypeError::*}, - /// sexp::{SExp::*, SLeaf::*, util::*}, - /// }; - /// ``` - pub fn type_check(&self) -> Result { - todo!() - } + OtherError } -- cgit v1.2.3