@@ -337,7 +337,7 @@ manageMemory typeEnv globalEnv root =
337337 -- 2. Variables deleted in at least one case has to be deleted in all, so make a union U of all such vars
338338 -- but remove the ones that were not present before the 'match'
339339 -- 3. In each case - take the intersection of U and the vars deleted in that case and add this result to its deleters
340- matchExpr@ (XObj (Match _ ) _ _) : expr : cases ->
340+ matchExpr@ (XObj (Match matchMode ) _ _) : expr : cases ->
341341 do
342342 visitedExpr <- visit expr
343343 case visitedExpr of
@@ -346,7 +346,7 @@ manageMemory typeEnv globalEnv root =
346346 do
347347 _ <- unmanage typeEnv globalEnv okVisitedExpr
348348 MemState preDeleters deps lifetimes <- get
349- vistedCasesAndDeps <- mapM visitMatchCase (pairwise cases)
349+ vistedCasesAndDeps <- mapM ( visitMatchCase matchMode) (pairwise cases)
350350 case sequence vistedCasesAndDeps of
351351 Left e -> pure (Left e)
352352 Right okCasesAndDeps ->
@@ -415,32 +415,32 @@ manageMemory typeEnv globalEnv root =
415415 Right (XObj (Lst (okF : okArgs)) i t)
416416 [] -> pure (Right xobj)
417417 visitList _ = error " Must visit list."
418- visitMatchCase :: (XObj , XObj ) -> State MemState (Either TypeError ((Set. Set Deleter , (XObj , XObj )), Set. Set Ty ))
419- visitMatchCase (lhs@ XObj {}, rhs@ XObj {}) =
418+ visitMatchCase :: MatchMode -> (XObj , XObj ) -> State MemState (Either TypeError ((Set. Set Deleter , (XObj , XObj )), Set. Set Ty ))
419+ visitMatchCase matchMode (lhs@ XObj {}, rhs@ XObj {}) =
420420 do
421421 MemState preDeleters _ _ <- get
422- _ <- visitCaseLhs lhs
422+ _ <- visitCaseLhs matchMode lhs
423423 visitedRhs <- visit rhs
424424 _ <- unmanage typeEnv globalEnv rhs
425425 MemState postDeleters postDeps postLifetimes <- get
426426 put (MemState preDeleters postDeps postLifetimes) -- Restore managed variables, TODO: Use a "local" state monad instead?
427427 pure $ do
428428 okVisitedRhs <- visitedRhs
429429 pure ((postDeleters, (lhs, okVisitedRhs)), postDeps)
430- visitCaseLhs :: XObj -> State MemState (Either TypeError [() ])
431- visitCaseLhs (XObj (Lst vars) _ _) =
430+ visitCaseLhs :: MatchMode -> XObj -> State MemState (Either TypeError [() ])
431+ visitCaseLhs matchMode (XObj (Lst vars) _ _) =
432432 do
433- result <- mapM visitCaseLhs vars
433+ result <- mapM ( visitCaseLhs matchMode) vars
434434 let result' = sequence result
435435 pure (fmap concat result')
436- visitCaseLhs xobj@ (XObj (Sym (SymPath _ name) _) _ _)
437- | isVarName name = do
436+ visitCaseLhs matchMode xobj@ (XObj (Sym (SymPath _ name) _) _ _)
437+ | (matchMode == MatchValue ) && isVarName name = do
438438 manage typeEnv globalEnv xobj
439439 pure (Right [] )
440440 | otherwise = pure (Right [] )
441- visitCaseLhs (XObj Ref _ _) =
441+ visitCaseLhs _ (XObj Ref _ _) =
442442 pure (Right [] )
443- visitCaseLhs x =
443+ visitCaseLhs _ x =
444444 error (" Unhandled: " ++ show x)
445445 visitLetBinding :: (XObj , XObj ) -> State MemState (Either TypeError (XObj , XObj ))
446446 visitLetBinding (name, expr) =
0 commit comments