@@ -337,7 +337,7 @@ manageMemory typeEnv globalEnv root =
337
337
-- 2. Variables deleted in at least one case has to be deleted in all, so make a union U of all such vars
338
338
-- but remove the ones that were not present before the 'match'
339
339
-- 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 ->
341
341
do
342
342
visitedExpr <- visit expr
343
343
case visitedExpr of
@@ -346,7 +346,7 @@ manageMemory typeEnv globalEnv root =
346
346
do
347
347
_ <- unmanage typeEnv globalEnv okVisitedExpr
348
348
MemState preDeleters deps lifetimes <- get
349
- vistedCasesAndDeps <- mapM visitMatchCase (pairwise cases)
349
+ vistedCasesAndDeps <- mapM ( visitMatchCase matchMode) (pairwise cases)
350
350
case sequence vistedCasesAndDeps of
351
351
Left e -> pure (Left e)
352
352
Right okCasesAndDeps ->
@@ -415,32 +415,32 @@ manageMemory typeEnv globalEnv root =
415
415
Right (XObj (Lst (okF : okArgs)) i t)
416
416
[] -> pure (Right xobj)
417
417
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 {}) =
420
420
do
421
421
MemState preDeleters _ _ <- get
422
- _ <- visitCaseLhs lhs
422
+ _ <- visitCaseLhs matchMode lhs
423
423
visitedRhs <- visit rhs
424
424
_ <- unmanage typeEnv globalEnv rhs
425
425
MemState postDeleters postDeps postLifetimes <- get
426
426
put (MemState preDeleters postDeps postLifetimes) -- Restore managed variables, TODO: Use a "local" state monad instead?
427
427
pure $ do
428
428
okVisitedRhs <- visitedRhs
429
429
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) _ _) =
432
432
do
433
- result <- mapM visitCaseLhs vars
433
+ result <- mapM ( visitCaseLhs matchMode) vars
434
434
let result' = sequence result
435
435
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
438
438
manage typeEnv globalEnv xobj
439
439
pure (Right [] )
440
440
| otherwise = pure (Right [] )
441
- visitCaseLhs (XObj Ref _ _) =
441
+ visitCaseLhs _ (XObj Ref _ _) =
442
442
pure (Right [] )
443
- visitCaseLhs x =
443
+ visitCaseLhs _ x =
444
444
error (" Unhandled: " ++ show x)
445
445
visitLetBinding :: (XObj , XObj ) -> State MemState (Either TypeError (XObj , XObj ))
446
446
visitLetBinding (name, expr) =
0 commit comments