Skip to content

Commit

Permalink
More clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
geo2a committed Mar 25, 2019
1 parent 4451b14 commit 3c8dbed
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 60 deletions.
19 changes: 0 additions & 19 deletions src/Machine/Semantics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,25 +180,6 @@ add reg addr = \read write -> Just $
in write (F Zero) result *>
write (Reg reg) result


-- | Add a value from memory location to one in a register.
-- Applicative.
addV :: MachineValue v => Register -> MemoryAddress
-> SemanticsV Applicative MachineKey v ()
addV reg addr = \read write -> Just $
let void :: a -> ()
void _ = ()

-- write1 :: MachineValue v => MachineKey -> f v -> f ()
write1 k v = void <$> write k v

-- write2 :: MachineValue v => MachineKey -> MachineKey -> f v -> f ()
-- write2 k1 k2 v = write1 k1 (write k2 v)
write2 k1 k2 v = void <$> write k1 (write k2 v)

result = (+) <$> read (Reg reg) <*> read (Addr addr)
in write2 (F Zero) (Reg reg) result

-- | Add a value from memory location to one in a register. Tracks overflow.
-- Selective.
addS :: MachineValue a => Register -> MemoryAddress -> Semantics Selective MachineKey a ()
Expand Down
8 changes: 0 additions & 8 deletions src/Machine/Semantics/Dependencies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,3 @@ dependencies task =
task trackingRead trackingWrite
where trackingRead k = Const [Left k]
trackingWrite k fv = fv *> Const [Right k]

dependenciesV :: SemanticsV Applicative k v a
-> Maybe ([k], [k])
dependenciesV task =
partitionEithers . getConst <$>
task trackingRead trackingWrite
where trackingRead k = Const [Left k]
trackingWrite k fv = fv *> Const [Right k]
34 changes: 1 addition & 33 deletions src/Metalanguage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FlexibleInstances #-}

module Metalanguage (
Semantics, SemanticsV, SemanticsITE, FS
Semantics
) where

import Prelude hiding (Read, Monad)
Expand All @@ -27,35 +27,3 @@ import Machine.Types.Value
type Semantics c k v a = forall f. c f => (k -> f v) ->
(k -> f v -> f ()) ->
Maybe (f a)

type Read k f g = forall a. MachineValue (g a) => k a -> f (g a)

type Write k f g = forall a. MachineValue (g a) => k a -> f (g a) -> f (g a)

type FS c k a = forall f g. (c f, Functor g) => Read k f g -> Write k f g -> f (g a)

-- | A type class for keys, equipped with an associated type family that
-- can be used to determine the type of value corresponding to the key.
class Key k where
-- | The name of the key. Useful for avoiding heterogeneous lists of keys.
showKey :: k a -> String

-- -- | Calculate data dependencies of a semantic computation
-- -- The computation must have only static dependencies, hence the
-- -- 'Selective' constraint.
-- dependencies :: Key k => FS Selective k a -> ([String], [String])
-- dependencies task =
-- partitionEithers . getConst $
-- task trackingRead trackingWrite
-- where
-- trackingRead k = Const [Left (showKey k)]
-- trackingWrite k fv = fv *> Const [Right (showKey k)]

type SemanticsV c k v a = forall f. c f => (k -> f v) ->
(k -> f v -> f v) ->
Maybe (f a)

type SemanticsITE c k v a = forall f. c f => (k -> f v) ->
(k -> f v -> f ()) ->
(f v -> f () -> f () -> f ()) ->
Maybe (f a)

0 comments on commit 3c8dbed

Please sign in to comment.