From dade0a13a207573386c58fee19f0ce563281f317 Mon Sep 17 00:00:00 2001 From: crumbtoo Date: Wed, 6 Dec 2023 17:15:03 -0700 Subject: [PATCH] cleanup --- src/Core/Examples.hs | 12 ++++++++++++ src/Core/Lex.x | 2 -- src/Core/Parse.y | 3 +-- src/GM.hs | 18 +++++++++++------- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/Core/Examples.hs b/src/Core/Examples.hs index 656e609..330561a 100644 --- a/src/Core/Examples.hs +++ b/src/Core/Examples.hs @@ -117,6 +117,18 @@ simple1 = [coreProg| main = s k k 3; |] +caseBool1 = [coreProg| + _if c x y = case c of + { 1 -> x + ; 0 -> y + }; + + false = Pack{0 0}; + true = Pack{1 0}; + + main = _if false ((+#) 2 3) ((*#) 4 5); +|] + corePrelude :: Module corePrelude = Module (Just ("Prelude", [])) $ -- non-primitive defs diff --git a/src/Core/Lex.x b/src/Core/Lex.x index d01034a..bd98c89 100644 --- a/src/Core/Lex.x +++ b/src/Core/Lex.x @@ -68,7 +68,6 @@ rlp :- "{" { constTok TokenLBrace } "}" { constTok TokenRBrace } ";" { constTok TokenSemicolon } - "," { constTok TokenComma } "{-#" { constTok TokenLPragma `andBegin` pragma } "let" { constTok TokenLet } @@ -121,7 +120,6 @@ data CoreToken = TokenLet | TokenIn | TokenModule | TokenWhere - | TokenComma | TokenPack -- temp | TokenCase | TokenOf diff --git a/src/Core/Parse.y b/src/Core/Parse.y index 4c04368..dbc2412 100644 --- a/src/Core/Parse.y +++ b/src/Core/Parse.y @@ -36,7 +36,6 @@ import Data.Default.Class (def) where { Located _ _ _ TokenWhere } case { Located _ _ _ TokenCase } of { Located _ _ _ TokenOf } - ',' { Located _ _ _ TokenComma } pack { Located _ _ _ TokenPack } -- temp in { Located _ _ _ TokenIn } litint { Located _ _ _ (TokenLitInt $$) } @@ -136,7 +135,7 @@ Words : word Words { $1 : $2 } | word { [$1] } PackCon :: { Expr } -PackCon : pack '{' litint ',' litint '}' { Con $3 $5 } +PackCon : pack '{' litint litint '}' { Con $3 $4 } Bindings :: { [Binding] } Bindings : Binding ';' Bindings { $1 : $3 } diff --git a/src/GM.hs b/src/GM.hs index 7ed184f..6c55718 100644 --- a/src/GM.hs +++ b/src/GM.hs @@ -658,7 +658,7 @@ buildInitialHeap (Program ss) = mapAccumL allocateSc mempty compiledScs argOffset n = each . _2 %~ (+n) idPack :: Tag -> Int -> String -idPack t n = printf "Pack{%d,%d}" t n +idPack t n = printf "Pack{%d %d}" t n ---------------------------------------------------------------------------------- @@ -781,15 +781,19 @@ showNodeAtP p st a = case hLookup a h of Just (NameKey n) -> n Just (ConstrKey t n) -> idPack t n _ -> errTxtInvalidAddress - Just (NAp f x) -> pprec $ showNodeAtP (p+1) st f <+> showNodeAtP (p+1) st x - where pprec = maybeParens (p > 0) + -- TODO: left-associativity + Just (NAp f x) -> pprec $ showNodeAtP (p+1) st f + <+> showNodeAtP (p+1) st x Just (NInd a') -> pprec $ "NInd -> " <> showNodeAtP (p+1) st a' - where pprec = maybeParens (p > 0) - Just (NConstr t as) -> pprec $ "NConstr" <+> int t <+> text (show as) - where pprec = maybeParens (p > 0) + Just (NConstr t as) -> pprec $ "NConstr" + <+> int t + <+> brackets (list $ showNodeAtP 0 st <$> as) + where list = hcat . punctuate ", " Just NUninitialised -> "" Nothing -> errTxtInvalidAddress - where h = st ^. gmHeap + where + h = st ^. gmHeap + pprec = maybeParens (p > 0) showSc :: GmState -> (Name, Addr) -> Doc showSc st (k,a) = "Supercomb " <> qquotes (text k) <> colon