diff options
Diffstat (limited to 'src/SPL')
-rw-r--r-- | src/SPL/Serialize.hs | 12 | ||||
-rw-r--r-- | src/SPL/Syntax.hs | 36 |
2 files changed, 38 insertions, 10 deletions
diff --git a/src/SPL/Serialize.hs b/src/SPL/Serialize.hs new file mode 100644 index 0000000..5a82469 --- /dev/null +++ b/src/SPL/Serialize.hs @@ -0,0 +1,12 @@ +-- vim: et ts=2 sw=2 ai: +module SPL.Serialize +where + +import SPL.Syntax + +import GHC.Generics +import Data.Serialize +import Data.ByteString + +serializeProgram :: Program -> ByteString +serializeProgram = encode 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 |