-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring to use new ConenctTile implementation. Need to resolve po…
…tential existence of invalid states
- Loading branch information
1 parent
50ba7ee
commit 992b919
Showing
7 changed files
with
184 additions
and
45 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
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,8 +1,41 @@ | ||
module TIS100.Tiles.ConnectedTile where | ||
|
||
import TIS100.Tiles.Base (Port', Value) | ||
import TIS100.Tiles.Base qualified as Tiles | ||
|
||
class (Show t) => IsConnectedTile t where | ||
getRunState :: t -> Tiles.RunState | ||
setRunState :: t -> Tiles.RunState -> t | ||
|
||
readable :: t -> Port' -> Bool | ||
writable :: t -> Port' -> Bool | ||
|
||
isWaitingOnRead :: t -> Maybe Port' | ||
isWaitingOnWrite :: t -> Maybe Port' | ||
|
||
class ConnectedTile t where | ||
readValueFrom :: t -> Port' -> (t, Maybe Value) | ||
writeValueTo :: t -> Port' -> Value -> t | ||
step :: t -> t | ||
|
||
step :: t -> t | ||
|
||
data ConnectedTile | ||
= forall t. | ||
(IsConnectedTile t) => | ||
ConnectedTile t | ||
|
||
instance Show ConnectedTile where | ||
show (ConnectedTile t) = show t | ||
|
||
instance IsConnectedTile ConnectedTile where | ||
getRunState (ConnectedTile t) = getRunState t | ||
setRunState (ConnectedTile t) rs = ConnectedTile $ setRunState t rs | ||
|
||
readable (ConnectedTile t) p = readable t p | ||
writable (ConnectedTile t) p = writable t p | ||
|
||
isWaitingOnRead (ConnectedTile t) = isWaitingOnRead t | ||
isWaitingOnWrite (ConnectedTile t) = isWaitingOnWrite t | ||
|
||
readValueFrom (ConnectedTile t) p = (ConnectedTile t', v) where (t', v) = readValueFrom t p | ||
|
||
writeValueTo (ConnectedTile t) p v = ConnectedTile $ writeValueTo t p v |
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,11 +1,22 @@ | ||
module TIS100.Tiles.Inactive where | ||
|
||
import TIS100.Tiles.ConnectedTile (ConnectedTile (..)) | ||
import TIS100.Tiles.Base qualified as Tiles | ||
import TIS100.Tiles.ConnectedTile (ConnectedTile (..), IsConnectedTile (..)) | ||
|
||
data InactiveTile = InactiveTile | ||
deriving (Eq, Show) | ||
|
||
instance ConnectedTile InactiveTile where | ||
instance IsConnectedTile InactiveTile where | ||
getRunState _ = Tiles.Ready | ||
setRunState _ _ = InactiveTile | ||
|
||
readable _ _ = False | ||
writable _ _ = False | ||
|
||
isWaitingOnRead _ = Just Tiles.ANY | ||
isWaitingOnWrite _ = Just Tiles.ANY | ||
|
||
readValueFrom t _ = (t, Nothing) | ||
writeValueTo t _ _ = t | ||
|
||
step = id |
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,13 +1,24 @@ | ||
module TIS100.Tiles.T30 where | ||
|
||
import TIS100.Tiles.Base (Value (..)) | ||
import TIS100.Tiles.ConnectedTile (ConnectedTile (..)) | ||
import TIS100.Tiles.Base qualified as Tiles | ||
import TIS100.Tiles.ConnectedTile (ConnectedTile (..), IsConnectedTile (..)) | ||
|
||
newtype T30 = T30 [Value] | ||
newtype T30 = T30 [Tiles.Value] | ||
deriving (Eq, Show) | ||
|
||
instance ConnectedTile T30 where | ||
instance IsConnectedTile T30 where | ||
getRunState _ = Tiles.Ready | ||
setRunState t _ = t | ||
|
||
readable (T30 []) _ = False | ||
readable _ _ = True | ||
writable _ _ = True | ||
|
||
isWaitingOnRead _ = Just Tiles.ANY | ||
isWaitingOnWrite _ = Just Tiles.ANY | ||
|
||
readValueFrom (T30 []) _ = (T30 [], Nothing) | ||
readValueFrom (T30 (v : vs)) _ = (T30 vs, Just v) | ||
writeValueTo (T30 vs) _ v = T30 (vs ++ [v]) | ||
step = id | ||
|
||
step = id |