Commit f7fb5c63 authored by Mark Florisson's avatar Mark Florisson

Remove Importer.py and with statements in FusedNode

parent 9c93f96e
...@@ -1956,17 +1956,27 @@ class PyxCodeWriter(object): ...@@ -1956,17 +1956,27 @@ class PyxCodeWriter(object):
def indent(self, levels=1): def indent(self, levels=1):
self.level += levels self.level += levels
return True
def dedent(self, levels=1): def dedent(self, levels=1):
self.level -= levels self.level -= levels
def indenter(self, line): def indenter(self, line):
""" """
Instead of
with pyx_code.indenter("for i in range(10):"): with pyx_code.indenter("for i in range(10):"):
pyx_code.putln("print i") pyx_code.putln("print i")
write
if pyx_code.indenter("for i in range(10);"):
pyx_code.putln("print i")
pyx_code.dedent()
""" """
self.putln(line) self.putln(line)
return self self.indent()
return True
def getvalue(self): def getvalue(self):
result = self.buffer.getvalue() result = self.buffer.getvalue()
...@@ -2000,10 +2010,6 @@ class PyxCodeWriter(object): ...@@ -2000,10 +2010,6 @@ class PyxCodeWriter(object):
def named_insertion_point(self, name): def named_insertion_point(self, name):
setattr(self, name, self.insertion_point()) setattr(self, name, self.insertion_point())
__enter__ = indent
def __exit__(self, exc_value, exc_type, exc_tb):
self.dedent()
class ClosureTempAllocator(object): class ClosureTempAllocator(object):
def __init__(self, klass): def __init__(self, klass):
......
...@@ -279,21 +279,25 @@ class FusedCFuncDefNode(StatListNode): ...@@ -279,21 +279,25 @@ class FusedCFuncDefNode(StatListNode):
def _buffer_check_numpy_dtype_setup_cases(self, pyx_code): def _buffer_check_numpy_dtype_setup_cases(self, pyx_code):
"Setup some common cases to match dtypes against specializations" "Setup some common cases to match dtypes against specializations"
with pyx_code.indenter("if dtype.kind in ('i', 'u'):"): if pyx_code.indenter("if dtype.kind in ('i', 'u'):"):
pyx_code.putln("pass") pyx_code.putln("pass")
pyx_code.named_insertion_point("dtype_int") pyx_code.named_insertion_point("dtype_int")
pyx_code.dedent()
with pyx_code.indenter("elif dtype.kind == 'f':"): if pyx_code.indenter("elif dtype.kind == 'f':"):
pyx_code.putln("pass") pyx_code.putln("pass")
pyx_code.named_insertion_point("dtype_float") pyx_code.named_insertion_point("dtype_float")
pyx_code.dedent()
with pyx_code.indenter("elif dtype.kind == 'c':"): if pyx_code.indenter("elif dtype.kind == 'c':"):
pyx_code.putln("pass") pyx_code.putln("pass")
pyx_code.named_insertion_point("dtype_complex") pyx_code.named_insertion_point("dtype_complex")
pyx_code.dedent()
with pyx_code.indenter("elif dtype.kind == 'O':"): if pyx_code.indenter("elif dtype.kind == 'O':"):
pyx_code.putln("pass") pyx_code.putln("pass")
pyx_code.named_insertion_point("dtype_object") pyx_code.named_insertion_point("dtype_object")
pyx_code.dedent()
match = "dest_sig[{{dest_sig_idx}}] = '{{specialized_type_name}}'" match = "dest_sig[{{dest_sig_idx}}] = '{{specialized_type_name}}'"
no_match = "dest_sig[{{dest_sig_idx}}] = None" no_match = "dest_sig[{{dest_sig_idx}}] = None"
...@@ -323,10 +327,11 @@ class FusedCFuncDefNode(StatListNode): ...@@ -323,10 +327,11 @@ class FusedCFuncDefNode(StatListNode):
if dtype.is_int: if dtype.is_int:
cond += ' and {{signed_match}}' cond += ' and {{signed_match}}'
with codewriter.indenter("if %s:" % cond): if codewriter.indenter("if %s:" % cond):
# codewriter.putln("print 'buffer match found based on numpy dtype'") # codewriter.putln("print 'buffer match found based on numpy dtype'")
codewriter.putln(self.match) codewriter.putln(self.match)
codewriter.putln("break") codewriter.putln("break")
codewriter.dedent()
def _buffer_parse_format_string_check(self, pyx_code, decl_code, def _buffer_parse_format_string_check(self, pyx_code, decl_code,
specialized_type, env): specialized_type, env):
...@@ -378,9 +383,9 @@ class FusedCFuncDefNode(StatListNode): ...@@ -378,9 +383,9 @@ class FusedCFuncDefNode(StatListNode):
""" """
from Cython.Compiler import ExprNodes from Cython.Compiler import ExprNodes
if buffer_types: if buffer_types:
with pyx_code.indenter(u"else:"): if pyx_code.indenter(u"else:"):
# The first thing to find a match in this loop breaks out of the loop # The first thing to find a match in this loop breaks out of the loop
with pyx_code.indenter(u"while 1:"): if pyx_code.indenter(u"while 1:"):
pyx_code.put_chunk( pyx_code.put_chunk(
u""" u"""
if numpy is not None: if numpy is not None:
...@@ -409,6 +414,9 @@ class FusedCFuncDefNode(StatListNode): ...@@ -409,6 +414,9 @@ class FusedCFuncDefNode(StatListNode):
pyx_code.putln(self.no_match) pyx_code.putln(self.no_match)
pyx_code.putln("break") pyx_code.putln("break")
pyx_code.dedent()
pyx_code.dedent()
else: else:
pyx_code.putln("else: %s" % self.no_match) pyx_code.putln("else: %s" % self.no_match)
......
"""
Transparently import a module from the compiler on which the compiler
does not depend for its bootstrapping. This way one can write code
that is not supported in certain Python versions but which is supported
by Cython.
"""
import os
import sys
import imp
import shutil
import pyximport
# set up the PyxArgs global variable in pyximport (why is that a global :)
importers = pyximport.install(pyimport=True)
pyximport.uninstall(*importers)
def importer(modulename, version=None):
try:
# Check for an already compiled module
return __import__(modulename, None, None, [''])
except ImportError:
pass
dirname = os.path.dirname
root = dirname(dirname(dirname(os.path.abspath(__file__))))
filename = os.path.join(root, *modulename.split('.')) + ".pyx"
if version and sys.version_info[:2] < version:
return pyximport.load_module(modulename, filename)
else:
mod = imp.new_module(modulename)
exec open(filename).read() in mod.__dict__, mod.__dict__
sys.modules[modulename] = mod
return mod
#shutil.copy(filename, os.path.splitext(filename)[0] + '.py')
#return __import__(modulename, None, None, [''])
...@@ -18,7 +18,6 @@ from Cython.Compiler.TreeFragment import TreeFragment ...@@ -18,7 +18,6 @@ from Cython.Compiler.TreeFragment import TreeFragment
from Cython.Compiler.StringEncoding import EncodedString from Cython.Compiler.StringEncoding import EncodedString
from Cython.Compiler.Errors import error, warning, CompileError, InternalError from Cython.Compiler.Errors import error, warning, CompileError, InternalError
from Cython.Compiler.Code import UtilityCode from Cython.Compiler.Code import UtilityCode
from Cython.Compiler import Importer
import copy import copy
...@@ -1489,8 +1488,7 @@ if VALUE is not None: ...@@ -1489,8 +1488,7 @@ if VALUE is not None:
return node return node
FusedNode = Importer.importer("Cython.Compiler.FusedNode", from Cython.Compiler import FusedNode
version=(2, 5))
node = FusedNode.FusedCFuncDefNode(node, env) node = FusedNode.FusedCFuncDefNode(node, env)
self.fused_function = node self.fused_function = node
......
...@@ -112,7 +112,7 @@ def compile_cython_modules(profile=False, compile_more=False, cython_with_refnan ...@@ -112,7 +112,7 @@ def compile_cython_modules(profile=False, compile_more=False, cython_with_refnan
"Cython.Compiler.FlowControl", "Cython.Compiler.FlowControl",
"Cython.Compiler.Code", "Cython.Compiler.Code",
"Cython.Runtime.refnanny", "Cython.Runtime.refnanny",
"Cython.Compiler.FusedNode", # "Cython.Compiler.FusedNode",
] ]
if compile_more: if compile_more:
compiled_modules.extend([ compiled_modules.extend([
......
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