From eee7489ade3862519c1feb7dece04570469a1da3 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 12 Dec 2019 20:17:13 +0100 Subject: General cleanup --- VM.hs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'VM.hs') diff --git a/VM.hs b/VM.hs index 3d78519..08e7c63 100644 --- a/VM.hs +++ b/VM.hs @@ -60,22 +60,28 @@ vmRunBB info state (BB _ inss term) = do vmRunInstr :: Info -> State -> Instruction -> IO State -- vmRunInstr _ _ ins | traceShow ins False = undefined -vmRunInstr info@(Info _ _ datas) state@(State { sTempMap = tmap, sArgs = args, sCloVals = closure }) (dest, instr) = case instr of - IAssign ref -> return (assignRef state dest (findRef tmap ref)) +vmRunInstr info@(Info _ _ datas) state (dest, instr) = case instr of + IAssign ref -> + return (assignRef state dest (findRef (sTempMap state) ref)) IParam i -> - if i < length args then return (assignRef state dest (args !! i)) - else error $ show args ++ ", " ++ show i ++ ", param-out-of-range" + let args = sArgs state + in if i < length args then return (assignRef state dest (args !! i)) + else error $ show args ++ ", " ++ show i ++ ", param-out-of-range" IClosure i -> - if i < length closure then return (assignRef state dest (closure !! i)) - else error $ show closure ++ ", " ++ show i ++ ", closure-out-of-range" + let closure = sCloVals state + in if i < length closure then return (assignRef state dest (closure !! i)) + else error $ show closure ++ ", " ++ show i ++ ", closure-out-of-range" IData i -> if i < length datas then return (assignRef state dest (toRunValue (datas !! i))) else error "data-out-of-range" ICallC cl as -> do (rv, state') <- callClosure info state cl as return (assignRef state' dest rv) - IAllocClo name clrefs -> return (assignRef state dest (RVClosure name (map (findRef tmap) clrefs))) - IDiscard _ -> return state + IAllocClo name clrefs -> + let cloVals = (map (findRef (sTempMap state)) clrefs) + in return (assignRef state dest (RVClosure name cloVals)) + IDiscard _ -> + return state -- TODO: erase temporary from state for IDiscard (RTemp i) vmRunTerm :: Info -> State -> Terminator -> IO (RunValue, State) vmRunTerm info@(Info bbmap _ _) state@(State { sTempMap = tmap }) term = case term of -- cgit v1.2.3-70-g09d2