From d38065bcc3f89077914f519b8c66e00c8a7843d0 Mon Sep 17 00:00:00 2001 From: Olle Fredriksson Date: Fri, 19 Jul 2024 00:51:24 +0200 Subject: [PATCH] wip --- src/Low/Pretty.hs | 26 +++++++++++++------------- src/Lower.hs | 17 ++++++++--------- src/ReferenceCounting.hs | 4 ++-- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/Low/Pretty.hs b/src/Low/Pretty.hs index b9c097b..bc4cc18 100644 --- a/src/Low/Pretty.hs +++ b/src/Low/Pretty.hs @@ -86,15 +86,15 @@ prettyTerm env = \case "case" <+> prettyOperand env scrutinee <+> "of" - <> line - <> indent - 2 - ( vcat $ - (prettyBranch env <$> branches) - <> [ "_" <+> "->" <+> prettyTerm env branch - | Just branch <- [defaultBranch] - ] - ) + <> line + <> indent + 2 + ( vcat $ + (prettyBranch env <$> branches) + <> [ "_" <+> "->" <+> prettyTerm env branch + | Just branch <- [defaultBranch] + ] + ) Syntax.Call function args -> "call" <+> prettyLoweredGlobal env function @@ -129,8 +129,8 @@ prettySeq env = \case <+> pretty name' <+> "=" <+> prettyTerm env term - <> line - <> prettySeq env' body + <> line + <> prettySeq env' body Syntax.Seq term1 term2 -> prettyTerm env term1 <> line @@ -221,5 +221,5 @@ prettyFunction env = \case "(" <> pretty passArgBy <+> pretty name' - <> ")" - <> prettyFunction env' function' + <> ")" + <> prettyFunction env' function' diff --git a/src/Lower.hs b/src/Lower.hs index a261bb3..eacffe9 100644 --- a/src/Lower.hs +++ b/src/Lower.hs @@ -49,7 +49,7 @@ data Value data LetOperation = Case !Operand [Branch] (Maybe Value) - | Call !Name.Lowered [Operand ] + | Call !Name.Lowered [Operand] | StackAllocate !Operand | HeapAllocate !Name.QualifiedConstructor !Operand | HeapPayload !Operand @@ -58,7 +58,7 @@ data LetOperation | Load !Operand !Representation deriving (Show) -data SeqOperation +data SeqOperation = Store !Operand !Operand !Representation | Copy !Operand !Operand !Operand deriving (Show) @@ -96,9 +96,9 @@ type Collect = StateT (Tsil Collectible) M let_ :: PassBy -> Name -> LetOperation -> Collect Operand let_ repr name operation = do - var <- lift freshVar - modify (Tsil.:> CollectibleLet repr name var operation) - pure $ Var var + var <- lift freshVar + modify (Tsil.:> CollectibleLet repr name var operation) + pure $ Var var letReference :: Name -> LetOperation -> Collect Operand letReference = let_ PassBy.Reference @@ -384,7 +384,7 @@ storeConstrArgs context indices mdst offset = \case [] -> pure offset arg : args -> do dst <- mdst - argDst <- letOffset "constr_arg_dst" dst offset + argDst <- letOffset "constr_arg_dst" dst offset argSize <- storeTerm context indices argDst arg offset' <- letAddRepresentation "constr_arg_offset" offset argSize storeConstrArgs context indices (pure dst) offset' args @@ -412,8 +412,8 @@ generateTypeSize -> CC.Syntax.Type v -> Collect Operand generateTypeSize context indices type_ = do - size <- generateTermWithType context Nothing indices type_ $ CC.Syntax.Global $ Name.Lifted Builtin.TypeName 0 - forceValue Representation.type_ size + size <- generateTermWithType context Nothing indices type_ $ CC.Syntax.Global $ Name.Lifted Builtin.TypeName 0 + forceValue Representation.type_ size generateTermWithType :: CC.Context v @@ -701,4 +701,3 @@ readbackBranch :: Index.Map v Var -> Branch -> Low.Syntax.Branch v readbackBranch env = \case ConstructorBranch con value -> Low.Syntax.ConstructorBranch con $ readback env value LiteralBranch lit value -> Low.Syntax.LiteralBranch lit $ readback env value - diff --git a/src/ReferenceCounting.hs b/src/ReferenceCounting.hs index 9c51735..8afff13 100644 --- a/src/ReferenceCounting.hs +++ b/src/ReferenceCounting.hs @@ -358,7 +358,7 @@ increase value repr | otherwise = pure value decreaseBefore - :: Foldable f + :: (Foldable f) => f (Var, Representation) -> Value -> Value @@ -373,7 +373,7 @@ decreaseBefore vars value = vars decreaseAfter - :: Foldable f + :: (Foldable f) => f (Var, Representation) -> Value -> PassBy