Skip to content

Commit

Permalink
Fixed top-level factoring
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Jul 24, 2023
1 parent 7de1257 commit eaeeb5c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ codeGen :: (Trace, ?flags :: Opt.Flags)
codeGen letBound p rs μ0 = trace ("GENERATING " ++ name ++ ": " ++ show p ++ "\nMACHINE: " ++ show (elems rs) ++ " => " ++ show m) $ makeLetBinding m rs newMeta
where
name = maybe "TOP LEVEL" show letBound
addCoinsTop = maybe addCoinsNeeded (const id) letBound
m = finalise (histo alg p)
alg :: Combinator (Cofree Combinator (CodeGen o a)) x -> CodeGen o a x
alg = deep |> (\x -> CodeGen (shallow (imap extract x)))
-- it is now safe to add coins to the top-level of a binding, because it is always assumed to not cut
finalise cg = addCoinsNeeded (runCodeGenStack (runCodeGen cg (In4 Ret)) μ0 0)
finalise cg = addCoinsTop (runCodeGenStack (runCodeGen cg (In4 Ret)) μ0 0)

pattern (:<$>:) :: Core.Defunc (a -> b) -> Cofree Combinator k a -> Combinator (Cofree Combinator k) b
pattern f :<$>: p <- (_ :< Pure f) :<*>: p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ newtype CutAnalysis a = CutAnalysis { doCut :: Bool -> (Fix Combinator a, Bool)
-- TODO: UnguardedEffects should track a set of registers
data Guardedness (a :: Type) = Guarded | UnguardedEffect | NoEffect deriving stock Eq

-- FIXME: the top-level binding needs a `cut unit *>` at the top-level

guardednessAlg :: Combinator Guardedness a -> Guardedness a
guardednessAlg Pure{} = NoEffect
guardednessAlg Satisfy{} = Guarded
Expand Down

0 comments on commit eaeeb5c

Please sign in to comment.