Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
fcfaa416
Commit
fcfaa416
authored
Nov 27, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up new-style temps after use (breaks code for now)
parent
d69599e4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
0 deletions
+50
-0
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+19
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+9
-0
Cython/Compiler/UtilNodes.py
Cython/Compiler/UtilNodes.py
+22
-0
No files found.
Cython/Compiler/Code.py
View file @
fcfaa416
...
@@ -137,6 +137,25 @@ class FunctionState(object):
...
@@ -137,6 +137,25 @@ class FunctionState(object):
self
.
temps_free
[
type
]
=
freelist
self
.
temps_free
[
type
]
=
freelist
freelist
.
append
(
name
)
freelist
.
append
(
name
)
def
temps_in_use
(
self
):
"""Return a list of (cname,type) tuples of temp names and their type
that are currently in use.
"""
used
=
[]
for
name
,
type
in
self
.
temps_allocated
:
freelist
=
self
.
temps_free
.
get
(
type
)
if
freelist
is
None
or
name
not
in
freelist
:
used
.
append
((
name
,
type
))
return
used
def
py_temps_in_use
(
self
):
"""Return a list of (cname,type) tuples of temp names and their type
that are currently in use. This includes only Python object types.
"""
return
[(
name
,
type
)
for
name
,
type
in
self
.
temps_in_use
()
if
type
.
is_pyobject
]
class
GlobalState
(
object
):
class
GlobalState
(
object
):
# filename_table {string : int} for finding filename table indexes
# filename_table {string : int} for finding filename table indexes
# filename_list [string] filenames in filename table order
# filename_list [string] filenames in filename table order
...
...
Cython/Compiler/Nodes.py
View file @
fcfaa416
...
@@ -1060,7 +1060,12 @@ class FuncDefNode(StatNode, BlockNode):
...
@@ -1060,7 +1060,12 @@ class FuncDefNode(StatNode, BlockNode):
if
code
.
error_label
in
code
.
labels_used
:
if
code
.
error_label
in
code
.
labels_used
:
code
.
put_goto
(
code
.
return_label
)
code
.
put_goto
(
code
.
return_label
)
code
.
put_label
(
code
.
error_label
)
code
.
put_label
(
code
.
error_label
)
# cleanup temps the old way
code
.
put_var_xdecrefs
(
lenv
.
temp_entries
)
code
.
put_var_xdecrefs
(
lenv
.
temp_entries
)
# cleanup temps the new way
for
cname
,
type
in
code
.
funcstate
.
temps_allocated
:
if
type
.
is_pyobject
:
code
.
put_xdecref
(
cname
,
type
)
# Clean up buffers -- this calls a Python function
# Clean up buffers -- this calls a Python function
# so need to save and restore error state
# so need to save and restore error state
...
@@ -3287,8 +3292,12 @@ class ReturnStatNode(StatNode):
...
@@ -3287,8 +3292,12 @@ class ReturnStatNode(StatNode):
"%s = %s;"
%
(
"%s = %s;"
%
(
Naming
.
retval_cname
,
Naming
.
retval_cname
,
self
.
return_type
.
default_value
))
self
.
return_type
.
default_value
))
# free temps the old way
for
entry
in
self
.
temps_in_use
:
for
entry
in
self
.
temps_in_use
:
code
.
put_var_decref_clear
(
entry
)
code
.
put_var_decref_clear
(
entry
)
# free temps the new way
for
cname
,
type
in
code
.
funcstate
.
py_temps_in_use
():
code
.
put_decref_clear
(
cname
,
type
)
#code.putln(
#code.putln(
# "goto %s;" %
# "goto %s;" %
# code.return_label)
# code.return_label)
...
...
Cython/Compiler/UtilNodes.py
View file @
fcfaa416
...
@@ -11,12 +11,17 @@ from ExprNodes import AtomicExprNode
...
@@ -11,12 +11,17 @@ from ExprNodes import AtomicExprNode
class
TempHandle
(
object
):
class
TempHandle
(
object
):
temp
=
None
temp
=
None
needs_xdecref
=
False
def
__init__
(
self
,
type
):
def
__init__
(
self
,
type
):
self
.
type
=
type
self
.
type
=
type
self
.
needs_cleanup
=
type
.
is_pyobject
def
ref
(
self
,
pos
):
def
ref
(
self
,
pos
):
return
TempRefNode
(
pos
,
handle
=
self
,
type
=
self
.
type
)
return
TempRefNode
(
pos
,
handle
=
self
,
type
=
self
.
type
)
def
cleanup_ref
(
self
,
pos
):
return
CleanupTempRefNode
(
pos
,
handle
=
self
,
type
=
self
.
type
)
class
TempRefNode
(
AtomicExprNode
):
class
TempRefNode
(
AtomicExprNode
):
# handle TempHandle
# handle TempHandle
...
@@ -40,10 +45,22 @@ class TempRefNode(AtomicExprNode):
...
@@ -40,10 +45,22 @@ class TempRefNode(AtomicExprNode):
def
generate_assignment_code
(
self
,
rhs
,
code
):
def
generate_assignment_code
(
self
,
rhs
,
code
):
if
self
.
type
.
is_pyobject
:
if
self
.
type
.
is_pyobject
:
rhs
.
make_owned_reference
(
code
)
rhs
.
make_owned_reference
(
code
)
# TODO: analyse control flow to see if this is necessary
code
.
put_xdecref
(
self
.
result
(),
self
.
ctype
())
code
.
put_xdecref
(
self
.
result
(),
self
.
ctype
())
code
.
putln
(
'%s = %s;'
%
(
self
.
result
(),
rhs
.
result_as
(
self
.
ctype
())))
code
.
putln
(
'%s = %s;'
%
(
self
.
result
(),
rhs
.
result_as
(
self
.
ctype
())))
rhs
.
generate_post_assignment_code
(
code
)
rhs
.
generate_post_assignment_code
(
code
)
class
CleanupTempRefNode
(
TempRefNode
):
# handle TempHandle
def
generate_assignment_code
(
self
,
rhs
,
code
):
pass
def
generate_execution_code
(
self
,
code
):
if
self
.
type
.
is_pyobject
:
code
.
put_decref_clear
(
self
.
result
(),
self
.
type
)
self
.
handle
.
needs_cleanup
=
False
class
TempsBlockNode
(
Node
):
class
TempsBlockNode
(
Node
):
"""
"""
Creates a block which allocates temporary variables.
Creates a block which allocates temporary variables.
...
@@ -65,6 +82,11 @@ class TempsBlockNode(Node):
...
@@ -65,6 +82,11 @@ class TempsBlockNode(Node):
handle
.
temp
=
code
.
funcstate
.
allocate_temp
(
handle
.
type
)
handle
.
temp
=
code
.
funcstate
.
allocate_temp
(
handle
.
type
)
self
.
body
.
generate_execution_code
(
code
)
self
.
body
.
generate_execution_code
(
code
)
for
handle
in
self
.
temps
:
for
handle
in
self
.
temps
:
if
handle
.
needs_cleanup
:
if
handle
.
needs_xdecref
:
code
.
put_xdecref_clear
(
handle
.
temp
,
handle
.
type
)
else
:
code
.
put_decref_clear
(
handle
.
temp
,
handle
.
type
)
code
.
funcstate
.
release_temp
(
handle
.
temp
)
code
.
funcstate
.
release_temp
(
handle
.
temp
)
def
analyse_control_flow
(
self
,
env
):
def
analyse_control_flow
(
self
,
env
):
...
...
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