Update changelog for v3.10.2.2 release
[packages/hoopl.git] / testing / Expr.hs
1 {-# OPTIONS_GHC -Wall #-}
2 {-# LANGUAGE RankNTypes, ScopedTypeVariables, GADTs, EmptyDataDecls, PatternGuards, TypeFamilies, NamedFieldPuns #-}
3 module Expr (Expr(..), BinOp(..), Lit(..), Var) where
4
5 import PP
6
7 data Expr = Lit Lit
8 | Var Var
9 | Load Expr
10 | Binop BinOp Expr Expr deriving (Eq)
11
12 data BinOp = Add | Sub | Mul | Div | Eq | Ne | Lt | Gt | Lte | Gte deriving Eq
13
14 data Lit = Bool Bool | Int Integer deriving Eq
15 type Var = String
16
17 --------------------------------------------------------------------------------
18 --- Prettyprinting
19 --------------------------------------------------------------------------------
20
21 instance Show Expr where
22 show (Lit i) = show i
23 show (Var v) = v
24 show (Load e) = "m[" ++ show e ++ "]"
25 show (Binop b e1 e2) = sub e1 ++ " " ++ show b ++ " " ++ sub e2
26 where sub e@(Binop _ _ _) = tuple [show e]
27 sub e = show e
28
29 instance Show Lit where
30 show (Int i) = show i
31 show (Bool b) = show b
32
33 instance Show BinOp where
34 show Add = "+"
35 show Sub = "-"
36 show Mul = "*"
37 show Div = "/"
38 show Eq = "="
39 show Ne = "/="
40 show Gt = ">"
41 show Lt = "<"
42 show Gte = ">="
43 show Lte = "<="