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

3
.gitignore vendored
View File

@@ -6,4 +6,5 @@ dist-newstyle
*.hi
.ghc.environment.*
*.tix
.direnv
.direnv
result

View File

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

View File

@@ -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

View File

@@ -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)
:| []