-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In Storage we want key terms to be compared as if they had no tags. We achieve this by introucing a newtype for keys and stripping out the tags as part of the Hashable/Eq instance definitions
- Loading branch information
1 parent
d39cc4e
commit 6b29c46
Showing
5 changed files
with
33 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,37 @@ | ||
module Juvix.Compiler.Nockma.Evaluator.Storage where | ||
|
||
import Juvix.Compiler.Nockma.Language | ||
import Juvix.Compiler.Nockma.Pretty.Base | ||
import Juvix.Prelude.Base | ||
|
||
newtype Storage a = Storage | ||
{_storageKeyValueData :: HashMap (Term a) (Term a)} | ||
{_storageKeyValueData :: HashMap (StorageKey a) (Term a)} | ||
|
||
emptyStorage :: (Hashable a) => Storage a | ||
emptyStorage = Storage {_storageKeyValueData = mempty} | ||
newtype StorageKey a = StorageKey {_storageKeyTerm :: Term a} | ||
|
||
makeLenses ''Storage | ||
makeLenses ''StorageKey | ||
|
||
stripTags :: Term a -> Term a | ||
stripTags = \case | ||
TermAtom a -> TermAtom (set atomTag Nothing a) | ||
TermCell c -> | ||
TermCell | ||
( set cellTag Nothing | ||
. over cellLeft stripTags | ||
. over cellRight stripTags | ||
. over (cellCall . _Just . stdlibCallArgs) stripTags | ||
$ c | ||
) | ||
|
||
instance (Eq a) => Eq (StorageKey a) where | ||
s1 == s2 = stripTags (s1 ^. storageKeyTerm) == stripTags (s2 ^. storageKeyTerm) | ||
|
||
instance (Hashable a) => Hashable (StorageKey a) where | ||
hashWithSalt s k = hashWithSalt s (stripTags (k ^. storageKeyTerm)) | ||
|
||
instance (PrettyCode a, NockNatural a) => PrettyCode (StorageKey a) where | ||
ppCode k = ppCode (stripTags (k ^. storageKeyTerm)) | ||
|
||
emptyStorage :: (Hashable a) => Storage a | ||
emptyStorage = Storage {_storageKeyValueData = mempty} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters