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
60be9a7b
Commit
60be9a7b
authored
Nov 03, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix fused type -> object compiler crash & resolve fused type variable declarations from modules
parent
0991b1eb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
1 deletion
+33
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+9
-0
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+2
-1
tests/run/fused_types.pyx
tests/run/fused_types.pyx
+22
-0
No files found.
Cython/Compiler/Nodes.py
View file @
60be9a7b
...
@@ -799,8 +799,11 @@ class CSimpleBaseTypeNode(CBaseTypeNode):
...
@@ -799,8 +799,11 @@ class CSimpleBaseTypeNode(CBaseTypeNode):
else
:
else
:
if
self
.
module_path
:
if
self
.
module_path
:
scope
=
env
.
find_imported_module
(
self
.
module_path
,
self
.
pos
)
scope
=
env
.
find_imported_module
(
self
.
module_path
,
self
.
pos
)
if
scope
:
scope
.
fused_to_specific
=
env
.
fused_to_specific
else
:
else
:
scope
=
env
scope
=
env
if
scope
:
if
scope
:
if
scope
.
is_c_class_scope
:
if
scope
.
is_c_class_scope
:
scope
=
scope
.
global_scope
()
scope
=
scope
.
global_scope
()
...
@@ -2757,6 +2760,10 @@ class DefNode(FuncDefNode):
...
@@ -2757,6 +2760,10 @@ class DefNode(FuncDefNode):
def
analyse_argument_types
(
self
,
env
):
def
analyse_argument_types
(
self
,
env
):
directive_locals
=
self
.
directive_locals
=
env
.
directives
[
'locals'
]
directive_locals
=
self
.
directive_locals
=
env
.
directives
[
'locals'
]
allow_none_for_extension_args
=
env
.
directives
[
'allow_none_for_extension_args'
]
allow_none_for_extension_args
=
env
.
directives
[
'allow_none_for_extension_args'
]
f2s
=
env
.
fused_to_specific
env
.
fused_to_specific
=
None
for
arg
in
self
.
args
:
for
arg
in
self
.
args
:
if
hasattr
(
arg
,
'name'
):
if
hasattr
(
arg
,
'name'
):
name_declarator
=
None
name_declarator
=
None
...
@@ -2801,6 +2808,8 @@ class DefNode(FuncDefNode):
...
@@ -2801,6 +2808,8 @@ class DefNode(FuncDefNode):
if
arg
.
or_none
:
if
arg
.
or_none
:
error
(
arg
.
pos
,
"Only Python type arguments can have 'or None'"
)
error
(
arg
.
pos
,
"Only Python type arguments can have 'or None'"
)
env
.
fused_to_specific
=
f2s
def
analyse_signature
(
self
,
env
):
def
analyse_signature
(
self
,
env
):
if
self
.
entry
.
is_special
:
if
self
.
entry
.
is_special
:
if
self
.
decorators
:
if
self
.
decorators
:
...
...
Cython/Compiler/PyrexTypes.py
View file @
60be9a7b
...
@@ -1108,7 +1108,7 @@ class CType(PyrexType):
...
@@ -1108,7 +1108,7 @@ class CType(PyrexType):
return
0
return
0
class
FusedType
(
Pyrex
Type
):
class
FusedType
(
C
Type
):
"""
"""
Represents a Fused Type. All it needs to do is keep track of the types
Represents a Fused Type. All it needs to do is keep track of the types
it aggregates, as it will be replaced with its specific version wherever
it aggregates, as it will be replaced with its specific version wherever
...
@@ -1121,6 +1121,7 @@ class FusedType(PyrexType):
...
@@ -1121,6 +1121,7 @@ class FusedType(PyrexType):
"""
"""
is_fused
=
1
is_fused
=
1
exception_check
=
0
def
__init__
(
self
,
types
,
name
=
None
):
def
__init__
(
self
,
types
,
name
=
None
):
self
.
types
=
types
self
.
types
=
types
...
...
tests/run/fused_types.pyx
View file @
60be9a7b
# mode: run
# mode: run
cimport
cython
cimport
cython
from
cython
cimport
integral
from
cython
cimport
integral
from
cpython
cimport
Py_INCREF
from
cpython
cimport
Py_INCREF
...
@@ -220,3 +221,24 @@ def test_normal_class():
...
@@ -220,3 +221,24 @@ def test_normal_class():
short 10
short 10
"""
"""
NormalClass
().
method
[
pure_cython
.
short
](
10
)
NormalClass
().
method
[
pure_cython
.
short
](
10
)
def
test_fused_declarations
(
cython
.
integral
i
,
cython
.
floating
f
):
"""
>>> test_fused_declarations[pure_cython.short, pure_cython.float](5, 6.6)
short
float
25 43.56
>>> test_fused_declarations[pure_cython.long, pure_cython.double](5, 6.6)
long
double
25 43.56
"""
cdef
cython
.
integral
squared_int
=
i
*
i
cdef
cython
.
floating
squared_float
=
f
*
f
assert
cython
.
typeof
(
squared_int
)
==
cython
.
typeof
(
i
)
assert
cython
.
typeof
(
squared_float
)
==
cython
.
typeof
(
f
)
print
cython
.
typeof
(
squared_int
)
print
cython
.
typeof
(
squared_float
)
print
'%d %.2f'
%
(
squared_int
,
squared_float
)
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