zuspec-dataclasses 0.0.1.17421055506rc0__py3-none-any.whl → 0.0.1.17516204125rc0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ from .tlm import *
9
9
  # from .core_lib import *
10
10
  # from vsc_dataclasses.expr import *
11
11
 
12
- from .bit import Bit
12
+ from .bit import Bit, uint64_t
13
13
  from .component import Component
14
14
  from .struct import Struct
15
15
  from .ports import Input, Output, Port
@@ -1,4 +1,4 @@
1
1
 
2
2
  BASE="0.0.1"
3
- SUFFIX=".17421055506rc0"
3
+ SUFFIX=".17516204125rc0"
4
4
  VERSION="%s%s" % (BASE, SUFFIX)
@@ -1,61 +1,72 @@
1
1
  import abc
2
2
  import zuspec.dataclasses as zdc
3
3
  from typing import Annotated, TypeVar, Type, Union
4
+ from .bit import BitVal
5
+ from .decorators import dataclass, constraint
4
6
  from .struct import StructPacked
5
7
 
8
+ class AddrHandle(): pass
9
+
6
10
  class AddrTrait(zdc.Struct): pass
7
11
 
8
12
 
9
13
  class AddrSpaceBase:
10
14
  pass
11
15
 
12
- uint64_t = Annotated[int, "abc"]
16
+ # uint64_t = Annotated[int, "abc"]
13
17
 
14
18
  AddrTraitT = TypeVar('AddrTraitT', bound=AddrTrait)
15
19
 
20
+ @dataclass
16
21
  class AddrRegion[AddrTraitT]():
17
- trait : Type[AddrTraitT] = zdc.trait()
18
- pass
19
-
20
- class MyTrait(AddrTrait):
21
- a : int = 5
22
+ trait : Type[AddrTraitT] = zdc.field()
22
23
 
24
+ @dataclass
23
25
  class TransparentAddrSpace[AddrTraitT](AddrSpaceBase):
24
26
 
25
- def add_region(self, region : AddrRegion[AddrTraitT]): pass
26
-
27
- pass
28
-
29
- class MyAddrTrait(AddrTrait):
30
- pass
31
-
32
- class Other(object):
33
- pass
27
+ @abc.abstractmethod
28
+ def add_region(self, region : AddrRegion[AddrTraitT]) -> AddrHandle:
29
+ """Adds a region to the address space, returning a handle to that region"""
30
+ pass
34
31
 
35
- t : TransparentAddrSpace = TransparentAddrSpace()
36
- o = Other()
32
+ @dataclass
33
+ class AddrClaim[AddrTraitT]():
34
+ trait : AddrTraitT = zdc.field(rand=True)
35
+ size : int = zdc.field(rand=True)
37
36
 
38
- r = AddrRegion[MyTrait]()
39
- r2 = AddrRegion[Other]()
37
+ @constraint
38
+ def size_align_c(self):
39
+ self.size > 0
40
40
 
41
- t.add_region(r2)
42
41
 
43
- r.trait.a
42
+ @abc.abstractmethod
43
+ def handle(self, offset : int = 0) -> AddrHandle:
44
+ """Returns a handle corresponding to the claim"""
45
+ pass
44
46
 
45
- RegT = TypeVar("RegT", bound=Union[int,StructPacked])
47
+ RegT = TypeVar("RegT", bound=Union[BitVal,StructPacked])
46
48
 
47
49
  class Reg[RegT](object):
48
50
 
49
51
  @abc.abstractmethod
50
- def read(self) -> Type[RegT]: pass
52
+ async def read(self) -> Type[RegT]:
53
+ """Reads the value of the register"""
54
+ pass
51
55
 
52
56
  @abc.abstractmethod
53
- def write(self, data : Type[RegT]): pass
57
+ async def write(self, data : Type[RegT]):
58
+ """Writes the value of the register"""
59
+ pass
54
60
 
55
61
  class RegGroup(object):
56
62
  @abc.abstractmethod
57
- def get_handle(self): pass
63
+ def get_handle(self) -> AddrHandle:
64
+ """Gets the address handle that corresponds to this group"""
65
+ pass
58
66
 
59
67
  @abc.abstractmethod
60
- def set_handle(self, h): pass
68
+ def set_handle(self, h):
69
+ """Sets the address handle corresponding to this root group"""
70
+ pass
71
+
61
72
 
zuspec/dataclasses/bit.py CHANGED
@@ -1,5 +1,5 @@
1
1
  import dataclasses as dc
