Make it possible to show ANF code

This commit is contained in:
Dan Doel 2020-06-01 16:45:10 -04:00
parent ca146f4197
commit edce1f8d1e
2 changed files with 20 additions and 1 deletions

View File

@ -681,11 +681,12 @@ type Ctx v = [Cte v]
-- Should be a completely closed term
data SuperNormal v
= Lambda { conventions :: [Mem], bound :: ANormal v }
deriving (Show)
data SuperGroup v
= Rec
{ group :: [(v, SuperNormal v)]
, entry :: SuperNormal v
}
} deriving (Show)
type ANFM v
= ReaderT (Set v, Reference -> Word64, Reference -> RTag)

View File

@ -7,6 +7,9 @@
{-# language PatternSynonyms #-}
{-# language DeriveTraversable #-}
{-# language UndecidableInstances #-}
{-# language QuantifiedConstraints #-}
module Unison.ABT.Normalized
( ABT(..)
, Term(.., TAbs, TTm, TAbss)
@ -40,6 +43,21 @@ data Term f v = Term
, out :: ABT f v
}
instance (forall a b. Show a => Show b => Show (f a b), Show v)
=> Show (ABT f v)
where
showsPrec p a = showParen (p >= 9) $ case a of
Abs v tm
-> showString "Abs " . showsPrec 10 v
. showString " " . showsPrec 10 tm
Tm e -> showString "Tm " . showsPrec 10 e
instance (forall a b. Show a => Show b => Show (f a b), Show v)
=> Show (Term f v)
where
showsPrec p (Term _ e)
= showParen (p >= 9) $ showString "Term " . showsPrec 10 e
pattern TAbs :: Var v => v -> Term f v -> Term f v
pattern TAbs u bd <- Term _ (Abs u bd)
where TAbs u bd = Term (Set.delete u (freeVars bd)) (Abs u bd)