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
124fd89a
Commit
124fd89a
authored
Oct 03, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Type inference tests.
parent
51db01c9
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
4 deletions
+90
-4
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+6
-1
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+1
-1
Cython/Compiler/TypeInference.py
Cython/Compiler/TypeInference.py
+2
-1
tests/run/isinstance.pyx
tests/run/isinstance.pyx
+1
-1
tests/run/type_inference.pyx
tests/run/type_inference.pyx
+80
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
124fd89a
...
@@ -13,7 +13,7 @@ import Nodes
...
@@ -13,7 +13,7 @@ import Nodes
from
Nodes
import
Node
from
Nodes
import
Node
import
PyrexTypes
import
PyrexTypes
from
PyrexTypes
import
py_object_type
,
c_long_type
,
typecast
,
error_type
,
unspecified_type
from
PyrexTypes
import
py_object_type
,
c_long_type
,
typecast
,
error_type
,
unspecified_type
from
Builtin
import
list_type
,
tuple_type
,
set_type
,
dict_type
,
unicode_type
,
bytes_type
from
Builtin
import
list_type
,
tuple_type
,
set_type
,
dict_type
,
unicode_type
,
bytes_type
,
type_type
import
Builtin
import
Builtin
import
Symtab
import
Symtab
import
Options
import
Options
...
@@ -990,6 +990,11 @@ class NameNode(AtomicExprNode):
...
@@ -990,6 +990,11 @@ class NameNode(AtomicExprNode):
self
.
entry
=
env
.
lookup
(
self
.
name
)
self
.
entry
=
env
.
lookup
(
self
.
name
)
if
self
.
entry
is
None
:
if
self
.
entry
is
None
:
return
py_object_type
return
py_object_type
elif
(
self
.
entry
.
type
.
is_extension_type
or
self
.
entry
.
type
.
is_builtin_type
)
and
\
self
.
name
==
self
.
entry
.
type
.
name
:
# Unfortunately the type attribute of type objects
# is used for the pointer to the type the represent.
return
type_type
else
:
else
:
return
self
.
entry
.
type
return
self
.
entry
.
type
...
...
Cython/Compiler/Options.py
View file @
124fd89a
...
@@ -68,7 +68,7 @@ option_defaults = {
...
@@ -68,7 +68,7 @@ option_defaults = {
'c99_complex'
:
False
,
# Don't use macro wrappers for complex arith, not sure what to name this...
'c99_complex'
:
False
,
# Don't use macro wrappers for complex arith, not sure what to name this...
'callspec'
:
""
,
'callspec'
:
""
,
'profile'
:
False
,
'profile'
:
False
,
'infer_types'
:
Tru
e
,
'infer_types'
:
Fals
e
,
'autotestdict'
:
True
,
'autotestdict'
:
True
,
# test support
# test support
...
...
Cython/Compiler/TypeInference.py
View file @
124fd89a
...
@@ -152,7 +152,8 @@ class SimpleAssignmentTypeInferer:
...
@@ -152,7 +152,8 @@ class SimpleAssignmentTypeInferer:
if
types
:
if
types
:
entry
.
type
=
reduce
(
spanning_type
,
types
)
entry
.
type
=
reduce
(
spanning_type
,
types
)
else
:
else
:
print
"No assignments"
,
entry
.
pos
,
entry
# List comprehension?
# print "No assignments", entry.pos, entry
entry
.
type
=
py_object_type
entry
.
type
=
py_object_type
resolve_dependancy
(
entry
)
resolve_dependancy
(
entry
)
# Deal with simple circular dependancies...
# Deal with simple circular dependancies...
...
...
tests/run/isinstance.pyx
View file @
124fd89a
...
@@ -35,7 +35,7 @@ def test_all():
...
@@ -35,7 +35,7 @@ def test_all():
assert
not
isinstance
(
u"foo"
,
int
)
assert
not
isinstance
(
u"foo"
,
int
)
# Non-optimized
# Non-optimized
foo
=
A
cdef
object
foo
=
A
assert
isinstance
(
A
(),
foo
)
assert
isinstance
(
A
(),
foo
)
assert
isinstance
(
0
,
(
int
,
long
))
assert
isinstance
(
0
,
(
int
,
long
))
assert
not
isinstance
(
u"xyz"
,
(
int
,
long
))
assert
not
isinstance
(
u"xyz"
,
(
int
,
long
))
...
...
tests/run/type_inference.pyx
0 → 100644
View file @
124fd89a
# cython: infer_types = True
__doc__
=
u"""
>>> simple()
>>> multiple_assignments()
>>> arithmatic()
>>> cascade()
>>> increment()
>>> loop()
"""
from
cython
cimport
typeof
def
simple
():
i
=
3
assert
typeof
(
i
)
==
"long"
x
=
1.41
assert
typeof
(
x
)
==
"double"
xptr
=
&
x
assert
typeof
(
xptr
)
==
"double *"
xptrptr
=
&
xptr
assert
typeof
(
xptrptr
)
==
"double **"
s
=
"abc"
assert
typeof
(
s
)
==
"char *"
u
=
u"xyz"
assert
typeof
(
u
)
==
"unicode object"
L
=
[
1
,
2
,
3
]
assert
typeof
(
L
)
==
"list object"
t
=
(
4
,
5
,
6
)
assert
typeof
(
t
)
==
"tuple object"
def
multiple_assignments
():
a
=
3
a
=
4
a
=
5
assert
typeof
(
a
)
==
"long"
b
=
a
b
=
3.1
b
=
3.14159
assert
typeof
(
b
)
==
"double"
c
=
a
c
=
b
c
=
[
1
,
2
,
3
]
assert
typeof
(
c
)
==
"Python object"
def
arithmatic
():
a
=
1
+
2
assert
typeof
(
a
)
==
"long"
b
=
1
+
1.5
assert
typeof
(
b
)
==
"double"
c
=
1
+
<
object
>
2
assert
typeof
(
c
)
==
"Python object"
d
=
"abc %s"
%
"x"
assert
typeof
(
d
)
==
"Python object"
def
cascade
():
a
=
1.0
b
=
a
+
2
c
=
b
+
3
d
=
c
+
4
assert
typeof
(
d
)
==
"double"
e
=
a
+
b
+
c
+
d
assert
typeof
(
e
)
==
"double"
def
increment
():
a
=
5
a
+=
1
assert
typeof
(
a
)
==
"long"
def
loop
():
for
a
in
range
(
10
):
pass
assert
typeof
(
a
)
==
"long"
b
=
1.0
for
b
in
range
(
5
):
pass
assert
typeof
(
b
)
==
"double"
for
c
from
0
<=
c
<
10
by
.
5
:
pass
assert
typeof
(
c
)
==
"double"
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