summaryrefslogtreecommitdiff
path: root/VM.hs
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-12-12 20:17:13 +0100
committertomsmeding <tom.smeding@gmail.com>2019-12-12 21:02:12 +0100
commiteee7489ade3862519c1feb7dece04570469a1da3 (patch)
treeabd985962c1254ee1b181f9c655cdc854b799595 /VM.hs
parent21683f6922202e4588e6c84bc281d6b9690cba77 (diff)
General cleanup
Diffstat (limited to 'VM.hs')
-rw-r--r--VM.hs22
1 files changed, 14 insertions, 8 deletions
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