From f0d8ac7739066940f23076276a795166410f3809 Mon Sep 17 00:00:00 2001 From: Lucas Kramer Date: Tue, 20 Aug 2024 12:28:53 -0700 Subject: [PATCH] Addressing Ravi's comments --- src/Libraries/Base1/Prelude.bs | 11 ++++++++--- src/Libraries/Base1/SplitPorts.bs | 12 +++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Libraries/Base1/Prelude.bs b/src/Libraries/Base1/Prelude.bs index 349a60cd..0bae7959 100644 --- a/src/Libraries/Base1/Prelude.bs +++ b/src/Libraries/Base1/Prelude.bs @@ -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 = @@ -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 @@ -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 () @@ -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 @@ -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) {- diff --git a/src/Libraries/Base1/SplitPorts.bs b/src/Libraries/Base1/SplitPorts.bs index e09f8e6a..57aeafb8 100644 --- a/src/Libraries/Base1/SplitPorts.bs +++ b/src/Libraries/Base1/SplitPorts.bs @@ -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 @@ -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 @@ -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