Skip to content

Commit

Permalink
[#23] First definition of the frontend language
Browse files Browse the repository at this point in the history
  • Loading branch information
JustusAdam committed Nov 26, 2018
1 parent a716be7 commit e683635
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ library:
- Ohua.DFLang.Optimizations
- Ohua.DFGraph
- Ohua.DFGraph.Show
- Ohua.Frontend.Lang
- Ohua.Serialize.JSON
- Ohua.Stage
- Ohua.Util
Expand Down
67 changes: 67 additions & 0 deletions core/src/Ohua/Frontend/Lang.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
module Ohua.Frontend.Lang where

import Ohua.Prelude

import Data.Functor.Foldable.TH (makeBaseFunctor)
import Data.Generics.Uniplate.Direct

data Pat
= VarP Binding
| TupP [Pat]
deriving (Show, Eq, Generic)

data Expr
= VarE Binding
| LitE Lit
| LetE Pat Expr Expr
| AppE Expr Expr
| LambdaE Pat Expr
| IfE Expr Expr Expr
| MapE Expr Expr
| BindE Expr Expr
| StmtE Expr Expr
| SeqE Expr Expr
| TupE [Expr]
deriving (Show, Eq, Generic)

makeBaseFunctor ''Pat

instance Uniplate Pat where
uniplate = \case
TupP ps -> plate TupP ||* ps
other -> plate other

instance Hashable Pat
instance NFData Pat


makeBaseFunctor ''Expr

instance Uniplate Expr where
uniplate = \case
LetE p e1 e2 -> plate (LetE p) |* e1 |* e2
AppE e2 e2 -> plate AppE |* e1 |* e2
LambdaE p e -> plate (LambdaE p) |* e
IfE e1 e2 e3 -> plate IfE |* e1 |* e2 |* e3
MapE e1 e2 -> plate MapE |* e1 |* e2
BindE e1 e2 -> plate BindE |* e1 |* e2
StmtE e1 e2 -> plate StmtE |* e1 |* e2
TupE es -> plate TupE ||* es
SeqE e1 e2 -> plate SeqE |* e1 |* e2
other -> plate other

instance Biplate Expr Pat where
biplate = \case
LetE p e1 e2 -> plate LetE |* p |+ e1 |+ e2
AppE e2 e2 -> plate AppE |+ e1 |+ e2
LambdaE p e -> plate LambdaE |* p |+ e
IfE e1 e2 e3 -> plate IfE |+ e1 |+ e2 |+ e3
MapE e1 e2 -> plate MapE |+ e1 |+ e2
BindE e1 e2 -> plate BindE |+ e1 |+ e2
StmtE e1 e2 -> plate StmtE |+ e1 |+ e2
TupE es -> plate TupE ||+ es
SeqE e1 e2 -> plate SeqE |+ e1 |+ e2
other -> plate other

instance Hashable Expr
instance NFData Expr

0 comments on commit e683635

Please sign in to comment.