diff options
author | tomsmeding <tom.smeding@gmail.com> | 2019-12-12 20:17:13 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2019-12-12 21:02:12 +0100 |
commit | eee7489ade3862519c1feb7dece04570469a1da3 (patch) | |
tree | abd985962c1254ee1b181f9c655cdc854b799595 /VM.hs | |
parent | 21683f6922202e4588e6c84bc281d6b9690cba77 (diff) |
General cleanup
Diffstat (limited to 'VM.hs')
-rw-r--r-- | VM.hs | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -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 |