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
f53e00e3
Commit
f53e00e3
authored
Jan 31, 2010
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure new can be used as a non-keyword.
parent
c176a809
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
8 deletions
+72
-8
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+1
-1
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+25
-5
Cython/Compiler/Scanning.py
Cython/Compiler/Scanning.py
+8
-0
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+1
-1
Demos/setup.py
Demos/setup.py
+2
-1
tests/run/new_as_nonkeyword.pyx
tests/run/new_as_nonkeyword.pyx
+35
-0
No files found.
Cython/Compiler/Parsing.py
View file @
f53e00e3
...
...
@@ -300,7 +300,7 @@ def p_yield_expression(s):
#power: atom trailer* ('**' factor)*
def
p_power
(
s
):
if
s
.
systring
==
'new'
:
if
s
.
systring
==
'new'
and
s
.
peek
()[
0
]
==
'IDENT'
:
return
p_new_expr
(
s
)
n1
=
p_atom
(
s
)
while
s
.
sy
in
(
'('
,
'['
,
'.'
):
...
...
Cython/Compiler/PyrexTypes.py
View file @
f53e00e3
...
...
@@ -2194,14 +2194,34 @@ modifiers_and_name_to_type = {
(
1
,
0
,
"bint"
):
c_bint_type
,
}
def
is_promotion
(
type
,
other_type
):
if
type
.
is_numeric
and
other_type
.
is_numeric
:
return
(
type
.
is_int
and
type
.
is_int
and
type
.
signed
==
other_type
.
signed
)
\
or
(
type
.
is_float
and
other_type
.
is_float
)
\
or
(
type
.
is_enum
and
other_type
.
is_int
)
def
is_promotion0
(
src_type
,
dst_type
):
if
src_type
.
is_numeric
and
dst_type
.
is_numeric
:
if
src_type
.
is_int
and
dst_type
.
is_int
:
if
src_type
.
is_enum
:
return
True
elif
src_type
.
signed
:
return
dst_type
.
signed
and
src_type
.
rank
<=
dst_type
.
rank
elif
dst_type
.
signed
:
# and not src_type.signed
src_type
.
rank
<
dst_type
.
rank
else
:
return
src_type
.
rank
<=
dst_type
.
rank
elif
src_type
.
is_float
and
dst_type
.
is_float
:
return
src_type
.
rank
<=
dst_type
.
rank
else
:
return
False
else
:
return
False
def
is_promotion
(
src_type
,
dst_type
):
# It's hard to find a hard definition of promotion, but empirical
# evidence suggests that the below is all that's allowed.
if
src_type
.
is_numeric
:
if
dst_type
.
same_as
(
c_int_type
):
return
src_type
.
is_enum
or
(
src_type
.
is_int
and
(
not
src_type
.
signed
)
+
src_type
.
rank
<
dst_type
.
rank
)
elif
dst_type
.
same_as
(
c_double_type
):
return
src_type
.
is_float
and
src_type
.
rank
<=
dst_type
.
rank
return
False
def
best_match
(
args
,
functions
,
pos
=
None
):
"""
Finds the best function to be called
...
...
Cython/Compiler/Scanning.py
View file @
f53e00e3
...
...
@@ -473,6 +473,14 @@ class PyrexScanner(Scanner):
t
=
"%s %s"
%
(
self
.
sy
,
self
.
systring
)
print
(
"--- %3d %2d %s"
%
(
line
,
col
,
t
))
def
peek
(
self
):
saved
=
self
.
sy
,
self
.
systring
self
.
next
()
next
=
self
.
sy
,
self
.
systring
self
.
unread
(
*
next
)
self
.
sy
,
self
.
systring
=
saved
return
next
def
put_back
(
self
,
sy
,
systring
):
self
.
unread
(
self
.
sy
,
self
.
systring
)
self
.
sy
=
sy
...
...
Cython/Compiler/Symtab.py
View file @
f53e00e3
...
...
@@ -470,7 +470,7 @@ class Scope(object):
if visibility == 'extern' and entry.visibility == 'extern':
if self.is_cpp():
temp = self.add_cfunction(name, type, pos, cname, visibility, modifiers)
entry.overloaded_alternatives.append(temp
)
temp.overloaded_alternatives = entry.all_alternatives(
)
entry = temp
else:
warning(pos, "
Function
signature
does
not
match
previous
declaration
", 1)
...
...
Demos/setup.py
View file @
f53e00e3
...
...
@@ -13,10 +13,11 @@ except:
ext_modules
=
[
Extension
(
"primes"
,
[
"primes.pyx"
]),
Extension
(
"spam"
,
[
"spam.pyx"
]),
Extension
(
"square"
,
[
"square.pyx"
],
language
=
"c++"
),
]
for
file
in
glob
.
glob
(
"*.pyx"
):
if
file
!=
"numeric_demo.pyx"
:
if
file
!=
"numeric_demo.pyx"
and
file
!=
"square.pyx"
:
ext_modules
.
append
(
Extension
(
file
[:
-
4
],
[
file
],
include_dirs
=
numpy_include_dirs
))
setup
(
...
...
tests/run/new_as_nonkeyword.pyx
0 → 100644
View file @
f53e00e3
cdef
extern
from
*
:
int
new
(
int
new
)
def
new
(
x
):
"""
>>> new(3)
3
"""
cdef
int
new
=
x
return
new
def
x
(
new
):
"""
>>> x(10)
110
>>> x(1)
1
"""
if
new
*
new
!=
new
:
return
new
+
new
**
2
return
new
class
A
:
def
new
(
self
,
n
):
"""
>>> a = A()
>>> a.new(3)
6
>>> a.new(5)
120
"""
if
n
<=
1
:
return
1
else
:
return
n
*
self
.
new
(
n
-
1
)
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