Introduce keyword like $previous to clearly indicate overlapping fields
- Dominant language
- Python
- Stars
- 92
- Forks
- 30
- PR merge metrics
- No merged PRs in 30d
Description
It could be helpful to introduce a keyword like $previous to indicate the offset of the previous field.
Currently in .emb if we want to have multiple overlapping fields the .emb has to use variations like the following to indicate that a field is offset at the same place as the previous field:
```
let hdr_size = EventHeader.$size_in_bytes
0 [+hdr_size] EventHeader header
$next [+1] UInt num_hci_command_packets
$next [+2] OpCode command_opcode_enum
$next-2 [+2] OpCodeBits command_opcode_bits
```
```
0 [+hdr_size] EventHeader header
hdr_size [+1] UInt num_hci_command_packets
hdr_size+1 [+2] OpCode command_opcode_enum
hdr_size+1 [+2] OpCodeBits command_opcode_bits
```
Introducing a `$previous` keyword would make these overlaps more obvious and reduce risk of a math error by the developer:
```
let hdr_size = EventHeader.$size_in_bytes
0 [+hdr_size] EventHeader header
$next [+1] UInt num_hci_command_packets
$next [+2] OpCode command_opcode_enum
$previous [+2] OpCodeBits command_opcode_bits
```
Note that #99 would provide an alternative like the following also, but it feels like $previous would be easier to implement and clearer in these overlapping case.
```
let hdr_size = EventHeader.$size_in_bytes
0 [+hdr_size] EventHeader header
$next [+1] UInt num_hci_command_packets
$next [+2] OpCode command_opcode_enum
$offset_of(command_opcode_enum) [+2] OpCodeBits command_opcode_bits
```
Contributor guide
Assessment
This issue has not been assessed yet.