Skip to content

Commit

Permalink
Fixed type confusion bug when compiling unary minus
Browse files Browse the repository at this point in the history
Previously when `-a` was compiled in a `real` context but `a` is an integer
`a` itself was being compiled in the real context, which is wrong.
Instead a has to be compiled as an int and only then then converted to real.
  • Loading branch information
lep committed Mar 5, 2023
1 parent 2d7a22c commit 2bba412
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Hot/Instruction/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,12 @@ compileExpr e =

H.Call (Op "-") [a] -> do
r <- newRegister
t <- compileExpr a
-- We need to compile `a` from `-a` as the type of `a` itself,
-- which does sound weird, but neccessary as otherwise a would be
-- put into the – let's say – real slot of the register when `a`
-- itself would be an integer
ta <- typeOfExpr a
t <- typed ta $ compileExpr a
emit $ Negate ta r t
typedGet ta r

Expand Down
6 changes: 3 additions & 3 deletions Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ compileX o = do
toCompile <- forM (inputPaths o) $ \j -> do
src <- liftIO $ readFile j
J.Programm ast <- exceptT $ parse J.programm j src
traceShowM ast
--traceShowM ast
return ast
return (commonj, J.Programm $ concat toCompile)
case x of
Expand All @@ -236,8 +236,8 @@ compileX o = do
prog = jass_opt j
prog' = H.jass2hot . fst $ Rename.compile Rename.Init id st prog
asm = ins_opt $ Ins.compile typeHierachy prog'
traceShowM j
traceShowM prog
--traceShowM j
--traceShowM prog
hPutBuilder stdout $ Ins.serializeAsm asm
when (showSerialize o) $ do
putStrLn ""
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
buildInputs = [
pkgs.gnumake
pkgs.cabal-install
ghcPackages
];
in rec {
packages = {
Expand Down

0 comments on commit 2bba412

Please sign in to comment.