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
Show 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,6 +22,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -22,6 +22,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# body StatListNode
# body StatListNode
def
analyse_declarations
(
self
,
env
):
def
analyse_declarations
(
self
,
env
):
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
env
.
doc
=
self
.
doc
self
.
body
.
analyse_declarations
(
env
)
self
.
body
.
analyse_declarations
(
env
)
...
@@ -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,
in
t 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_From
Long
(i); if(!x) return 0;"
)
"PyObject *x = PyInt_From
Ssize
(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, 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"
))
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*/'
%
(
mod
name
,
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
)
...
@@ -1122,6 +1138,28 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1122,6 +1138,28 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
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 *
# variables to None.
# variables to None.
...
...
Cython/Compiler/Nodes.py
View file @
25194156
...
@@ -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
...
...
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