~jojo/Carth

a2b169019187479b09ffaae012612ed189936245 — JoJo 2 years ago 1d5e891 backend-c
Handle enums in Lower.asVariant

It was already partly implemented, but full support was only there for
tagged unions. Trivial to fix though.
1 files changed, 7 insertions(+), 3 deletions(-)

M src/Back/Lower.hs
M src/Back/Lower.hs => src/Back/Lower.hs +7 -3
@@ 1098,10 1098,14 @@ lowerMatch dest matchees decisionTree = do
                ++ ", x = "
                ++ show x
        asVariant _ vi x = do
            let tidData = case typeof x of
                    Low.TPtr (Low.TConst tid) -> tid
            let
                tidData = case typeof x of
                    Low.TPtr (Low.TConst tid) -> tid -- Structs are kept on the stack
                    Low.TConst tid -> tid -- A TConst-typed value not on the stack? It has to be an enum.
                    t ->
                        ice $ "Lower.asVariant: type of matchee is not TPtr to TConst, " ++ show t
                        ice
                            $ "Lower.asVariant: type of matchee is not TPtr to TConst (tagged union) or TConst (enum), t = "
                            ++ show t
            variantTypeId tidData vi >>= \case
                ZeroSized -> pure (Low.Block [] ZeroSized)
                Sized vtid -> do