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
Gwenaël Samain
cython
Commits
3979e943
Commit
3979e943
authored
Sep 27, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement locals()
parent
28b719dd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
1 deletion
+41
-1
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+1
-0
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+2
-1
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+29
-0
tests/run/locals.pyx
tests/run/locals.pyx
+9
-0
No files found.
Cython/Compiler/Builtin.py
View file @
3979e943
...
@@ -30,6 +30,7 @@ builtin_function_table = [
...
@@ -30,6 +30,7 @@ builtin_function_table = [
(
'issubclass'
,
"OO"
,
"b"
,
"PyObject_IsSubclass"
),
(
'issubclass'
,
"OO"
,
"b"
,
"PyObject_IsSubclass"
),
(
'iter'
,
"O"
,
"O"
,
"PyObject_GetIter"
),
(
'iter'
,
"O"
,
"O"
,
"PyObject_GetIter"
),
(
'len'
,
"O"
,
"Z"
,
"PyObject_Length"
),
(
'len'
,
"O"
,
"Z"
,
"PyObject_Length"
),
(
'locals'
,
""
,
"O"
,
"__pyx_locals"
),
#('map', "", "", ""),
#('map', "", "", ""),
#('max', "", "", ""),
#('max', "", "", ""),
#('min', "", "", ""),
#('min', "", "", ""),
...
...
Cython/Compiler/Main.py
View file @
3979e943
...
@@ -79,7 +79,7 @@ class Context:
...
@@ -79,7 +79,7 @@ class Context:
from
ParseTreeTransforms
import
WithTransform
,
NormalizeTree
,
PostParse
,
PxdPostParse
from
ParseTreeTransforms
import
WithTransform
,
NormalizeTree
,
PostParse
,
PxdPostParse
from
ParseTreeTransforms
import
AnalyseDeclarationsTransform
,
AnalyseExpressionsTransform
from
ParseTreeTransforms
import
AnalyseDeclarationsTransform
,
AnalyseExpressionsTransform
from
ParseTreeTransforms
import
CreateClosureClasses
,
MarkClosureVisitor
,
DecoratorTransform
from
ParseTreeTransforms
import
CreateClosureClasses
,
MarkClosureVisitor
,
DecoratorTransform
from
ParseTreeTransforms
import
InterpretCompilerDirectives
from
ParseTreeTransforms
import
InterpretCompilerDirectives
,
TransformBuiltinMethods
from
AutoDocTransforms
import
EmbedSignature
from
AutoDocTransforms
import
EmbedSignature
from
Optimize
import
FlattenInListTransform
,
SwitchTransform
,
FinalOptimizePhase
from
Optimize
import
FlattenInListTransform
,
SwitchTransform
,
FinalOptimizePhase
from
Buffer
import
IntroduceBufferAuxiliaryVars
from
Buffer
import
IntroduceBufferAuxiliaryVars
...
@@ -102,6 +102,7 @@ class Context:
...
@@ -102,6 +102,7 @@ class Context:
WithTransform
(
self
),
WithTransform
(
self
),
DecoratorTransform
(
self
),
DecoratorTransform
(
self
),
AnalyseDeclarationsTransform
(
self
),
AnalyseDeclarationsTransform
(
self
),
TransformBuiltinMethods
(
self
),
IntroduceBufferAuxiliaryVars
(
self
),
IntroduceBufferAuxiliaryVars
(
self
),
_check_c_classes
,
_check_c_classes
,
AnalyseExpressionsTransform
(
self
),
AnalyseExpressionsTransform
(
self
),
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
3979e943
...
@@ -534,6 +534,7 @@ property NAME:
...
@@ -534,6 +534,7 @@ property NAME:
return
property
return
property
class
AnalyseExpressionsTransform
(
CythonTransform
):
class
AnalyseExpressionsTransform
(
CythonTransform
):
def
visit_ModuleNode
(
self
,
node
):
def
visit_ModuleNode
(
self
,
node
):
node
.
body
.
analyse_expressions
(
node
.
scope
)
node
.
body
.
analyse_expressions
(
node
.
scope
)
self
.
visitchildren
(
node
)
self
.
visitchildren
(
node
)
...
@@ -591,3 +592,31 @@ class CreateClosureClasses(CythonTransform):
...
@@ -591,3 +592,31 @@ class CreateClosureClasses(CythonTransform):
return
node
return
node
class
EnvTransform
(
CythonTransform
):
"""
This transformation keeps a stack of the environments.
"""
def
__call__
(
self
,
root
):
self
.
env_stack
=
[
root
.
scope
]
return
super
(
EnvTransform
,
self
).
__call__
(
root
)
def
visit_FuncDefNode
(
self
,
node
):
self
.
env_stack
.
append
(
node
.
local_scope
)
self
.
visitchildren
(
node
)
self
.
env_stack
.
pop
()
return
node
class
TransformBuiltinMethods
(
EnvTransform
):
def
visit_SimpleCallNode
(
self
,
node
):
self
.
visitchildren
(
node
)
if
isinstance
(
node
.
function
,
ExprNodes
.
NameNode
):
if
node
.
function
.
name
==
'locals'
:
pos
=
node
.
pos
lenv
=
self
.
env_stack
[
-
1
]
items
=
[
ExprNodes
.
DictItemNode
(
pos
,
key
=
ExprNodes
.
IdentifierStringNode
(
pos
,
value
=
var
),
value
=
ExprNodes
.
NameNode
(
pos
,
name
=
var
))
for
var
in
lenv
.
entries
]
return
ExprNodes
.
DictNode
(
pos
,
key_value_pairs
=
items
)
return
node
tests/run/locals.pyx
0 → 100644
View file @
3979e943
__doc__
=
"""
sage: get_locals(1,2,3)
{'args': (2, 3), 'kwds': {}, 'x': 1, 'y': 'hi', 'z': 5}
"""
def
get_locals
(
x
,
*
args
,
**
kwds
):
y
=
"hi"
cdef
int
z
=
5
return
locals
()
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