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
a96882e1
Commit
a96882e1
authored
Jun 17, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use explicit relative imports everywhere and enable absolute imports by default
parent
3b9f95ef
Changes
58
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
58 changed files
with
571 additions
and
445 deletions
+571
-445
Cython/Build/BuildExecutable.py
Cython/Build/BuildExecutable.py
+4
-1
Cython/Build/Cythonize.py
Cython/Build/Cythonize.py
+6
-4
Cython/Build/Dependencies.py
Cython/Build/Dependencies.py
+8
-6
Cython/Build/Inline.py
Cython/Build/Inline.py
+9
-7
Cython/Build/IpythonMagic.py
Cython/Build/IpythonMagic.py
+3
-3
Cython/Build/__init__.py
Cython/Build/__init__.py
+1
-1
Cython/Compiler/AnalysedTreeTransforms.py
Cython/Compiler/AnalysedTreeTransforms.py
+8
-6
Cython/Compiler/Annotate.py
Cython/Compiler/Annotate.py
+5
-3
Cython/Compiler/AutoDocTransforms.py
Cython/Compiler/AutoDocTransforms.py
+6
-4
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+13
-11
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+7
-5
Cython/Compiler/CmdLine.py
Cython/Compiler/CmdLine.py
+7
-5
Cython/Compiler/Code.pxd
Cython/Compiler/Code.pxd
+2
-0
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+19
-17
Cython/Compiler/CodeGeneration.py
Cython/Compiler/CodeGeneration.py
+5
-2
Cython/Compiler/CythonScope.py
Cython/Compiler/CythonScope.py
+9
-6
Cython/Compiler/Errors.py
Cython/Compiler/Errors.py
+7
-3
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+37
-36
Cython/Compiler/FlowControl.pxd
Cython/Compiler/FlowControl.pxd
+3
-1
Cython/Compiler/FlowControl.py
Cython/Compiler/FlowControl.py
+10
-8
Cython/Compiler/FusedNode.py
Cython/Compiler/FusedNode.py
+8
-8
Cython/Compiler/Interpreter.py
Cython/Compiler/Interpreter.py
+5
-3
Cython/Compiler/Lexicon.py
Cython/Compiler/Lexicon.py
+4
-2
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+21
-15
Cython/Compiler/MemoryView.py
Cython/Compiler/MemoryView.py
+13
-11
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+19
-17
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+49
-47
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+18
-17
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+2
-0
Cython/Compiler/ParseTreeTransforms.pxd
Cython/Compiler/ParseTreeTransforms.pxd
+3
-1
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+22
-20
Cython/Compiler/Parsing.pxd
Cython/Compiler/Parsing.pxd
+3
-1
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+15
-15
Cython/Compiler/Pipeline.py
Cython/Compiler/Pipeline.py
+38
-38
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+23
-18
Cython/Compiler/Scanning.pxd
Cython/Compiler/Scanning.pxd
+3
-1
Cython/Compiler/Scanning.py
Cython/Compiler/Scanning.py
+9
-7
Cython/Compiler/StringEncoding.py
Cython/Compiler/StringEncoding.py
+3
-0
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+16
-13
Cython/Compiler/TreeFragment.py
Cython/Compiler/TreeFragment.py
+17
-12
Cython/Compiler/TreePath.py
Cython/Compiler/TreePath.py
+2
-0
Cython/Compiler/TypeInference.py
Cython/Compiler/TypeInference.py
+10
-8
Cython/Compiler/TypeSlots.py
Cython/Compiler/TypeSlots.py
+6
-3
Cython/Compiler/UtilNodes.py
Cython/Compiler/UtilNodes.py
+8
-5
Cython/Compiler/UtilityCode.py
Cython/Compiler/UtilityCode.py
+9
-6
Cython/Compiler/Version.py
Cython/Compiler/Version.py
+3
-1
Cython/Compiler/Visitor.pxd
Cython/Compiler/Visitor.pxd
+2
-0
Cython/Compiler/Visitor.py
Cython/Compiler/Visitor.py
+10
-7
Cython/Plex/DFA.py
Cython/Plex/DFA.py
+7
-4
Cython/Plex/Lexicons.py
Cython/Plex/Lexicons.py
+9
-6
Cython/Plex/Machines.py
Cython/Plex/Machines.py
+4
-1
Cython/Plex/Regexps.py
Cython/Plex/Regexps.py
+4
-1
Cython/Plex/Scanners.pxd
Cython/Plex/Scanners.pxd
+2
-0
Cython/Plex/Scanners.py
Cython/Plex/Scanners.py
+5
-2
Cython/Plex/Timing.py
Cython/Plex/Timing.py
+13
-12
Cython/Plex/Traditional.py
Cython/Plex/Traditional.py
+7
-2
Cython/Plex/Transitions.py
Cython/Plex/Transitions.py
+4
-5
Cython/Plex/__init__.py
Cython/Plex/__init__.py
+6
-7
No files found.
Cython/Build/BuildExecutable.py
View file @
a96882e1
...
@@ -7,12 +7,15 @@ Basic usage:
...
@@ -7,12 +7,15 @@ Basic usage:
python cythonrun somefile.py [ARGS]
python cythonrun somefile.py [ARGS]
"""
"""
from
__future__
import
absolute_import
DEBUG
=
True
DEBUG
=
True
import
sys
import
sys
import
os
import
os
from
distutils
import
sysconfig
from
distutils
import
sysconfig
def
get_config_var
(
name
,
default
=
''
):
def
get_config_var
(
name
,
default
=
''
):
return
sysconfig
.
get_config_var
(
name
)
or
default
return
sysconfig
.
get_config_var
(
name
)
or
default
...
@@ -81,7 +84,7 @@ def ccompile(basename):
...
@@ -81,7 +84,7 @@ def ccompile(basename):
runcmd
([
CC
,
'-c'
,
'-o'
,
basename
+
'.o'
,
basename
+
'.c'
,
'-I'
+
INCDIR
]
+
CFLAGS
.
split
())
runcmd
([
CC
,
'-c'
,
'-o'
,
basename
+
'.o'
,
basename
+
'.c'
,
'-I'
+
INCDIR
]
+
CFLAGS
.
split
())
def
cycompile
(
input_file
,
options
=
()):
def
cycompile
(
input_file
,
options
=
()):
from
Cython
.Compiler
import
Version
,
CmdLine
,
Main
from
.
.Compiler
import
Version
,
CmdLine
,
Main
options
,
sources
=
CmdLine
.
parse_command_line
(
list
(
options
or
())
+
[
'--embed'
,
input_file
])
options
,
sources
=
CmdLine
.
parse_command_line
(
list
(
options
or
())
+
[
'--embed'
,
input_file
])
_debug
(
'Using Cython %s to compile %s'
,
Version
.
version
,
input_file
)
_debug
(
'Using Cython %s to compile %s'
,
Version
.
version
,
input_file
)
result
=
Main
.
compile
(
sources
,
options
)
result
=
Main
.
compile
(
sources
,
options
)
...
...
Cython/Build/Cythonize.py
View file @
a96882e1
#!/usr/bin/env python
#!/usr/bin/env python
from
__future__
import
absolute_import
import
os
import
os
import
shutil
import
shutil
import
tempfile
import
tempfile
from
distutils.core
import
setup
from
distutils.core
import
setup
from
Cython.Build.Dependencies
import
cythonize
,
extended_iglob
from
Cython.Utils
import
is_package_dir
from
.Dependencies
import
cythonize
,
extended_iglob
from
Cython.Compiler
import
Options
from
..Utils
import
is_package_dir
from
..Compiler
import
Options
try
:
try
:
import
multiprocessing
import
multiprocessing
...
...
Cython/Build/Dependencies.py
View file @
a96882e1
from
__future__
import
absolute_import
import
cython
import
cython
from
Cython
import
__version__
from
..
import
__version__
import
re
,
os
,
sys
,
time
import
re
,
os
,
sys
,
time
from
glob
import
iglob
from
glob
import
iglob
...
@@ -42,9 +44,9 @@ except ImportError:
...
@@ -42,9 +44,9 @@ except ImportError:
from
distutils.extension
import
Extension
from
distutils.extension
import
Extension
from
Cython
import
Utils
from
..
import
Utils
from
Cython
.Utils
import
cached_function
,
cached_method
,
path_exists
,
find_root_package_dir
from
.
.Utils
import
cached_function
,
cached_method
,
path_exists
,
find_root_package_dir
from
Cython
.Compiler.Main
import
Context
,
CompilationOptions
,
default_options
from
.
.Compiler.Main
import
Context
,
CompilationOptions
,
default_options
join_path
=
cached_function
(
os
.
path
.
join
)
join_path
=
cached_function
(
os
.
path
.
join
)
...
@@ -871,8 +873,8 @@ else:
...
@@ -871,8 +873,8 @@ else:
# TODO: Share context? Issue: pyx processing leaks into pxd module
# TODO: Share context? Issue: pyx processing leaks into pxd module
@
record_results
@
record_results
def
cythonize_one
(
pyx_file
,
c_file
,
fingerprint
,
quiet
,
options
=
None
,
raise_on_failure
=
True
):
def
cythonize_one
(
pyx_file
,
c_file
,
fingerprint
,
quiet
,
options
=
None
,
raise_on_failure
=
True
):
from
Cython
.Compiler.Main
import
compile
,
default_options
from
.
.Compiler.Main
import
compile
,
default_options
from
Cython
.Compiler.Errors
import
CompileError
,
PyrexError
from
.
.Compiler.Errors
import
CompileError
,
PyrexError
if
fingerprint
:
if
fingerprint
:
if
not
os
.
path
.
exists
(
options
.
cache
):
if
not
os
.
path
.
exists
(
options
.
cache
):
...
...
Cython/Build/Inline.py
View file @
a96882e1
from
__future__
import
absolute_import
import
sys
,
os
,
re
,
inspect
import
sys
,
os
,
re
,
inspect
import
imp
import
imp
...
@@ -10,14 +12,14 @@ from distutils.core import Distribution, Extension
...
@@ -10,14 +12,14 @@ from distutils.core import Distribution, Extension
from
distutils.command.build_ext
import
build_ext
from
distutils.command.build_ext
import
build_ext
import
Cython
import
Cython
from
Cython
.Compiler.Main
import
Context
,
CompilationOptions
,
default_options
from
.
.Compiler.Main
import
Context
,
CompilationOptions
,
default_options
from
Cython
.Compiler.ParseTreeTransforms
import
(
CythonTransform
,
from
.
.Compiler.ParseTreeTransforms
import
(
CythonTransform
,
SkipDeclarations
,
AnalyseDeclarationsTransform
,
EnvTransform
)
SkipDeclarations
,
AnalyseDeclarationsTransform
,
EnvTransform
)
from
Cython
.Compiler.TreeFragment
import
parse_from_strings
from
.
.Compiler.TreeFragment
import
parse_from_strings
from
Cython.Build
.Dependencies
import
strip_string_literals
,
cythonize
,
cached_function
from
.Dependencies
import
strip_string_literals
,
cythonize
,
cached_function
from
Cython
.Compiler
import
Pipeline
,
Nodes
from
.
.Compiler
import
Pipeline
,
Nodes
from
Cython
.Utils
import
get_cython_cache_dir
from
.
.Utils
import
get_cython_cache_dir
import
cython
as
cython_module
import
cython
as
cython_module
# A utility function to convert user-supplied ASCII strings to unicode.
# A utility function to convert user-supplied ASCII strings to unicode.
...
@@ -48,7 +50,7 @@ def unbound_symbols(code, context=None):
...
@@ -48,7 +50,7 @@ def unbound_symbols(code, context=None):
code
=
to_unicode
(
code
)
code
=
to_unicode
(
code
)
if
context
is
None
:
if
context
is
None
:
context
=
Context
([],
default_options
)
context
=
Context
([],
default_options
)
from
Cython
.Compiler.ParseTreeTransforms
import
AnalyseDeclarationsTransform
from
.
.Compiler.ParseTreeTransforms
import
AnalyseDeclarationsTransform
tree
=
parse_from_strings
(
'(tree fragment)'
,
code
)
tree
=
parse_from_strings
(
'(tree fragment)'
,
code
)
for
phase
in
Pipeline
.
create_pipeline
(
context
,
'pyx'
):
for
phase
in
Pipeline
.
create_pipeline
(
context
,
'pyx'
):
if
phase
is
None
:
if
phase
is
None
:
...
...
Cython/Build/IpythonMagic.py
View file @
a96882e1
...
@@ -44,7 +44,7 @@ Parts of this code were taken from Cython.inline.
...
@@ -44,7 +44,7 @@ Parts of this code were taken from Cython.inline.
# The full license is in the file COPYING.txt, distributed with this software.
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
from
__future__
import
print_function
from
__future__
import
absolute_import
,
print_function
import
imp
import
imp
import
io
import
io
...
@@ -74,8 +74,8 @@ from IPython.utils.path import get_ipython_cache_dir
...
@@ -74,8 +74,8 @@ from IPython.utils.path import get_ipython_cache_dir
from
IPython.utils.text
import
dedent
from
IPython.utils.text
import
dedent
import
Cython
import
Cython
from
Cython
.Compiler.Errors
import
CompileError
from
.
.Compiler.Errors
import
CompileError
from
Cython.Build
.Dependencies
import
cythonize
from
.Dependencies
import
cythonize
@
magics_class
@
magics_class
...
...
Cython/Build/__init__.py
View file @
a96882e1
from
Dependencies
import
cythonize
from
.
Dependencies
import
cythonize
Cython/Compiler/AnalysedTreeTransforms.py
View file @
a96882e1
from
Visitor
import
ScopeTrackingTransform
from
__future__
import
absolute_import
from
Nodes
import
StatListNode
,
SingleAssignmentNode
,
CFuncDefNode
,
DefNode
from
ExprNodes
import
DictNode
,
DictItemNode
,
NameNode
,
UnicodeNode
from
.Visitor
import
ScopeTrackingTransform
from
PyrexTypes
import
py_object_type
from
.Nodes
import
StatListNode
,
SingleAssignmentNode
,
CFuncDefNode
,
DefNode
from
StringEncoding
import
EncodedString
from
.ExprNodes
import
DictNode
,
DictItemNode
,
NameNode
,
UnicodeNode
import
Symtab
from
.PyrexTypes
import
py_object_type
from
.StringEncoding
import
EncodedString
from
.
import
Symtab
class
AutoTestDictTransform
(
ScopeTrackingTransform
):
class
AutoTestDictTransform
(
ScopeTrackingTransform
):
# Handles autotestdict directive
# Handles autotestdict directive
...
...
Cython/Compiler/Annotate.py
View file @
a96882e1
# Note: Work in progress
# Note: Work in progress
from
__future__
import
absolute_import
import
os
import
os
import
re
import
re
import
codecs
import
codecs
...
@@ -7,9 +9,9 @@ import textwrap
...
@@ -7,9 +9,9 @@ import textwrap
from
xml.sax.saxutils
import
escape
as
html_escape
from
xml.sax.saxutils
import
escape
as
html_escape
from
StringIO
import
StringIO
from
StringIO
import
StringIO
import
Version
from
.
import
Version
from
Code
import
CCodeWriter
from
.
Code
import
CCodeWriter
from
Cython
import
Utils
from
..
import
Utils
class
AnnotationCCodeWriter
(
CCodeWriter
):
class
AnnotationCCodeWriter
(
CCodeWriter
):
...
...
Cython/Compiler/AutoDocTransforms.py
View file @
a96882e1
from
Cython.Compiler.Visitor
import
CythonTransform
from
__future__
import
absolute_import
from
Cython.Compiler.StringEncoding
import
EncodedString
from
Cython.Compiler
import
Options
from
.Visitor
import
CythonTransform
from
Cython.Compiler
import
PyrexTypes
,
ExprNodes
from
.StringEncoding
import
EncodedString
from
.
import
Options
from
.
import
PyrexTypes
,
ExprNodes
class
EmbedSignature
(
CythonTransform
):
class
EmbedSignature
(
CythonTransform
):
...
...
Cython/Compiler/Buffer.py
View file @
a96882e1
from
Cython.Compiler.Visitor
import
CythonTransform
from
__future__
import
absolute_import
from
Cython.Compiler.ModuleNode
import
ModuleNode
from
Cython.Compiler.Errors
import
CompileError
from
.Visitor
import
CythonTransform
from
Cython.Compiler.UtilityCode
import
CythonUtilityCode
from
.ModuleNode
import
ModuleNode
from
Cython.Compiler.Code
import
UtilityCode
,
TempitaUtilityCode
from
.Errors
import
CompileError
from
.UtilityCode
import
CythonUtilityCode
from
Cython.Compiler
import
Options
from
.Code
import
UtilityCode
,
TempitaUtilityCode
from
Cython.Compiler
import
Interpreter
from
Cython.Compiler
import
PyrexTypes
from
.
import
Options
from
Cython.Compiler
import
Naming
from
.
import
Interpreter
from
Cython.Compiler
import
Symtab
from
.
import
PyrexTypes
from
.
import
Naming
from
.
import
Symtab
def
dedent
(
text
,
reindent
=
0
):
def
dedent
(
text
,
reindent
=
0
):
...
...
Cython/Compiler/Builtin.py
View file @
a96882e1
...
@@ -2,11 +2,13 @@
...
@@ -2,11 +2,13 @@
# Builtin Definitions
# Builtin Definitions
#
#
from
Symtab
import
BuiltinScope
,
StructOrUnionScope
from
__future__
import
absolute_import
from
Code
import
UtilityCode
from
TypeSlots
import
Signature
from
.Symtab
import
BuiltinScope
,
StructOrUnionScope
import
PyrexTypes
from
.Code
import
UtilityCode
import
Options
from
.TypeSlots
import
Signature
from
.
import
PyrexTypes
from
.
import
Options
# C-level implementations of builtin types, functions and methods
# C-level implementations of builtin types, functions and methods
...
...
Cython/Compiler/CmdLine.py
View file @
a96882e1
...
@@ -2,9 +2,11 @@
...
@@ -2,9 +2,11 @@
# Cython - Command Line Parsing
# Cython - Command Line Parsing
#
#
from
__future__
import
absolute_import
import
os
import
os
import
sys
import
sys
import
Options
from
.
import
Options
usage
=
"""
\
usage
=
"""
\
Cython (http://cython.org) is a compiler for code written in the
Cython (http://cython.org) is a compiler for code written in the
...
@@ -46,6 +48,7 @@ Options:
...
@@ -46,6 +48,7 @@ Options:
-X, --directive <name>=<value>[,<name=value,...] Overrides a compiler directive
-X, --directive <name>=<value>[,<name=value,...] Overrides a compiler directive
"""
"""
#The following experimental options are supported only on MacOSX:
#The following experimental options are supported only on MacOSX:
# -C, --compile Compile generated .c file to .o file
# -C, --compile Compile generated .c file to .o file
# --link Link .o file to produce extension module (implies -C)
# --link Link .o file to produce extension module (implies -C)
...
@@ -56,10 +59,9 @@ def bad_usage():
...
@@ -56,10 +59,9 @@ def bad_usage():
sys
.
stderr
.
write
(
usage
)
sys
.
stderr
.
write
(
usage
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
def
parse_command_line
(
args
):
from
Cython.Compiler.Main
import
\
def
parse_command_line
(
args
):
CompilationOptions
,
default_options
from
.Main
import
CompilationOptions
,
default_options
def
pop_arg
():
def
pop_arg
():
if
args
:
if
args
:
...
@@ -156,7 +158,7 @@ def parse_command_line(args):
...
@@ -156,7 +158,7 @@ def parse_command_line(args):
sys
.
exit
(
1
)
sys
.
exit
(
1
)
elif
option
.
startswith
(
'--debug'
):
elif
option
.
startswith
(
'--debug'
):
option
=
option
[
2
:].
replace
(
'-'
,
'_'
)
option
=
option
[
2
:].
replace
(
'-'
,
'_'
)
import
DebugFlags
from
.
import
DebugFlags
if
option
in
dir
(
DebugFlags
):
if
option
in
dir
(
DebugFlags
):
setattr
(
DebugFlags
,
option
,
True
)
setattr
(
DebugFlags
,
option
,
True
)
else
:
else
:
...
...
Cython/Compiler/Code.pxd
View file @
a96882e1
from
__future__
import
absolute_import
cimport
cython
cimport
cython
#cdef class UtilityCodeBase(object):
#cdef class UtilityCodeBase(object):
...
...
Cython/Compiler/Code.py
View file @
a96882e1
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
# Code output module
# Code output module
#
#
from
__future__
import
absolute_import
import
cython
import
cython
cython
.
declare
(
os
=
object
,
re
=
object
,
operator
=
object
,
cython
.
declare
(
os
=
object
,
re
=
object
,
operator
=
object
,
Naming
=
object
,
Options
=
object
,
StringEncoding
=
object
,
Naming
=
object
,
Options
=
object
,
StringEncoding
=
object
,
...
@@ -21,13 +23,13 @@ try:
...
@@ -21,13 +23,13 @@ try:
except
ImportError
:
except
ImportError
:
import
md5
as
hashlib
import
md5
as
hashlib
import
Naming
from
.
import
Naming
import
Options
from
.
import
Options
import
StringEncoding
from
.
import
DebugFlags
from
Cython
import
Utils
from
.
import
StringEncoding
from
Scanning
import
SourceDescriptor
from
..
import
Utils
from
Cython.StringIOTree
import
StringIOTree
from
.Scanning
import
SourceDescriptor
import
DebugFlags
from
..StringIOTree
import
StringIOTree
try
:
try
:
from
__builtin__
import
basestring
from
__builtin__
import
basestring
...
@@ -452,7 +454,7 @@ def sub_tempita(s, context, file=None, name=None):
...
@@ -452,7 +454,7 @@ def sub_tempita(s, context, file=None, name=None):
elif name:
elif name:
context['__name'] = name
context['__name'] = name
from
Cython
.Tempita import sub
from
.
.Tempita import sub
return sub(s, **context)
return sub(s, **context)
class TempitaUtilityCode(UtilityCode):
class TempitaUtilityCode(UtilityCode):
...
@@ -1621,11 +1623,11 @@ class CCodeWriter(object):
...
@@ -1621,11 +1623,11 @@ class CCodeWriter(object):
self
.
level
+=
1
self
.
level
+=
1
def
putln_tempita
(
self
,
code
,
**
context
):
def
putln_tempita
(
self
,
code
,
**
context
):
from
Cython
.Tempita
import
sub
from
.
.Tempita
import
sub
self
.
putln
(
sub
(
code
,
**
context
))
self
.
putln
(
sub
(
code
,
**
context
))
def
put_tempita
(
self
,
code
,
**
context
):
def
put_tempita
(
self
,
code
,
**
context
):
from
Cython
.Tempita
import
sub
from
.
.Tempita
import
sub
self
.
put
(
sub
(
code
,
**
context
))
self
.
put
(
sub
(
code
,
**
context
))
def
increase_indent
(
self
):
def
increase_indent
(
self
):
...
@@ -1701,7 +1703,7 @@ class CCodeWriter(object):
...
@@ -1701,7 +1703,7 @@ class CCodeWriter(object):
if
type
.
is_pyobject
:
if
type
.
is_pyobject
:
self
.
putln
(
"%s = NULL;"
%
decl
)
self
.
putln
(
"%s = NULL;"
%
decl
)
elif
type
.
is_memoryviewslice
:
elif
type
.
is_memoryviewslice
:
import
MemoryView
from
.
import
MemoryView
self
.
putln
(
"%s = %s;"
%
(
decl
,
MemoryView
.
memslice_entry_init
))
self
.
putln
(
"%s = %s;"
%
(
decl
,
MemoryView
.
memslice_entry_init
))
else
:
else
:
self
.
putln
(
"%s%s;"
%
(
static
and
"static "
or
""
,
decl
))
self
.
putln
(
"%s%s;"
%
(
static
and
"static "
or
""
,
decl
))
...
@@ -1742,7 +1744,7 @@ class CCodeWriter(object):
...
@@ -1742,7 +1744,7 @@ class CCodeWriter(object):
return
entry
.
cname
return
entry
.
cname
def
as_pyobject
(
self
,
cname
,
type
):
def
as_pyobject
(
self
,
cname
,
type
):
from
PyrexTypes
import
py_object_type
,
typecast
from
.
PyrexTypes
import
py_object_type
,
typecast
return
typecast
(
py_object_type
,
type
,
cname
)
return
typecast
(
py_object_type
,
type
,
cname
)
def
put_gotref
(
self
,
cname
):
def
put_gotref
(
self
,
cname
):
...
@@ -1870,12 +1872,12 @@ class CCodeWriter(object):
...
@@ -1870,12 +1872,12 @@ class CCodeWriter(object):
self
.
put_var_xdecref_clear
(
entry
)
self
.
put_var_xdecref_clear
(
entry
)
def
put_incref_memoryviewslice
(
self
,
slice_cname
,
have_gil
=
False
):
def
put_incref_memoryviewslice
(
self
,
slice_cname
,
have_gil
=
False
):
import
MemoryView
from
.
import
MemoryView
self
.
globalstate
.
use_utility_code
(
MemoryView
.
memviewslice_init_code
)
self
.
globalstate
.
use_utility_code
(
MemoryView
.
memviewslice_init_code
)
self
.
putln
(
"__PYX_INC_MEMVIEW(&%s, %d);"
%
(
slice_cname
,
int
(
have_gil
)))
self
.
putln
(
"__PYX_INC_MEMVIEW(&%s, %d);"
%
(
slice_cname
,
int
(
have_gil
)))
def
put_xdecref_memoryviewslice
(
self
,
slice_cname
,
have_gil
=
False
):
def
put_xdecref_memoryviewslice
(
self
,
slice_cname
,
have_gil
=
False
):
import
MemoryView
from
.
import
MemoryView
self
.
globalstate
.
use_utility_code
(
MemoryView
.
memviewslice_init_code
)
self
.
globalstate
.
use_utility_code
(
MemoryView
.
memviewslice_init_code
)
self
.
putln
(
"__PYX_XDEC_MEMVIEW(&%s, %d);"
%
(
slice_cname
,
int
(
have_gil
)))
self
.
putln
(
"__PYX_XDEC_MEMVIEW(&%s, %d);"
%
(
slice_cname
,
int
(
have_gil
)))
...
@@ -1883,7 +1885,7 @@ class CCodeWriter(object):
...
@@ -1883,7 +1885,7 @@ class CCodeWriter(object):
self
.
put_xgiveref
(
"%s.memview"
%
slice_cname
)
self
.
put_xgiveref
(
"%s.memview"
%
slice_cname
)
def
put_init_to_py_none
(
self
,
cname
,
type
,
nanny
=
True
):
def
put_init_to_py_none
(
self
,
cname
,
type
,
nanny
=
True
):
from
PyrexTypes
import
py_object_type
,
typecast
from
.
PyrexTypes
import
py_object_type
,
typecast
py_none
=
typecast
(
type
,
py_object_type
,
"Py_None"
)
py_none
=
typecast
(
type
,
py_object_type
,
"Py_None"
)
if
nanny
:
if
nanny
:
self
.
putln
(
"%s = %s; __Pyx_INCREF(Py_None);"
%
(
cname
,
py_none
))
self
.
putln
(
"%s = %s; __Pyx_INCREF(Py_None);"
%
(
cname
,
py_none
))
...
@@ -1908,7 +1910,7 @@ class CCodeWriter(object):
...
@@ -1908,7 +1910,7 @@ class CCodeWriter(object):
# that's better than ours.
# that's better than ours.
elif
allow_skip
:
elif
allow_skip
:
return
return
from
TypeSlots
import
method_coexist
from
.
TypeSlots
import
method_coexist
if
entry
.
doc
:
if
entry
.
doc
:
doc_code
=
entry
.
doc_cname
doc_code
=
entry
.
doc_cname
else
:
else
:
...
@@ -1986,7 +1988,7 @@ class CCodeWriter(object):
...
@@ -1986,7 +1988,7 @@ class CCodeWriter(object):
return
self
.
putln
(
"if (%s < 0) %s"
%
(
value
,
self
.
error_goto
(
pos
)))
return
self
.
putln
(
"if (%s < 0) %s"
%
(
value
,
self
.
error_goto
(
pos
)))
def
put_error_if_unbound
(
self
,
pos
,
entry
,
in_nogil_context
=
False
):
def
put_error_if_unbound
(
self
,
pos
,
entry
,
in_nogil_context
=
False
):
import
ExprNodes
from
.
import
ExprNodes
if
entry
.
from_closure
:
if
entry
.
from_closure
:
func
=
'__Pyx_RaiseClosureNameError'
func
=
'__Pyx_RaiseClosureNameError'
self
.
globalstate
.
use_utility_code
(
self
.
globalstate
.
use_utility_code
(
...
...
Cython/Compiler/CodeGeneration.py
View file @
a96882e1
from
Cython.Compiler.Visitor
import
VisitorTransform
from
__future__
import
absolute_import
from
Cython.Compiler.Nodes
import
StatListNode
from
.Visitor
import
VisitorTransform
from
.Nodes
import
StatListNode
class
ExtractPxdCode
(
VisitorTransform
):
class
ExtractPxdCode
(
VisitorTransform
):
"""
"""
...
...
Cython/Compiler/CythonScope.py
View file @
a96882e1
from
Symtab
import
ModuleScope
from
__future__
import
absolute_import
from
PyrexTypes
import
*
from
UtilityCode
import
CythonUtilityCode
from
.Symtab
import
ModuleScope
from
Errors
import
error
from
.PyrexTypes
import
*
from
Scanning
import
StringSourceDescriptor
from
.UtilityCode
import
CythonUtilityCode
import
MemoryView
from
.Errors
import
error
from
.Scanning
import
StringSourceDescriptor
from
.
import
MemoryView
class
CythonScope
(
ModuleScope
):
class
CythonScope
(
ModuleScope
):
is_cython_builtin
=
1
is_cython_builtin
=
1
...
...
Cython/Compiler/Errors.py
View file @
a96882e1
...
@@ -2,15 +2,19 @@
...
@@ -2,15 +2,19 @@
# Errors
# Errors
#
#
from
__future__
import
absolute_import
import
sys
import
sys
from
Cython.Utils
import
open_new_file
import
DebugFlags
from
..Utils
import
open_new_file
import
Options
from
.
import
DebugFlags
from
.
import
Options
class
PyrexError
(
Exception
):
class
PyrexError
(
Exception
):
pass
pass
class
PyrexWarning
(
Exception
):
class
PyrexWarning
(
Exception
):
pass
pass
...
...
Cython/Compiler/ExprNodes.py
View file @
a96882e1
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
# Parse tree nodes for expressions
# Parse tree nodes for expressions
#
#
from
__future__
import
absolute_import
import
cython
import
cython
cython
.
declare
(
error
=
object
,
warning
=
object
,
warn_once
=
object
,
InternalError
=
object
,
cython
.
declare
(
error
=
object
,
warning
=
object
,
warn_once
=
object
,
InternalError
=
object
,
CompileError
=
object
,
UtilityCode
=
object
,
TempitaUtilityCode
=
object
,
CompileError
=
object
,
UtilityCode
=
object
,
TempitaUtilityCode
=
object
,
...
@@ -17,26 +19,26 @@ import sys
...
@@ -17,26 +19,26 @@ import sys
import
copy
import
copy
import
operator
import
operator
from
Errors
import
error
,
warning
,
warn_once
,
InternalError
,
CompileError
from
.
Errors
import
error
,
warning
,
warn_once
,
InternalError
,
CompileError
from
Errors
import
hold_errors
,
release_errors
,
held_errors
,
report_error
from
.
Errors
import
hold_errors
,
release_errors
,
held_errors
,
report_error
from
Code
import
UtilityCode
,
TempitaUtilityCode
from
.
Code
import
UtilityCode
,
TempitaUtilityCode
import
StringEncoding
from
.
import
StringEncoding
import
Naming
from
.
import
Naming
import
Nodes
from
.
import
Nodes
from
Nodes
import
Node
from
.
Nodes
import
Node
import
PyrexTypes
from
.
import
PyrexTypes
from
PyrexTypes
import
py_object_type
,
c_long_type
,
typecast
,
error_type
,
\
from
.
PyrexTypes
import
py_object_type
,
c_long_type
,
typecast
,
error_type
,
\
unspecified_type
unspecified_type
import
TypeSlots
from
.
import
TypeSlots
from
Builtin
import
list_type
,
tuple_type
,
set_type
,
dict_type
,
type_type
,
\
from
.
Builtin
import
list_type
,
tuple_type
,
set_type
,
dict_type
,
type_type
,
\
unicode_type
,
str_type
,
bytes_type
,
bytearray_type
,
basestring_type
,
slice_type
unicode_type
,
str_type
,
bytes_type
,
bytearray_type
,
basestring_type
,
slice_type
import
Builtin
from
.
import
Builtin
import
Symtab
from
.
import
Symtab
from
Cython
import
Utils
from
..
import
Utils
from
Annotate
import
AnnotationItem
from
.
Annotate
import
AnnotationItem
from
Cython.Compiler
import
Future
from
.
import
Future
from
Cython
.Debugging
import
print_call_chain
from
.
.Debugging
import
print_call_chain
from
DebugFlags
import
debug_disposal_code
,
debug_temp_alloc
,
\
from
.
DebugFlags
import
debug_disposal_code
,
debug_temp_alloc
,
\
debug_coercion
debug_coercion
try
:
try
:
...
@@ -726,7 +728,7 @@ class ExprNode(Node):
...
@@ -726,7 +728,7 @@ class ExprNode(Node):
node
.
coerce_to
(
dst_type
,
env
)
node
.
coerce_to
(
dst_type
,
env
)
if
dst_type
.
is_memoryviewslice
:
if
dst_type
.
is_memoryviewslice
:
import
MemoryView
from
.
import
MemoryView
if
not
src
.
type
.
is_memoryviewslice
:
if
not
src
.
type
.
is_memoryviewslice
:
if
src
.
type
.
is_pyobject
:
if
src
.
type
.
is_pyobject
:
src
=
CoerceToMemViewSliceNode
(
src
,
dst_type
,
env
)
src
=
CoerceToMemViewSliceNode
(
src
,
dst_type
,
env
)
...
@@ -1180,7 +1182,7 @@ def _analyse_name_as_type(name, pos, env):
...
@@ -1180,7 +1182,7 @@ def _analyse_name_as_type(name, pos, env):
if
type
is
not
None
:
if
type
is
not
None
:
return
type
return
type
hold_errors
()
hold_errors
()
from
TreeFragment
import
TreeFragment
from
.
TreeFragment
import
TreeFragment
pos
=
(
pos
[
0
],
pos
[
1
],
pos
[
2
]
-
7
)
pos
=
(
pos
[
0
],
pos
[
1
],
pos
[
2
]
-
7
)
try
:
try
:
declaration
=
TreeFragment
(
u"sizeof(%s)"
%
name
,
name
=
pos
[
0
].
filename
,
initial_pos
=
pos
)
declaration
=
TreeFragment
(
u"sizeof(%s)"
%
name
,
name
=
pos
[
0
].
filename
,
initial_pos
=
pos
)
...
@@ -1702,7 +1704,7 @@ class NameNode(AtomicExprNode):
...
@@ -1702,7 +1704,7 @@ class NameNode(AtomicExprNode):
if
entry
:
if
entry
:
entry
.
used
=
1
entry
.
used
=
1
if
entry
.
type
.
is_buffer
:
if
entry
.
type
.
is_buffer
:
import
Buffer
from
.
import
Buffer
Buffer
.
used_buffer_aux_vars
(
entry
)
Buffer
.
used_buffer_aux_vars
(
entry
)
self
.
analyse_rvalue_entry
(
env
)
self
.
analyse_rvalue_entry
(
env
)
return
self
return
self
...
@@ -1726,7 +1728,7 @@ class NameNode(AtomicExprNode):
...
@@ -1726,7 +1728,7 @@ class NameNode(AtomicExprNode):
self
.
type
=
PyrexTypes
.
error_type
self
.
type
=
PyrexTypes
.
error_type
self
.
entry
.
used
=
1
self
.
entry
.
used
=
1
if
self
.
entry
.
type
.
is_buffer
:
if
self
.
entry
.
type
.
is_buffer
:
import
Buffer
from
.
import
Buffer
Buffer
.
used_buffer_aux_vars
(
self
.
entry
)
Buffer
.
used_buffer_aux_vars
(
self
.
entry
)
return
self
return
self
...
@@ -1763,7 +1765,7 @@ class NameNode(AtomicExprNode):
...
@@ -1763,7 +1765,7 @@ class NameNode(AtomicExprNode):
self
.
gil_error
()
self
.
gil_error
()
elif
self
.
entry
.
type
.
is_memoryviewslice
:
elif
self
.
entry
.
type
.
is_memoryviewslice
:
if
self
.
cf_is_null
or
self
.
cf_maybe_null
:
if
self
.
cf_is_null
or
self
.
cf_maybe_null
:
import
MemoryView
from
.
import
MemoryView
MemoryView
.
err_if_nogil_initialized_check
(
self
.
pos
,
env
)
MemoryView
.
err_if_nogil_initialized_check
(
self
.
pos
,
env
)
gil_message
=
"Accessing Python global or builtin"
gil_message
=
"Accessing Python global or builtin"
...
@@ -2051,7 +2053,7 @@ class NameNode(AtomicExprNode):
...
@@ -2051,7 +2053,7 @@ class NameNode(AtomicExprNode):
Slices, coercions from objects, return values etc are new references.
Slices, coercions from objects, return values etc are new references.
We have a borrowed reference in case of dst = src
We have a borrowed reference in case of dst = src
"""
"""
import
MemoryView
from
.
import
MemoryView
MemoryView
.
put_acquire_memoryviewslice
(
MemoryView
.
put_acquire_memoryviewslice
(
lhs_cname
=
self
.
result
(),
lhs_cname
=
self
.
result
(),
...
@@ -2073,7 +2075,7 @@ class NameNode(AtomicExprNode):
...
@@ -2073,7 +2075,7 @@ class NameNode(AtomicExprNode):
rhstmp
=
code
.
funcstate
.
allocate_temp
(
self
.
entry
.
type
,
manage_ref
=
False
)
rhstmp
=
code
.
funcstate
.
allocate_temp
(
self
.
entry
.
type
,
manage_ref
=
False
)
code
.
putln
(
'%s = %s;'
%
(
rhstmp
,
rhs
.
result_as
(
self
.
ctype
())))
code
.
putln
(
'%s = %s;'
%
(
rhstmp
,
rhs
.
result_as
(
self
.
ctype
())))
import
Buffer
from
.
import
Buffer
Buffer
.
put_assign_to_buffer
(
self
.
result
(),
rhstmp
,
self
.
entry
,
Buffer
.
put_assign_to_buffer
(
self
.
result
(),
rhstmp
,
self
.
entry
,
is_initialized
=
not
self
.
lhs_of_first_assignment
,
is_initialized
=
not
self
.
lhs_of_first_assignment
,
pos
=
self
.
pos
,
code
=
code
)
pos
=
self
.
pos
,
code
=
code
)
...
@@ -2829,7 +2831,6 @@ class IndexNode(ExprNode):
...
@@ -2829,7 +2831,6 @@ class IndexNode(ExprNode):
template_values
=
self
.
index
.
args
template_values
=
self
.
index
.
args
else
:
else
:
template_values
=
[
self
.
index
]
template_values
=
[
self
.
index
]
import
Nodes
type_node
=
Nodes
.
TemplatedTypeNode
(
type_node
=
Nodes
.
TemplatedTypeNode
(
pos
=
self
.
pos
,
pos
=
self
.
pos
,
positional_args
=
template_values
,
positional_args
=
template_values
,
...
@@ -2989,7 +2990,7 @@ class IndexNode(ExprNode):
...
@@ -2989,7 +2990,7 @@ class IndexNode(ExprNode):
elif
is_memslice
:
elif
is_memslice
:
# memoryviewslice indexing or slicing
# memoryviewslice indexing or slicing
import
MemoryView
from
.
import
MemoryView
skip_child_analysis
=
True
skip_child_analysis
=
True
newaxes
=
[
newaxis
for
newaxis
in
indices
if
newaxis
.
is_none
]
newaxes
=
[
newaxis
for
newaxis
in
indices
if
newaxis
.
is_none
]
...
@@ -3682,7 +3683,7 @@ class IndexNode(ExprNode):
...
@@ -3682,7 +3683,7 @@ class IndexNode(ExprNode):
self
.
free_subexpr_temps
(
code
)
self
.
free_subexpr_temps
(
code
)
def
buffer_entry
(
self
):
def
buffer_entry
(
self
):
import
Buffer
,
MemoryView
from
.
import
Buffer
,
MemoryView
base
=
self
.
base
base
=
self
.
base
if
self
.
base
.
is_nonecheck
:
if
self
.
base
.
is_nonecheck
:
...
@@ -3713,7 +3714,7 @@ class IndexNode(ExprNode):
...
@@ -3713,7 +3714,7 @@ class IndexNode(ExprNode):
code
.
putln
(
"%s = %s;"
%
(
temp
,
index
.
result
()))
code
.
putln
(
"%s = %s;"
%
(
temp
,
index
.
result
()))
# Generate buffer access code using these temps
# Generate buffer access code using these temps
import
Buffer
from
.
import
Buffer
buffer_entry
=
self
.
buffer_entry
()
buffer_entry
=
self
.
buffer_entry
()
if
buffer_entry
.
type
.
is_buffer
:
if
buffer_entry
.
type
.
is_buffer
:
negative_indices
=
buffer_entry
.
type
.
negative_indices
negative_indices
=
buffer_entry
.
type
.
negative_indices
...
@@ -3759,12 +3760,12 @@ class IndexNode(ExprNode):
...
@@ -3759,12 +3760,12 @@ class IndexNode(ExprNode):
def
generate_memoryviewslice_setslice_code
(
self
,
rhs
,
code
):
def
generate_memoryviewslice_setslice_code
(
self
,
rhs
,
code
):
"memslice1[...] = memslice2 or memslice1[:] = memslice2"
"memslice1[...] = memslice2 or memslice1[:] = memslice2"
import
MemoryView
from
.
import
MemoryView
MemoryView
.
copy_broadcast_memview_src_to_dst
(
rhs
,
self
,
code
)
MemoryView
.
copy_broadcast_memview_src_to_dst
(
rhs
,
self
,
code
)
def
generate_memoryviewslice_assign_scalar_code
(
self
,
rhs
,
code
):
def
generate_memoryviewslice_assign_scalar_code
(
self
,
rhs
,
code
):
"memslice1[...] = 0.0 or memslice1[:] = 0.0"
"memslice1[...] = 0.0 or memslice1[:] = 0.0"
import
MemoryView
from
.
import
MemoryView
MemoryView
.
assign_scalar
(
self
,
rhs
,
code
)
MemoryView
.
assign_scalar
(
self
,
rhs
,
code
)
...
@@ -5027,7 +5028,7 @@ class GeneralCallNode(CallNode):
...
@@ -5027,7 +5028,7 @@ class GeneralCallNode(CallNode):
# match keyword arguments that are passed out-of-order, but keep
# match keyword arguments that are passed out-of-order, but keep
# the evaluation of non-simple arguments in order by moving them
# the evaluation of non-simple arguments in order by moving them
# into temps
# into temps
from
Cython.Compiler
.UtilNodes
import
EvalWithTempExprNode
,
LetRefNode
from
.UtilNodes
import
EvalWithTempExprNode
,
LetRefNode
temps
=
[]
temps
=
[]
if
len
(
kwargs
.
key_value_pairs
)
>
matched_kwargs_count
:
if
len
(
kwargs
.
key_value_pairs
)
>
matched_kwargs_count
:
unmatched_args
=
declared_args
[
len
(
args
):]
unmatched_args
=
declared_args
[
len
(
args
):]
...
@@ -5489,7 +5490,7 @@ class AttributeNode(ExprNode):
...
@@ -5489,7 +5490,7 @@ class AttributeNode(ExprNode):
if
self
.
is_py_attr
:
if
self
.
is_py_attr
:
self
.
gil_error
()
self
.
gil_error
()
elif
self
.
type
.
is_memoryviewslice
:
elif
self
.
type
.
is_memoryviewslice
:
import
MemoryView
from
.
import
MemoryView
MemoryView
.
err_if_nogil_initialized_check
(
self
.
pos
,
env
,
'attribute'
)
MemoryView
.
err_if_nogil_initialized_check
(
self
.
pos
,
env
,
'attribute'
)
gil_message
=
"Accessing Python attribute"
gil_message
=
"Accessing Python attribute"
...
@@ -5634,7 +5635,7 @@ class AttributeNode(ExprNode):
...
@@ -5634,7 +5635,7 @@ class AttributeNode(ExprNode):
code
.
put_gotref
(
select_code
)
code
.
put_gotref
(
select_code
)
code
.
put_decref
(
select_code
,
self
.
ctype
())
code
.
put_decref
(
select_code
,
self
.
ctype
())
elif
self
.
type
.
is_memoryviewslice
:
elif
self
.
type
.
is_memoryviewslice
:
import
MemoryView
from
.
import
MemoryView
MemoryView
.
put_assign_to_memviewslice
(
MemoryView
.
put_assign_to_memviewslice
(
select_code
,
rhs
,
rhs
.
result
(),
self
.
type
,
code
)
select_code
,
rhs
,
rhs
.
result
(),
self
.
type
,
code
)
...
@@ -8536,7 +8537,7 @@ class CythonArrayNode(ExprNode):
...
@@ -8536,7 +8537,7 @@ class CythonArrayNode(ExprNode):
shape_type
=
PyrexTypes
.
c_py_ssize_t_type
shape_type
=
PyrexTypes
.
c_py_ssize_t_type
def
analyse_types
(
self
,
env
):
def
analyse_types
(
self
,
env
):
import
MemoryView
from
.
import
MemoryView
self
.
operand
=
self
.
operand
.
analyse_types
(
env
)
self
.
operand
=
self
.
operand
.
analyse_types
(
env
)
if
self
.
array_dtype
:
if
self
.
array_dtype
:
...
@@ -8653,7 +8654,7 @@ class CythonArrayNode(ExprNode):
...
@@ -8653,7 +8654,7 @@ class CythonArrayNode(ExprNode):
return
env
.
global_scope
().
context
.
cython_scope
.
viewscope
.
lookup
(
"array"
).
type
return
env
.
global_scope
().
context
.
cython_scope
.
viewscope
.
lookup
(
"array"
).
type
def
generate_result_code
(
self
,
code
):
def
generate_result_code
(
self
,
code
):
import
Buffer
from
.
import
Buffer
shapes
=
[
self
.
shape_type
.
cast_code
(
shape
.
result
())
shapes
=
[
self
.
shape_type
.
cast_code
(
shape
.
result
())
for
shape
in
self
.
shapes
]
for
shape
in
self
.
shapes
]
...
...
Cython/Compiler/FlowControl.pxd
View file @
a96882e1
from
__future__
import
absolute_import
cimport
cython
cimport
cython
from
Cython.Compiler
.Visitor
cimport
CythonTransform
,
TreeVisitor
from
.Visitor
cimport
CythonTransform
,
TreeVisitor
cdef
class
ControlBlock
:
cdef
class
ControlBlock
:
cdef
public
set
children
cdef
public
set
children
...
...
Cython/Compiler/FlowControl.py
View file @
a96882e1
from
__future__
import
absolute_import
import
cython
import
cython
cython
.
declare
(
PyrexTypes
=
object
,
ExprNodes
=
object
,
Nodes
=
object
,
cython
.
declare
(
PyrexTypes
=
object
,
ExprNodes
=
object
,
Nodes
=
object
,
Builtin
=
object
,
InternalError
=
object
,
Builtin
=
object
,
InternalError
=
object
,
...
@@ -6,15 +8,15 @@ cython.declare(PyrexTypes=object, ExprNodes=object, Nodes=object,
...
@@ -6,15 +8,15 @@ cython.declare(PyrexTypes=object, ExprNodes=object, Nodes=object,
object_expr
=
object
,
object_expr_not_none
=
object
,
object_expr
=
object
,
object_expr_not_none
=
object
,
fake_rhs_expr
=
object
,
TypedExprNode
=
object
)
fake_rhs_expr
=
object
,
TypedExprNode
=
object
)
import
Builtin
from
.
import
Builtin
import
ExprNodes
from
.
import
ExprNodes
import
Nodes
from
.
import
Nodes
import
Options
from
.
import
Options
from
PyrexTypes
import
py_object_type
,
unspecified_type
from
.
PyrexTypes
import
py_object_type
,
unspecified_type
import
PyrexTypes
from
.
import
PyrexTypes
from
Visitor
import
TreeVisitor
,
CythonTransform
from
.
Visitor
import
TreeVisitor
,
CythonTransform
from
Errors
import
error
,
warning
,
InternalError
from
.
Errors
import
error
,
warning
,
InternalError
class
TypedExprNode
(
ExprNodes
.
ExprNode
):
class
TypedExprNode
(
ExprNodes
.
ExprNode
):
# Used for declaring assignments of a specified type without a known entry.
# Used for declaring assignments of a specified type without a known entry.
...
...
Cython/Compiler/FusedNode.py
View file @
a96882e1
from
__future__
import
absolute_import
import
copy
import
copy
from
Cython.Compiler
import
(
ExprNodes
,
PyrexTypes
,
MemoryView
,
from
.
import
(
ExprNodes
,
PyrexTypes
,
MemoryView
,
ParseTreeTransforms
,
StringEncoding
,
ParseTreeTransforms
,
StringEncoding
,
Errors
)
Errors
)
from
.ExprNodes
import
CloneNode
,
ProxyNode
,
TupleNode
from
Cython.Compiler.ExprNodes
import
CloneNode
,
ProxyNode
,
TupleNode
from
.Nodes
import
FuncDefNode
,
CFuncDefNode
,
StatListNode
,
DefNode
from
Cython.Compiler.Nodes
import
(
FuncDefNode
,
CFuncDefNode
,
StatListNode
,
DefNode
)
class
FusedCFuncDefNode
(
StatListNode
):
class
FusedCFuncDefNode
(
StatListNode
):
"""
"""
...
@@ -384,7 +385,6 @@ class FusedCFuncDefNode(StatListNode):
...
@@ -384,7 +385,6 @@ class FusedCFuncDefNode(StatListNode):
to each specialization, which obtains the buffer each time and tries
to each specialization, which obtains the buffer each time and tries
to match the format string.
to match the format string.
"""
"""
from
Cython.Compiler
import
ExprNodes
if
buffer_types
:
if
buffer_types
:
if
pyx_code
.
indenter
(
u"else:"
):
if
pyx_code
.
indenter
(
u"else:"
):
# The first thing to find a match in this loop breaks out of the loop
# The first thing to find a match in this loop breaks out of the loop
...
@@ -520,7 +520,7 @@ class FusedCFuncDefNode(StatListNode):
...
@@ -520,7 +520,7 @@ class FusedCFuncDefNode(StatListNode):
arg tuple and kwargs dict (or None) and the defaults tuple
arg tuple and kwargs dict (or None) and the defaults tuple
as arguments from the Binding Fused Function's tp_call.
as arguments from the Binding Fused Function's tp_call.
"""
"""
from
Cython.Compiler
import
TreeFragment
,
Code
,
MemoryView
,
UtilityCode
from
.
import
TreeFragment
,
Code
,
UtilityCode
# { (arg_pos, FusedType) : specialized_type }
# { (arg_pos, FusedType) : specialized_type }
seen_fused_types
=
set
()
seen_fused_types
=
set
()
...
...
Cython/Compiler/Interpreter.py
View file @
a96882e1
...
@@ -6,9 +6,11 @@ For now this only covers parse tree to value conversion of
...
@@ -6,9 +6,11 @@ For now this only covers parse tree to value conversion of
compile-time values.
compile-time values.
"""
"""
from
Nodes
import
*
from
__future__
import
absolute_import
from
ExprNodes
import
*
from
Errors
import
CompileError
from
.Nodes
import
*
from
.ExprNodes
import
*
from
.Errors
import
CompileError
class
EmptyScope
(
object
):
class
EmptyScope
(
object
):
...
...
Cython/Compiler/Lexicon.py
View file @
a96882e1
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
# Cython Scanner - Lexical Definitions
# Cython Scanner - Lexical Definitions
#
#
from
__future__
import
absolute_import
raw_prefixes
=
"rR"
raw_prefixes
=
"rR"
bytes_prefixes
=
"bB"
bytes_prefixes
=
"bB"
string_prefixes
=
"uU"
+
bytes_prefixes
string_prefixes
=
"uU"
+
bytes_prefixes
...
@@ -12,10 +14,10 @@ IDENT = 'IDENT'
...
@@ -12,10 +14,10 @@ IDENT = 'IDENT'
def
make_lexicon
():
def
make_lexicon
():
from
Cython
.Plex
import
\
from
.
.Plex
import
\
Str
,
Any
,
AnyBut
,
AnyChar
,
Rep
,
Rep1
,
Opt
,
Bol
,
Eol
,
Eof
,
\
Str
,
Any
,
AnyBut
,
AnyChar
,
Rep
,
Rep1
,
Opt
,
Bol
,
Eol
,
Eof
,
\
TEXT
,
IGNORE
,
State
,
Lexicon
TEXT
,
IGNORE
,
State
,
Lexicon
from
Scanning
import
Method
from
.
Scanning
import
Method
letter
=
Any
(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"
)
letter
=
Any
(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"
)
digit
=
Any
(
"0123456789"
)
digit
=
Any
(
"0123456789"
)
...
...
Cython/Compiler/Main.py
View file @
a96882e1
...
@@ -2,23 +2,29 @@
...
@@ -2,23 +2,29 @@
# Cython Top Level
# Cython Top Level
#
#
import
os
,
sys
,
re
,
codecs
from
__future__
import
absolute_import
import
os
import
re
import
sys
import
codecs
if
sys
.
version_info
[:
2
]
<
(
2
,
6
)
or
(
3
,
0
)
<=
sys
.
version_info
[:
2
]
<
(
3
,
2
):
if
sys
.
version_info
[:
2
]
<
(
2
,
6
)
or
(
3
,
0
)
<=
sys
.
version_info
[:
2
]
<
(
3
,
2
):
sys
.
stderr
.
write
(
"Sorry, Cython requires Python 2.6+ or 3.2+, found %d.%d
\
n
"
%
tuple
(
sys
.
version_info
[:
2
]))
sys
.
stderr
.
write
(
"Sorry, Cython requires Python 2.6+ or 3.2+, found %d.%d
\
n
"
%
tuple
(
sys
.
version_info
[:
2
]))
sys
.
exit
(
1
)
sys
.
exit
(
1
)
import
Errors
from
.
import
Errors
# Do not import Parsing here, import it when needed, because Parsing imports
# Do not import Parsing here, import it when needed, because Parsing imports
# Nodes, which globally needs debug command line options initialized to set a
# Nodes, which globally needs debug command line options initialized to set a
# conditional metaclass. These options are processed by CmdLine called from
# conditional metaclass. These options are processed by CmdLine called from
# main() in this file.
# main() in this file.
# import Parsing
# import Parsing
import
Version
from
.Scanning
import
PyrexScanner
,
FileSourceDescriptor
from
Scanning
import
PyrexScanner
,
FileSourceDescriptor
from
.Errors
import
PyrexError
,
CompileError
,
error
,
warning
from
Errors
import
PyrexError
,
CompileError
,
error
,
warning
from
.Symtab
import
ModuleScope
from
Symtab
import
ModuleScope
from
..
import
__version__
as
version
from
Cython
import
Utils
from
..
import
Utils
import
Options
from
.
import
Options
module_name_pattern
=
re
.
compile
(
r"[A-Za-z_][A-Za-z0-9_]*(\
.[A-Z
a-z_][A-Za-z0-9_]*)*$"
)
module_name_pattern
=
re
.
compile
(
r"[A-Za-z_][A-Za-z0-9_]*(\
.[A-Z
a-z_][A-Za-z0-9_]*)*$"
)
...
@@ -58,7 +64,7 @@ class Context(object):
...
@@ -58,7 +64,7 @@ class Context(object):
# an infinite loop.
# an infinite loop.
# Better code organization would fix it.
# Better code organization would fix it.
import
Builtin
,
CythonScope
from
.
import
Builtin
,
CythonScope
self
.
modules
=
{
"__builtin__"
:
Builtin
.
builtin_scope
}
self
.
modules
=
{
"__builtin__"
:
Builtin
.
builtin_scope
}
self
.
cython_scope
=
CythonScope
.
create_cython_scope
(
self
)
self
.
cython_scope
=
CythonScope
.
create_cython_scope
(
self
)
self
.
modules
[
"cython"
]
=
self
.
cython_scope
self
.
modules
[
"cython"
]
=
self
.
cython_scope
...
@@ -81,14 +87,14 @@ class Context(object):
...
@@ -81,14 +87,14 @@ class Context(object):
def
set_language_level
(
self
,
level
):
def
set_language_level
(
self
,
level
):
self
.
language_level
=
level
self
.
language_level
=
level
if
level
>=
3
:
if
level
>=
3
:
from
Future
import
print_function
,
unicode_literals
,
absolute_import
from
.
Future
import
print_function
,
unicode_literals
,
absolute_import
self
.
future_directives
.
update
([
print_function
,
unicode_literals
,
absolute_import
])
self
.
future_directives
.
update
([
print_function
,
unicode_literals
,
absolute_import
])
self
.
modules
[
'builtins'
]
=
self
.
modules
[
'__builtin__'
]
self
.
modules
[
'builtins'
]
=
self
.
modules
[
'__builtin__'
]
# pipeline creation functions can now be found in Pipeline.py
# pipeline creation functions can now be found in Pipeline.py
def
process_pxd
(
self
,
source_desc
,
scope
,
module_name
):
def
process_pxd
(
self
,
source_desc
,
scope
,
module_name
):
import
Pipeline
from
.
import
Pipeline
if
isinstance
(
source_desc
,
FileSourceDescriptor
)
and
source_desc
.
_file_type
==
'pyx'
:
if
isinstance
(
source_desc
,
FileSourceDescriptor
)
and
source_desc
.
_file_type
==
'pyx'
:
source
=
CompilationSource
(
source_desc
,
module_name
,
os
.
getcwd
())
source
=
CompilationSource
(
source_desc
,
module_name
,
os
.
getcwd
())
result_sink
=
create_default_resultobj
(
source
,
self
.
options
)
result_sink
=
create_default_resultobj
(
source
,
self
.
options
)
...
@@ -294,7 +300,7 @@ class Context(object):
...
@@ -294,7 +300,7 @@ class Context(object):
try
:
try
:
f
=
Utils
.
open_source_file
(
source_filename
,
"rU"
)
f
=
Utils
.
open_source_file
(
source_filename
,
"rU"
)
try
:
try
:
import
Parsing
from
.
import
Parsing
s
=
PyrexScanner
(
f
,
source_desc
,
source_encoding
=
f
.
encoding
,
s
=
PyrexScanner
(
f
,
source_desc
,
source_encoding
=
f
.
encoding
,
scope
=
scope
,
context
=
self
)
scope
=
scope
,
context
=
self
)
tree
=
Parsing
.
p_module
(
s
,
pxd
,
full_module_name
)
tree
=
Parsing
.
p_module
(
s
,
pxd
,
full_module_name
)
...
@@ -391,7 +397,7 @@ def create_default_resultobj(compilation_source, options):
...
@@ -391,7 +397,7 @@ def create_default_resultobj(compilation_source, options):
return
result
return
result
def
run_pipeline
(
source
,
options
,
full_module_name
=
None
,
context
=
None
):
def
run_pipeline
(
source
,
options
,
full_module_name
=
None
,
context
=
None
):
import
Pipeline
from
.
import
Pipeline
source_ext
=
os
.
path
.
splitext
(
source
)[
1
]
source_ext
=
os
.
path
.
splitext
(
source
)[
1
]
options
.
configure_language_defaults
(
source_ext
[
1
:])
# py/pyx
options
.
configure_language_defaults
(
source_ext
[
1
:])
# py/pyx
...
@@ -619,14 +625,14 @@ def main(command_line = 0):
...
@@ -619,14 +625,14 @@ def main(command_line = 0):
args
=
sys
.
argv
[
1
:]
args
=
sys
.
argv
[
1
:]
any_failures
=
0
any_failures
=
0
if
command_line
:
if
command_line
:
from
CmdLine
import
parse_command_line
from
.
CmdLine
import
parse_command_line
options
,
sources
=
parse_command_line
(
args
)
options
,
sources
=
parse_command_line
(
args
)
else
:
else
:
options
=
CompilationOptions
(
default_options
)
options
=
CompilationOptions
(
default_options
)
sources
=
args
sources
=
args
if
options
.
show_version
:
if
options
.
show_version
:
sys
.
stderr
.
write
(
"Cython version %s
\
n
"
%
Version
.
version
)
sys
.
stderr
.
write
(
"Cython version %s
\
n
"
%
version
)
if
options
.
working_path
!=
""
:
if
options
.
working_path
!=
""
:
os
.
chdir
(
options
.
working_path
)
os
.
chdir
(
options
.
working_path
)
try
:
try
:
...
...
Cython/Compiler/MemoryView.py
View file @
a96882e1
from
Errors
import
CompileError
,
error
from
__future__
import
absolute_import
import
ExprNodes
from
ExprNodes
import
IntNode
,
NameNode
,
AttributeNode
from
.Errors
import
CompileError
,
error
import
Options
from
.
import
ExprNodes
from
Code
import
UtilityCode
,
TempitaUtilityCode
from
.ExprNodes
import
IntNode
,
NameNode
,
AttributeNode
from
UtilityCode
import
CythonUtilityCode
from
.
import
Options
import
Buffer
from
.Code
import
UtilityCode
,
TempitaUtilityCode
import
PyrexTypes
from
.UtilityCode
import
CythonUtilityCode
import
ModuleNode
from
.
import
Buffer
from
.
import
PyrexTypes
from
.
import
ModuleNode
START_ERR
=
"Start must not be given."
START_ERR
=
"Start must not be given."
STOP_ERR
=
"Axis specification only allowed in the 'step' slot."
STOP_ERR
=
"Axis specification only allowed in the 'step' slot."
...
@@ -75,7 +77,7 @@ def put_init_entry(mv_cname, code):
...
@@ -75,7 +77,7 @@ def put_init_entry(mv_cname, code):
def
mangle_dtype_name
(
dtype
):
def
mangle_dtype_name
(
dtype
):
# a dumb wrapper for now; move Buffer.mangle_dtype_name in here later?
# a dumb wrapper for now; move Buffer.mangle_dtype_name in here later?
import
Buffer
from
.
import
Buffer
return
Buffer
.
mangle_dtype_name
(
dtype
)
return
Buffer
.
mangle_dtype_name
(
dtype
)
#def axes_to_str(axes):
#def axes_to_str(axes):
...
@@ -949,4 +951,4 @@ view_utility_whitelist = ('array', 'memoryview', 'array_cwrapper',
...
@@ -949,4 +951,4 @@ view_utility_whitelist = ('array', 'memoryview', 'array_cwrapper',
'indirect_contiguous'
)
'indirect_contiguous'
)
memviewslice_declare_code
.
requires
.
append
(
view_utility_code
)
memviewslice_declare_code
.
requires
.
append
(
view_utility_code
)
copy_contents_new_utility
.
requires
.
append
(
view_utility_code
)
copy_contents_new_utility
.
requires
.
append
(
view_utility_code
)
\ No newline at end of file
Cython/Compiler/ModuleNode.py
View file @
a96882e1
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
# Module parse tree node
# Module parse tree node
#
#
from
__future__
import
absolute_import
import
cython
import
cython
cython
.
declare
(
Naming
=
object
,
Options
=
object
,
PyrexTypes
=
object
,
TypeSlots
=
object
,
cython
.
declare
(
Naming
=
object
,
Options
=
object
,
PyrexTypes
=
object
,
TypeSlots
=
object
,
error
=
object
,
warning
=
object
,
py_object_type
=
object
,
UtilityCode
=
object
,
error
=
object
,
warning
=
object
,
py_object_type
=
object
,
UtilityCode
=
object
,
...
@@ -9,23 +11,23 @@ cython.declare(Naming=object, Options=object, PyrexTypes=object, TypeSlots=objec
...
@@ -9,23 +11,23 @@ cython.declare(Naming=object, Options=object, PyrexTypes=object, TypeSlots=objec
import
os
import
os
import
operator
import
operator
from
PyrexTypes
import
CPtrType
from
.
PyrexTypes
import
CPtrType
import
Future
from
.
import
Future
import
Annotate
from
.
import
Annotate
import
Code
from
.
import
Code
import
Naming
from
.
import
Naming
import
Nodes
from
.
import
Nodes
import
Options
from
.
import
Options
import
TypeSlots
from
.
import
TypeSlots
import
Version
from
.
import
Version
import
PyrexTypes
from
.
import
PyrexTypes
from
Errors
import
error
,
warning
from
.
Errors
import
error
,
warning
from
PyrexTypes
import
py_object_type
from
.
PyrexTypes
import
py_object_type
from
Cython
.Utils
import
open_new_file
,
replace_suffix
,
decode_filename
from
.
.Utils
import
open_new_file
,
replace_suffix
,
decode_filename
from
Code
import
UtilityCode
from
.
Code
import
UtilityCode
from
StringEncoding
import
EncodedString
from
.
StringEncoding
import
EncodedString
...
@@ -455,7 +457,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -455,7 +457,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
key
in
vtab_dict
:
if
key
in
vtab_dict
:
# FIXME: this should *never* happen, but apparently it does
# FIXME: this should *never* happen, but apparently it does
# for Cython generated utility code
# for Cython generated utility code
from
Cython.Compiler
.UtilityCode
import
NonManglingModuleScope
from
.UtilityCode
import
NonManglingModuleScope
assert
isinstance
(
entry
.
scope
,
NonManglingModuleScope
),
str
(
entry
.
scope
)
assert
isinstance
(
entry
.
scope
,
NonManglingModuleScope
),
str
(
entry
.
scope
)
assert
isinstance
(
vtab_dict
[
key
].
scope
,
NonManglingModuleScope
),
str
(
vtab_dict
[
key
].
scope
)
assert
isinstance
(
vtab_dict
[
key
].
scope
,
NonManglingModuleScope
),
str
(
vtab_dict
[
key
].
scope
)
else
:
else
:
...
@@ -577,7 +579,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -577,7 +579,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"#else"
)
code
.
putln
(
"#else"
)
code
.
globalstate
[
"end"
].
putln
(
"#endif /* Py_PYTHON_H */"
)
code
.
globalstate
[
"end"
].
putln
(
"#endif /* Py_PYTHON_H */"
)
from
Cython
import
__version__
from
..
import
__version__
code
.
putln
(
'#define CYTHON_ABI "%s"'
%
__version__
.
replace
(
'.'
,
'_'
))
code
.
putln
(
'#define CYTHON_ABI "%s"'
%
__version__
.
replace
(
'.'
,
'_'
))
code
.
put
(
UtilityCode
.
load_as_string
(
"CModulePreamble"
,
"ModuleSetupCode.c"
)[
1
])
code
.
put
(
UtilityCode
.
load_as_string
(
"CModulePreamble"
,
"ModuleSetupCode.c"
)[
1
])
...
...
Cython/Compiler/Nodes.py
View file @
a96882e1
This diff is collapsed.
Click to expand it.
Cython/Compiler/Optimize.py
View file @
a96882e1
from
Cython.Compiler
import
TypeSlots
from
__future__
import
absolute_import
from
Cython.Compiler.ExprNodes
import
not_a_constant
from
.
import
TypeSlots
from
.ExprNodes
import
not_a_constant
import
cython
import
cython
cython
.
declare
(
UtilityCode
=
object
,
EncodedString
=
object
,
BytesLiteral
=
object
,
cython
.
declare
(
UtilityCode
=
object
,
EncodedString
=
object
,
BytesLiteral
=
object
,
Nodes
=
object
,
ExprNodes
=
object
,
PyrexTypes
=
object
,
Builtin
=
object
,
Nodes
=
object
,
ExprNodes
=
object
,
PyrexTypes
=
object
,
Builtin
=
object
,
UtilNodes
=
object
,
Naming
=
object
)
UtilNodes
=
object
)
import
Nodes
from
.
import
Nodes
import
ExprNodes
from
.
import
ExprNodes
import
PyrexTypes
from
.
import
PyrexTypes
import
Visitor
from
.
import
Visitor
import
Builtin
from
.
import
Builtin
import
UtilNodes
from
.
import
UtilNodes
import
Options
from
.
import
Options
import
Naming
from
.Code
import
UtilityCode
from
Code
import
UtilityCode
from
.StringEncoding
import
EncodedString
,
BytesLiteral
from
StringEncoding
import
EncodedString
,
BytesLiteral
from
.Errors
import
error
from
Errors
import
error
from
.ParseTreeTransforms
import
SkipDeclarations
from
ParseTreeTransforms
import
SkipDeclarations
import
copy
import
copy
import
codecs
import
codecs
...
...
Cython/Compiler/Options.py
View file @
a96882e1
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
# Cython - Compilation-wide options and pragma declarations
# Cython - Compilation-wide options and pragma declarations
#
#
from
__future__
import
absolute_import
# Perform lookups on builtin names only once, at module initialisation
# Perform lookups on builtin names only once, at module initialisation
# time. This will prevent the module from getting imported if a
# time. This will prevent the module from getting imported if a
# builtin name that it uses cannot be found during initialisation.
# builtin name that it uses cannot be found during initialisation.
...
...
Cython/Compiler/ParseTreeTransforms.pxd
View file @
a96882e1
from
__future__
import
absolute_import
cimport
cython
cimport
cython
from
Cython.Compiler
.Visitor
cimport
(
from
.Visitor
cimport
(
CythonTransform
,
VisitorTransform
,
TreeVisitor
,
CythonTransform
,
VisitorTransform
,
TreeVisitor
,
ScopeTrackingTransform
,
EnvTransform
)
ScopeTrackingTransform
,
EnvTransform
)
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
a96882e1
from
__future__
import
absolute_import
import
copy
import
cython
import
cython
cython
.
declare
(
PyrexTypes
=
object
,
Naming
=
object
,
ExprNodes
=
object
,
Nodes
=
object
,
cython
.
declare
(
PyrexTypes
=
object
,
Naming
=
object
,
ExprNodes
=
object
,
Nodes
=
object
,
Options
=
object
,
UtilNodes
=
object
,
LetNode
=
object
,
Options
=
object
,
UtilNodes
=
object
,
LetNode
=
object
,
LetRefNode
=
object
,
TreeFragment
=
object
,
EncodedString
=
object
,
LetRefNode
=
object
,
TreeFragment
=
object
,
EncodedString
=
object
,
error
=
object
,
warning
=
object
,
copy
=
object
)
error
=
object
,
warning
=
object
,
copy
=
object
)
import
PyrexTypes
from
.
import
PyrexTypes
import
Naming
from
.
import
Naming
import
ExprNodes
from
.
import
ExprNodes
import
Nodes
from
.
import
Nodes
import
Options
from
.
import
Options
import
Builtin
from
.
import
Builtin
from
Cython.Compiler.Visitor
import
VisitorTransform
,
TreeVisitor
from
Cython.Compiler.Visitor
import
CythonTransform
,
EnvTransform
,
ScopeTrackingTransform
from
Cython.Compiler.UtilNodes
import
LetNode
,
LetRefNode
,
ResultRefNode
from
Cython.Compiler.TreeFragment
import
TreeFragment
from
Cython.Compiler.StringEncoding
import
EncodedString
from
Cython.Compiler.Errors
import
error
,
warning
,
CompileError
,
InternalError
from
Cython.Compiler.Code
import
UtilityCode
import
copy
from
.Visitor
import
VisitorTransform
,
TreeVisitor
from
.Visitor
import
CythonTransform
,
EnvTransform
,
ScopeTrackingTransform
from
.UtilNodes
import
LetNode
,
LetRefNode
,
ResultRefNode
from
.TreeFragment
import
TreeFragment
from
.StringEncoding
import
EncodedString
from
.Errors
import
error
,
warning
,
CompileError
,
InternalError
from
.Code
import
UtilityCode
class
NameNodeCollector
(
TreeVisitor
):
class
NameNodeCollector
(
TreeVisitor
):
...
@@ -1526,7 +1528,7 @@ if VALUE is not None:
...
@@ -1526,7 +1528,7 @@ if VALUE is not None:
def
_create_fused_function
(
self
,
env
,
node
):
def
_create_fused_function
(
self
,
env
,
node
):
"Create a fused function for a DefNode with fused arguments"
"Create a fused function for a DefNode with fused arguments"
from
Cython.Compiler
import
FusedNode
from
.
import
FusedNode
if
self
.
fused_function
or
self
.
in_lambda
:
if
self
.
fused_function
or
self
.
in_lambda
:
if
self
.
fused_function
not
in
self
.
fused_error_funcs
:
if
self
.
fused_function
not
in
self
.
fused_error_funcs
:
...
@@ -2540,8 +2542,8 @@ class TransformBuiltinMethods(EnvTransform):
...
@@ -2540,8 +2542,8 @@ class TransformBuiltinMethods(EnvTransform):
if
attribute
==
u'compiled'
:
if
attribute
==
u'compiled'
:
node
=
ExprNodes
.
BoolNode
(
node
.
pos
,
value
=
True
)
node
=
ExprNodes
.
BoolNode
(
node
.
pos
,
value
=
True
)
elif
attribute
==
u'__version__'
:
elif
attribute
==
u'__version__'
:
import
Cyth
on
from
..
import
__version__
as
versi
on
node
=
ExprNodes
.
StringNode
(
node
.
pos
,
value
=
EncodedString
(
Cython
.
__version__
))
node
=
ExprNodes
.
StringNode
(
node
.
pos
,
value
=
EncodedString
(
version
))
elif
attribute
==
u'NULL'
:
elif
attribute
==
u'NULL'
:
node
=
ExprNodes
.
NullNode
(
node
.
pos
)
node
=
ExprNodes
.
NullNode
(
node
.
pos
)
elif
attribute
in
(
u'set'
,
u'frozenset'
):
elif
attribute
in
(
u'set'
,
u'frozenset'
):
...
@@ -2740,8 +2742,8 @@ class ReplaceFusedTypeChecks(VisitorTransform):
...
@@ -2740,8 +2742,8 @@ class ReplaceFusedTypeChecks(VisitorTransform):
super
(
ReplaceFusedTypeChecks
,
self
).
__init__
()
super
(
ReplaceFusedTypeChecks
,
self
).
__init__
()
self
.
local_scope
=
local_scope
self
.
local_scope
=
local_scope
# defer the import until now to avoid circular import time dependencies
# defer the import until now to avoid circular import time dependencies
from
Cython.Compiler
import
Optimize
from
.Optimize
import
ConstantFolding
self
.
transform
=
Optimize
.
ConstantFolding
(
reevaluate
=
True
)
self
.
transform
=
ConstantFolding
(
reevaluate
=
True
)
def
visit_IfStatNode
(
self
,
node
):
def
visit_IfStatNode
(
self
,
node
):
"""
"""
...
...
Cython/Compiler/Parsing.pxd
View file @
a96882e1
# We declare all of these here to type the first argument.
# We declare all of these here to type the first argument.
from
__future__
import
absolute_import
cimport
cython
cimport
cython
from
Cython.Compiler
.Scanning
cimport
PyrexScanner
from
.Scanning
cimport
PyrexScanner
ctypedef
object
(
*
p_sub_expr_func
)(
PyrexScanner
obj
)
ctypedef
object
(
*
p_sub_expr_func
)(
PyrexScanner
obj
)
...
...
Cython/Compiler/Parsing.py
View file @
a96882e1
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
# Parser
# Parser
#
#
from
__future__
import
absolute_import
# This should be done automatically
# This should be done automatically
import
cython
import
cython
cython
.
declare
(
Nodes
=
object
,
ExprNodes
=
object
,
EncodedString
=
object
,
cython
.
declare
(
Nodes
=
object
,
ExprNodes
=
object
,
EncodedString
=
object
,
...
@@ -15,17 +17,18 @@ cython.declare(Nodes=object, ExprNodes=object, EncodedString=object,
...
@@ -15,17 +17,18 @@ cython.declare(Nodes=object, ExprNodes=object, EncodedString=object,
import
re
import
re
from
unicodedata
import
lookup
as
lookup_unicodechar
from
unicodedata
import
lookup
as
lookup_unicodechar
from
Cython.Compiler.Scanning
import
PyrexScanner
,
FileSourceDescriptor
from
.Scanning
import
PyrexScanner
,
FileSourceDescriptor
import
Nodes
from
.
import
Nodes
import
ExprNodes
from
.
import
ExprNodes
import
Builtin
from
.
import
Builtin
import
StringEncoding
from
.
import
StringEncoding
from
StringEncoding
import
EncodedString
,
BytesLiteral
,
_unicode
,
_bytes
from
.StringEncoding
import
EncodedString
,
BytesLiteral
,
_unicode
,
_bytes
from
ModuleNode
import
ModuleNode
from
.ModuleNode
import
ModuleNode
from
Errors
import
error
,
warning
from
.Errors
import
error
,
warning
from
Cython
import
Utils
from
..
import
Utils
import
Future
from
.
import
Future
import
Options
from
.
import
Options
class
Ctx
(
object
):
class
Ctx
(
object
):
# Parsing context
# Parsing context
...
@@ -3249,7 +3252,6 @@ def p_cpp_class_definition(s, pos, ctx):
...
@@ -3249,7 +3252,6 @@ def p_cpp_class_definition(s, pos, ctx):
templates
=
templates
)
templates
=
templates
)
#----------------------------------------------
#----------------------------------------------
#
#
# Debugging
# Debugging
...
@@ -3257,8 +3259,6 @@ def p_cpp_class_definition(s, pos, ctx):
...
@@ -3257,8 +3259,6 @@ def p_cpp_class_definition(s, pos, ctx):
#----------------------------------------------
#----------------------------------------------
def
print_parse_tree
(
f
,
node
,
level
,
key
=
None
):
def
print_parse_tree
(
f
,
node
,
level
,
key
=
None
):
from
types
import
ListType
,
TupleType
from
Nodes
import
Node
ind
=
" "
*
level
ind
=
" "
*
level
if
node
:
if
node
:
f
.
write
(
ind
)
f
.
write
(
ind
)
...
@@ -3271,7 +3271,7 @@ def print_parse_tree(f, node, level, key = None):
...
@@ -3271,7 +3271,7 @@ def print_parse_tree(f, node, level, key = None):
print_parse_tree
(
f
,
node
[
i
],
level
+
1
)
print_parse_tree
(
f
,
node
[
i
],
level
+
1
)
f
.
write
(
"%s)
\
n
"
%
ind
)
f
.
write
(
"%s)
\
n
"
%
ind
)
return
return
elif
isinstance
(
node
,
Node
):
elif
isinstance
(
node
,
Node
s
.
Node
):
try
:
try
:
tag
=
node
.
tag
tag
=
node
.
tag
except
AttributeError
:
except
AttributeError
:
...
...
Cython/Compiler/Pipeline.py
View file @
a96882e1
from
__future__
import
absolute_import
import
itertools
import
itertools
from
time
import
time
from
time
import
time
import
Errors
from
.
import
Errors
import
DebugFlags
from
.
import
DebugFlags
import
Options
from
.
import
Options
from
Visitor
import
CythonTransform
from
.
Visitor
import
CythonTransform
from
Errors
import
CompileError
,
InternalError
,
AbortError
from
.
Errors
import
CompileError
,
InternalError
,
AbortError
import
Naming
from
.
import
Naming
#
#
# Really small pipeline stages
# Really small pipeline stages
...
@@ -56,8 +58,6 @@ def generate_pyx_code_stage_factory(options, result):
...
@@ -56,8 +58,6 @@ def generate_pyx_code_stage_factory(options, result):
def
inject_pxd_code_stage_factory
(
context
):
def
inject_pxd_code_stage_factory
(
context
):
def
inject_pxd_code_stage
(
module_node
):
def
inject_pxd_code_stage
(
module_node
):
from
textwrap
import
dedent
stats
=
module_node
.
body
.
stats
for
name
,
(
statlistnode
,
scope
)
in
context
.
pxds
.
iteritems
():
for
name
,
(
statlistnode
,
scope
)
in
context
.
pxds
.
iteritems
():
module_node
.
merge_in
(
statlistnode
,
scope
)
module_node
.
merge_in
(
statlistnode
,
scope
)
return
module_node
return
module_node
...
@@ -127,28 +127,28 @@ class UseUtilityCodeDefinitions(CythonTransform):
...
@@ -127,28 +127,28 @@ class UseUtilityCodeDefinitions(CythonTransform):
def
create_pipeline
(
context
,
mode
,
exclude_classes
=
()):
def
create_pipeline
(
context
,
mode
,
exclude_classes
=
()):
assert
mode
in
(
'pyx'
,
'py'
,
'pxd'
)
assert
mode
in
(
'pyx'
,
'py'
,
'pxd'
)
from
Visitor
import
PrintTree
from
.
Visitor
import
PrintTree
from
ParseTreeTransforms
import
WithTransform
,
NormalizeTree
,
PostParse
,
PxdPostParse
from
.
ParseTreeTransforms
import
WithTransform
,
NormalizeTree
,
PostParse
,
PxdPostParse
from
ParseTreeTransforms
import
ForwardDeclareTypes
,
AnalyseDeclarationsTransform
from
.
ParseTreeTransforms
import
ForwardDeclareTypes
,
AnalyseDeclarationsTransform
from
ParseTreeTransforms
import
AnalyseExpressionsTransform
,
FindInvalidUseOfFusedTypes
from
.
ParseTreeTransforms
import
AnalyseExpressionsTransform
,
FindInvalidUseOfFusedTypes
from
ParseTreeTransforms
import
CreateClosureClasses
,
MarkClosureVisitor
,
DecoratorTransform
from
.
ParseTreeTransforms
import
CreateClosureClasses
,
MarkClosureVisitor
,
DecoratorTransform
from
ParseTreeTransforms
import
InterpretCompilerDirectives
,
TransformBuiltinMethods
from
.
ParseTreeTransforms
import
InterpretCompilerDirectives
,
TransformBuiltinMethods
from
ParseTreeTransforms
import
ExpandInplaceOperators
,
ParallelRangeTransform
from
.
ParseTreeTransforms
import
ExpandInplaceOperators
,
ParallelRangeTransform
from
ParseTreeTransforms
import
CalculateQualifiedNamesTransform
from
.
ParseTreeTransforms
import
CalculateQualifiedNamesTransform
from
TypeInference
import
MarkParallelAssignments
,
MarkOverflowingArithmetic
from
.
TypeInference
import
MarkParallelAssignments
,
MarkOverflowingArithmetic
from
ParseTreeTransforms
import
AdjustDefByDirectives
,
AlignFunctionDefinitions
from
.
ParseTreeTransforms
import
AdjustDefByDirectives
,
AlignFunctionDefinitions
from
ParseTreeTransforms
import
RemoveUnreachableCode
,
GilCheck
from
.
ParseTreeTransforms
import
RemoveUnreachableCode
,
GilCheck
from
FlowControl
import
ControlFlowAnalysis
from
.
FlowControl
import
ControlFlowAnalysis
from
AnalysedTreeTransforms
import
AutoTestDictTransform
from
.
AnalysedTreeTransforms
import
AutoTestDictTransform
from
AutoDocTransforms
import
EmbedSignature
from
.
AutoDocTransforms
import
EmbedSignature
from
Optimize
import
FlattenInListTransform
,
SwitchTransform
,
IterationTransform
from
.
Optimize
import
FlattenInListTransform
,
SwitchTransform
,
IterationTransform
from
Optimize
import
EarlyReplaceBuiltinCalls
,
OptimizeBuiltinCalls
from
.
Optimize
import
EarlyReplaceBuiltinCalls
,
OptimizeBuiltinCalls
from
Optimize
import
InlineDefNodeCalls
from
.
Optimize
import
InlineDefNodeCalls
from
Optimize
import
ConstantFolding
,
FinalOptimizePhase
from
.
Optimize
import
ConstantFolding
,
FinalOptimizePhase
from
Optimize
import
DropRefcountingTransform
from
.
Optimize
import
DropRefcountingTransform
from
Optimize
import
ConsolidateOverflowCheck
from
.
Optimize
import
ConsolidateOverflowCheck
from
Buffer
import
IntroduceBufferAuxiliaryVars
from
.
Buffer
import
IntroduceBufferAuxiliaryVars
from
ModuleNode
import
check_c_declarations
,
check_c_declarations_pxd
from
.
ModuleNode
import
check_c_declarations
,
check_c_declarations_pxd
if
mode
==
'pxd'
:
if
mode
==
'pxd'
:
...
@@ -221,12 +221,12 @@ def create_pyx_pipeline(context, options, result, py=False, exclude_classes=()):
...
@@ -221,12 +221,12 @@ def create_pyx_pipeline(context, options, result, py=False, exclude_classes=()):
mode
=
'pyx'
mode
=
'pyx'
test_support
=
[]
test_support
=
[]
if
options
.
evaluate_tree_assertions
:
if
options
.
evaluate_tree_assertions
:
from
Cython
.TestUtils
import
TreeAssertVisitor
from
.
.TestUtils
import
TreeAssertVisitor
test_support
.
append
(
TreeAssertVisitor
())
test_support
.
append
(
TreeAssertVisitor
())
if
options
.
gdb_debug
:
if
options
.
gdb_debug
:
from
Cython
.Debugger
import
DebugWriter
# requires Py2.5+
from
.
.Debugger
import
DebugWriter
# requires Py2.5+
from
ParseTreeTransforms
import
DebugTransform
from
.
ParseTreeTransforms
import
DebugTransform
context
.
gdb_debug_outputwriter
=
DebugWriter
.
CythonDebugWriter
(
context
.
gdb_debug_outputwriter
=
DebugWriter
.
CythonDebugWriter
(
options
.
output_dir
)
options
.
output_dir
)
debug_transform
=
[
DebugTransform
(
context
,
options
,
result
)]
debug_transform
=
[
DebugTransform
(
context
,
options
,
result
)]
...
@@ -244,7 +244,7 @@ def create_pyx_pipeline(context, options, result, py=False, exclude_classes=()):
...
@@ -244,7 +244,7 @@ def create_pyx_pipeline(context, options, result, py=False, exclude_classes=()):
[
generate_pyx_code_stage_factory
(
options
,
result
)]))
[
generate_pyx_code_stage_factory
(
options
,
result
)]))
def
create_pxd_pipeline
(
context
,
scope
,
module_name
):
def
create_pxd_pipeline
(
context
,
scope
,
module_name
):
from
CodeGeneration
import
ExtractPxdCode
from
.
CodeGeneration
import
ExtractPxdCode
# The pxd pipeline ends up with a CCodeWriter containing the
# The pxd pipeline ends up with a CCodeWriter containing the
# code of the pxd, as well as a pxd scope.
# code of the pxd, as well as a pxd scope.
...
@@ -258,10 +258,10 @@ def create_py_pipeline(context, options, result):
...
@@ -258,10 +258,10 @@ def create_py_pipeline(context, options, result):
return
create_pyx_pipeline
(
context
,
options
,
result
,
py
=
True
)
return
create_pyx_pipeline
(
context
,
options
,
result
,
py
=
True
)
def
create_pyx_as_pxd_pipeline
(
context
,
result
):
def
create_pyx_as_pxd_pipeline
(
context
,
result
):
from
ParseTreeTransforms
import
AlignFunctionDefinitions
,
\
from
.
ParseTreeTransforms
import
AlignFunctionDefinitions
,
\
MarkClosureVisitor
,
WithTransform
,
AnalyseDeclarationsTransform
MarkClosureVisitor
,
WithTransform
,
AnalyseDeclarationsTransform
from
Optimize
import
ConstantFolding
,
FlattenInListTransform
from
.
Optimize
import
ConstantFolding
,
FlattenInListTransform
from
Nodes
import
StatListNode
from
.
Nodes
import
StatListNode
pipeline
=
[]
pipeline
=
[]
pyx_pipeline
=
create_pyx_pipeline
(
context
,
context
.
options
,
result
,
pyx_pipeline
=
create_pyx_pipeline
(
context
,
context
.
options
,
result
,
exclude_classes
=
[
exclude_classes
=
[
...
@@ -312,7 +312,7 @@ def insert_into_pipeline(pipeline, transform, before=None, after=None):
...
@@ -312,7 +312,7 @@ def insert_into_pipeline(pipeline, transform, before=None, after=None):
#
#
def
run_pipeline
(
pipeline
,
source
,
printtree
=
True
):
def
run_pipeline
(
pipeline
,
source
,
printtree
=
True
):
from
Cython.Compiler
.Visitor
import
PrintTree
from
.Visitor
import
PrintTree
error
=
None
error
=
None
data
=
source
data
=
source
...
...
Cython/Compiler/PyrexTypes.py
View file @
a96882e1
...
@@ -2,11 +2,16 @@
...
@@ -2,11 +2,16 @@
# Cython/Python language types
# Cython/Python language types
#
#
from
Code
import
UtilityCode
,
LazyUtilityCode
,
TempitaUtilityCode
from
__future__
import
absolute_import
import
StringEncoding
import
Naming
import
copy
import
copy
from
Errors
import
error
from
.Code
import
UtilityCode
,
LazyUtilityCode
,
TempitaUtilityCode
from
.
import
StringEncoding
from
.
import
Naming
from
.Errors
import
error
class
BaseType
(
object
):
class
BaseType
(
object
):
#
#
...
@@ -508,7 +513,7 @@ class MemoryViewSliceType(PyrexType):
...
@@ -508,7 +513,7 @@ class MemoryViewSliceType(PyrexType):
the *first* axis' packing spec and 'follow' for all other packing
the *first* axis' packing spec and 'follow' for all other packing
specs.
specs.
"""
"""
import
MemoryView
from
.
import
MemoryView
self
.
dtype
=
base_dtype
self
.
dtype
=
base_dtype
self
.
axes
=
axes
self
.
axes
=
axes
...
@@ -542,14 +547,14 @@ class MemoryViewSliceType(PyrexType):
...
@@ -542,14 +547,14 @@ class MemoryViewSliceType(PyrexType):
# XXX: we put these guards in for now...
# XXX: we put these guards in for now...
assert
not
pyrex
assert
not
pyrex
assert
not
dll_linkage
assert
not
dll_linkage
import
MemoryView
from
.
import
MemoryView
return
self
.
base_declaration_code
(
return
self
.
base_declaration_code
(
MemoryView
.
memviewslice_cname
,
MemoryView
.
memviewslice_cname
,
entity_code
)
entity_code
)
def
attributes_known
(
self
):
def
attributes_known
(
self
):
if
self
.
scope
is
None
:
if
self
.
scope
is
None
:
import
Symtab
from
.
import
Symtab
self
.
scope
=
scope
=
Symtab
.
CClassScope
(
self
.
scope
=
scope
=
Symtab
.
CClassScope
(
'mvs_class_'
+
self
.
specialization_suffix
(),
'mvs_class_'
+
self
.
specialization_suffix
(),
...
@@ -565,7 +570,7 @@ class MemoryViewSliceType(PyrexType):
...
@@ -565,7 +570,7 @@ class MemoryViewSliceType(PyrexType):
return
True
return
True
def
declare_attribute
(
self
,
attribute
,
env
,
pos
):
def
declare_attribute
(
self
,
attribute
,
env
,
pos
):
import
MemoryView
,
Options
from
.
import
MemoryView
,
Options
scope
=
self
.
scope
scope
=
self
.
scope
...
@@ -652,7 +657,7 @@ class MemoryViewSliceType(PyrexType):
...
@@ -652,7 +657,7 @@ class MemoryViewSliceType(PyrexType):
return
cname
+
'.memview'
return
cname
+
'.memview'
def
create_from_py_utility_code
(
self
,
env
):
def
create_from_py_utility_code
(
self
,
env
):
import
MemoryView
,
Buffer
from
.
import
MemoryView
,
Buffer
# We don't have 'code', so use a LazyUtilityCode with a callback.
# We don't have 'code', so use a LazyUtilityCode with a callback.
def
lazy_utility_callback
(
code
):
def
lazy_utility_callback
(
code
):
...
@@ -741,13 +746,13 @@ class MemoryViewSliceType(PyrexType):
...
@@ -741,13 +746,13 @@ class MemoryViewSliceType(PyrexType):
def
axes_to_code
(
self
):
def
axes_to_code
(
self
):
"""Return a list of code constants for each axis"""
"""Return a list of code constants for each axis"""
import
MemoryView
from
.
import
MemoryView
d
=
MemoryView
.
_spec_to_const
d
=
MemoryView
.
_spec_to_const
return
[
"(%s | %s)"
%
(
d
[
a
],
d
[
p
])
for
a
,
p
in
self
.
axes
]
return
[
"(%s | %s)"
%
(
d
[
a
],
d
[
p
])
for
a
,
p
in
self
.
axes
]
def
axes_to_name
(
self
):
def
axes_to_name
(
self
):
"""Return an abbreviated name for our axes"""
"""Return an abbreviated name for our axes"""
import
MemoryView
from
.
import
MemoryView
d
=
MemoryView
.
_spec_to_abbrev
d
=
MemoryView
.
_spec_to_abbrev
return
""
.
join
([
"%s%s"
%
(
d
[
a
],
d
[
p
])
for
a
,
p
in
self
.
axes
])
return
""
.
join
([
"%s%s"
%
(
d
[
a
],
d
[
p
])
for
a
,
p
in
self
.
axes
])
...
@@ -755,7 +760,7 @@ class MemoryViewSliceType(PyrexType):
...
@@ -755,7 +760,7 @@ class MemoryViewSliceType(PyrexType):
return
"!%s.memview"
%
result_code
return
"!%s.memview"
%
result_code
def
__str__
(
self
):
def
__str__
(
self
):
import
MemoryView
from
.
import
MemoryView
axes_code_list
=
[]
axes_code_list
=
[]
for
idx
,
(
access
,
packing
)
in
enumerate
(
self
.
axes
):
for
idx
,
(
access
,
packing
)
in
enumerate
(
self
.
axes
):
...
@@ -1220,7 +1225,7 @@ class CConstType(BaseType):
...
@@ -1220,7 +1225,7 @@ class CConstType(BaseType):
def
__init__
(
self
,
const_base_type
):
def
__init__
(
self
,
const_base_type
):
self
.
const_base_type
=
const_base_type
self
.
const_base_type
=
const_base_type
if
const_base_type
.
has_attributes
and
const_base_type
.
scope
is
not
None
:
if
const_base_type
.
has_attributes
and
const_base_type
.
scope
is
not
None
:
import
Symtab
from
.
import
Symtab
self
.
scope
=
Symtab
.
CConstScope
(
const_base_type
.
scope
)
self
.
scope
=
Symtab
.
CConstScope
(
const_base_type
.
scope
)
def
__repr__
(
self
):
def
__repr__
(
self
):
...
@@ -1366,7 +1371,7 @@ class CNumericType(CType):
...
@@ -1366,7 +1371,7 @@ class CNumericType(CType):
def
attributes_known
(
self
):
def
attributes_known
(
self
):
if
self
.
scope
is
None
:
if
self
.
scope
is
None
:
import
Symtab
from
.
import
Symtab
self
.
scope
=
scope
=
Symtab
.
CClassScope
(
self
.
scope
=
scope
=
Symtab
.
CClassScope
(
''
,
''
,
None
,
None
,
...
@@ -1720,7 +1725,7 @@ class CComplexType(CNumericType):
...
@@ -1720,7 +1725,7 @@ class CComplexType(CNumericType):
def
attributes_known
(
self
):
def
attributes_known
(
self
):
if
self
.
scope
is
None
:
if
self
.
scope
is
None
:
import
Symtab
from
.
import
Symtab
self
.
scope
=
scope
=
Symtab
.
CClassScope
(
self
.
scope
=
scope
=
Symtab
.
CClassScope
(
''
,
''
,
None
,
None
,
...
@@ -3035,7 +3040,7 @@ class CppClassType(CType):
...
@@ -3035,7 +3040,7 @@ class CppClassType(CType):
'cname'
:
cname
,
'cname'
:
cname
,
'maybe_unordered'
:
self
.
maybe_unordered
(),
'maybe_unordered'
:
self
.
maybe_unordered
(),
}
}
from
UtilityCode
import
CythonUtilityCode
from
.
UtilityCode
import
CythonUtilityCode
env
.
use_utility_code
(
CythonUtilityCode
.
load
(
cls
.
replace
(
'unordered_'
,
''
)
+
".from_py"
,
"CppConvert.pyx"
,
context
=
context
))
env
.
use_utility_code
(
CythonUtilityCode
.
load
(
cls
.
replace
(
'unordered_'
,
''
)
+
".from_py"
,
"CppConvert.pyx"
,
context
=
context
))
self
.
from_py_function
=
cname
self
.
from_py_function
=
cname
return
True
return
True
...
@@ -3064,7 +3069,7 @@ class CppClassType(CType):
...
@@ -3064,7 +3069,7 @@ class CppClassType(CType):
'cname'
:
cname
,
'cname'
:
cname
,
'maybe_unordered'
:
self
.
maybe_unordered
(),
'maybe_unordered'
:
self
.
maybe_unordered
(),
}
}
from
UtilityCode
import
CythonUtilityCode
from
.
UtilityCode
import
CythonUtilityCode
env
.
use_utility_code
(
CythonUtilityCode
.
load
(
cls
.
replace
(
'unordered_'
,
''
)
+
".to_py"
,
"CppConvert.pyx"
,
context
=
context
))
env
.
use_utility_code
(
CythonUtilityCode
.
load
(
cls
.
replace
(
'unordered_'
,
''
)
+
".to_py"
,
"CppConvert.pyx"
,
context
=
context
))
self
.
to_py_function
=
cname
self
.
to_py_function
=
cname
return
True
return
True
...
@@ -3544,7 +3549,7 @@ def best_match(args, functions, pos=None, env=None):
...
@@ -3544,7 +3549,7 @@ def best_match(args, functions, pos=None, env=None):
", "
.
join
([
param
.
name
for
param
in
set
(
func_type
.
templates
)
-
set
(
deductions
.
keys
())]))))
", "
.
join
([
param
.
name
for
param
in
set
(
func_type
.
templates
)
-
set
(
deductions
.
keys
())]))))
else
:
else
:
type_list
=
[
deductions
[
param
]
for
param
in
func_type
.
templates
]
type_list
=
[
deductions
[
param
]
for
param
in
func_type
.
templates
]
from
Symtab
import
Entry
from
.
Symtab
import
Entry
specialization
=
Entry
(
specialization
=
Entry
(
name
=
func
.
name
+
"[%s]"
%
","
.
join
([
str
(
t
)
for
t
in
type_list
]),
name
=
func
.
name
+
"[%s]"
%
","
.
join
([
str
(
t
)
for
t
in
type_list
]),
cname
=
func
.
cname
+
"<%s>"
%
","
.
join
([
t
.
declaration_code
(
""
)
for
t
in
type_list
]),
cname
=
func
.
cname
+
"<%s>"
%
","
.
join
([
t
.
declaration_code
(
""
)
for
t
in
type_list
]),
...
...
Cython/Compiler/Scanning.pxd
View file @
a96882e1
from
__future__
import
absolute_import
import
cython
import
cython
from
Cython
.Plex.Scanners
cimport
Scanner
from
.
.Plex.Scanners
cimport
Scanner
cdef
class
Method
:
cdef
class
Method
:
cdef
object
name
cdef
object
name
...
...
Cython/Compiler/Scanning.py
View file @
a96882e1
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
# Cython Scanner
# Cython Scanner
#
#
from
__future__
import
absolute_import
import
os
import
os
import
platform
import
platform
...
@@ -10,14 +12,14 @@ import cython
...
@@ -10,14 +12,14 @@ import cython
cython
.
declare
(
EncodedString
=
object
,
any_string_prefix
=
unicode
,
IDENT
=
unicode
,
cython
.
declare
(
EncodedString
=
object
,
any_string_prefix
=
unicode
,
IDENT
=
unicode
,
print_function
=
object
)
print_function
=
object
)
from
Cython
import
Utils
from
..
import
Utils
from
Cython
.Plex.Scanners
import
Scanner
from
.
.Plex.Scanners
import
Scanner
from
Cython
.Plex.Errors
import
UnrecognizedInput
from
.
.Plex.Errors
import
UnrecognizedInput
from
Errors
import
error
from
.
Errors
import
error
from
Lexicon
import
any_string_prefix
,
make_lexicon
,
IDENT
from
.
Lexicon
import
any_string_prefix
,
make_lexicon
,
IDENT
from
Future
import
print_function
from
.
Future
import
print_function
from
StringEncoding
import
EncodedString
from
.
StringEncoding
import
EncodedString
debug_scanner
=
0
debug_scanner
=
0
trace_scanner
=
0
trace_scanner
=
0
...
...
Cython/Compiler/StringEncoding.py
View file @
a96882e1
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
# Cython -- encoding related tools
# Cython -- encoding related tools
#
#
from
__future__
import
absolute_import
import
re
import
re
import
sys
import
sys
...
@@ -17,6 +19,7 @@ empty_unicode = _unicode()
...
@@ -17,6 +19,7 @@ empty_unicode = _unicode()
join_bytes
=
empty_bytes
.
join
join_bytes
=
empty_bytes
.
join
class
UnicodeLiteralBuilder
(
object
):
class
UnicodeLiteralBuilder
(
object
):
"""Assemble a unicode string.
"""Assemble a unicode string.
"""
"""
...
...
Cython/Compiler/Symtab.py
View file @
a96882e1
...
@@ -2,17 +2,19 @@
...
@@ -2,17 +2,19 @@
# Symbol Table
# Symbol Table
#
#
from
__future__
import
absolute_import
import
copy
import
copy
import
re
import
re
from
Errors
import
warning
,
error
,
InternalError
from
.
Errors
import
warning
,
error
,
InternalError
from
StringEncoding
import
EncodedString
from
.
StringEncoding
import
EncodedString
import
Options
,
Naming
from
.
import
Options
,
Naming
import
PyrexTypes
from
.
import
PyrexTypes
from
PyrexTypes
import
py_object_type
,
unspecified_type
from
.
PyrexTypes
import
py_object_type
,
unspecified_type
from
TypeSlots
import
\
from
.
TypeSlots
import
\
pyfunction_signature
,
pymethod_signature
,
\
pyfunction_signature
,
pymethod_signature
,
\
get_special_method_signature
,
get_property_accessor_signature
get_special_method_signature
,
get_property_accessor_signature
import
Code
from
.
import
Code
import
__builtin__
as
builtins
import
__builtin__
as
builtins
iso_c99_keywords
=
set
(
iso_c99_keywords
=
set
(
...
@@ -23,6 +25,7 @@ iso_c99_keywords = set(
...
@@ -23,6 +25,7 @@ iso_c99_keywords = set(
'volatile'
,
'while'
,
'volatile'
,
'while'
,
'_Bool'
,
'_Complex'', _Imaginary'
,
'inline'
,
'restrict'
])
'_Bool'
,
'_Complex'', _Imaginary'
,
'inline'
,
'restrict'
])
def
c_safe_identifier
(
cname
):
def
c_safe_identifier
(
cname
):
# There are some C limitations on struct entry names.
# There are some C limitations on struct entry names.
if
((
cname
[:
2
]
==
'__'
if
((
cname
[:
2
]
==
'__'
...
@@ -431,7 +434,7 @@ class Scope(object):
...
@@ -431,7 +434,7 @@ class Scope(object):
entries
[
name
]
=
entry
entries
[
name
]
=
entry
if
type
.
is_memoryviewslice
:
if
type
.
is_memoryviewslice
:
import
MemoryView
from
.
import
MemoryView
entry
.
init
=
MemoryView
.
memslice_entry_init
entry
.
init
=
MemoryView
.
memslice_entry_init
entry
.
scope
=
self
entry
.
scope
=
self
...
@@ -801,7 +804,7 @@ class Scope(object):
...
@@ -801,7 +804,7 @@ class Scope(object):
return
PyrexTypes
.
best_match
(
operands
,
function
.
all_alternatives
())
return
PyrexTypes
.
best_match
(
operands
,
function
.
all_alternatives
())
def
lookup_operator_for_types
(
self
,
pos
,
operator
,
types
):
def
lookup_operator_for_types
(
self
,
pos
,
operator
,
types
):
from
Nodes
import
Node
from
.
Nodes
import
Node
class
FakeOperand
(
Node
):
class
FakeOperand
(
Node
):
pass
pass
operands
=
[
FakeOperand
(
pos
,
type
=
type
)
for
type
in
types
]
operands
=
[
FakeOperand
(
pos
,
type
=
type
)
for
type
in
types
]
...
@@ -823,7 +826,7 @@ class Scope(object):
...
@@ -823,7 +826,7 @@ class Scope(object):
return
0
return
0
def
infer_types
(
self
):
def
infer_types
(
self
):
from
TypeInference
import
get_type_inferer
from
.
TypeInference
import
get_type_inferer
get_type_inferer
().
infer_types
(
self
)
get_type_inferer
().
infer_types
(
self
)
def
is_cpp
(
self
):
def
is_cpp
(
self
):
...
@@ -995,7 +998,7 @@ class ModuleScope(Scope):
...
@@ -995,7 +998,7 @@ class ModuleScope(Scope):
is_cython_builtin
=
0
is_cython_builtin
=
0
def
__init__
(
self
,
name
,
parent_module
,
context
):
def
__init__
(
self
,
name
,
parent_module
,
context
):
import
Builtin
from
.
import
Builtin
self
.
parent_module
=
parent_module
self
.
parent_module
=
parent_module
outer_scope
=
Builtin
.
builtin_scope
outer_scope
=
Builtin
.
builtin_scope
Scope
.
__init__
(
self
,
name
,
outer_scope
,
parent_module
)
Scope
.
__init__
(
self
,
name
,
outer_scope
,
parent_module
)
...
@@ -1461,7 +1464,7 @@ class ModuleScope(Scope):
...
@@ -1461,7 +1464,7 @@ class ModuleScope(Scope):
# variable entry attached to it. For the variable entry,
# variable entry attached to it. For the variable entry,
# we use a read-only C global variable whose name is an
# we use a read-only C global variable whose name is an
# expression that refers to the type object.
# expression that refers to the type object.
import
Builtin
from
.
import
Builtin
var_entry
=
Entry
(
name
=
entry
.
name
,
var_entry
=
Entry
(
name
=
entry
.
name
,
type
=
Builtin
.
type_type
,
type
=
Builtin
.
type_type
,
pos
=
entry
.
pos
,
pos
=
entry
.
pos
,
...
@@ -1475,7 +1478,7 @@ class ModuleScope(Scope):
...
@@ -1475,7 +1478,7 @@ class ModuleScope(Scope):
return
self
.
cpp
return
self
.
cpp
def
infer_types
(
self
):
def
infer_types
(
self
):
from
TypeInference
import
PyObjectTypeInferer
from
.
TypeInference
import
PyObjectTypeInferer
PyObjectTypeInferer
().
infer_types
(
self
)
PyObjectTypeInferer
().
infer_types
(
self
)
...
...
Cython/Compiler/TreeFragment.py
View file @
a96882e1
...
@@ -2,22 +2,26 @@
...
@@ -2,22 +2,26 @@
# TreeFragments - parsing of strings to trees
# TreeFragments - parsing of strings to trees
#
#
import
re
from
StringIO
import
StringIO
from
Scanning
import
PyrexScanner
,
StringSourceDescriptor
from
Symtab
import
ModuleScope
import
PyrexTypes
from
Visitor
import
VisitorTransform
from
Nodes
import
Node
,
StatListNode
from
ExprNodes
import
NameNode
import
Parsing
import
Main
import
UtilNodes
"""
"""
Support for parsing strings into code trees.
Support for parsing strings into code trees.
"""
"""
from
__future__
import
absolute_import
import
re
from
StringIO
import
StringIO
from
.Scanning
import
PyrexScanner
,
StringSourceDescriptor
from
.Symtab
import
ModuleScope
from
.
import
PyrexTypes
from
.Visitor
import
VisitorTransform
from
.Nodes
import
Node
,
StatListNode
from
.ExprNodes
import
NameNode
from
.
import
Parsing
from
.
import
Main
from
.
import
UtilNodes
class
StringParseContext
(
Main
.
Context
):
class
StringParseContext
(
Main
.
Context
):
def
__init__
(
self
,
name
,
include_directories
=
None
):
def
__init__
(
self
,
name
,
include_directories
=
None
):
if
include_directories
is
None
:
include_directories
=
[]
if
include_directories
is
None
:
include_directories
=
[]
...
@@ -30,6 +34,7 @@ class StringParseContext(Main.Context):
...
@@ -30,6 +34,7 @@ class StringParseContext(Main.Context):
raise
AssertionError
(
"Not yet supporting any cimports/includes from string code snippets"
)
raise
AssertionError
(
"Not yet supporting any cimports/includes from string code snippets"
)
return
ModuleScope
(
module_name
,
parent_module
=
None
,
context
=
self
)
return
ModuleScope
(
module_name
,
parent_module
=
None
,
context
=
self
)
def
parse_from_strings
(
name
,
code
,
pxds
=
{},
level
=
None
,
initial_pos
=
None
,
def
parse_from_strings
(
name
,
code
,
pxds
=
{},
level
=
None
,
initial_pos
=
None
,
context
=
None
,
allow_struct_enum_decorator
=
False
):
context
=
None
,
allow_struct_enum_decorator
=
False
):
"""
"""
...
...
Cython/Compiler/TreePath.py
View file @
a96882e1
...
@@ -6,6 +6,8 @@ function selects a part of the expression, e.g. a child node, a
...
@@ -6,6 +6,8 @@ function selects a part of the expression, e.g. a child node, a
specific descendant or a node that holds an attribute.
specific descendant or a node that holds an attribute.
"""
"""
from
__future__
import
absolute_import
import
re
import
re
import
operator
import
operator
...
...
Cython/Compiler/TypeInference.py
View file @
a96882e1
from
Errors
import
error
,
message
from
__future__
import
absolute_import
import
ExprNodes
import
Nodes
from
.Errors
import
error
,
message
import
Builtin
from
.
import
ExprNodes
import
PyrexTypes
from
.
import
Nodes
from
Cython
import
Utils
from
.
import
Builtin
from
PyrexTypes
import
py_object_type
,
unspecified_type
from
.
import
PyrexTypes
from
Visitor
import
CythonTransform
,
EnvTransform
from
..
import
Utils
from
.PyrexTypes
import
py_object_type
,
unspecified_type
from
.Visitor
import
CythonTransform
,
EnvTransform
class
TypedExprNode
(
ExprNodes
.
ExprNode
):
class
TypedExprNode
(
ExprNodes
.
ExprNode
):
...
...
Cython/Compiler/TypeSlots.py
View file @
a96882e1
...
@@ -3,13 +3,16 @@
...
@@ -3,13 +3,16 @@
# and associated know-how.
# and associated know-how.
#
#
import
Naming
from
__future__
import
absolute_import
import
PyrexTypes
import
StringEncoding
from
.
import
Naming
from
.
import
PyrexTypes
from
.
import
StringEncoding
invisible
=
[
'__cinit__'
,
'__dealloc__'
,
'__richcmp__'
,
invisible
=
[
'__cinit__'
,
'__dealloc__'
,
'__richcmp__'
,
'__nonzero__'
,
'__bool__'
]
'__nonzero__'
,
'__bool__'
]
class
Signature
(
object
):
class
Signature
(
object
):
# Method slot signature descriptor.
# Method slot signature descriptor.
#
#
...
...
Cython/Compiler/UtilNodes.py
View file @
a96882e1
...
@@ -4,11 +4,14 @@
...
@@ -4,11 +4,14 @@
# so it is convenient to have them in a seperate module.
# so it is convenient to have them in a seperate module.
#
#
import
Nodes
from
__future__
import
absolute_import
import
ExprNodes
from
Nodes
import
Node
from
.
import
Nodes
from
ExprNodes
import
AtomicExprNode
from
.
import
ExprNodes
from
PyrexTypes
import
c_ptr_type
from
.Nodes
import
Node
from
.ExprNodes
import
AtomicExprNode
from
.PyrexTypes
import
c_ptr_type
class
TempHandle
(
object
):
class
TempHandle
(
object
):
# THIS IS DEPRECATED, USE LetRefNode instead
# THIS IS DEPRECATED, USE LetRefNode instead
...
...
Cython/Compiler/UtilityCode.py
View file @
a96882e1
from
TreeFragment
import
parse_from_strings
,
StringParseContext
from
__future__
import
absolute_import
import
Symtab
import
Naming
from
.TreeFragment
import
parse_from_strings
,
StringParseContext
import
Code
from
.
import
Symtab
from
.
import
Naming
from
.
import
Code
class
NonManglingModuleScope
(
Symtab
.
ModuleScope
):
class
NonManglingModuleScope
(
Symtab
.
ModuleScope
):
...
@@ -83,13 +86,13 @@ class CythonUtilityCode(Code.UtilityCodeBase):
...
@@ -83,13 +86,13 @@ class CythonUtilityCode(Code.UtilityCodeBase):
self
.
from_scope
=
from_scope
self
.
from_scope
=
from_scope
def
get_tree
(
self
,
entries_only
=
False
,
cython_scope
=
None
):
def
get_tree
(
self
,
entries_only
=
False
,
cython_scope
=
None
):
from
AnalysedTreeTransforms
import
AutoTestDictTransform
from
.
AnalysedTreeTransforms
import
AutoTestDictTransform
# The AutoTestDictTransform creates the statement "__test__ = {}",
# The AutoTestDictTransform creates the statement "__test__ = {}",
# which when copied into the main ModuleNode overwrites
# which when copied into the main ModuleNode overwrites
# any __test__ in user code; not desired
# any __test__ in user code; not desired
excludes
=
[
AutoTestDictTransform
]
excludes
=
[
AutoTestDictTransform
]
import
Pipeline
,
ParseTreeTransforms
from
.
import
Pipeline
,
ParseTreeTransforms
context
=
CythonUtilityCodeContext
(
self
.
name
)
context
=
CythonUtilityCodeContext
(
self
.
name
)
context
.
prefix
=
self
.
prefix
context
.
prefix
=
self
.
prefix
context
.
cython_scope
=
cython_scope
context
.
cython_scope
=
cython_scope
...
...
Cython/Compiler/Version.py
View file @
a96882e1
# for backwards compatibility
# for backwards compatibility
from
Cython
import
__version__
as
version
from
__future__
import
absolute_import
from
..
import
__version__
as
version
# For generated by string.
# For generated by string.
...
...
Cython/Compiler/Visitor.pxd
View file @
a96882e1
from
__future__
import
absolute_import
cimport
cython
cimport
cython
cdef
class
TreeVisitor
:
cdef
class
TreeVisitor
:
...
...
Cython/Compiler/Visitor.py
View file @
a96882e1
...
@@ -3,14 +3,17 @@
...
@@ -3,14 +3,17 @@
#
#
# Tree visitor and transform framework
# Tree visitor and transform framework
#
#
from
__future__
import
absolute_import
import
inspect
import
inspect
from
Cython.Compiler
import
TypeSlots
from
.
import
TypeSlots
from
Cython.Compiler
import
Builtin
from
.
import
Builtin
from
Cython.Compiler
import
Nodes
from
.
import
Nodes
from
Cython.Compiler
import
ExprNodes
from
.
import
ExprNodes
from
Cython.Compiler
import
Errors
from
.
import
Errors
from
Cython.Compiler
import
DebugFlags
from
.
import
DebugFlags
import
cython
import
cython
...
@@ -270,7 +273,7 @@ class CythonTransform(VisitorTransform):
...
@@ -270,7 +273,7 @@ class CythonTransform(VisitorTransform):
self
.
context
=
context
self
.
context
=
context
def
__call__
(
self
,
node
):
def
__call__
(
self
,
node
):
import
ModuleNode
from
.
import
ModuleNode
if
isinstance
(
node
,
ModuleNode
.
ModuleNode
):
if
isinstance
(
node
,
ModuleNode
.
ModuleNode
):
self
.
current_directives
=
node
.
directives
self
.
current_directives
=
node
.
directives
return
super
(
CythonTransform
,
self
).
__call__
(
node
)
return
super
(
CythonTransform
,
self
).
__call__
(
node
)
...
...
Cython/Plex/DFA.py
View file @
a96882e1
...
@@ -6,9 +6,12 @@
...
@@ -6,9 +6,12 @@
#
#
#=======================================================================
#=======================================================================
import
Machines
from
__future__
import
absolute_import
from
Machines
import
LOWEST_PRIORITY
from
Transitions
import
TransitionMap
from
.
import
Machines
from
.Machines
import
LOWEST_PRIORITY
from
.Transitions
import
TransitionMap
def
nfa_to_dfa
(
old_machine
,
debug
=
None
):
def
nfa_to_dfa
(
old_machine
,
debug
=
None
):
"""
"""
...
@@ -147,7 +150,7 @@ class StateMap(object):
...
@@ -147,7 +150,7 @@ class StateMap(object):
return
tuple
(
lst
)
return
tuple
(
lst
)
def
dump
(
self
,
file
):
def
dump
(
self
,
file
):
from
Transitions
import
state_set_str
from
.
Transitions
import
state_set_str
for
new_state
in
self
.
new_machine
.
states
:
for
new_state
in
self
.
new_machine
.
states
:
old_state_set
=
self
.
new_to_old_dict
[
id
(
new_state
)]
old_state_set
=
self
.
new_to_old_dict
[
id
(
new_state
)]
file
.
write
(
" State %s <-- %s
\
n
"
%
(
file
.
write
(
" State %s <-- %s
\
n
"
%
(
...
...
Cython/Plex/Lexicons.py
View file @
a96882e1
...
@@ -6,18 +6,21 @@
...
@@ -6,18 +6,21 @@
#
#
#=======================================================================
#=======================================================================
from
__future__
import
absolute_import
import
types
import
types
import
Actions
from
.
import
Actions
import
DFA
from
.
import
DFA
import
Errors
from
.
import
Errors
import
Machines
from
.
import
Machines
import
Regexps
from
.
import
Regexps
# debug_flags for Lexicon constructor
# debug_flags for Lexicon constructor
DUMP_NFA
=
1
DUMP_NFA
=
1
DUMP_DFA
=
2
DUMP_DFA
=
2
class
State
(
object
):
class
State
(
object
):
"""
"""
This class is used as part of a Plex.Lexicon specification to
This class is used as part of a Plex.Lexicon specification to
...
@@ -114,7 +117,7 @@ class Lexicon(object):
...
@@ -114,7 +117,7 @@ class Lexicon(object):
if
type
(
specifications
)
!=
types
.
ListType
:
if
type
(
specifications
)
!=
types
.
ListType
:
raise
Errors
.
InvalidScanner
(
"Scanner definition is not a list"
)
raise
Errors
.
InvalidScanner
(
"Scanner definition is not a list"
)
if
timings
:
if
timings
:
from
Timing
import
time
from
.
Timing
import
time
total_time
=
0.0
total_time
=
0.0
time1
=
time
()
time1
=
time
()
nfa
=
Machines
.
Machine
()
nfa
=
Machines
.
Machine
()
...
...
Cython/Plex/Machines.py
View file @
a96882e1
...
@@ -6,12 +6,15 @@
...
@@ -6,12 +6,15 @@
#
#
#=======================================================================
#=======================================================================
from
__future__
import
absolute_import
import
sys
import
sys
from
Transitions
import
TransitionMap
from
.
Transitions
import
TransitionMap
LOWEST_PRIORITY
=
-
sys
.
maxint
LOWEST_PRIORITY
=
-
sys
.
maxint
class
Machine
(
object
):
class
Machine
(
object
):
"""A collection of Nodes representing an NFA or DFA."""
"""A collection of Nodes representing an NFA or DFA."""
states
=
None
# [Node]
states
=
None
# [Node]
...
...
Cython/Plex/Regexps.py
View file @
a96882e1
...
@@ -6,10 +6,12 @@
...
@@ -6,10 +6,12 @@
#
#
#=======================================================================
#=======================================================================
from
__future__
import
absolute_import
import
types
import
types
from
sys
import
maxint
as
maxint
from
sys
import
maxint
as
maxint
import
Errors
from
.
import
Errors
#
#
# Constants
# Constants
...
@@ -21,6 +23,7 @@ EOF = 'eof'
...
@@ -21,6 +23,7 @@ EOF = 'eof'
nl_code
=
ord
(
'
\
n
'
)
nl_code
=
ord
(
'
\
n
'
)
#
#
# Helper functions
# Helper functions
#
#
...
...
Cython/Plex/Scanners.pxd
View file @
a96882e1
from
__future__
import
absolute_import
import
cython
import
cython
from
Cython.Plex.Actions
cimport
Action
from
Cython.Plex.Actions
cimport
Action
...
...
Cython/Plex/Scanners.py
View file @
a96882e1
...
@@ -7,14 +7,17 @@
...
@@ -7,14 +7,17 @@
#
#
#=======================================================================
#=======================================================================
from
__future__
import
absolute_import
import
cython
import
cython
cython
.
declare
(
BOL
=
object
,
EOL
=
object
,
EOF
=
object
,
NOT_FOUND
=
object
)
cython
.
declare
(
BOL
=
object
,
EOL
=
object
,
EOF
=
object
,
NOT_FOUND
=
object
)
import
Errors
from
.
import
Errors
from
Regexps
import
BOL
,
EOL
,
EOF
from
.
Regexps
import
BOL
,
EOL
,
EOF
NOT_FOUND
=
object
()
NOT_FOUND
=
object
()
class
Scanner
(
object
):
class
Scanner
(
object
):
"""
"""
A Scanner is used to read tokens from a stream of characters
A Scanner is used to read tokens from a stream of characters
...
...
Cython/Plex/Timing.py
View file @
a96882e1
...
@@ -2,21 +2,22 @@
...
@@ -2,21 +2,22 @@
# Get time in platform-dependent way
# Get time in platform-dependent way
#
#
from
__future__
import
absolute_import
import
os
import
os
from
sys
import
platform
,
exit
,
stderr
from
sys
import
platform
,
exit
,
stderr
if
platform
==
'mac'
:
if
platform
==
'mac'
:
import
MacOS
import
MacOS
def
time
():
def
time
():
return
MacOS
.
GetTicks
()
/
60.0
return
MacOS
.
GetTicks
()
/
60.0
timekind
=
"real"
timekind
=
"real"
elif
hasattr
(
os
,
'times'
):
elif
hasattr
(
os
,
'times'
):
def
time
():
def
time
():
t
=
os
.
times
()
t
=
os
.
times
()
return
t
[
0
]
+
t
[
1
]
return
t
[
0
]
+
t
[
1
]
timekind
=
"cpu"
timekind
=
"cpu"
else
:
else
:
stderr
.
write
(
stderr
.
write
(
"Don't know how to get time on platform %s
\
n
"
%
repr
(
platform
))
"Don't know how to get time on platform %s
\
n
"
%
repr
(
platform
))
exit
(
1
)
exit
(
1
)
Cython/Plex/Traditional.py
View file @
a96882e1
...
@@ -6,12 +6,16 @@
...
@@ -6,12 +6,16 @@
#
#
#=======================================================================
#=======================================================================
from
Regexps
import
Alt
,
Seq
,
Rep
,
Rep1
,
Opt
,
Any
,
AnyBut
,
Bol
,
Eol
,
Char
from
__future__
import
absolute_import
from
Errors
import
PlexError
from
.Regexps
import
Alt
,
Seq
,
Rep
,
Rep1
,
Opt
,
Any
,
AnyBut
,
Bol
,
Eol
,
Char
from
.Errors
import
PlexError
class
RegexpSyntaxError
(
PlexError
):
class
RegexpSyntaxError
(
PlexError
):
pass
pass
def
re
(
s
):
def
re
(
s
):
"""
"""
Convert traditional string representation of regular expression |s|
Convert traditional string representation of regular expression |s|
...
@@ -19,6 +23,7 @@ def re(s):
...
@@ -19,6 +23,7 @@ def re(s):
"""
"""
return
REParser
(
s
).
parse_re
()
return
REParser
(
s
).
parse_re
()
class
REParser
(
object
):
class
REParser
(
object
):
def
__init__
(
self
,
s
):
def
__init__
(
self
,
s
):
...
...
Cython/Plex/Transitions.py
View file @
a96882e1
#
#
# Plex - Transition Maps
# Plex - Transition Maps
#
#
# This version represents state sets direcly as dicts
# This version represents state sets directly as dicts for speed.
# for speed.
#
#
from
__future__
import
absolute_import
from
sys
import
maxint
as
maxint
from
sys
import
maxint
as
maxint
class
TransitionMap
(
object
):
class
TransitionMap
(
object
):
"""
"""
A TransitionMap maps an input event to a set of states.
A TransitionMap maps an input event to a set of states.
...
@@ -242,6 +244,3 @@ class TransitionMap(object):
...
@@ -242,6 +244,3 @@ class TransitionMap(object):
def
state_set_str
(
set
):
def
state_set_str
(
set
):
return
"[%s]"
%
','
.
join
([
"S%d"
%
state
.
number
for
state
in
set
])
return
"[%s]"
%
','
.
join
([
"S%d"
%
state
.
number
for
state
in
set
])
Cython/Plex/__init__.py
View file @
a96882e1
...
@@ -30,11 +30,10 @@ see the attached docstrings for more information.
...
@@ -30,11 +30,10 @@ see the attached docstrings for more information.
creating a Lexicon.
creating a Lexicon.
"""
"""
from
Actions
import
TEXT
,
IGNORE
,
Begin
from
__future__
import
absolute_import
from
Lexicons
import
Lexicon
,
State
from
Regexps
import
RE
,
Seq
,
Alt
,
Rep1
,
Empty
,
Str
,
Any
,
AnyBut
,
AnyChar
,
Range
from
Regexps
import
Opt
,
Rep
,
Bol
,
Eol
,
Eof
,
Case
,
NoCase
from
Scanners
import
Scanner
from
.Actions
import
TEXT
,
IGNORE
,
Begin
from
.Lexicons
import
Lexicon
,
State
from
.Regexps
import
RE
,
Seq
,
Alt
,
Rep1
,
Empty
,
Str
,
Any
,
AnyBut
,
AnyChar
,
Range
from
.Regexps
import
Opt
,
Rep
,
Bol
,
Eol
,
Eof
,
Case
,
NoCase
from
.Scanners
import
Scanner
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