refactor: CInt Integer
All checks were successful
build / build (push) Successful in 16s

This commit is contained in:
2026-04-24 13:36:53 -06:00
parent e03e918bf4
commit 25b62cb69d
4 changed files with 11 additions and 12 deletions

1
.gitignore vendored
View File

@@ -7,3 +7,4 @@ dist-newstyle
.ghc.environment.* .ghc.environment.*
*.tix *.tix
.direnv .direnv
result

View File

@@ -24,7 +24,7 @@
shell.tools = { shell.tools = {
cabal = {}; cabal = {};
# hlint = {}; # hlint = {};
# haskell-language-server = {}; haskell-language-server = {};
}; };
# Non-Haskell shell tools go here # Non-Haskell shell tools go here
shell.buildInputs = with final; [ shell.buildInputs = with final; [

View File

@@ -170,15 +170,14 @@ instance Pretty ExtTy where
-- | Constant/immediate -- | Constant/immediate
data Const data Const
-- MAYBE just use a signed type -- 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 | CSingle Float -- ^ Single-precision float
| CDouble Double -- ^ Double-precision float | CDouble Double -- ^ Double-precision float
| CGlobal (Ident 'Global) -- ^ Global symbol | CGlobal (Ident 'Global) -- ^ Global symbol
deriving (Show, Eq) deriving (Show, Eq)
instance Pretty Const where instance Pretty Const where
pretty (CInt negative int) | negative = pretty '-' <> pretty int pretty (CInt int) = pretty int
| otherwise = pretty int
pretty (CSingle float) = "s_" <> pretty float pretty (CSingle float) = "s_" <> pretty float
pretty (CDouble double) = "d_" <> pretty double pretty (CDouble double) = "d_" <> pretty double
pretty (CGlobal ident) = pretty ident pretty (CGlobal ident) = pretty ident

View File

@@ -31,8 +31,8 @@ goldenTests = testGroup "golden tests"
] ]
, t "type" ([Word, Long, Single, Double], [BaseTy Word, Byte, HalfWord]) , t "type" ([Word, Long, Single, Double], [BaseTy Word, Byte, HalfWord])
, t "const" , t "const"
[ CInt True 1 [ CInt (-1)
, CInt False 2 , CInt 2
, CSingle 0.1 , CSingle 0.1
, CDouble (-0.2) , CDouble (-0.2)
, CGlobal "global" , CGlobal "global"
@@ -45,7 +45,7 @@ goldenTests = testGroup "golden tests"
, t "opaque" $ Opaque "t" 8 16 , t "opaque" $ Opaque "t" 8 16
, t "data" $ DataDef [Export] "d" (Just 8) , t "data" $ DataDef [Export] "d" (Just 8)
[ FieldZero 16 [ 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" , t "function" $ FuncDef [Export] (Just $ AbiAggregateTy "t") "f"
(Just "env") [Param (AbiBaseTy Word) "a", Param (AbiBaseTy Double) "b"] Variadic $ (Just "env") [Param (AbiBaseTy Word) "a", Param (AbiBaseTy Double) "b"] Variadic $
@@ -92,8 +92,7 @@ goldenTests = testGroup "golden tests"
(renderStrict . layoutPretty defaultLayoutOptions) (renderStrict . layoutPretty defaultLayoutOptions)
valInt :: Int -> Val valInt :: Int -> Val
valInt i | i >= 0 = ValConst $ CInt False $ fromIntegral i valInt i = ValConst $ CInt $ fromIntegral i
| otherwise = ValConst $ CInt True $ fromIntegral $ negate i
one, two :: Val one, two :: Val
one = valInt 1 one = valInt 1
@@ -107,7 +106,7 @@ helloWorld = Program [] [helloString] [helloMain]
where where
helloString = DataDef [] "str" Nothing helloString = DataDef [] "str" Nothing
[ FieldExtTy Byte $ String "hello world" :| [] [ FieldExtTy Byte $ String "hello world" :| []
, FieldExtTy Byte $ Const (CInt False 0) :| [] , FieldExtTy Byte $ Const (CInt 0) :| []
] ]
helloMain = FuncDef [Export] (Just $ AbiBaseTy Word) "main" helloMain = FuncDef [Export] (Just $ AbiBaseTy Word) "main"
Nothing [] NoVariadic $ Nothing [] NoVariadic $
@@ -118,5 +117,5 @@ helloWorld = Program [] [helloString] [helloMain]
[Arg (AbiBaseTy Long) $ ValGlobal "str"] [Arg (AbiBaseTy Long) $ ValGlobal "str"]
[] []
] ]
(Ret $ Just $ ValConst $ CInt False 0) (Ret $ Just $ ValConst $ CInt 0)
:| [] :| []