Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
bba54be8
Commit
bba54be8
authored
Jun 11, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
490109ae
10bc414d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
94 additions
and
51 deletions
+94
-51
.hgignore
.hgignore
+2
-0
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+22
-21
Cython/Compiler/Errors.py
Cython/Compiler/Errors.py
+9
-4
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+8
-8
Cython/Compiler/Scanning.py
Cython/Compiler/Scanning.py
+10
-11
Makefile
Makefile
+0
-5
setup.py
setup.py
+27
-2
tests/run/r_uintindex.pyx
tests/run/r_uintindex.pyx
+16
-0
No files found.
.hgignore
View file @
bba54be8
...
@@ -5,7 +5,9 @@ syntax: glob
...
@@ -5,7 +5,9 @@ syntax: glob
Cython/Compiler/Lexicon.pickle
Cython/Compiler/Lexicon.pickle
BUILD/
BUILD/
build/
.coverage
.coverage
*~
*~
*.orig
*.orig
*.rej
*.rej
*.dep
Cython/Compiler/Code.py
View file @
bba54be8
...
@@ -33,10 +33,11 @@ class CCodeWriter:
...
@@ -33,10 +33,11 @@ class CCodeWriter:
def
__init__
(
self
,
f
):
def
__init__
(
self
,
f
):
#self.f = open_new_file(outfile_name)
#self.f = open_new_file(outfile_name)
self
.
f
=
f
self
.
f
=
f
self
.
_write
=
f
.
write
self
.
level
=
0
self
.
level
=
0
self
.
bol
=
1
self
.
bol
=
1
self
.
marker
=
None
self
.
marker
=
None
self
.
last_marker
=
1
self
.
last_marker
_line
=
0
self
.
label_counter
=
1
self
.
label_counter
=
1
self
.
error_label
=
None
self
.
error_label
=
None
self
.
filename_table
=
{}
self
.
filename_table
=
{}
...
@@ -49,14 +50,14 @@ class CCodeWriter:
...
@@ -49,14 +50,14 @@ class CCodeWriter:
self
.
emit_marker
()
self
.
emit_marker
()
if
code
:
if
code
:
self
.
put
(
code
)
self
.
put
(
code
)
self
.
f
.
write
(
"
\
n
"
);
self
.
_
write
(
"
\
n
"
);
self
.
bol
=
1
self
.
bol
=
1
def
emit_marker
(
self
):
def
emit_marker
(
self
):
self
.
f
.
write
(
"
\
n
"
);
self
.
_
write
(
"
\
n
"
);
self
.
indent
()
self
.
indent
()
self
.
f
.
write
(
"/* %s */
\
n
"
%
self
.
marker
)
self
.
_write
(
"/* %s */
\
n
"
%
self
.
marker
[
1
]
)
self
.
last_marker
=
self
.
marker
self
.
last_marker
_line
=
self
.
marker
[
0
]
self
.
marker
=
None
self
.
marker
=
None
def
put
(
self
,
code
):
def
put
(
self
,
code
):
...
@@ -65,7 +66,7 @@ class CCodeWriter:
...
@@ -65,7 +66,7 @@ class CCodeWriter:
self
.
level
+=
dl
self
.
level
+=
dl
if
self
.
bol
:
if
self
.
bol
:
self
.
indent
()
self
.
indent
()
self
.
f
.
write
(
code
)
self
.
_
write
(
code
)
self
.
bol
=
0
self
.
bol
=
0
if
dl
>
0
:
if
dl
>
0
:
self
.
level
+=
dl
self
.
level
+=
dl
...
@@ -85,18 +86,19 @@ class CCodeWriter:
...
@@ -85,18 +86,19 @@ class CCodeWriter:
self
.
putln
(
"}"
)
self
.
putln
(
"}"
)
def
indent
(
self
):
def
indent
(
self
):
self
.
f
.
write
(
" "
*
self
.
level
)
self
.
_
write
(
" "
*
self
.
level
)
def
get_py_version_hex
(
self
,
pyversion
):
def
get_py_version_hex
(
self
,
pyversion
):
return
"0x%02X%02X%02X%02X"
%
(
tuple
(
pyversion
)
+
(
0
,
0
,
0
,
0
))[:
4
]
return
"0x%02X%02X%02X%02X"
%
(
tuple
(
pyversion
)
+
(
0
,
0
,
0
,
0
))[:
4
]
def
file_contents
(
self
,
source_desc
):
def
commented_
file_contents
(
self
,
source_desc
):
try
:
try
:
return
self
.
input_file_contents
[
source_desc
]
return
self
.
input_file_contents
[
source_desc
]
except
KeyError
:
except
KeyError
:
F
=
[
line
.
encode
(
'ASCII'
,
'replace'
).
replace
(
F
=
[
u' * '
+
line
.
rstrip
().
replace
(
'*/'
,
'*[inserted by cython to avoid comment closer]/'
)
u'*/'
,
u'*[inserted by cython to avoid comment closer]/'
for
line
in
source_desc
.
get_lines
(
decode
=
True
)]
).
encode
(
'ASCII'
,
'replace'
)
# + Py2 auto-decode to unicode
for
line
in
source_desc
.
get_lines
()]
self
.
input_file_contents
[
source_desc
]
=
F
self
.
input_file_contents
[
source_desc
]
=
F
return
F
return
F
...
@@ -104,19 +106,18 @@ class CCodeWriter:
...
@@ -104,19 +106,18 @@ class CCodeWriter:
if
pos
is
None
:
if
pos
is
None
:
return
return
source_desc
,
line
,
col
=
pos
source_desc
,
line
,
col
=
pos
if
self
.
last_marker_line
==
line
:
return
assert
isinstance
(
source_desc
,
SourceDescriptor
)
assert
isinstance
(
source_desc
,
SourceDescriptor
)
contents
=
self
.
file_contents
(
source_desc
)
contents
=
self
.
commented_
file_contents
(
source_desc
)
context
=
''
lines
=
contents
[
max
(
0
,
line
-
3
):
line
]
# line numbers start at 1
for
i
in
range
(
max
(
0
,
line
-
3
),
min
(
line
+
2
,
len
(
contents
))):
lines
[
-
1
]
+=
u' # <<<<<<<<<<<<<<'
s
=
contents
[
i
]
lines
+=
contents
[
line
:
line
+
2
]
if
i
+
1
==
line
:
# line numbers in pyrex start counting up from 1
s
=
s
.
rstrip
()
+
' # <<<<<<<<<<<<<< '
+
'
\
n
'
context
+=
" * "
+
s
marker
=
'"%s":%d
\
n
%s'
%
(
source_desc
.
get_description
().
encode
(
'ASCII'
,
'replace'
),
line
,
context
)
marker
=
u'"%s":%d
\
n
%s
\
n
'
%
(
if
self
.
last_marker
!=
marker
:
source_desc
.
get_escaped_description
(),
line
,
u'
\
n
'
.
join
(
lines
))
self
.
marker
=
marker
self
.
marker
=
(
line
,
marker
)
def
init_labels
(
self
):
def
init_labels
(
self
):
self
.
label_counter
=
0
self
.
label_counter
=
0
...
...
Cython/Compiler/Errors.py
View file @
bba54be8
...
@@ -17,10 +17,15 @@ def context(position):
...
@@ -17,10 +17,15 @@ def context(position):
source
=
position
[
0
]
source
=
position
[
0
]
assert
not
(
isinstance
(
source
,
unicode
)
or
isinstance
(
source
,
str
)),
(
assert
not
(
isinstance
(
source
,
unicode
)
or
isinstance
(
source
,
str
)),
(
"Please replace filename strings with Scanning.FileSourceDescriptor instances %r"
%
source
)
"Please replace filename strings with Scanning.FileSourceDescriptor instances %r"
%
source
)
F
=
list
(
source
.
get_lines
())
try
:
s
=
''
.
join
(
F
[
min
(
0
,
position
[
1
]
-
6
):
position
[
1
]])
F
=
list
(
source
.
get_lines
())
s
+=
' '
*
(
position
[
2
]
-
1
)
+
'^'
except
UnicodeDecodeError
:
s
=
'-'
*
60
+
'
\
n
...
\
n
'
+
s
+
'
\
n
'
+
'-'
*
60
+
'
\
n
'
# file has an encoding problem
s
=
"[unprintable code]
\
n
"
else
:
s
=
''
.
join
(
F
[
max
(
0
,
position
[
1
]
-
6
):
position
[
1
]])
s
=
'...
\
n
'
+
s
+
' '
*
(
position
[
2
]
-
1
)
+
'^
\
n
'
s
=
'-'
*
60
+
'
\
n
'
+
s
+
'-'
*
60
+
'
\
n
'
return
s
return
s
class
CompileError
(
PyrexError
):
class
CompileError
(
PyrexError
):
...
...
Cython/Compiler/Nodes.py
View file @
bba54be8
...
@@ -153,24 +153,24 @@ class Node(object):
...
@@ -153,24 +153,24 @@ class Node(object):
self
.
body
.
annotate
(
code
)
self
.
body
.
annotate
(
code
)
def
end_pos
(
self
):
def
end_pos
(
self
):
if
not
self
.
child_attrs
:
return
self
.
pos
try
:
try
:
return
self
.
_end_pos
return
self
.
_end_pos
except
AttributeError
:
except
AttributeError
:
flat
=
[]
pos
=
self
.
pos
for
attr
in
self
.
child_attrs
:
for
attr
in
self
.
child_attrs
:
child
=
getattr
(
self
,
attr
)
child
=
getattr
(
self
,
attr
)
# Sometimes lists, sometimes nodes
# Sometimes lists, sometimes nodes
if
child
is
None
:
if
child
is
None
:
pass
pass
elif
isinstance
(
child
,
list
):
elif
isinstance
(
child
,
list
):
flat
+=
child
for
c
in
child
:
pos
=
max
(
pos
,
c
.
end_pos
())
else
:
else
:
flat
.
append
(
child
)
pos
=
max
(
pos
,
child
.
end_pos
())
if
len
(
flat
)
==
0
:
self
.
_end_pos
=
pos
self
.
_end_pos
=
self
.
pos
return
pos
else
:
self
.
_end_pos
=
max
([
child
.
end_pos
()
for
child
in
flat
])
return
self
.
_end_pos
class
BlockNode
:
class
BlockNode
:
...
...
Cython/Compiler/Scanning.py
View file @
bba54be8
...
@@ -209,8 +209,15 @@ class SourceDescriptor:
...
@@ -209,8 +209,15 @@ class SourceDescriptor:
"""
"""
A SourceDescriptor should be considered immutable.
A SourceDescriptor should be considered immutable.
"""
"""
_escaped_description
=
None
def
__str__
(
self
):
def
__str__
(
self
):
assert
False
# To catch all places where a descriptor is used directly as a filename
assert
False
# To catch all places where a descriptor is used directly as a filename
def
get_escaped_description
(
self
):
if
self
.
_escaped_description
is
None
:
self
.
_escaped_description
=
\
self
.
get_description
().
encode
(
'ASCII'
,
'replace'
).
decode
(
"ASCII"
)
return
self
.
_escaped_description
class
FileSourceDescriptor
(
SourceDescriptor
):
class
FileSourceDescriptor
(
SourceDescriptor
):
"""
"""
...
@@ -223,16 +230,8 @@ class FileSourceDescriptor(SourceDescriptor):
...
@@ -223,16 +230,8 @@ class FileSourceDescriptor(SourceDescriptor):
def
__init__
(
self
,
filename
):
def
__init__
(
self
,
filename
):
self
.
filename
=
filename
self
.
filename
=
filename
def
get_lines
(
self
,
decode
=
False
):
def
get_lines
(
self
):
# decode is True when called from Code.py (which reserializes in a standard way to ASCII),
return
Utils
.
open_source_file
(
self
.
filename
)
# while decode is False when called from Errors.py.
#
# Note that if changing Errors.py in this respect, raising errors over wrong encoding
# will no longer be able to produce the line where the encoding problem occurs ...
if
decode
:
return
Utils
.
open_source_file
(
self
.
filename
)
else
:
return
open
(
self
.
filename
)
def
get_description
(
self
):
def
get_description
(
self
):
return
self
.
filename
return
self
.
filename
...
@@ -258,7 +257,7 @@ class StringSourceDescriptor(SourceDescriptor):
...
@@ -258,7 +257,7 @@ class StringSourceDescriptor(SourceDescriptor):
self
.
name
=
name
self
.
name
=
name
self
.
codelines
=
[
x
+
"
\
n
"
for
x
in
code
.
split
(
"
\
n
"
)]
self
.
codelines
=
[
x
+
"
\
n
"
for
x
in
code
.
split
(
"
\
n
"
)]
def
get_lines
(
self
,
decode
=
False
):
def
get_lines
(
self
):
return
self
.
codelines
return
self
.
codelines
def
get_description
(
self
):
def
get_description
(
self
):
...
...
Makefile
View file @
bba54be8
VERSION
=
0.9.6.3
PYTHON
?=
python
PYTHON
?=
python
version
:
@
echo
"Setting version to
$(VERSION)
"
@
echo
"version = '
$(VERSION)
'"
>
Cython/Compiler/Version.py
clean
:
clean
:
@
echo
Cleaning Source
@
echo
Cleaning Source
@
rm
-f
*
.pyc
*
/
*
.pyc
*
/
*
/
*
.pyc
@
rm
-f
*
.pyc
*
/
*
.pyc
*
/
*
/
*
.pyc
...
...
setup.py
View file @
bba54be8
from
distutils.core
import
setup
from
distutils.core
import
setup
,
Extension
from
distutils.sysconfig
import
get_python_lib
from
distutils.sysconfig
import
get_python_lib
import
os
,
sys
import
os
,
os
.
path
import
sys
import
sys
from
Cython.Compiler.Version
import
version
from
Cython.Compiler.Version
import
version
...
@@ -22,6 +22,31 @@ if os.name == "posix":
...
@@ -22,6 +22,31 @@ if os.name == "posix":
else
:
else
:
scripts
=
[
"cython.py"
]
scripts
=
[
"cython.py"
]
try
:
sys
.
argv
.
remove
(
"--no-compile"
)
except
ValueError
:
try
:
from
Cython.Compiler.Main
import
compile
source_root
=
os
.
path
.
dirname
(
__file__
)
compiled_modules
=
[
"Cython.Plex.Scanners"
]
extensions
=
[]
for
module
in
compiled_modules
:
source_file
=
os
.
path
.
join
(
source_root
,
*
module
.
split
(
'.'
))
print
(
"Compiling module %s ..."
%
module
)
result
=
compile
(
source_file
+
".py"
)
if
result
.
c_file
:
extensions
.
append
(
Extension
(
module
,
sources
=
[
result
.
c_file
])
)
else
:
print
(
"Compilation failed"
)
if
extensions
:
setup_args
[
'ext_modules'
]
=
extensions
except
Exception
:
print
(
"ERROR: %s"
%
sys
.
exc_info
()[
1
])
print
(
"Extension module compilation failed, using plain Python implementation"
)
setup
(
setup
(
name
=
'Cython'
,
name
=
'Cython'
,
version
=
version
,
version
=
version
,
...
...
tests/run/r_uintindex.pyx
0 → 100644
View file @
bba54be8
__doc__
=
u"""
>>> print idx_uint( ["buckle", "my", "shoe"], 2)
shoe
>>> print idx_ulong(["buckle", "my", "shoe"], 2)
shoe
"""
def
idx_ulong
(
seq
,
i
):
cdef
unsigned
long
u
u
=
i
return
seq
[
u
]
def
idx_uint
(
seq
,
i
):
cdef
unsigned
int
u
u
=
i
return
seq
[
u
]
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