aboutsummaryrefslogtreecommitdiff
path: root/Sjit/Compile.icl
diff options
context:
space:
mode:
authorCamil Staps2018-12-25 02:18:27 +0100
committerCamil Staps2018-12-25 02:18:27 +0100
commitbac1fc7844857d1928f4ded2448df3018f4f7f20 (patch)
tree892fc24bff69bfdadf651472b740f063b6e9d026 /Sjit/Compile.icl
parentDon't generate pop 0 (diff)
Inline +, *, - and /
Diffstat (limited to 'Sjit/Compile.icl')
-rw-r--r--Sjit/Compile.icl19
1 files changed, 10 insertions, 9 deletions
diff --git a/Sjit/Compile.icl b/Sjit/Compile.icl
index 8fd81a2..527676f 100644
--- a/Sjit/Compile.icl
+++ b/Sjit/Compile.icl
@@ -64,10 +64,6 @@ where
header :: [(!String, ![Instr])]
header =
[ ("_", [PushI 0,Call 0 /* main address */,Halt])
- , ("+", [IAddRet])
- , ("*", [IMulRet])
- , ("-", [ISubRet])
- , ("/", [IDivRet])
]
initJITState :: !Int -> JITState
@@ -105,10 +101,10 @@ where
JmpTrue _ -> 0
Ret -> -1
Halt -> -2
- IAddRet -> -1
- IMulRet -> -1
- ISubRet -> -1
- IDivRet -> -1
+ IAdd -> -1
+ IMul -> -1
+ ISub -> -1
+ IDiv -> -1
PlaceHolder _ n -> n
reserve :: !Int !CompileState -> m (!Int, !CompileState) | Monad m
@@ -155,7 +151,12 @@ where
expr (App f args) cs
# args = if (args=:[]) [Int 0] args
= foldM (flip expr) cs (reverse args) >>= \cs -> case get f cs.funs of
- Nothing -> Left ("undefined function '" +++ toString f +++ "'")
+ Nothing -> case f of
+ "+" -> gen [IAdd] cs
+ "-" -> gen [ISub] cs
+ "*" -> gen [IMul] cs
+ "/" -> gen [IDiv] cs
+ _ -> Left ("undefined function '" +++ toString f +++ "'")
Just f -> case length args of
1 -> gen [Call f] cs
n -> gen [Pop (n-1),Call f] cs