From bac1fc7844857d1928f4ded2448df3018f4f7f20 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 25 Dec 2018 02:18:27 +0100 Subject: Inline +, *, - and / --- Sjit/Compile.icl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'Sjit/Compile.icl') 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 -- cgit v1.2.3