Fixed the ordering of data types.

This commit is contained in:
Samuel Hammersberg 2023-04-12 15:15:38 +02:00
parent 2b7715714e
commit 0ab13e5979

View file

@ -9,8 +9,9 @@ import Codegen.LlvmIr as LIR (llvmIrToString)
import Control.Monad.State (
execStateT,
)
import Data.List (sortBy)
import Grammar.ErrM (Err)
import Monomorphizer.MonomorphizerIr as MIR (Program (..))
import Monomorphizer.MonomorphizerIr as MIR (Def (DBind, DData), Program (..))
{- | Compiles an AST and produces a LLVM Ir string.
An easy way to actually "compile" this output is to
@ -19,4 +20,9 @@ import Monomorphizer.MonomorphizerIr as MIR (Program (..))
generateCode :: MIR.Program -> Err String
generateCode (MIR.Program scs) = do
let codegen = initCodeGenerator scs
llvmIrToString . instructions <$> execStateT (compileScs scs) codegen
llvmIrToString . instructions <$> execStateT (compileScs (sortBy lowData scs)) codegen
lowData :: Def -> Def -> Ordering
lowData (DData _) (DBind _) = LT
lowData (DBind _) (DData _) = GT
lowData _ _ = EQ