@@ -739,12 +739,9 @@ stepCESK cesk = case cesk of
739739 -- To evaluate an import:
740740 -- (1) stick a 'suspend' at the end of the term
741741 -- corresponding to the imported module, so we can save the resulting environment
742- -- (2) push an FBind frame on the stack to continue with the
743- -- rest of the code once we're done processing the import.
744- -- Note that the environment in the FBind will be ignored
745- -- in favor of the environment resulting from the suspend.
746- -- (3) push an FExec frame to execute the import itself.
747- Just m -> In (insertSuspend $ erase m ^. sTerm) e s (FExec : FBind Nothing Nothing t e : k)
742+ -- (2) push an FImport frame on the stack to continue with the
743+ -- body in the context of the input once we're done processing it.
744+ Just m -> In (insertSuspend $ erase m ^. sTerm) e s (FImport t : k)
748745 -- XXX keep a map from imports to corresponding Env, don't re-evaluate if it's already
749746 -- in the map. To make this sound, need to disallow all but defs in an import.
750747 -- Ignore explicit parens.
@@ -817,6 +814,16 @@ stepCESK cesk = case cesk of
817814 Nothing -> addValueBinding x v e
818815 Just (ty, reqs) -> addBinding x (WithType v ty reqs) e
819816 return $ In t2 e' s (FExec : k)
817+ -- If we have suspended at the end of an import, go ahead and
818+ -- evaluate the suspend without waiting for an FExec, since the body
819+ -- of the import may or may not be something we need to execute
820+ -- (e.g. "import blah in x + 1" vs "import blah in move; foo")
821+ Out (VSuspend t e) s (FImport body : k) -> return $ In t e s (FSuspend e : FImport body : k)
822+ -- This case shouldn't happen: we will always insert a call to
823+ -- 'suspend' at the end of an import, so we will reach the 'FImport'
824+ -- frame in a 'Suspended' state, so we can restore the suspended
825+ -- environment.
826+ Out _ s (FImport _ : _) -> badMachineState s " FImport frame in non-suspended state"
820827 -- To execute a suspend instruction, evaluate its argument and then
821828 -- suspend.
822829 Out (VSuspend t e) s (FExec : k) -> return $ In t e s (FSuspend e : k)
@@ -852,6 +859,10 @@ stepCESK cesk = case cesk of
852859 Nothing -> addValueBinding x v e
853860 Just (ty, reqs) -> addBinding x (WithType v ty reqs) e
854861 return $ In t2 e' s (FExec : k)
862+ -- If we we're suspended after processing an import, resume by
863+ -- evaluating the body of the import in the suspended context we got
864+ -- after processing the import.
865+ Suspended _ e s (FImport t : k) -> return $ In t e s k
855866 -- Otherwise, if we're suspended with nothing else left to do,
856867 -- return the machine unchanged (but throw away the rest of the
857868 -- continuation stack).
0 commit comments