From 65c8beecb14f6d09c49504d74beedd58cc7ddd17 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Wed, 7 Sep 2022 16:26:50 +0100 Subject: Better project layout, removed warnings --- src/Micro/Ast.hs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/Micro/Ast.hs (limited to 'src/Micro/Ast.hs') diff --git a/src/Micro/Ast.hs b/src/Micro/Ast.hs new file mode 100644 index 0000000..45697de --- /dev/null +++ b/src/Micro/Ast.hs @@ -0,0 +1,46 @@ +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)) ++ ") -> " ++ case rtyp of + Just t -> show t + Nothing -> "()" + +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 pos + Var Ident Type Expr 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 rtyp = + FuncType (map (\(_, t, _, _) -> t) params) rtyp -- cgit v1.2.3