Skip to content

Commit

Permalink
Addressing Ravi's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
krame505 committed Aug 20, 2024
1 parent 9d7921f commit f0d8ac7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/Libraries/Base1/Prelude.bs
Original file line number Diff line number Diff line change
Expand Up @@ -4450,7 +4450,6 @@ class (WrapField :: $ -> * -> * -> *) name f w | name f -> w where
-- Save the port types for a field in the wrapped interface, given the module name
-- and the prefix, arg_names and result pragmas.
saveFieldPortTypes :: StrArg name -> f -> Maybe Name__ -> String -> List String -> String -> Module ()
saveFieldPortTypes _ _ _ _ _ _ = return ()

instance (WrapMethod m w) => (WrapField name m w) where
toWrapField _ prefix names =
Expand All @@ -4466,14 +4465,17 @@ instance (WrapMethod m w) => (WrapField name m w) where
instance WrapField name PrimAction PrimAction where
toWrapField _ _ _ = id
fromWrapField _ = id
saveFieldPortTypes _ _ _ _ _ _ = return ()

instance WrapField name Clock Clock where
toWrapField _ _ _ = id
fromWrapField _ = id
saveFieldPortTypes _ _ _ _ _ _ = return ()

instance WrapField name Reset Reset where
toWrapField _ _ _ = id
fromWrapField _ = id
saveFieldPortTypes _ _ _ _ _ _ = return ()

instance (Bits a n) => WrapField name (Inout a) (Inout_ n) where
toWrapField _ _ _ = primInoutCast0
Expand All @@ -4489,11 +4491,9 @@ class WrapMethod m w | m -> w where

-- Compute the actual argument base names for a method, given the prefix and arg_names pragmas.
methodArgBaseNames :: m -> String -> List String -> Integer -> List String
methodArgBaseNames _ _ _ _ = Nil

-- Compute the list of input port names for a method, from the argument base names.
inputPortNames :: m -> List String -> List String
inputPortNames _ _ = Nil

-- Save the port types for a method, given the module name, argument base names and result name.
saveMethodPortTypes :: m -> Maybe Name__ -> List String -> String -> Module ()
Expand All @@ -4504,6 +4504,7 @@ instance (SplitPorts a p, TupleSize p n, WrapPorts p pb, WrapMethod b v, Curry (
fromWrapMethod f = fromWrapMethod ∘ uncurryN f ∘ packPorts ∘ splitPorts

methodArgBaseNames _ prefix (Cons h t) i = Cons
-- arg_names can start with a digit
(if prefix == "" && not (isDigit $ stringHead h) then h else prefix +++ "_" +++ h)
(methodArgBaseNames (_ :: b) prefix t $ i + 1)
methodArgBaseNames _ prefix Nil i = Cons
Expand All @@ -4521,11 +4522,15 @@ instance (SplitPorts a p, TupleSize p n, WrapPorts p pb, WrapMethod b v, Curry (
instance (Bits a n) => WrapMethod (ActionValue a) (ActionValue_ n) where
toWrapMethod = toActionValue_
fromWrapMethod = fromActionValue_
methodArgBaseNames _ _ _ _ = Nil
inputPortNames _ _ = Nil
saveMethodPortTypes _ modName _ result = primSavePortType modName result $ typeOf (_ :: a)

instance (Bits a n) => WrapMethod a (Bit n) where
toWrapMethod = pack
fromWrapMethod = unpack
methodArgBaseNames _ _ _ _ = Nil
inputPortNames _ _ = Nil
saveMethodPortTypes _ modName _ result = primSavePortType modName result $ typeOf (_ :: a)

{-
Expand Down
12 changes: 7 additions & 5 deletions src/Libraries/Base1/SplitPorts.bs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ instance (ShallowSplitPorts' r p) => ShallowSplitPorts' (Meta (MetaField name id
shallowSplitPorts' (Meta x) = shallowSplitPorts' x
shallowUnsplitPorts' = Meta ∘ shallowUnsplitPorts'
shallowSplitPortNames' _ base = shallowSplitPortNames' (_ :: r) $
-- Avoid an extra underscore, since data fields names are _[0-9]+
if stringHead (stringOf name) == '_'
then base +++ stringOf name
else base +++ "_" +++ stringOf name
Expand Down Expand Up @@ -106,25 +107,25 @@ instance DeepSplitPorts () () where

instance (DeepSplitTuplePorts (a, b) p) => DeepSplitPorts (a, b) p where
deepSplitPorts = deepSplitTuplePorts
deepUnsplitPorts = deepUndeepSplitTuplePorts
deepUnsplitPorts = deepUnsplitTuplePorts
deepSplitPortNames = deepSplitTuplePortNames 1

class DeepSplitTuplePorts a p | a -> p where
deepSplitTuplePorts :: a -> p
deepUndeepSplitTuplePorts :: p -> a
deepUnsplitTuplePorts :: p -> a
deepSplitTuplePortNames :: Integer -> a -> String -> List String

instance (DeepSplitPorts a p, DeepSplitTuplePorts b q, AppendTuple p q r) => DeepSplitTuplePorts (a, b) r where
deepSplitTuplePorts (a, b) = deepSplitPorts a `appendTuple` deepSplitTuplePorts b
deepUndeepSplitTuplePorts x = case splitTuple x of
(a, b) -> (deepUnsplitPorts a, deepUndeepSplitTuplePorts b)
deepUnsplitTuplePorts x = case splitTuple x of
(a, b) -> (deepUnsplitPorts a, deepUnsplitTuplePorts b)
deepSplitTuplePortNames i _ base =
deepSplitPortNames (_ :: a) (base +++ "_" +++ integerToString i) `List.append`
deepSplitTuplePortNames (i + 1) (_ :: b) base

instance (DeepSplitPorts a p) => DeepSplitTuplePorts a p where
deepSplitTuplePorts = deepSplitPorts
deepUndeepSplitTuplePorts x = deepUnsplitPorts x
deepUnsplitTuplePorts x = deepUnsplitPorts x
deepSplitTuplePortNames i _ base = deepSplitPortNames (_ :: a) $ base +++ "_" +++ integerToString i


Expand Down Expand Up @@ -178,6 +179,7 @@ instance (DeepSplitPorts'' r p) => DeepSplitPorts'' (Meta (MetaField name idx) r
deepSplitPorts'' (Meta x) = deepSplitPorts'' x
deepUnsplitPorts'' = Meta ∘ deepUnsplitPorts''
deepSplitPortNames'' _ base = deepSplitPortNames'' (_ :: r) $
-- Avoid an extra underscore, since data fields names are _[0-9]+
if stringHead (stringOf name) == '_'
then base +++ stringOf name
else base +++ "_" +++ stringOf name
Expand Down

0 comments on commit f0d8ac7

Please sign in to comment.