diff options
author | Erin van der Veen | 2018-02-08 10:23:27 +0100 |
---|---|---|
committer | Erin van der Veen | 2018-02-08 10:23:27 +0100 |
commit | 4776243a670916144f8de1f853b29b0b1d78fffe (patch) | |
tree | a71712176d2acb7decec5573d6f37b07ac9f3afe /src/SPL/Syntax.hs | |
parent | Implement pprint for Nop (diff) |
Create Program Serializer2-serialization
Diffstat (limited to 'src/SPL/Syntax.hs')
-rw-r--r-- | src/SPL/Syntax.hs | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/src/SPL/Syntax.hs b/src/SPL/Syntax.hs index f52b866..d4775a4 100644 --- a/src/SPL/Syntax.hs +++ b/src/SPL/Syntax.hs @@ -1,14 +1,19 @@ -- vim: et ts=2 sw=2 ai: +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DefaultSignatures #-} module SPL.Syntax where +import GHC.Generics +import Data.Serialize + type Name = String data Program = Program { funs :: [Function] , vars :: [Variable] } - deriving (Show) + deriving (Show, Generic) data Function = Function { fname :: Name @@ -17,14 +22,14 @@ data Function = Function , fvars :: [Variable] , fcode :: Statement } - deriving (Show) + deriving (Show, Generic) data Variable = Variable { vname :: Name , vtype :: Maybe Type , vval :: Expression } - deriving (Show) + deriving (Show, Generic) data Type = TInt @@ -35,7 +40,7 @@ data Type | TTuple Type Type | TArrow [Type] Type | TVar Name - deriving (Show) + deriving (Show, Generic) data Statement = If Expression Statement (Maybe Statement) @@ -45,7 +50,7 @@ data Statement | Return (Maybe Expression) | Seq Statement Statement | Nop - deriving (Show) + deriving (Show, Generic) data Expression = Var Name @@ -55,14 +60,14 @@ data Expression | Literal Literal | FunCall Name [Expression] | Tuple Expression Expression - deriving (Show) + deriving (Show, Generic) data Field = Hd | Tl | Fst | Snd - deriving (Show) + deriving (Show, Generic) data Op2 = Add @@ -79,16 +84,27 @@ data Op2 | And | Or | Cons - deriving (Show) + deriving (Show, Generic) data Op1 = Not | Neg - deriving (Show) + deriving (Show, Generic) data Literal = LInt Int | LChar Char | LBool Bool | LNil - deriving (Show) + deriving (Show, Generic) + +instance Serialize Program +instance Serialize Function +instance Serialize Variable +instance Serialize Type +instance Serialize Statement +instance Serialize Expression +instance Serialize Field +instance Serialize Op2 +instance Serialize Op1 +instance Serialize Literal |