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
76750ffb
Commit
76750ffb
authored
Jul 10, 2007
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added pre-import option, which assumes all undeclared names come from the given module.
Emulates behavior of from <module> import *
parent
4bce9494
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
3 deletions
+40
-3
Cython/Compiler/CmdLine.py
Cython/Compiler/CmdLine.py
+5
-0
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+1
-1
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+11
-0
Cython/Compiler/Naming.py
Cython/Compiler/Naming.py
+1
-0
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+2
-0
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+20
-2
No files found.
Cython/Compiler/CmdLine.py
View file @
76750ffb
...
@@ -18,6 +18,9 @@ Options:
...
@@ -18,6 +18,9 @@ Options:
-o, --output-file <filename> Specify name of generated C file
-o, --output-file <filename> Specify name of generated C file
-p, --embed-positions If specified, the positions in Pyrex files of each
-p, --embed-positions If specified, the positions in Pyrex files of each
function definition is embedded in its docstring.
function definition is embedded in its docstring.
-z, --pre-import <module> If specified, assume undeclared names in this
module. Emulates the behavior of putting
"from <module> import *" at the top of the file.
"""
"""
#The following experimental options are supported only on MacOSX:
#The following experimental options are supported only on MacOSX:
# -C, --compile Compile generated .c file to .o file
# -C, --compile Compile generated .c file to .o file
...
@@ -70,6 +73,8 @@ def parse_command_line(args):
...
@@ -70,6 +73,8 @@ def parse_command_line(args):
options
.
output_file
=
pop_arg
()
options
.
output_file
=
pop_arg
()
elif
option
in
(
"-p"
,
"--embed-positions"
):
elif
option
in
(
"-p"
,
"--embed-positions"
):
Options
.
embed_pos_in_docstring
=
1
Options
.
embed_pos_in_docstring
=
1
elif
option
in
(
"-z"
,
"--pre-import"
):
Options
.
pre_import
=
pop_arg
()
else
:
else
:
bad_usage
()
bad_usage
()
else
:
else
:
...
...
Cython/Compiler/Code.py
View file @
76750ffb
...
@@ -311,7 +311,7 @@ class CCodeWriter:
...
@@ -311,7 +311,7 @@ class CCodeWriter:
lbl
)
lbl
)
def
error_goto_if
(
self
,
cond
,
pos
):
def
error_goto_if
(
self
,
cond
,
pos
):
if
Options
.
gcc_branch_hints
or
0
:
# TODO this path is almost _never_ taken, yet this macro makes is slower!
if
Options
.
gcc_branch_hints
:
return
"if (unlikely(%s)) %s"
%
(
cond
,
self
.
error_goto
(
pos
))
return
"if (unlikely(%s)) %s"
%
(
cond
,
self
.
error_goto
(
pos
))
else
:
else
:
return
"if (%s) %s"
%
(
cond
,
self
.
error_goto
(
pos
))
return
"if (%s) %s"
%
(
cond
,
self
.
error_goto
(
pos
))
...
...
Cython/Compiler/ModuleNode.py
View file @
76750ffb
...
@@ -163,6 +163,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -163,6 +163,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
''
)
code
.
putln
(
''
)
code
.
putln
(
'static PyObject *%s;'
%
env
.
module_cname
)
code
.
putln
(
'static PyObject *%s;'
%
env
.
module_cname
)
code
.
putln
(
'static PyObject *%s;'
%
Naming
.
builtins_cname
)
code
.
putln
(
'static PyObject *%s;'
%
Naming
.
builtins_cname
)
if
Options
.
pre_import
is
not
None
:
code
.
putln
(
'static PyObject *%s;'
%
Naming
.
preimport_cname
)
code
.
putln
(
'static int %s;'
%
Naming
.
lineno_cname
)
code
.
putln
(
'static int %s;'
%
Naming
.
lineno_cname
)
code
.
putln
(
'static char *%s;'
%
Naming
.
filename_cname
)
code
.
putln
(
'static char *%s;'
%
Naming
.
filename_cname
)
code
.
putln
(
'static char **%s;'
%
Naming
.
filetable_cname
)
code
.
putln
(
'static char **%s;'
%
Naming
.
filetable_cname
)
...
@@ -1122,6 +1124,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1122,6 +1124,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
env
.
module_cname
,
env
.
module_cname
,
Naming
.
builtins_cname
,
Naming
.
builtins_cname
,
code
.
error_goto
(
self
.
pos
)))
code
.
error_goto
(
self
.
pos
)))
if
Options
.
pre_import
is
not
None
:
code
.
putln
(
'%s = PyImport_AddModule("%s");'
%
(
Naming
.
preimport_cname
,
Options
.
pre_import
))
code
.
putln
(
"if (!%s) %s;"
%
(
Naming
.
preimport_cname
,
code
.
error_goto
(
self
.
pos
)));
def
generate_intern_code
(
self
,
env
,
code
):
def
generate_intern_code
(
self
,
env
,
code
):
if
env
.
intern_map
:
if
env
.
intern_map
:
...
...
Cython/Compiler/Naming.py
View file @
76750ffb
...
@@ -35,6 +35,7 @@ args_cname = pyrex_prefix + "args"
...
@@ -35,6 +35,7 @@ args_cname = pyrex_prefix + "args"
kwdlist_cname
=
pyrex_prefix
+
"argnames"
kwdlist_cname
=
pyrex_prefix
+
"argnames"
obj_base_cname
=
pyrex_prefix
+
"base"
obj_base_cname
=
pyrex_prefix
+
"base"
builtins_cname
=
pyrex_prefix
+
"b"
builtins_cname
=
pyrex_prefix
+
"b"
preimport_cname
=
pyrex_prefix
+
"i"
moddict_cname
=
pyrex_prefix
+
"d"
moddict_cname
=
pyrex_prefix
+
"d"
dummy_cname
=
pyrex_prefix
+
"dummy"
dummy_cname
=
pyrex_prefix
+
"dummy"
filename_cname
=
pyrex_prefix
+
"filename"
filename_cname
=
pyrex_prefix
+
"filename"
...
...
Cython/Compiler/Options.py
View file @
76750ffb
...
@@ -7,3 +7,5 @@ cache_builtins = 1 # Perform lookups on builtin names only once
...
@@ -7,3 +7,5 @@ cache_builtins = 1 # Perform lookups on builtin names only once
embed_pos_in_docstring
=
0
embed_pos_in_docstring
=
0
gcc_branch_hints
=
1
gcc_branch_hints
=
1
pre_import
=
None
Cython/Compiler/Symtab.py
View file @
76750ffb
...
@@ -448,12 +448,27 @@ class Scope:
...
@@ -448,12 +448,27 @@ class Scope:
return
1
return
1
return
0
return
0
class
PreImportScope
(
Scope
):
def
__init__
(
self
):
Scope
.
__init__
(
self
,
Options
.
pre_import
,
None
,
None
)
def
declare_builtin
(
self
,
name
,
pos
):
entry
=
self
.
declare
(
name
,
name
,
py_object_type
,
pos
)
entry
.
is_variable
=
True
entry
.
is_pyglobal
=
True
entry
.
namespace_cname
=
Naming
.
preimport_cname
return
entry
class
BuiltinScope
(
Scope
):
class
BuiltinScope
(
Scope
):
# The builtin namespace.
# The builtin namespace.
def
__init__
(
self
):
def
__init__
(
self
):
Scope
.
__init__
(
self
,
"__builtin__"
,
None
,
None
)
if
Options
.
pre_import
is
None
:
Scope
.
__init__
(
self
,
"__builtin__"
,
None
,
None
)
else
:
Scope
.
__init__
(
self
,
"__builtin__"
,
PreImportScope
(),
None
)
for
name
,
definition
in
self
.
builtin_functions
.
iteritems
():
for
name
,
definition
in
self
.
builtin_functions
.
iteritems
():
if
len
(
definition
)
<
4
:
definition
.
append
(
None
)
# exception_value
if
len
(
definition
)
<
4
:
definition
.
append
(
None
)
# exception_value
if
len
(
definition
)
<
5
:
definition
.
append
(
False
)
# exception_check
if
len
(
definition
)
<
5
:
definition
.
append
(
False
)
# exception_check
...
@@ -468,7 +483,10 @@ class BuiltinScope(Scope):
...
@@ -468,7 +483,10 @@ class BuiltinScope(Scope):
def
declare_builtin
(
self
,
name
,
pos
):
def
declare_builtin
(
self
,
name
,
pos
):
if
not
hasattr
(
__builtin__
,
name
):
if
not
hasattr
(
__builtin__
,
name
):
error
(
pos
,
"undeclared name not builtin: %s"
%
name
)
if
self
.
outer_scope
is
not
None
:
return
self
.
outer_scope
.
declare_builtin
(
name
,
pos
)
else
:
error
(
pos
,
"undeclared name not builtin: %s"
%
name
)
entry
=
self
.
declare
(
name
,
name
,
py_object_type
,
pos
)
entry
=
self
.
declare
(
name
,
name
,
py_object_type
,
pos
)
if
Options
.
cache_builtins
:
if
Options
.
cache_builtins
:
entry
.
is_builtin
=
1
entry
.
is_builtin
=
1
...
...
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