Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify
  • Loading branch information
picnixz committed Aug 22, 2024
commit 588e81cdd90656d313a6a24093346c1460041a88
44 changes: 0 additions & 44 deletions InternalDocs/locations.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,47 +103,3 @@ start column divided by 8 (and rounded down).

* Start column: `(code*8) + ((second_byte>>4)&7)`
* End column: `start_column + (second_byte&15)`

## Artificial constructions

When constructing artificial `co_linetable` values, only non-None values should
be specified. For instance:

```py
import dis

def foo():
pass

co_firstlineno = 42
foo.__code__ = foo.__code__.replace(
co_firstlineno=co_firstlineno,
co_linetable=bytes([
# RESUME
(1 << 7) | (13 << 3) | (1 - 1),
# sentinel # no column info # number of units - 1
*encode_varint(svarint_to_varint(2)), # relative start line delta
# RETURN_CONST (None)
(1 << 7) | (14 << 3) | (1 - 1),
# sentinel # has column info # number of units - 1
*encode_varint(svarint_to_varint(5)), # relative start line delta
*encode_varint(12), # end line delta
*encode_varint(3), # start column (starts from 1)
*encode_varint(8), # end column (starts from 1)
])
)

instructions = list(dis.get_instructions(foo))
assert len(instructions) == 2

assert instructions[0].opname == 'RESUME'
assert instructions[1].opname == 'RETURN_CONST'

ip0, ip1 = instructions[0].positions, instructions[1].positions
assert ip0 == (co_firstlineno + 2, co_firstlineno + 2, None, None)
assert ip1 == (ip0.lineno + 5, ip1.lineno + 12, (3 - 1), (8 - 1))
```

Note that the indexation of the start and end column values are assumed to
start from 1 and are absolute but that `dis.Positions` is using 0-based values
for the column start and end offsets, when available.