From 9ed91003736b1028d6734f8dde3be98a7e192d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madeleine=20Sydney=20=C5=9Alaga?= Date: Mon, 17 Aug 2026 17:28:35 -0600 Subject: [PATCH] --- src/Gyehoek/Stack/Syntax.hs | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/Gyehoek/Stack/Syntax.hs b/src/Gyehoek/Stack/Syntax.hs index feb9887..0423aaa 100644 --- a/src/Gyehoek/Stack/Syntax.hs +++ b/src/Gyehoek/Stack/Syntax.hs @@ -37,7 +37,17 @@ instance Each Block Block Instr Instr where data Instr = DefinePop Name | DefinePopCont Name - | PushCont (List Name) Block + | PushCont Cont + | Push Name + | Call Name + deriving stock (Show, Generic, Data) + +data Cont + = KVar Name + | Kappa Kappa + deriving stock (Show, Generic, Data) + +data Kappa = MkKappa (List Name) Block deriving stock (Show, Generic, Data) @@ -57,6 +67,8 @@ instance SexpIso Instr where $ With (g_DefinePop >>>) $ With (g_DefinePopCont >>>) $ With (g_PushCont >>>) + $ With (g_Push >>>) + $ With (g_Call >>>) $ End where def :: Text -> S.SexpGrammar Name @@ -68,11 +80,24 @@ instance SexpIso Instr where g_DefinePopCont = def "pop-cont!" g_PushCont = S.list $ S.el (S.sym "push-cont!") - >>> S.el (S.list $ - S.el Gyehoek.Sexp.kappaKeyword - >>> S.el (S.sexpIso @(List Name)) - >>> S.rest (S.sexpIso @Instr) - >>> S.onTail (S.iso coerce coerce)) + >>> S.el (S.sexpIso @Cont) + g_Push = S.list $ S.el (S.sym "push!") >>> S.el S.sexpIso + g_Call = S.list $ S.el (S.sym "call!") >>> S.el S.sexpIso + +instance SexpIso Cont where + sexpIso = match + $ With (S.sexpIso @Name >>>) + $ With (S.sexpIso @Kappa >>>) + $ End + +instance SexpIso Kappa where + sexpIso = with \g_kappa -> + (S.list $ + S.el Gyehoek.Sexp.kappaKeyword + >>> S.el (S.sexpIso @(List Name)) + >>> S.rest (S.sexpIso @Instr) + >>> S.onTail (S.iso coerce coerce)) + >>> g_kappa programFromSexps :: Foldable f => f S.Sexp -> Program programFromSexps = MkProgram . foldMap f