2
- from typing import Dict
2
+ from typing import Dict, Generic, TypeVar, Literal, Type
3
3
 
4
4
  class BitMeta(type):
5
5
 
@@ -20,7 +20,55 @@ class BitMeta(type):
20
20
  self.type_m[W] = t
21
21
  return t
22
22
 
23
+ T = TypeVar('T')
23
24
 
24
- class Bit(metaclass=BitMeta):
25
- T : int = 1
26
- pass
25
+ class Bit[T]: pass
26
+
27
+ class Int[T]: pass
28
+
29
+ # T : int = 1
30
+
31
+ # def __class_getitem__(cls, W : int) -> 'Bit[T]':
32
+ # return "abc"
33
+ # return cls
34
+ # pass
35
+ # pass
36
+
37
+
38
+ #W = TypeVar('W')
39
+
40
+ #def bit_t(W : int) -> _GenericA[Bit[T]]:
41
+ # return Bit[Literal[W]]
42
+
43
+ #def int_t(W : int) -> Int:
44
+ # return Int[Literal[W]]
45
+
46
+ class Bits():
47
+ pass
48
+
49
+ class IntVal():
50
+ pass
51
+
52
+ class BitVal(int):
53
+ def __new__(cls, v : int, w : int):
54
+ ret = super().__new__(cls, v)
55
+ setattr(ret, "W", w)
56
+ return ret
57
+ def __getitem__(self, v):
58
+ return 5
59
+
60
+ def __add__(self, rhs):
61
+ pass
62
+
63
+ v = BitVal(5, 16)
64
+ v += 5
65
+
66
+ def bv(v : int, w : int=1) -> BitVal:
67
+ return BitVal(v, w)
68
+
69
+ a = bv(5,32)
70
+
71
+ def iv(): pass
72
+
73
+ uint64_t = Bit[Literal[64]]
74
+ #int64_t = Int[Literal[64]]
@@ -9,6 +9,11 @@ class Component(Struct):
9
9
  - The root component and fields of component type are constructed
10
10
  - The 'init_down' method is invoked in a depth-first manner
11
11
  - The 'init_up' method is invoked
