module Micro.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) ++ ") -> " ++ maybe "()" show rtyp showList :: [Type] -> String showList xs = intercalate ", " $ fmap show xs type FuncParam = (Ident, Type, Bool, SourcePos) data Expr = Num Integer SourcePos | Bool' Bool SourcePos | BinOp Op SourcePos Expr Expr | Variable Ident SourcePos | -- v type value private local pos Var Ident Type Expr Bool Bool SourcePos | -- fn [params] return body private anomyous pos Func Ident [FuncParam] (Maybe Type) [Expr] Bool Bool SourcePos | Call Expr [Expr] SourcePos | Return (Maybe Expr) SourcePos | Module String SourcePos deriving (Eq, Ord, Show) data Op = Assign | Plus | Minus | Mul | Div deriving (Eq, Ord, Show) toFuncType :: [FuncParam] -> Maybe Type -> Type toFuncType params = FuncType (map (\(_, t, _, _) -> t) params)