From 6fd45215558272cc4a2ee5e9cba631ffd0c03148 Mon Sep 17 00:00:00 2001 From: Lukasz Czajka Date: Fri, 14 Apr 2023 10:51:46 +0200 Subject: [PATCH] changes for review --- .../Compiler/Asm/Translation/FromCore.hs | 21 +++++++++++-------- src/Juvix/Compiler/Builtins/Bool.hs | 2 +- src/Juvix/Compiler/Builtins/Control.hs | 2 +- src/Juvix/Compiler/Builtins/Debug.hs | 4 ++-- src/Juvix/Data/Universe.hs | 3 +++ 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Juvix/Compiler/Asm/Translation/FromCore.hs b/src/Juvix/Compiler/Asm/Translation/FromCore.hs index 5182c6e5dd..8bdf6e9dbc 100644 --- a/src/Juvix/Compiler/Asm/Translation/FromCore.hs +++ b/src/Juvix/Compiler/Asm/Translation/FromCore.hs @@ -137,21 +137,24 @@ genCode infoTable fi = goBuiltinApp isTail tempSize refs (Core.BuiltinApp {..}) = case _builtinAppOp of OpSeq -> - case _builtinAppArgs of - [arg1, arg2] -> - DL.append - (go False tempSize refs arg1) - ( DL.cons - (mkInstr Pop) - (go isTail tempSize refs arg2) - ) - _ -> impossible + goSeq isTail tempSize refs _builtinAppArgs _ -> snocReturn isTail $ DL.append (DL.concat (map (go False tempSize refs) (reverse _builtinAppArgs))) (genOp _builtinAppOp) + goSeq :: Bool -> Int -> BinderList Value -> [Core.Node] -> Code' + goSeq isTail tempSize refs = \case + [arg1, arg2] -> + DL.append + (go False tempSize refs arg1) + ( DL.cons + (mkInstr Pop) + (go isTail tempSize refs arg2) + ) + _ -> impossible + goConstr :: Bool -> Int -> BinderList Value -> Core.Constr -> Code' goConstr isTail tempSize refs = \case Core.Constr _ (Core.BuiltinTag Core.TagTrue) _ -> diff --git a/src/Juvix/Compiler/Builtins/Bool.hs b/src/Juvix/Compiler/Builtins/Bool.hs index 625141190e..f4fe026405 100644 --- a/src/Juvix/Compiler/Builtins/Bool.hs +++ b/src/Juvix/Compiler/Builtins/Bool.hs @@ -36,7 +36,7 @@ registerIf f = do true_ <- toExpression <$> getBuiltinName (getLoc f) BuiltinBoolTrue false_ <- toExpression <$> getBuiltinName (getLoc f) BuiltinBoolFalse let if_ = f ^. funDefName - u = ExpressionUniverse (Universe {_universeLevel = Nothing, _universeLoc = error "Universe with no location"}) + u = ExpressionUniverse smallUniverseNoLoc vart <- freshVar "t" vare <- freshVar "e" hole <- freshHole diff --git a/src/Juvix/Compiler/Builtins/Control.hs b/src/Juvix/Compiler/Builtins/Control.hs index 1696b79aee..c8d6dc814e 100644 --- a/src/Juvix/Compiler/Builtins/Control.hs +++ b/src/Juvix/Compiler/Builtins/Control.hs @@ -6,7 +6,7 @@ import Juvix.Prelude registerSeq :: (Members '[Builtins, NameIdGen] r) => FunctionDef -> Sem r () registerSeq f = do - let u = ExpressionUniverse (Universe {_universeLevel = Nothing, _universeLoc = error "Universe with no location"}) + let u = ExpressionUniverse smallUniverseNoLoc a <- freshVar "a" b <- freshVar "b" let seq = f ^. funDefName diff --git a/src/Juvix/Compiler/Builtins/Debug.hs b/src/Juvix/Compiler/Builtins/Debug.hs index 6f08884142..0eb973a37b 100644 --- a/src/Juvix/Compiler/Builtins/Debug.hs +++ b/src/Juvix/Compiler/Builtins/Debug.hs @@ -8,7 +8,7 @@ import Juvix.Prelude registerTrace :: (Members '[Builtins, NameIdGen] r) => AxiomDef -> Sem r () registerTrace f = do let ftype = f ^. axiomType - u = ExpressionUniverse (Universe {_universeLevel = Nothing, _universeLoc = error "Universe with no location"}) + u = ExpressionUniverse smallUniverseNoLoc a <- freshVar "a" let freeVars = HashSet.fromList [a] unless @@ -19,7 +19,7 @@ registerTrace f = do registerFail :: (Members '[Builtins, NameIdGen] r) => AxiomDef -> Sem r () registerFail f = do let ftype = f ^. axiomType - u = ExpressionUniverse (Universe {_universeLevel = Nothing, _universeLoc = error "Universe with no location"}) + u = ExpressionUniverse smallUniverseNoLoc a <- freshVar "a" let freeVars = HashSet.fromList [a] string_ <- getBuiltinName (getLoc f) BuiltinString diff --git a/src/Juvix/Data/Universe.hs b/src/Juvix/Data/Universe.hs index fe66197142..5f66fafb57 100644 --- a/src/Juvix/Data/Universe.hs +++ b/src/Juvix/Data/Universe.hs @@ -41,6 +41,9 @@ smallUniverse = Universe (Just smallLevel) isSmallUniverse :: Universe -> Bool isSmallUniverse = (== smallLevel) . getUniverseLevel +smallUniverseNoLoc :: Universe +smallUniverseNoLoc = smallUniverse (error "Universe with no location") + instance HasAtomicity Universe where atomicity u = case u ^. universeLevel of Nothing -> Atom