12
+
13
+ A Component class supports the following decorated methods:
14
+ - sync
15
+ - constraint
16
+ - activity
12
17
  """
13
18
 
14
19
  def build(self): pass
@@ -5,7 +5,7 @@ Created on Mar 19, 2022
5
5
  '''
6
6
  import dataclasses
7
7
  import dataclasses as dc
8
- from typing import Any, Callable, Dict, Self, TypeVar
8
+ from typing import Any, Callable, Dict, Self, TypeVar, Generic, Type
9
9
  # from vsc_dataclasses.decorators import *
10
10
  # from .impl.action_decorator_impl import ActionDecoratorImpl
11
11
  # from .impl.exec_decorator_impl import ExecDecoratorImpl
@@ -23,6 +23,8 @@ from typing import Any, Callable, Dict, Self, TypeVar
23
23
  from .annotation import Annotation, AnnotationSync
24
24
  from .ports import Input, Output
25
25
  from .clock import Clock
26
+ from .component import Component
27
+ from .timebase import TimeBase
26
28
 
27
29
  def dataclass(cls, **kwargs):
28
30
  return dc.dataclass(cls, **kwargs)
@@ -94,8 +96,9 @@ def always(instr : BitLiteral):
94
96
  a = bit(20)[3:4]
95
97
 
96
98
  SelfT = TypeVar('SelfT')
99
+ T = TypeVar('T')
97
100
 
98
- class bind[T](object):
101
+ class bind(Generic[T]):
99
102
  def __init__(self, c : Callable[[T],Dict[Any,Any]]):
100
103
  self._c = c
101
104
  def __call__(self, s) -> Dict[Any,Any]:
@@ -103,7 +106,13 @@ class bind[T](object):
103
106
 
104
107
  #a = bind2(lambda s:{s.}, selfT=Self)
105
108
 
106
- def field(rand=False, bind : Callable[[object],Dict[Any,Any]] = None):
109
+ from typing import Optional
110
+
111
+ def field(
112
+ rand=False,
113
+ width=-1,
114
+ bind : Optional[Callable[[object],Dict[Any,Any]]] = None,
115
+ **kwargs):
107
116
  pass
108
117
 
109
118
  # @staticmethod
@@ -146,16 +155,39 @@ def reg(offset=0):
146
155
  def const(**kwargs):
147
156
  return dc.field()
148
157
 
149
- def sync(*args, clock=None, reset=None):
150
- # TODO: handle two forms
151
- if len(args) == 0:
152
- def __call__(T):
153
- Annotation.apply(T, AnnotationSync(clock=clock, reset=reset))
154
- return T
155
- return __call__
156
- else:
157
- Annotation.apply(args[0], AnnotationSync(clock=clock, reset=reset))
158
- return args[0]
158
+ SyncHostT = TypeVar('SyncHostT', bound=Component)
159
+ SyncMethodT = TypeVar('SyncMethodT', bound=Callable[[SyncHostT],Any])
160
+
161
+ @dc.dataclass
162
+ class Sync(object):
163
+ method : Callable[[Component],Any] = dc.field()
164
+ timebase : TimeBase = dc.field()
165
+
166
+ ComponentT = TypeVar('ComponentT', bound=Component)
167
+
168
+ def sync(t : Callable[[ComponentT],Any]) -> Sync:
169
+ """
170
+ Sync marks a method that has a dependency on a timebase.
171
+ The method is automatically evaluated by the timebase at
172
+ each timestep (eg clock period) of the timebase. The
173
+ timebase will automatically assign the reset value
174
+ to variables assigned within the decorated method when
175
+ the timebase is reset.
176
+ A sync-decorated method may not be directly called.
177
+ """
178
+ # # TODO: handle two forms
179
+ # if len(args) == 0:
180
+ # def __call__(T):
181
+ # Annotation.apply(T, AnnotationSync(clock=clock, reset=reset))
182
+ # return T
183
+ # return __call__
184
+ # else:
185
+ # Annotation.apply(args[0], AnnotationSync(clock=clock, reset=reset))
186
+ # return args[0]
187
+ ret = Sync(t)
188
+ return ret
189
+ # return Sync(t)
190
+
159
191
 
160
192
  # def action(*args, **kwargs):
161
193
  # if len(args) == 1 and len(kwargs) == 0 and callable(args[0]):
zuspec/dataclasses/tlm.py CHANGED
@@ -10,3 +10,9 @@ class IPut[T]():
10
10
  class IGet[T]():
11
11
  get : Callable[[], Awaitable[T]] = dc.field()
12
12
 
13
+ @dc.dataclass
14
+ class IReqRsp[ReqT,RspT]():
15
+ put : Callable[[Type[ReqT]], Awaitable] = dc.field()
16
+ get : Callable[[], Awaitable[RspT]] = dc.field()
17
+
18
+
@@ -1,5 +1,5 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zuspec-dataclasses
3
- Version: 0.0.1.17421055506rc0
3
+ Version: 0.0.1.17516204125rc0
4
4
  License-File: LICENSE
5
5
  Dynamic: license-file
@@ -1,28 +1,28 @@
1
- zuspec/dataclasses/__init__.py,sha256=N7A7kcH2MWv11kqVA-s0SyKnWBAKD6ijQXJOrzfRyf8,452
2
- zuspec/dataclasses/__version__.py,sha256=w206wPrAQOLdhYE50Ud54WEWjFUOPqdoT2NoUpjn64o,71
1
+ zuspec/dataclasses/__init__.py,sha256=-a466Myi0Gs7JWbIm2LiNKkHFuIjoGsjj5aMrAyQuBs,462
2
+ zuspec/dataclasses/__version__.py,sha256=2pHn0_iz8uobg16bUlzrP3GDosLHvXeTtklooC9fUFo,71
3
3
  zuspec/dataclasses/action.py,sha256=z7aMc6e_k_-NCzYDm8K1ymEPfcGeyqlO79of0Gucack,570
4
- zuspec/dataclasses/addr_reg.py,sha256=QmxPQ8lq1255ZfOjQRGFGWGGwK-pSpPFJ4mdzJlj8dw,1111
4
+ zuspec/dataclasses/addr_reg.py,sha256=14dgTvdkyHxzGLOJRqMkAFwKhnRM2iI3B6IdzioJQl8,1728
5
5
  zuspec/dataclasses/annotation.py,sha256=M41iS93Oi8M-ER_ZIBI8CIWJ1bvEMI0nHa-RxbmWJUs,328
6
- zuspec/dataclasses/bit.py,sha256=Zxm3F04GcfuJczmwCrMuvpcBCunWMZQFffB4JvNterI,614
6
+ zuspec/dataclasses/bit.py,sha256=PHGjvh-O4k7m-juXQzEMZJIn5k-h1cJaIHmgk0RhofM,1405
7
7
  zuspec/dataclasses/bundle.py,sha256=6fqjfoTS_-_izl4FlPFgurfOg3tnj_1fmEdSa1FF4C0,781
8
8
  zuspec/dataclasses/clock.py,sha256=pM0rO-3bp0SGJccxtU-17vIcF9EaSlqD-q1_9O0of1o,30
9
- zuspec/dataclasses/component.py,sha256=vzPCmLdAgm-x46Or18RtBYRClVUkbqIZ1yqp1nu5sL4,416
10
- zuspec/dataclasses/decorators.py,sha256=fSJpsTbahzQdtFtlVhDFSHFFuYmiRxg_3S_W1DpjLDY,9797
9
+ zuspec/dataclasses/component.py,sha256=oERqTHRdiI2oYW5q8ijYNY9FUMIrqLlqAVfZFipjzPU,524
10
+ zuspec/dataclasses/decorators.py,sha256=v6toBLONKbw5dj7DRoH9XEOSNghBNjuRWjc1C66LEHc,10762
11
11
  zuspec/dataclasses/dependency.py,sha256=kGxdFqKlviUP7qmvN-FbnXIiqCPdgRRel83feuu8OoU,532
12
12
  zuspec/dataclasses/ports.py,sha256=3pbBwdBzDMAJTZ15Qf6sSXB-XOH5cJ-G5H8kQa5JurQ,1106
13
13
  zuspec/dataclasses/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
14
14
  zuspec/dataclasses/reset.py,sha256=DV8tiKq_k-AGUNBbpJCJFx_EEfA07UgUJK2veYli0b0,30
15
15
  zuspec/dataclasses/struct.py,sha256=vId0487ZJmhnTbTg421B-iN9PtxNexCv9DMqRO8RXBU,973
16
16
  zuspec/dataclasses/timebase.py,sha256=rjEiGB2lNPMTewE-Z4iX-CHnbx1QVTUbtwEXnKMkesI,599
17
- zuspec/dataclasses/tlm.py,sha256=TjODFwvombQR7AVVI7HlW37MEm22Zu9JdVYpOCU4_Vg,277
17
+ zuspec/dataclasses/tlm.py,sha256=sbAlnkYhVidinbiMKBT_mbe5yr1dDU9F_6aKBAXZjjE,431
18
18
  zuspec/dataclasses/api/__init__.py,sha256=HfJhJ_B1RJSpJn5NmWzEK3l2IruubiEKd3xwLDuED6Q,30
19
19
  zuspec/dataclasses/api/visitor.py,sha256=8-5er0GxAWnvxhDmiR_OBn2iMxtymtol5qM09ucKdLI,1780
20
20
  zuspec/dataclasses/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  zuspec/dataclasses/util/extract_cpp_embedded_dsl.py,sha256=SyMMLumZD6fsubj40hyekYzWyrcoUGTijJH3NmK1ihY,5630
22
22
  zuspec/dataclasses/util/gen_cpp_dt_defs/__main__.py,sha256=t3CnHJKcN_N33sxCsDH-R36ghCcQ7xjMcjUrzUT2SGM,3447
23
23
  zuspec/impl/__init__.py,sha256=GZWCeBPdVzLR0RNPkmXNXPgdS-2vg5dMC1goTYJs3yI,33
24
- zuspec_dataclasses-0.0.1.17421055506rc0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
- zuspec_dataclasses-0.0.1.17421055506rc0.dist-info/METADATA,sha256=EZDxpqEdg2prfw4jvirp2j5sMETTp0ICrvue99A-Q44,121
26
- zuspec_dataclasses-0.0.1.17421055506rc0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- zuspec_dataclasses-0.0.1.17421055506rc0.dist-info/top_level.txt,sha256=3WM_V5g1RvpI4_z1TPY_AmroKhWIp6QJo4Vz5Tqbgak,7
28
- zuspec_dataclasses-0.0.1.17421055506rc0.dist-info/RECORD,,
24
+ zuspec_dataclasses-0.0.1.17516204125rc0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
+ zuspec_dataclasses-0.0.1.17516204125rc0.dist-info/METADATA,sha256=i1hPXCIb3njC6aXg7B4-7PEyGQFnISQB-cg4W36qFtY,121
26
+ zuspec_dataclasses-0.0.1.17516204125rc0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
+ zuspec_dataclasses-0.0.1.17516204125rc0.dist-info/top_level.txt,sha256=3WM_V5g1RvpI4_z1TPY_AmroKhWIp6QJo4Vz5Tqbgak,7
28
+ zuspec_dataclasses-0.0.1.17516204125rc0.dist-info/RECORD,,