Commit 25194156 authored by Robert Bradshaw's avatar Robert Bradshaw

copy ModuleNode changes to new file

parent 1c96a947
...@@ -22,7 +22,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -22,7 +22,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# body StatListNode # body StatListNode
def analyse_declarations(self, env): def analyse_declarations(self, env):
env.doc = self.doc if Options.embed_pos_in_docstring:
env.doc = 'File: %s (starting at line %s)'%relative_position(self.pos)
if not self.doc is None:
env.doc = env.doc + '\\n' + self.doc
else:
env.doc = self.doc
self.body.analyse_declarations(env) self.body.analyse_declarations(env)
def process_implementation(self, env, result): def process_implementation(self, env, result):
...@@ -97,6 +102,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -97,6 +102,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_const_definitions(env, code) self.generate_const_definitions(env, code)
self.generate_interned_name_decls(env, code) self.generate_interned_name_decls(env, code)
self.generate_py_string_decls(env, code) self.generate_py_string_decls(env, code)
self.generate_cached_builtins_decls(env, code)
self.body.generate_function_definitions(env, code) self.body.generate_function_definitions(env, code)
self.generate_interned_name_table(env, code) self.generate_interned_name_table(env, code)
self.generate_py_string_table(env, code) self.generate_py_string_table(env, code)
...@@ -129,11 +135,19 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -129,11 +135,19 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln('/* Generated by Pyrex %s on %s */' % ( code.putln('/* Generated by Pyrex %s on %s */' % (
Version.version, time.asctime())) Version.version, time.asctime()))
code.putln('') code.putln('')
code.putln('#define PY_SSIZE_T_CLEAN')
for filename in env.python_include_files: for filename in env.python_include_files:
code.putln('#include "%s"' % filename) code.putln('#include "%s"' % filename)
code.putln("#ifndef PY_LONG_LONG") code.putln("#ifndef PY_LONG_LONG")
code.putln(" #define PY_LONG_LONG LONG_LONG") code.putln(" #define PY_LONG_LONG LONG_LONG")
code.putln("#endif") code.putln("#endif")
code.putln("#if PY_VERSION_HEX < 0x02050000")
code.putln(" typedef int Py_ssize_t;")
code.putln(" #define PY_SSIZE_T_MAX INT_MAX")
code.putln(" #define PY_SSIZE_T_MIN INT_MIN")
code.putln(" #define PyInt_FromSsize_t(z) PyInt_FromLong(z)")
code.putln(" #define PyInt_AsSsize_t(o) PyInt_AsLong(o)")
code.putln("#endif")
self.generate_extern_c_macro_definition(code) self.generate_extern_c_macro_definition(code)
code.putln("%s double pow(double, double);" % Naming.extern_c_macro) code.putln("%s double pow(double, double);" % Naming.extern_c_macro)
self.generate_includes(env, cimported_modules, code) self.generate_includes(env, cimported_modules, code)
...@@ -445,7 +459,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -445,7 +459,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
type.vtabptr_cname)) type.vtabptr_cname))
for entry in py_attrs: for entry in py_attrs:
if entry.name == "__weakref__": if entry.name == "__weakref__":
code.putln("p->%s = 0;" % entry.cname) code.putln("p->%s = NULL;" % entry.cname)
else: else:
code.put_init_var_to_py_none(entry, "p->%s") code.put_init_var_to_py_none(entry, "p->%s")
entry = scope.lookup_here("__new__") entry = scope.lookup_here("__new__")
...@@ -577,12 +591,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -577,12 +591,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# a __getitem__ method is present. It converts its # a __getitem__ method is present. It converts its
# argument to a Python integer and calls mp_subscript. # argument to a Python integer and calls mp_subscript.
code.putln( code.putln(
"static PyObject *%s(PyObject *o, int i) {" % "static PyObject *%s(PyObject *o, Py_ssize_t i) {" %
scope.mangle_internal("sq_item")) scope.mangle_internal("sq_item"))
code.putln( code.putln(
"PyObject *r;") "PyObject *r;")
code.putln( code.putln(
"PyObject *x = PyInt_FromLong(i); if(!x) return 0;") "PyObject *x = PyInt_FromSsize(i); if(!x) return 0;")
code.putln( code.putln(
"r = o->ob_type->tp_as_mapping->mp_subscript(o, x);") "r = o->ob_type->tp_as_mapping->mp_subscript(o, x);")
code.putln( code.putln(
...@@ -668,7 +682,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -668,7 +682,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
del_entry = scope.lookup_here("__delslice__") del_entry = scope.lookup_here("__delslice__")
code.putln("") code.putln("")
code.putln( code.putln(
"static int %s(PyObject *o, int i, int j, PyObject *v) {" % "static int %s(PyObject *o, Py_ssize_t i, Py_ssize_t j, PyObject *v) {" %
scope.mangle_internal("sq_ass_slice")) scope.mangle_internal("sq_ass_slice"))
code.putln( code.putln(
"if (v) {") "if (v) {")
...@@ -925,7 +939,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -925,7 +939,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"0, /*ob_size*/") "0, /*ob_size*/")
code.putln( code.putln(
'"%s.%s", /*tp_name*/' % ( '"%s.%s", /*tp_name*/' % (
modname, scope.class_name)) self.full_module_name, scope.class_name))
if type.typedef_flag: if type.typedef_flag:
objstruct = type.objstruct_cname objstruct = type.objstruct_cname
else: else:
...@@ -1054,6 +1068,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1054,6 +1068,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_intern_code(env, code) self.generate_intern_code(env, code)
#code.putln("/*--- String init code ---*/") #code.putln("/*--- String init code ---*/")
self.generate_string_init_code(env, code) self.generate_string_init_code(env, code)
#code.putln("/*--- Builtin init code ---*/")
self.generate_builtin_init_code(env, code)
#code.putln("/*--- Global init code ---*/") #code.putln("/*--- Global init code ---*/")
self.generate_global_init_code(env, code) self.generate_global_init_code(env, code)
...@@ -1121,6 +1137,28 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1121,6 +1137,28 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"if (__Pyx_InitStrings(%s) < 0) %s;" % ( "if (__Pyx_InitStrings(%s) < 0) %s;" % (
Naming.stringtab_cname, Naming.stringtab_cname,
code.error_goto(self.pos))) code.error_goto(self.pos)))
def generate_builtin_init_code(self, env, code):
# Lookup and cache builtin objects.
if Options.cache_builtins:
for entry in env.builtin_scope().cached_entries:
if Options.intern_names:
#assert entry.interned_cname is not None
code.putln(
'%s = __Pyx_GetName(%s, %s); if (!%s) %s' % (
entry.cname,
Naming.builtins_cname,
entry.interned_cname,
entry.cname,
code.error_goto(entry.pos)))
else:
code.putln(
'%s = __Pyx_GetName(%s, "%s"); if (!%s) %s' % (
entry.cname,
Naming.builtins_cname,
self.entry.name,
entry.cname,
code.error_goto(entry.pos)))
def generate_global_init_code(self, env, code): def generate_global_init_code(self, env, code):
# Generate code to initialise global PyObject * # Generate code to initialise global PyObject *
......
...@@ -115,6 +115,14 @@ class BlockNode: ...@@ -115,6 +115,14 @@ class BlockNode:
code.putln( code.putln(
"static PyObject *%s;" % entry.pystring_cname) "static PyObject *%s;" % entry.pystring_cname)
def generate_cached_builtins_decls(self, env, code):
entries = env.builtin_scope().undeclared_cached_entries
if len(entries) > 0:
code.putln("")
for entry in entries:
code.putln("static PyObject *%s;" % entry.cname)
del entries[:]
class StatListNode(Node): class StatListNode(Node):
# stats a list of StatNode # stats a list of StatNode
......
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