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
25194156
Commit
25194156
authored
Jun 06, 2007
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
copy ModuleNode changes to new file
parent
1c96a947
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
6 deletions
+52
-6
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+44
-6
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+8
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
25194156
...
...
@@ -22,7 +22,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# body StatListNode
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
)
def
process_implementation
(
self
,
env
,
result
):
...
...
@@ -97,6 +102,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self
.
generate_const_definitions
(
env
,
code
)
self
.
generate_interned_name_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
.
generate_interned_name_table
(
env
,
code
)
self
.
generate_py_string_table
(
env
,
code
)
...
...
@@ -129,11 +135,19 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
'/* Generated by Pyrex %s on %s */'
%
(
Version
.
version
,
time
.
asctime
()))
code
.
putln
(
''
)
code
.
putln
(
'#define PY_SSIZE_T_CLEAN'
)
for
filename
in
env
.
python_include_files
:
code
.
putln
(
'#include "%s"'
%
filename
)
code
.
putln
(
"#ifndef PY_LONG_LONG"
)
code
.
putln
(
" #define PY_LONG_LONG LONG_LONG"
)
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
)
code
.
putln
(
"%s double pow(double, double);"
%
Naming
.
extern_c_macro
)
self
.
generate_includes
(
env
,
cimported_modules
,
code
)
...
...
@@ -445,7 +459,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
type
.
vtabptr_cname
))
for
entry
in
py_attrs
:
if
entry
.
name
==
"__weakref__"
:
code
.
putln
(
"p->%s =
0
;"
%
entry
.
cname
)
code
.
putln
(
"p->%s =
NULL
;"
%
entry
.
cname
)
else
:
code
.
put_init_var_to_py_none
(
entry
,
"p->%s"
)
entry
=
scope
.
lookup_here
(
"__new__"
)
...
...
@@ -577,12 +591,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# a __getitem__ method is present. It converts its
# argument to a Python integer and calls mp_subscript.
code
.
putln
(
"static PyObject *%s(PyObject *o,
in
t i) {"
%
"static PyObject *%s(PyObject *o,
Py_ssize_
t i) {"
%
scope
.
mangle_internal
(
"sq_item"
))
code
.
putln
(
"PyObject *r;"
)
code
.
putln
(
"PyObject *x = PyInt_From
Long
(i); if(!x) return 0;"
)
"PyObject *x = PyInt_From
Ssize
(i); if(!x) return 0;"
)
code
.
putln
(
"r = o->ob_type->tp_as_mapping->mp_subscript(o, x);"
)
code
.
putln
(
...
...
@@ -668,7 +682,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
del_entry
=
scope
.
lookup_here
(
"__delslice__"
)
code
.
putln
(
""
)
code
.
putln
(
"static int %s(PyObject *o,
int i, in
t j, PyObject *v) {"
%
"static int %s(PyObject *o,
Py_ssize_t i, Py_ssize_
t j, PyObject *v) {"
%
scope
.
mangle_internal
(
"sq_ass_slice"
))
code
.
putln
(
"if (v) {"
)
...
...
@@ -925,7 +939,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"0, /*ob_size*/"
)
code
.
putln
(
'"%s.%s", /*tp_name*/'
%
(
mod
name
,
scope
.
class_name
))
self
.
full_module_
name
,
scope
.
class_name
))
if
type
.
typedef_flag
:
objstruct
=
type
.
objstruct_cname
else
:
...
...
@@ -1054,6 +1068,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self
.
generate_intern_code
(
env
,
code
)
#code.putln("/*--- String init 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 ---*/")
self
.
generate_global_init_code
(
env
,
code
)
...
...
@@ -1121,6 +1137,28 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"if (__Pyx_InitStrings(%s) < 0) %s;"
%
(
Naming
.
stringtab_cname
,
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
):
# Generate code to initialise global PyObject *
...
...
Cython/Compiler/Nodes.py
View file @
25194156
...
...
@@ -115,6 +115,14 @@ class BlockNode:
code
.
putln
(
"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
):
# stats a list of StatNode
...
...
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