summaryrefslogtreecommitdiff
path: root/Language/C.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2021-09-19 18:06:03 +0200
committerTom Smeding <tom@tomsmeding.com>2021-09-19 18:06:03 +0200
commit956a60dc5253da43dc0fddaecf88116597023fdf (patch)
treef56402103483c853a0bdd7551092418025156e51 /Language/C.hs
Initial
Diffstat (limited to 'Language/C.hs')
-rw-r--r--Language/C.hs46
1 files changed, 46 insertions, 0 deletions
diff --git a/Language/C.hs b/Language/C.hs
new file mode 100644
index 0000000..530088c
--- /dev/null
+++ b/Language/C.hs
@@ -0,0 +1,46 @@
+module Language.C where
+
+
+data FunDef
+ = FunDef Type Name [(Type, Name)] StExpr
+ | ProcDef Name [(Type, Name)] [Stmt]
+ deriving (Show, Eq)
+
+data Type
+ = TInt Bits
+ | TUInt Bits
+ | TFloat
+ | TDouble
+ | TPtr Type
+ deriving (Show, Eq)
+
+data Bits = B8 | B16 | B32 | B64
+ deriving (Show, Eq)
+
+newtype Name = Name String
+ deriving (Show, Eq, Ord)
+
+-- Statement expression: conceptually gcc's ({ ... })
+data StExpr = StExpr [Stmt] Expr
+ deriving (Show, Eq)
+
+data Stmt
+ = SDecl Type Name (Maybe Expr)
+ | SAsg Name Expr
+ | SStore Name Expr Expr -- ^ name[expr] = expr
+ | SCall Name [Expr]
+ -- | @SFor ty i lo hi body@: @for (ty i = lo; i < hi; i++) body@
+ | SFor Type Name Expr Expr [Stmt]
+ | SIf Expr [Stmt] [Stmt]
+ deriving (Show, Eq)
+
+data Expr
+ = EOp Expr String Expr
+ | ENot Expr -- ^ @!expr@
+ | ELit String
+ | EVar Name
+ | ECall Name [Expr]
+ | EIndex Name Expr
+ | EPtrTo Expr
+ | ESizeOf Type
+ deriving (Show, Eq)