From 3cd38818905bd78a83339603f73d7551a8c4d6ac Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 22 Nov 2019 19:54:40 +0100 Subject: Fix bug with recursion in VM This was introduced in cf7b7db --- VM.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'VM.hs') diff --git a/VM.hs b/VM.hs index e0ed2f4..784c93b 100644 --- a/VM.hs +++ b/VM.hs @@ -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)) -- cgit v1.2.3-70-g09d2