-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
409b915
commit 903f065
Showing
31 changed files
with
603 additions
and
239 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{-# Language GeneralizedNewtypeDeriving #-} | ||
module HelVM.HelCam.Common.RAM.IntMapRAM ( | ||
HelVM.HelCam.Common.RAM.IntMapRAM.RAM, | ||
HelVM.HelCam.Common.RAM.IntMapRAM.empty, | ||
HelVM.HelCam.Common.RAM.IntMapRAM.fromList, | ||
load, | ||
store | ||
) where | ||
|
||
import HelVM.HelCam.Common.Util | ||
|
||
import Data.Default | ||
import Data.IntMap as IntMap | ||
|
||
newtype RAM s = MakeRAM (IntMap s) deriving (Foldable) | ||
type DRAM s = D (RAM s) | ||
|
||
-- Constructors | ||
empty :: Default s => RAM s | ||
empty = MakeRAM IntMap.empty | ||
|
||
fromList :: Default s => [s] -> RAM s | ||
fromList list = MakeRAM $ IntMap.fromList $ zip [0..] list | ||
|
||
-- Mutators | ||
load :: (Integral a, Default s) => RAM s -> a -> s | ||
load (MakeRAM m) address = index' m (fromIntegral address) ?: def | ||
|
||
store :: (Integral a, Default s) => a -> s -> DRAM s | ||
store address symbol (MakeRAM m) = MakeRAM $ insert' (fromIntegral address) symbol m | ||
|
||
-- Private | ||
index' :: IntMap s -> Int -> Maybe s | ||
index' = (!?) | ||
|
||
insert' :: Int -> s -> IntMap s -> IntMap s | ||
insert' = insert |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{-# Language GeneralizedNewtypeDeriving #-} | ||
module HelVM.HelCam.Common.RAM.ListRAM ( | ||
RAM, | ||
empty, | ||
fromList, | ||
load, | ||
store | ||
) where | ||
|
||
import HelVM.HelCam.Common.Util | ||
|
||
import Data.Default | ||
|
||
import Prelude hiding (empty, fromList) | ||
|
||
newtype RAM s = MakeRAM [s] deriving (Foldable) | ||
type DRAM s = D (RAM s) | ||
|
||
-- Constructors | ||
empty :: Default s => RAM s | ||
empty = MakeRAM [] | ||
|
||
fromList :: Default s => [s] -> RAM s | ||
fromList = MakeRAM | ||
|
||
-- Mutators | ||
load :: (Integral a, Default s) => RAM s -> a -> s | ||
load (MakeRAM m) address = index' m (fromIntegral address) ?: def | ||
|
||
store :: (Integral a, Default s) => a -> s -> DRAM s | ||
store address symbol (MakeRAM m) = MakeRAM $ insert' (fromIntegral address) symbol m | ||
|
||
-- Private | ||
index' :: [s] -> Int -> Maybe s | ||
index' = (!!?) | ||
|
||
insert' :: Default s => Int -> s -> [s] -> [s] | ||
insert' 0 symbol [] = [symbol] | ||
insert' 0 symbol (_:xs) = symbol : xs | ||
insert' address symbol [] = def : insert' (address-1) symbol [] | ||
insert' address symbol (x:xs) = x : insert' (address-1) symbol xs |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{-# Language GeneralizedNewtypeDeriving #-} | ||
module HelVM.HelCam.Common.RAM.SeqRAM ( | ||
RAM, | ||
HelVM.HelCam.Common.RAM.SeqRAM.empty, | ||
HelVM.HelCam.Common.RAM.SeqRAM.fromList, | ||
load, | ||
store | ||
) where | ||
|
||
import HelVM.HelCam.Common.Util | ||
|
||
import Data.Default | ||
import Data.Sequence as Seq | ||
|
||
newtype RAM s = MakeRAM (Seq s) deriving (Foldable) | ||
type DRAM s = D (RAM s) | ||
|
||
-- Constructors | ||
empty :: Default s => RAM s | ||
empty = MakeRAM Seq.empty | ||
|
||
fromList :: Default s => [s] -> RAM s | ||
fromList = MakeRAM . Seq.fromList | ||
|
||
-- Mutators | ||
load :: (Integral a, Default s) => RAM s -> a -> s | ||
load (MakeRAM m) address = index' m (fromIntegral address) ?: def | ||
|
||
store :: (Integral a, Default s) => a -> s -> DRAM s | ||
store address symbol (MakeRAM m) = MakeRAM $ insert' (fromIntegral address) symbol m | ||
|
||
-- Private | ||
index' :: Seq s -> Int -> Maybe s | ||
index' = (!?) | ||
|
||
insert' :: Default s => Int -> s -> Seq s -> Seq s | ||
insert' address symbol m = insert'' (Seq.length m) where | ||
insert'' l | ||
| address < l = Seq.update address symbol m | ||
| otherwise = m <> Seq.replicate (address - l) def |> symbol |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.