This commit is contained in:
2026-05-07 15:41:30 -06:00
parent c716948932
commit 0f75f7b4e6
11 changed files with 75 additions and 28 deletions
+14 -9
View File
@@ -17,8 +17,12 @@ import Gyehoek.Sexp qualified
type Name = Text
data Prim = PrimAdd | PrimSub | PrimMul | PrimDiv
deriving (Show, Generic)
data Prim e
= PrimAdd e e
| PrimSub e e
| PrimMul e e
| PrimDiv e e
deriving (Show, Generic, Functor, Foldable, Traversable)
data Lit
= LitInt Int
@@ -31,20 +35,22 @@ data Exp
| ExpApply Exp (List Exp)
| ExpBegin (List Exp)
| ExpLit Lit
| ExpPrim Prim
| ExpPrim (Prim Exp)
| ExpLambda (List Name) Exp
| ExpVar Name
deriving (Show, Generic)
instance SexpIso Prim where
instance SexpIso a => SexpIso (Prim a) where
sexpIso = match
$ With (. sym "+")
$ With (. sym "-")
$ With (. sym "*")
$ With (. sym "/")
$ With (. binop "prim-+")
$ With (. binop "prim--")
$ With (. binop "prim-*")
$ With (. binop "prim-/")
$ End
where
binop s = list $ el (sym s) >>> el sexpIso >>> el sexpIso
instance SexpIso Lit where
sexpIso = match
@@ -52,7 +58,6 @@ instance SexpIso Lit where
$ With (. sym "nil")
$ With (. sexpIso)
$ End
where
instance SexpIso Exp where
sexpIso = match