From 1d5af748b336f41d5a8a0614c8088ee52886f5cc Mon Sep 17 00:00:00 2001 From: crumbtoo Date: Thu, 14 Dec 2023 14:04:51 -0700 Subject: [PATCH] idCase test --- src/Core/Examples.hs | 10 ++++++++++ src/Core2Core.hs | 3 +-- tst/GMSpec.hs | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Core/Examples.hs b/src/Core/Examples.hs index b28bc00..430a94f 100644 --- a/src/Core/Examples.hs +++ b/src/Core/Examples.hs @@ -8,6 +8,7 @@ module Core.Examples ( fac3 , sumList , constDivZero + , idCase ) where ---------------------------------------------------------------------------------- import Core.Syntax @@ -181,6 +182,15 @@ constDivZero = [coreProg| main = k 3 ((/#) 1 0); |] +idCase :: Program' +idCase = [coreProg| + id x = x; + + main = id (case Pack{1 0} of + { 1 -> (+#) 2 3 + }) + |] + corePrelude :: Module Name corePrelude = Module (Just ("Prelude", [])) $ -- non-primitive defs diff --git a/src/Core2Core.hs b/src/Core2Core.hs index 412c6d2..ed885bc 100644 --- a/src/Core2Core.hs +++ b/src/Core2Core.hs @@ -46,8 +46,7 @@ type Floater = StateT [Name] (Writer [ScDef']) runFloater :: Floater a -> (a, [ScDef']) runFloater = flip evalStateT ns >>> runWriter where - -- TODO: safer, uncapturable names - ns = [ "nonstrict_case_" ++ showHex n "" | n <- [0..] ] + ns = [ "$nonstrict_case_" ++ showHex n "" | n <- [0..] ] -- TODO: formally define a "strict context" and reference that here -- the returned ScDefs are guaranteed to be free of non-strict cases. diff --git a/tst/GMSpec.hs b/tst/GMSpec.hs index 125bb58..dd5957a 100644 --- a/tst/GMSpec.hs +++ b/tst/GMSpec.hs @@ -36,3 +36,6 @@ spec = do it "k 3 ((/#) 1 0)" $ do resultOf Ex.constDivZero `shouldBe` Just (NNum 3) + it "id (case ... of { ... })" $ do + resultOf Ex.idCase `shouldBe` Just (NNum 5) +