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
06d7ad86
Commit
06d7ad86
authored
Jun 19, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Have the code generator transform generate the CompilationResult
parent
185adaa1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
76 deletions
+11
-76
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+11
-76
No files found.
Cython/Compiler/Main.py
View file @
06d7ad86
...
...
@@ -58,6 +58,8 @@ class Context:
#self.modules = {"__builtin__" : BuiltinScope()}
import
Builtin
self
.
modules
=
{
"__builtin__"
:
Builtin
.
builtin_scope
}
self
.
pxds
=
{}
self
.
pyxs
=
{}
self
.
include_directories
=
include_directories
self
.
future_directives
=
set
()
...
...
@@ -285,74 +287,6 @@ class Context:
names
.
reverse
()
return
"."
.
join
(
names
)
def
compile
(
self
,
source
,
options
=
None
,
full_module_name
=
None
):
raise
Exception
(
"Deprecated"
)
# Compile a Pyrex implementation file in this context
# and return a CompilationResult.
if
not
options
:
options
=
default_options
result
=
CompilationResult
()
cwd
=
os
.
getcwd
()
source
=
os
.
path
.
join
(
cwd
,
source
)
result
.
main_source_file
=
source
if
options
.
use_listing_file
:
result
.
listing_file
=
Utils
.
replace_suffix
(
source
,
".lis"
)
Errors
.
open_listing_file
(
result
.
listing_file
,
echo_to_stderr
=
options
.
errors_to_stderr
)
else
:
Errors
.
open_listing_file
(
None
)
if
options
.
output_file
:
result
.
c_file
=
os
.
path
.
join
(
cwd
,
options
.
output_file
)
else
:
if
options
.
cplus
:
c_suffix
=
".cpp"
else
:
c_suffix
=
".c"
result
.
c_file
=
Utils
.
replace_suffix
(
source
,
c_suffix
)
c_stat
=
None
if
result
.
c_file
:
try
:
c_stat
=
os
.
stat
(
result
.
c_file
)
except
EnvironmentError
:
pass
full_module_name
=
full_module_name
or
self
.
extract_module_name
(
source
,
options
)
source
=
FileSourceDescriptor
(
source
)
initial_pos
=
(
source
,
1
,
0
)
scope
=
self
.
find_module
(
full_module_name
,
pos
=
initial_pos
,
need_pxd
=
0
)
errors_occurred
=
False
try
:
tree
=
self
.
parse
(
source
,
scope
,
pxd
=
0
,
full_module_name
=
full_module_name
)
from
ParseTreeTransforms
import
WithTransform
,
PostParse
tree
=
PostParse
()(
tree
)
tree
=
WithTransform
()(
tree
)
tree
.
process_implementation
(
scope
,
options
,
result
)
except
CompileError
:
errors_occurred
=
True
Errors
.
close_listing_file
()
result
.
num_errors
=
Errors
.
num_errors
if
result
.
num_errors
>
0
:
errors_occurred
=
True
if
errors_occurred
and
result
.
c_file
:
try
:
Utils
.
castrate_file
(
result
.
c_file
,
os
.
stat
(
source
.
filename
))
except
EnvironmentError
:
pass
result
.
c_file
=
None
if
result
.
c_file
and
not
options
.
c_only
and
c_compile
:
result
.
object_file
=
c_compile
(
result
.
c_file
,
verbose_flag
=
options
.
show_version
,
cplus
=
options
.
cplus
)
if
not
options
.
obj_only
and
c_link
:
result
.
extension_file
=
c_link
(
result
.
object_file
,
extra_objects
=
options
.
objects
,
verbose_flag
=
options
.
show_version
,
cplus
=
options
.
cplus
)
return
result
def
setup_errors
(
self
,
options
):
if
options
.
use_listing_file
:
result
.
listing_file
=
Utils
.
replace_suffix
(
source
,
".lis"
)
...
...
@@ -393,21 +327,24 @@ def create_parse(context, scope):
source_desc
=
compsrc
.
source_desc
full_module_name
=
compsrc
.
full_module_name
tree
=
context
.
parse
(
source_desc
,
scope
,
pxd
=
0
,
full_module_name
=
full_module_name
)
tree
.
compilation_source
=
compsrc
return
tree
return
parse
def
create_generate_code
(
context
,
scope
,
options
,
result
):
def
create_generate_code
(
context
,
scope
,
options
):
def
generate_code
(
tree
):
result
=
create_default_resultobj
(
tree
.
compilation_source
.
source_desc
,
options
,
os
.
getcwd
())
tree
.
process_implementation
(
scope
,
options
,
result
)
return
result
return
generate_code
def
create_default_pipeline
(
context
,
scope
,
options
,
result
):
def
create_default_pipeline
(
context
,
scope
,
options
):
from
ParseTreeTransforms
import
WithTransform
,
PostParse
return
[
create_parse
(
context
,
scope
),
PostParse
(),
WithTransform
(),
create_generate_code
(
context
,
scope
,
options
,
result
)
create_generate_code
(
context
,
scope
,
options
)
]
def
create_default_resultobj
(
source_desc
,
options
,
cwd
):
...
...
@@ -444,22 +381,20 @@ def run_pipeline(source, options = None, full_module_name = None):
full_module_name
=
full_module_name
or
context
.
extract_module_name
(
source
,
options
)
source
=
CompilationSource
(
source_desc
,
full_module_name
)
# Set up result object
result
=
create_default_resultobj
(
source_desc
,
options
,
cwd
)
# Get pipeline
initial_pos
=
(
source_desc
,
1
,
0
)
scope
=
context
.
find_module
(
full_module_name
,
pos
=
initial_pos
,
need_pxd
=
0
)
pipeline
=
create_default_pipeline
(
context
,
scope
,
options
,
result
)
pipeline
=
create_default_pipeline
(
context
,
scope
,
options
)
data
=
source
errors_occurred
=
False
try
:
data
=
source
for
phase
in
pipeline
:
data
=
phase
(
data
)
except
CompileError
:
errors_occurred
=
True
result
=
data
context
.
teardown_errors
(
errors_occurred
,
options
,
result
,
source_desc
)
return
result
...
...
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