diff options
author | tomsmeding <tom.smeding@gmail.com> | 2019-11-22 19:54:40 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2019-11-22 19:56:03 +0100 |
commit | 3cd38818905bd78a83339603f73d7551a8c4d6ac (patch) | |
tree | b895f3f992ac34d7f60e967350b2c0541f15aab5 | |
parent | 4dd7ed521e22a0c81317b1e5ebdb235258e47a2a (diff) |
Fix bug with recursion in VM
This was introduced in cf7b7db
-rw-r--r-- | VM.hs | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -103,7 +103,14 @@ callClosure info@(Info bbmap gfds _) state@(State { sTempMap = tmap }) cl as = Just (GlobFuncDef b _ _) -> do (rv, state') <- vmRunBB info (state { sArgs = map (findRef tmap) as, sCloVals = clvals }) (bbmap Map.! b) - return (rv, state' { sArgs = sArgs state, sCloVals = sCloVals state }) + -- TODO: we restore tempmap here after the call, and that's + -- _really_ dodgy. I think it works because we never mutate + -- a reference after first assigning it, and without it + -- recursion fails, but it feels ugly. A proper solution + -- would be to further compile the IR down to something + -- that stores its values on a stack, so that recursion is + -- handled automatically. + return (rv, state' { sArgs = sArgs state, sCloVals = sCloVals state, sTempMap = sTempMap state }) Nothing -> -- Take 'tail as' to skip the first self-link argument vmRunBuiltin state clname (map (findRef tmap) (tail as)) |