Skip to content

Commit 5507eff

Browse files
authored
Improve format of InternalDocs/exception_handling.md (#134969)
1 parent 895119e commit 5507eff

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

InternalDocs/exception_handling.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The cost of raising an exception is increased, but not by much.
88

99
The following code:
1010

11-
```
11+
```python
1212
try:
1313
g(0)
1414
except:
@@ -18,7 +18,7 @@ except:
1818

1919
compiles into intermediate code like the following:
2020

21-
```
21+
```python
2222
RESUME 0
2323

2424
1 SETUP_FINALLY 8 (to L1)
@@ -118,13 +118,13 @@ All offsets and lengths are in code units, not bytes.
118118

119119
We want the format to be compact, but quickly searchable.
120120
For it to be compact, it needs to have variable sized entries so that we can store common (small) offsets compactly, but handle large offsets if needed.
121-
For it to be searchable quickly, we need to support binary search giving us log(n) performance in all cases.
121+
For it to be searchable quickly, we need to support binary search giving us `log(n)` performance in all cases.
122122
Binary search typically assumes fixed size entries, but that is not necessary, as long as we can identify the start of an entry.
123123

124124
It is worth noting that the size (end-start) is always smaller than the end, so we encode the entries as:
125125
`start, size, target, depth, push-lasti`.
126126

127-
Also, sizes are limited to 2**30 as the code length cannot exceed 2**31 and each code unit takes 2 bytes.
127+
Also, sizes are limited to `2**30` as the code length cannot exceed `2**31` and each code unit takes 2 bytes.
128128
It also happens that depth is generally quite small.
129129

130130
So, we need to encode:
@@ -140,7 +140,7 @@ lasti (1 bit)
140140
We need a marker for the start of the entry, so the first byte of entry will have the most significant bit set.
141141
Since the most significant bit is reserved for marking the start of an entry, we have 7 bits per byte to encode offsets.
142142
Encoding uses a standard varint encoding, but with only 7 bits instead of the usual 8.
143-
The 8 bits of a byte are (msb left) SXdddddd where S is the start bit. X is the extend bit meaning that the next byte is required to extend the offset.
143+
The 8 bits of a byte are (msb left) `SXdddddd` where `S` is the start bit. `X` is the extend bit meaning that the next byte is required to extend the offset.
144144

145145
In addition, we combine `depth` and `lasti` into a single value, `((depth<<1)+lasti)`, before encoding.
146146

0 commit comments

Comments
 (0)