Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
92f39720
Commit
92f39720
authored
Sep 01, 2000
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
patch by Neil Schemenauer to improve (fix?) line number generation
parent
3620857d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
34 deletions
+64
-34
Lib/compiler/pyassem.py
Lib/compiler/pyassem.py
+26
-15
Lib/compiler/pycodegen.py
Lib/compiler/pycodegen.py
+6
-2
Tools/compiler/compiler/pyassem.py
Tools/compiler/compiler/pyassem.py
+26
-15
Tools/compiler/compiler/pycodegen.py
Tools/compiler/compiler/pycodegen.py
+6
-2
No files found.
Lib/compiler/pyassem.py
View file @
92f39720
...
...
@@ -419,21 +419,32 @@ class LineAddrTable:
# compute deltas
addr
=
self
.
codeOffset
-
self
.
lastoff
line
=
lineno
-
self
.
lastline
while
addr
>
0
or
line
>
0
:
# write the values in 1-byte chunks that sum
# to desired value
trunc_addr
=
addr
trunc_line
=
line
if
trunc_addr
>
255
:
trunc_addr
=
255
if
trunc_line
>
255
:
trunc_line
=
255
self
.
lnotab
.
append
(
trunc_addr
)
self
.
lnotab
.
append
(
trunc_line
)
addr
=
addr
-
trunc_addr
line
=
line
-
trunc_line
self
.
lastline
=
lineno
self
.
lastoff
=
self
.
codeOffset
# Python assumes that lineno always increases with
# increasing bytecode address (lnotab is unsigned char).
# Depending on when SET_LINENO instructions are emitted
# this is not always true. Consider the code:
# a = (1,
# b)
# In the bytecode stream, the assignment to "a" occurs
# after the loading of "b". This works with the C Python
# compiler because it only generates a SET_LINENO instruction
# for the assignment.
if
line
>
0
:
while
addr
>
0
or
line
>
0
:
# write the values in 1-byte chunks that sum
# to desired value
trunc_addr
=
addr
trunc_line
=
line
if
trunc_addr
>
255
:
trunc_addr
=
255
if
trunc_line
>
255
:
trunc_line
=
255
self
.
lnotab
.
append
(
trunc_addr
)
self
.
lnotab
.
append
(
trunc_line
)
addr
=
addr
-
trunc_addr
line
=
line
-
trunc_line
self
.
lastline
=
lineno
self
.
lastoff
=
self
.
codeOffset
def
getCode
(
self
):
return
string
.
join
(
self
.
code
,
''
)
...
...
Lib/compiler/pycodegen.py
View file @
92f39720
...
...
@@ -70,6 +70,7 @@ class CodeGenerator:
self
.
loops
=
misc
.
Stack
()
self
.
curStack
=
0
self
.
maxStack
=
0
self
.
last_lineno
=
None
self
.
_setupGraphDelegation
()
def
_setupGraphDelegation
(
self
):
...
...
@@ -107,7 +108,8 @@ class CodeGenerator:
self
.
emit
(
prefix
+
'_GLOBAL'
,
name
)
def
set_lineno
(
self
,
node
):
"""Emit SET_LINENO if node has lineno attribute
"""Emit SET_LINENO if node has lineno attribute and it is
different than the last lineno emitted.
Returns true if SET_LINENO was emitted.
...
...
@@ -117,8 +119,9 @@ class CodeGenerator:
then, this method works around missing line numbers.
"""
lineno
=
getattr
(
node
,
'lineno'
,
None
)
if
lineno
is
not
None
:
if
lineno
is
not
None
and
lineno
!=
self
.
last_lineno
:
self
.
emit
(
'SET_LINENO'
,
lineno
)
self
.
last_lineno
=
lineno
return
1
return
0
...
...
@@ -414,6 +417,7 @@ class CodeGenerator:
pass
def
visitName
(
self
,
node
):
self
.
set_lineno
(
node
)
self
.
loadName
(
node
.
name
)
def
visitPass
(
self
,
node
):
...
...
Tools/compiler/compiler/pyassem.py
View file @
92f39720
...
...
@@ -419,21 +419,32 @@ class LineAddrTable:
# compute deltas
addr
=
self
.
codeOffset
-
self
.
lastoff
line
=
lineno
-
self
.
lastline
while
addr
>
0
or
line
>
0
:
# write the values in 1-byte chunks that sum
# to desired value
trunc_addr
=
addr
trunc_line
=
line
if
trunc_addr
>
255
:
trunc_addr
=
255
if
trunc_line
>
255
:
trunc_line
=
255
self
.
lnotab
.
append
(
trunc_addr
)
self
.
lnotab
.
append
(
trunc_line
)
addr
=
addr
-
trunc_addr
line
=
line
-
trunc_line
self
.
lastline
=
lineno
self
.
lastoff
=
self
.
codeOffset
# Python assumes that lineno always increases with
# increasing bytecode address (lnotab is unsigned char).
# Depending on when SET_LINENO instructions are emitted
# this is not always true. Consider the code:
# a = (1,
# b)
# In the bytecode stream, the assignment to "a" occurs
# after the loading of "b". This works with the C Python
# compiler because it only generates a SET_LINENO instruction
# for the assignment.
if
line
>
0
:
while
addr
>
0
or
line
>
0
:
# write the values in 1-byte chunks that sum
# to desired value
trunc_addr
=
addr
trunc_line
=
line
if
trunc_addr
>
255
:
trunc_addr
=
255
if
trunc_line
>
255
:
trunc_line
=
255
self
.
lnotab
.
append
(
trunc_addr
)
self
.
lnotab
.
append
(
trunc_line
)
addr
=
addr
-
trunc_addr
line
=
line
-
trunc_line
self
.
lastline
=
lineno
self
.
lastoff
=
self
.
codeOffset
def
getCode
(
self
):
return
string
.
join
(
self
.
code
,
''
)
...
...
Tools/compiler/compiler/pycodegen.py
View file @
92f39720
...
...
@@ -70,6 +70,7 @@ class CodeGenerator:
self
.
loops
=
misc
.
Stack
()
self
.
curStack
=
0
self
.
maxStack
=
0
self
.
last_lineno
=
None
self
.
_setupGraphDelegation
()
def
_setupGraphDelegation
(
self
):
...
...
@@ -107,7 +108,8 @@ class CodeGenerator:
self
.
emit
(
prefix
+
'_GLOBAL'
,
name
)
def
set_lineno
(
self
,
node
):
"""Emit SET_LINENO if node has lineno attribute
"""Emit SET_LINENO if node has lineno attribute and it is
different than the last lineno emitted.
Returns true if SET_LINENO was emitted.
...
...
@@ -117,8 +119,9 @@ class CodeGenerator:
then, this method works around missing line numbers.
"""
lineno
=
getattr
(
node
,
'lineno'
,
None
)
if
lineno
is
not
None
:
if
lineno
is
not
None
and
lineno
!=
self
.
last_lineno
:
self
.
emit
(
'SET_LINENO'
,
lineno
)
self
.
last_lineno
=
lineno
return
1
return
0
...
...
@@ -414,6 +417,7 @@ class CodeGenerator:
pass
def
visitName
(
self
,
node
):
self
.
set_lineno
(
node
)
self
.
loadName
(
node
.
name
)
def
visitPass
(
self
,
node
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment