Skip to content

Commit 7afa5b5

Browse files
authored
Version 3.1.0: Various changes and improvements (#44)
This PR introduces a number of changes and improvements to the library from real-world use: * Packtype grammar (i.e. `.pt` files) updates: * New `variants` keyword, which can be used for feature-flagging or allowing different activities to lag the bleeding edge; * New 'normative points' syntax, which can be used for declaring key items in an architectural specification that can then be used as anchors in prose, models, or coverage; * PackedAssembly gains a recursive tree printer, which can display complex structures allowing for easier reading of constituent fields; * PackedArray now extends from `Numeric` which allows it to be used in comparisons, it also gains a `__str__` method to allow it to be printed with ease; * Minor optimisations to `BitVector` which yield a small performance improvement; * Extensions to a range of utility methods to better handle core types, add support for copying instances, diffing two types, and more; * Moves the minimum Python version forward to 3.12 - this allows for a number of useful type hinting behaviours.
1 parent 3e108e6 commit 7afa5b5

49 files changed

Lines changed: 2103 additions & 406 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ jobs:
2525
timeout-minutes: 15
2626
steps :
2727
- uses: actions/checkout@v4
28-
- name: Set up Python 3.11
28+
- name: Set up Python 3.13
2929
uses: actions/setup-python@v5
3030
with:
31-
python-version: 3.11
31+
python-version: 3.13
3232
- name : Install Poetry and environment
3333
shell: bash
3434
run : |

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
timeout-minutes: 15
1414
steps :
1515
- uses: actions/checkout@v4
16-
- name: Set up Python 3.11
16+
- name: Set up Python 3.13
1717
uses: actions/setup-python@v5
1818
with:
19-
python-version: 3.11
19+
python-version: 3.13
2020
- name : Install Poetry and environment
2121
shell: bash
2222
run : |

.github/workflows/pr_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
python-version: ["3.11", "3.12", "3.13"]
15+
python-version: ["3.12", "3.13"]
1616

1717
steps:
1818
- uses: actions/checkout@v2

docs/syntax/constant.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ custom grammar:
1414
from packtype import Constant
1515

1616
@packtype.package()
17-
class MyPackage:
17+
class ThePackage:
1818
VALUE_A : Constant = 123
1919
VALUE_B : Constant[16] = 234
2020
```
2121

2222
=== "Packtype (.pt)"
2323

2424
```sv linenums="1"
25-
package my_package {
25+
package the_package {
2626
VALUE_A : constant = 123
2727
"Comments may be attached to values with a string following the definition"
2828
VALUE_B : constant[16] = 234
@@ -38,12 +38,12 @@ custom grammar:
3838
As rendered to SystemVerilog:
3939

4040
```sv linenums="1"
41-
package my_package;
41+
package the_package;
4242
4343
localparam VALUE_A = 123;
4444
localparam bit [15:0] VALUE_B = 234;
4545
46-
endpackage : my_package
46+
endpackage : the_package
4747
```
4848

4949
## Syntax
@@ -58,15 +58,15 @@ allocate it.
5858

5959
```python linenums="1"
6060
@packtype.package()
61-
class MyPackage:
61+
class ThePackage:
6262
# Format: <NAME> : Constant = <VALUE>
6363
MY_CONSTANT : Constant = 123
6464
```
6565

6666
=== "Packtype (.pt)"
6767

6868
```sv linenums="1"
69-
package my_package {
69+
package the_package {
7070
// Format: <NAME> : constant = <VALUE>
7171
MY_CONSTANT : constant = 123
7272
}
@@ -79,7 +79,7 @@ from the declaration:
7979

8080
```python linenums="1"
8181
@packtype.package()
82-
class MyPackage:
82+
class ThePackage:
8383
# Format: <NAME> = <VALUE>
8484
MY_CONSTANT = 123
8585
```
@@ -99,15 +99,15 @@ number of bits.
9999

100100
```python linenums="1"
101101
@packtype.package()
102-
class MyPackage:
102+
class ThePackage:
103103
# Format: <NAME> : Constant[<WIDTH>] = <VALUE>
104104
MY_CONSTANT : Constant[8] = 123
105105
```
106106

107107
=== "Packtype (.pt)"
108108

109109
```sv linenums="1"
110-
package my_package {
110+
package the_package {
111111
// Format: <NAME> : constant[<WIDTH>] = <VALUE>
112112
MY_CONSTANT : constant[8] = 123
113113
}
@@ -122,7 +122,7 @@ from other constant definitions within the package.
122122

123123
```python linenums="1"
124124
@packtype.package()
125-
class MyPackage:
125+
class ThePackage:
126126
DOUBLE_WIDTH : Constant = 32
127127
VALUE_A : Constant = 9
128128
VALUE_B : Constant = 3
@@ -132,7 +132,7 @@ from other constant definitions within the package.
132132
=== "Packtype (.pt)"
133133

134134
```sv linenums="1"
135-
package my_package {
135+
package the_package {
136136
DOUBLE_WIDTH : constant = 32
137137
VALUE_A : constant = 9
138138
VALUE_B : constant = 3
@@ -154,15 +154,15 @@ that is outside the legal range a `ValueError` will be raised:
154154

155155
```python linenums="1"
156156
@packtype.package()
157-
class MyPackage:
157+
class ThePackage:
158158
# Attempt to store 123 in a 4 bit value
159159
MY_CONSTANT : Constant[4] = 123
160160
```
161161

162162
=== "Packtype (.pt)"
163163

164164
```sv linenums="1"
165-
package my_package {
165+
package the_package {
166166
// Attempt to store 123 in a 4 bit value
167167
MY_CONSTANT : constant[4] = 123
168168
}

docs/syntax/docstrings.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ Descriptions can be added with normal [Python docstrings]((https://peps.python.o
1313
from packtype import Constant
1414

1515
@packtype.package()
16-
class MyPackage:
16+
class ThePackage:
1717
"""
1818
Package decription,
1919
using normal Python docstrings
2020
"""
2121
...
2222

23-
@MyPackage.enum()
23+
@ThePackage.enum()
2424
class Fruit:
2525
"""
2626
Class description,
@@ -35,7 +35,7 @@ Descriptions can be added with normal [Python docstrings]((https://peps.python.o
3535
=== "Packtype (.pt)"
3636

3737
```sv linenums="1"
38-
package my_package {
38+
package the_package {
3939
"""
4040
Package description
4141
using multiline docstring syntax

docs/syntax/enum.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ custom grammar:
1515
from packtype import Constant
1616

1717
@packtype.package()
18-
class MyPackage:
18+
class ThePackage:
1919
...
2020

21-
@MyPackage.enum()
21+
@ThePackage.enum()
2222
class Fruit:
2323
"""Description of the enumeration can go here"""
2424
APPLE : Constant
@@ -30,7 +30,7 @@ custom grammar:
3030
=== "Packtype (.pt)"
3131

3232
```sv linenums="1"
33-
package my_package {
33+
package the_package {
3434
enum fruit_t {
3535
"Description of the enumeration can go here"
3636
@prefix=FRUIT
@@ -45,7 +45,7 @@ custom grammar:
4545
As rendered to SystemVerilog:
4646

4747
```sv linenums="1"
48-
package my_package;
48+
package the_package;
4949
5050
typedef enum logic [1:0] {
5151
FRUIT_APPLE,
@@ -54,7 +54,7 @@ typedef enum logic [1:0] {
5454
FRUIT_BANANA
5555
} fruit_t;
5656
57-
endpackage : my_package
57+
endpackage : the_package
5858
```
5959

6060

@@ -151,7 +151,7 @@ values and continue to enumerate from that point:
151151
import packtype
152152
from packtype import Constant
153153

154-
@MyPackage.enum(width=8)
154+
@ThePackage.enum(width=8)
155155
class Opcodes:
156156
ALU_ADD : Constant = 0x10
157157
ALU_SUB : Constant # Infers 0x11
@@ -167,7 +167,7 @@ values and continue to enumerate from that point:
167167
=== "Packtype (.pt)"
168168

169169
```sv linenums="1"
170-
package my_package {
170+
package the_package {
171171
enum [8] opcodes_t {
172172
ALU_ADD : constant = 0x10
173173
ALU_SUB : constant // Infers 0x11

docs/syntax/instance.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@ custom grammar:
1313
from packtype import Constant, Scalar
1414

1515
@packtype.package()
16-
class MyPackage:
16+
class ThePackage:
1717
pass
1818

19-
@MyPackage.enum()
19+
@ThePackage.enum()
2020
class Month:
2121
JAN : Constant
2222
FEB : Constant
2323
...
2424
DEC : Constant
2525

26-
@MyPackage.struct()
26+
@ThePackage.struct()
2727
class Date:
2828
year : Scalar[12]
2929
month : Month
3030
day : Scalar[5]
3131

32-
MyPackage._pt_attach_instance("SUMMER_START", Month.JUN)
33-
MyPackage._pt_attach_instance("SUMMER_END", Month.AUG)
34-
MyPackage._pt_attach_instance("CHRISTMAS", Date(year=2025, month=Month.DEC, day=25))
32+
ThePackage._pt_attach_instance("SUMMER_START", Month.JUN)
33+
ThePackage._pt_attach_instance("SUMMER_END", Month.AUG)
34+
ThePackage._pt_attach_instance("CHRISTMAS", Date(year=2025, month=Month.DEC, day=25))
3535
```
3636

3737
=== "Packtype (.pt)"
3838

3939
```sv linenums="1"
40-
package my_package {
40+
package the_package {
4141
enum month_e {
4242
JAN : constant
4343
FEB : constant
@@ -64,7 +64,7 @@ custom grammar:
6464
As rendered to SystemVerilog:
6565

6666
```sv linenums="1"
67-
package my_package;
67+
package the_package;
6868
6969
localparam month_e SUMMER_START = month_e'(7);
7070
@@ -77,5 +77,5 @@ localparam date_t CHRISTMAS = '{
7777
, year: 12'h7E9
7878
};
7979
80-
endpackage : my_package
80+
endpackage : the_package
8181
```

docs/syntax/package.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ custom grammar:
1313
import packtype
1414

1515
@packtype.package()
16-
class MyPackage:
16+
class ThePackage:
1717
"""Description of what purpose this package serves"""
1818
...
1919
```
2020

2121
=== "Packtype (.pt)"
2222

2323
```sv linenums="1"
24-
package my_package {
24+
package the_package {
2525
"""Description of what purpose this package serves"""
2626
// ...
2727
}
@@ -30,11 +30,11 @@ custom grammar:
3030
As rendered to SystemVerilog:
3131

3232
```sv linenums="1"
33-
package my_package;
33+
package the_package;
3434
3535
// ...attached definitions...
3636
37-
endpackage : my_package
37+
endpackage : the_package
3838
```
3939

4040
## Imports

docs/syntax/scalar.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ custom grammar:
1414
from packtype import Constant, Scalar
1515

1616
@packtype.package()
17-
class MyPackage:
17+
class ThePackage:
1818
# Constants
1919
TYPE_A_W : Constant = 29
2020
TYPE_B_W : Constant = 13
@@ -28,7 +28,7 @@ custom grammar:
2828
=== "Packtype (.pt)"
2929

3030
```sv linenums="1"
31-
package my_package {
31+
package the_package {
3232
// Constants
3333
TYPE_A_W : constant = 29
3434
TYPE_B_W : constant = 13
@@ -49,7 +49,7 @@ custom grammar:
4949
As rendered to SystemVerilog:
5050

5151
```sv linenums="1"
52-
package my_package;
52+
package the_package;
5353
5454
localparam TYPE_A_W = 29;
5555
localparam TYPE_B_W = 13;
@@ -58,7 +58,7 @@ typedef logic [28:0] type_a_t;
5858
typedef logic [12:0] type_b_t;
5959
typedef logic [6:0] type_c_t;
6060
61-
endpackage : my_package
61+
endpackage : the_package
6262
```
6363

6464
!!! note
@@ -78,7 +78,7 @@ to unsigned.
7878

7979
```python
8080
@packtype.package()
81-
class MyPackage:
81+
class ThePackage:
8282
# Format: <NAME> : Scalar[<WIDTH>, <SIGNED>]
8383
MyType : Scalar[123, False]
8484
```

0 commit comments

Comments
 (0)