From 25b62cb69d8e3bd51f32c4bfe494fa78094f8fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madeleine=20Sydney=20=C5=9Alaga?= Date: Fri, 24 Apr 2026 13:36:53 -0600 Subject: [PATCH] refactor: CInt Integer --- .gitignore | 3 ++- flake.nix | 2 +- src/Language/QBE.hs | 5 ++--- test/Main.hs | 13 ++++++------- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 00eb306..b154770 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ dist-newstyle *.hi .ghc.environment.* *.tix -.direnv \ No newline at end of file +.direnv +result \ No newline at end of file diff --git a/flake.nix b/flake.nix index bcf2df5..de8db30 100644 --- a/flake.nix +++ b/flake.nix @@ -24,7 +24,7 @@ shell.tools = { cabal = {}; # hlint = {}; - # haskell-language-server = {}; + haskell-language-server = {}; }; # Non-Haskell shell tools go here shell.buildInputs = with final; [ diff --git a/src/Language/QBE.hs b/src/Language/QBE.hs index c94aa2a..77ad7be 100644 --- a/src/Language/QBE.hs +++ b/src/Language/QBE.hs @@ -170,15 +170,14 @@ instance Pretty ExtTy where -- | Constant/immediate data Const -- MAYBE just use a signed type - = CInt Bool Word64 -- ^ 64 bit integer. The 'Bool' is whether to negate. + = CInt Integer -- ^ Integer | CSingle Float -- ^ Single-precision float | CDouble Double -- ^ Double-precision float | CGlobal (Ident 'Global) -- ^ Global symbol deriving (Show, Eq) instance Pretty Const where - pretty (CInt negative int) | negative = pretty '-' <> pretty int - | otherwise = pretty int + pretty (CInt int) = pretty int pretty (CSingle float) = "s_" <> pretty float pretty (CDouble double) = "d_" <> pretty double pretty (CGlobal ident) = pretty ident diff --git a/test/Main.hs b/test/Main.hs index 0691ed5..090de61 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -31,8 +31,8 @@ goldenTests = testGroup "golden tests" ] , t "type" ([Word, Long, Single, Double], [BaseTy Word, Byte, HalfWord]) , t "const" - [ CInt True 1 - , CInt False 2 + [ CInt (-1) + , CInt 2 , CSingle 0.1 , CDouble (-0.2) , CGlobal "global" @@ -45,7 +45,7 @@ goldenTests = testGroup "golden tests" , t "opaque" $ Opaque "t" 8 16 , t "data" $ DataDef [Export] "d" (Just 8) [ FieldZero 16 - , FieldExtTy Byte $ Symbol "g" (Just 32) :| [String "foo\nbar\0baz", Const $ CInt True 1] + , FieldExtTy Byte $ Symbol "g" (Just 32) :| [String "foo\nbar\0baz", Const $ CInt (-1)] ] , t "function" $ FuncDef [Export] (Just $ AbiAggregateTy "t") "f" (Just "env") [Param (AbiBaseTy Word) "a", Param (AbiBaseTy Double) "b"] Variadic $ @@ -92,8 +92,7 @@ goldenTests = testGroup "golden tests" (renderStrict . layoutPretty defaultLayoutOptions) valInt :: Int -> Val -valInt i | i >= 0 = ValConst $ CInt False $ fromIntegral i - | otherwise = ValConst $ CInt True $ fromIntegral $ negate i +valInt i = ValConst $ CInt $ fromIntegral i one, two :: Val one = valInt 1 @@ -107,7 +106,7 @@ helloWorld = Program [] [helloString] [helloMain] where helloString = DataDef [] "str" Nothing [ FieldExtTy Byte $ String "hello world" :| [] - , FieldExtTy Byte $ Const (CInt False 0) :| [] + , FieldExtTy Byte $ Const (CInt 0) :| [] ] helloMain = FuncDef [Export] (Just $ AbiBaseTy Word) "main" Nothing [] NoVariadic $ @@ -118,5 +117,5 @@ helloWorld = Program [] [helloString] [helloMain] [Arg (AbiBaseTy Long) $ ValGlobal "str"] [] ] - (Ret $ Just $ ValConst $ CInt False 0) + (Ret $ Just $ ValConst $ CInt 0) :| []