Commit d179a356 authored by Stefan Behnel's avatar Stefan Behnel

merged in latest cython-devel

parents 90f8c776 d59f781c
......@@ -36,6 +36,8 @@ Options:
--line-directives Produce #line directives pointing to the .pyx source
--cplus Output a c++ rather than c file.
--embed Embed the Python interpreter in a main() method.
-2 Compile based on Python-2 syntax and code semantics.
-3 Compile based on Python-3 syntax and code semantics.
-X, --directive <name>=<value>[,<name=value,...] Overrides a compiler directive
"""
......@@ -114,6 +116,10 @@ def parse_command_line(args):
Options.convert_range = True
elif option == "--line-directives":
options.emit_linenums = True
elif option == '-2':
options.language_level = 2
elif option == '-3':
options.language_level = 3
elif option in ("-X", "--directive"):
try:
options.compiler_directives = Options.parse_directive_list(
......
......@@ -10,7 +10,7 @@ debug_temp_code_comments = 0
debug_trace_code_generation = 0
# Do not replace exceptions with user-friendly error messages
debug_no_exception_intercept = 1
debug_no_exception_intercept = 0
# Print a message each time a new stage in the pipeline is entered
debug_verbose_pipeline = 0
......@@ -804,8 +804,9 @@ class IntNode(ConstNode):
if self.type is dst_type:
return self
elif dst_type.is_float:
return FloatNode(self.pos, value=repr(float(self.value)))
node = IntNode(self.pos, value=self.value,
float_value = float(self.value)
return FloatNode(self.pos, value=repr(float_value), constant_result=float_value)
node = IntNode(self.pos, value=self.value, constant_result=self.constant_result,
unsigned=self.unsigned, longness=self.longness)
if dst_type.is_numeric and not dst_type.is_complex:
return node
......
......@@ -65,8 +65,9 @@ class Context(object):
# modules {string : ModuleScope}
# include_directories [string]
# future_directives [object]
# language_level int currently 2 or 3 for Python 2/3
def __init__(self, include_directories, compiler_directives, cpp=False):
def __init__(self, include_directories, compiler_directives, cpp=False, language_level=2):
#self.modules = {"__builtin__" : BuiltinScope()}
import Builtin, CythonScope
self.modules = {"__builtin__" : Builtin.builtin_scope}
......@@ -82,6 +83,15 @@ class Context(object):
os.path.join(os.path.dirname(__file__), os.path.pardir, 'Includes')))
self.include_directories = include_directories + [standard_include_path]
self.set_language_level(language_level)
def set_language_level(self, level):
self.language_level = level
if level >= 3:
from Future import print_function, unicode_literals
self.future_directives.add(print_function)
self.future_directives.add(unicode_literals)
def create_pipeline(self, pxd, py=False):
from Visitor import PrintTree
from ParseTreeTransforms import WithTransform, NormalizeTree, PostParse, PxdPostParse
......@@ -543,7 +553,8 @@ def create_default_resultobj(compilation_source, options):
def run_pipeline(source, options, full_module_name = None):
# Set up context
context = Context(options.include_path, options.compiler_directives, options.cplus)
context = Context(options.include_path, options.compiler_directives,
options.cplus, options.language_level)
# Set up source object
cwd = os.getcwd()
......@@ -598,6 +609,7 @@ class CompilationOptions(object):
quiet boolean Don't print source names in recursive mode
compiler_directives dict Overrides for pragma options (see Options.py)
evaluate_tree_assertions boolean Test support: evaluate parse tree assertions
language_level integer The Python language level: 2 or 3
cplus boolean Compile as c++ code
"""
......@@ -776,4 +788,5 @@ default_options = dict(
compiler_directives = {},
evaluate_tree_assertions = False,
emit_linenums = False,
language_level = 2,
)
......@@ -66,6 +66,7 @@ directive_defaults = {
'infer_types': None,
'infer_types.verbose': False,
'autotestdict': True,
'language_level': 2,
'warn': None,
'warn.undeclared': False,
......
......@@ -2706,6 +2706,9 @@ def p_module(s, pxd, full_module_name):
directive_comments = p_compiler_directive_comments(s)
s.parse_comments = False
if 'language_level' in directive_comments:
s.context.set_language_level('language_level')
doc = p_doc_string(s)
if pxd:
level = 'module_pxd'
......
......@@ -56,7 +56,8 @@ VER_DEP_MODULES = {
]),
(2,4) : (operator.le, lambda x: x in ['run.extern_builtins_T258'
]),
(2,6) : (operator.lt, lambda x: x in ['run.print_function'
(2,6) : (operator.lt, lambda x: x in ['run.print_function',
'run.cython3',
]),
(3,): (operator.ge, lambda x: x in ['run.non_future_division',
'compile.extsetslice',
......
# cython: language_level=3
def print_function(*args):
"""
>>> print_function(1,2,3)
1 2 3
"""
print(*args) # this isn't valid Py2 syntax
ustring = "abcdefg"
def unicode_literals():
"""
>>> print( unicode_literals() )
True
abcdefg
"""
print(isinstance(ustring, unicode) or type(ustring))
return ustring
......@@ -20,6 +20,42 @@ def test_modify():
print
return i,n
@cython.test_assert_path_exists("//ForFromStatNode")
@cython.test_fail_if_path_exists("//ForInStatNode")
def test_negindex():
"""
>>> test_negindex()
6
5
4
3
2
(2, 0)
"""
cdef int i, n = 5
for i in range(n+1, 1, -1):
print i
n = 0
return i,n
@cython.test_assert_path_exists("//ForFromStatNode",
"//ForFromStatNode//PrintStatNode//CoerceToPyTypeNode")
@cython.test_fail_if_path_exists("//ForInStatNode")
def test_negindex_inferred():
"""
>>> test_negindex_inferred()
5
4
3
2
(2, 0)
"""
cdef int n = 5
for i in range(n, 1, -1):
print i
n = 0
return i,n
@cython.test_assert_path_exists("//ForFromStatNode")
@cython.test_fail_if_path_exists("//ForInStatNode")
def test_fix():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment