aboutsummaryrefslogtreecommitdiff
path: root/src/Micro/Asm/Sdcc.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-12-20 19:53:05 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-12-20 19:53:05 +0000
commitc7cc8467ca1835c8f96ccb5be7c976a26d262433 (patch)
tree007845bfd68c97ce88056912942617424c2f93a8 /src/Micro/Asm/Sdcc.hs
parent9ebeada35c00160b19161928be74e44093686985 (diff)
downloadmicro-lang-hs-c7cc8467ca1835c8f96ccb5be7c976a26d262433.tar.gz
micro-lang-hs-c7cc8467ca1835c8f96ccb5be7c976a26d262433.zip
Updated to use GHC 9.4.x and floating dependencies
Diffstat (limited to 'src/Micro/Asm/Sdcc.hs')
-rw-r--r--src/Micro/Asm/Sdcc.hs44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/Micro/Asm/Sdcc.hs b/src/Micro/Asm/Sdcc.hs
index af4e7d7..9d94b16 100644
--- a/src/Micro/Asm/Sdcc.hs
+++ b/src/Micro/Asm/Sdcc.hs
@@ -1,6 +1,6 @@
module Micro.Asm.Sdcc where
-import qualified Micro.Ast as A
+import Micro.Ast qualified as A
import Text.Parsec (SourcePos, sourceColumn, sourceLine)
toIdent :: A.Ident -> String
@@ -46,14 +46,14 @@ mul8 :: A.Expr -> A.Expr -> SourcePos -> [String]
mul8 a b p = do
let loop = posToIdent p
let loop0 = loop ++ "z"
- oCode (emit a)
+ (emit a).oCode
++ [ "\tor a",
"\tjr z, " ++ toIdent loop0,
"\tld b, a",
"\tdec b",
"\tjr z, " ++ toIdent loop0
]
- ++ oCode (emit b)
+ ++ (emit b).oCode
++ [ "\tld c, a",
toLabel loop True,
"\tadd c",
@@ -64,12 +64,12 @@ mul8 a b p = do
mul :: A.Expr -> A.Expr -> SourcePos -> [String]
mul a b@(A.Num v _) p
- | v == 2 = oCode (emit a) ++ ["\tsla a"]
- | v == 4 = oCode (emit a) ++ replicate 2 "\tsla a"
- | v == 8 = oCode (emit a) ++ replicate 3 "\tsla a"
- | v == 16 = oCode (emit a) ++ replicate 4 "\tsla a"
- | v == 32 = oCode (emit a) ++ replicate 5 "\tsla a"
- | v < 6 = oCode (emit a) ++ ["\tld c, a"] ++ replicate (fromInteger v - 1) "\tadd c"
+ | v == 2 = (emit a).oCode ++ ["\tsla a"]
+ | v == 4 = (emit a).oCode ++ replicate 2 "\tsla a"
+ | v == 8 = (emit a).oCode ++ replicate 3 "\tsla a"
+ | v == 16 = (emit a).oCode ++ replicate 4 "\tsla a"
+ | v == 32 = (emit a).oCode ++ replicate 5 "\tsla a"
+ | v < 6 = (emit a).oCode ++ ["\tld c, a"] ++ replicate (fromInteger v - 1) "\tadd c"
| otherwise = mul8 a b p
mul _ _ _ = [";; unimplemented"]
@@ -98,28 +98,28 @@ emit x =
(A.BinOp A.Mul _ (A.Num a _) (A.Num b _)) -> o {oCode = [show a ++ "*" ++ show b]}
(A.BinOp A.Div _ (A.Num a _) (A.Num b _)) -> o {oCode = [show a ++ "/" ++ show b]}
(A.BinOp A.Plus _ a (A.Num 1 _)) ->
- o {oCode = oCode (emit a) ++ ["\tinc a"]}
+ o {oCode = (emit a).oCode ++ ["\tinc a"]}
(A.BinOp A.Plus _ a (A.Num v _)) ->
- o {oCode = oCode (emit a) ++ ["\tadd #" ++ show v]}
+ o {oCode = (emit a).oCode ++ ["\tadd #" ++ show v]}
(A.BinOp A.Plus _ a b) ->
- o {oCode = oCode (emit a) ++ ["\tld c, a"] ++ oCode (emit b) ++ ["\tadd c"]}
+ o {oCode = (emit a).oCode ++ ["\tld c, a"] ++ (emit b).oCode ++ ["\tadd c"]}
(A.BinOp A.Minus _ a (A.Num 1 _)) ->
- o {oCode = oCode (emit a) ++ ["\tdec a"]}
+ o {oCode = (emit a).oCode ++ ["\tdec a"]}
(A.BinOp A.Minus _ a (A.Num v _)) ->
- o {oCode = oCode (emit a) ++ ["\tsub #" ++ show v]}
+ o {oCode = (emit a).oCode ++ ["\tsub #" ++ show v]}
(A.BinOp A.Minus _ a b) ->
- o {oCode = oCode (emit a) ++ ["\tld c, a"] ++ oCode (emit b) ++ ["\tld b, a", "\tld a, c", "\tsub b"]}
+ o {oCode = (emit a).oCode ++ ["\tld c, a"] ++ (emit b).oCode ++ ["\tld b, a", "\tld a, c", "\tsub b"]}
(A.BinOp A.Mul _ _ (A.Num 0 _)) ->
o {oCode = ["\txor a"]}
(A.BinOp A.Mul _ (A.Num 0 _) _) ->
o {oCode = ["\txor a"]}
- (A.BinOp A.Mul _ (A.Num 1 _) b) -> o {oCode = oCode (emit b)}
- (A.BinOp A.Mul _ a (A.Num 1 _)) -> o {oCode = oCode (emit a)}
+ (A.BinOp A.Mul _ (A.Num 1 _) b) -> o {oCode = (emit b).oCode}
+ (A.BinOp A.Mul _ a (A.Num 1 _)) -> o {oCode = (emit a).oCode}
(A.BinOp A.Mul pos a b@(A.Num _ _)) -> o {oCode = mul a b pos}
(A.BinOp A.Mul pos a@(A.Num _ _) b) -> o {oCode = mul b a pos}
(A.BinOp A.Mul p a b) -> o {oCode = mul8 a b p}
(A.BinOp A.Assign _ (A.Variable id _) b) ->
- o {oCode = oCode (emit b) ++ ["\tld (" ++ toIdent id ++ "), a"]}
+ o {oCode = (emit b).oCode ++ ["\tld (" ++ toIdent id ++ "), a"]}
_ -> o {oCode = [";; unimplemented " ++ show x]}
where
o = Output [] [] [] []
@@ -127,8 +127,8 @@ emit x =
generate :: String -> [A.Expr] -> String
generate version ast = do
let out = map emit ast
- let pre = concatMap oPre out
- let dat = [area "_DATA", area "_INITIALIZED"] ++ concatMap oData out
- let code = [area "_CODE"] ++ concatMap oCode out ++ ["hlt0:", "\tjr hlt0"]
- let init = [area "_INITIALIZER"] ++ concatMap oInit out ++ [area "_GSINIT", area "_GSFINAL"]
+ let pre = concatMap (\f -> f.oPre) out
+ let dat = [area "_DATA", area "_INITIALIZED"] ++ concatMap (\f -> f.oData) out
+ let code = [area "_CODE"] ++ concatMap (\f -> f.oCode) out ++ ["hlt0:", "\tjr hlt0"]
+ let init = [area "_INITIALIZER"] ++ concatMap (\f -> f.oInit) out ++ [area "_GSINIT", area "_GSFINAL"]
unlines $ header version ++ pre ++ dat ++ code ++ init