module Ast where import Data.List (intercalate) import Text.Parsec (SourcePos) type Ident = String data Type = Type String | FuncType [Type] (Maybe Type) deriving (Eq, Ord) instance Show Type where show (Type t) = t show (FuncType params rtyp) = "(" ++ (intercalate ", " (fmap show params)) ++ ") -> " ++ case rtyp of Just t -> show t Nothing -> "()" showList :: [Type] -> String showList xs = intercalate ", " $ fmap show xs type FuncParam = (Ident, Type, SourcePos) data Expr = Num Integer SourcePos | BinOp Op Expr Expr | Var Ident SourcePos | -- fn [params] return body private pos Func Ident [FuncParam] (Maybe Type) [Expr] Bool SourcePos | Call Expr [Expr] SourcePos | Return (Maybe Expr) SourcePos | Module String SourcePos deriving (Eq, Ord, Show) data Op = Plus | Minus | Mul | Div deriving (Eq, Ord, Show) toFuncType :: [FuncParam] -> Maybe Type -> Type toFuncType params rtyp = FuncType (map (\(_, t, _) -> t) params) rtyp