From dfea90e16be8cdab9959bba543700b096a49aaa6 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 16 May 2018 10:11:03 -0400 Subject: [PATCH] Add a handler for Precise addresses. --- src/Control/Abstract/Addressable.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Control/Abstract/Addressable.hs b/src/Control/Abstract/Addressable.hs index 7d59b5b8a..d20032b5b 100644 --- a/src/Control/Abstract/Addressable.hs +++ b/src/Control/Abstract/Addressable.hs @@ -27,6 +27,12 @@ data Allocator location value return where Deref :: Address location value -> Allocator location value value +runAllocatorPrecise :: Members '[Fresh, Resumable (AddressError Precise value), State (Heap Precise Latest value)] effects => Evaluator Precise value (Allocator Precise value ': effects) a -> Evaluator Precise value effects a +runAllocatorPrecise = relay pure (\ eff yield -> case eff of + Alloc _ -> Address . Precise <$> fresh >>= yield + Deref addr -> lookupHeap addr >>= maybeM (throwAddressError (UnallocatedAddress addr)) >>= maybeM (throwAddressError (UninitializedAddress addr)) . getLast . unLatest >>= yield) + + -- | Defines 'alloc'ation and 'deref'erencing of 'Address'es in a Heap. class (Ord location, Show location) => Addressable location effects where derefCell :: Address location value -> Cell location value -> Evaluator location value effects (Maybe value)