Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
a75d888f
Commit
a75d888f
authored
Aug 28, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
3-arg execfile
parent
20ae1f2b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
40 deletions
+54
-40
src/codegen/irgen/hooks.cpp
src/codegen/irgen/hooks.cpp
+42
-0
src/codegen/irgen/hooks.h
src/codegen/irgen/hooks.h
+1
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+4
-36
test/tests/execfile_test.py
test/tests/execfile_test.py
+7
-4
No files found.
src/codegen/irgen/hooks.cpp
View file @
a75d888f
...
...
@@ -601,6 +601,48 @@ Box* eval(Box* boxedCode, Box* globals, Box* locals) {
return
evalMain
(
boxedCode
,
globals
,
locals
,
&
pcf
);
}
Box
*
execfile
(
Box
*
_fn
,
Box
*
globals
,
Box
*
locals
)
{
if
(
!
PyString_Check
(
_fn
))
{
raiseExcHelper
(
TypeError
,
"must be string, not %s"
,
getTypeName
(
_fn
));
}
BoxedString
*
fn
=
static_cast
<
BoxedString
*>
(
_fn
);
pickGlobalsAndLocals
(
globals
,
locals
);
#if LLVMREV < 217625
bool
exists
;
llvm_error_code
code
=
llvm
::
sys
::
fs
::
exists
(
fn
->
s
,
exists
);
#if LLVMREV < 210072
ASSERT
(
code
==
0
,
"%s: %s"
,
code
.
message
().
c_str
(),
fn
->
s
.
c_str
());
#else
assert
(
!
code
);
#endif
#else
bool
exists
=
llvm
::
sys
::
fs
::
exists
(
std
::
string
(
fn
->
s
()));
#endif
if
(
!
exists
)
raiseExcHelper
(
IOError
,
"No such file or directory: '%s'"
,
fn
->
s
().
data
());
AST_Module
*
parsed
=
caching_parse_file
(
fn
->
s
().
data
());
assert
(
parsed
);
CLFunction
*
caller_cl
=
getTopPythonFunction
();
assert
(
caller_cl
!=
NULL
);
assert
(
caller_cl
->
source
!=
NULL
);
FutureFlags
caller_future_flags
=
caller_cl
->
source
->
future_flags
;
PyCompilerFlags
pcf
;
pcf
.
cf_flags
=
caller_future_flags
;
CLFunction
*
cl
=
compileForEvalOrExec
(
parsed
,
parsed
->
body
,
fn
,
&
pcf
);
assert
(
cl
);
return
evalOrExec
(
cl
,
globals
,
locals
);
}
Box
*
execMain
(
Box
*
boxedCode
,
Box
*
globals
,
Box
*
locals
,
PyCompilerFlags
*
flags
)
{
if
(
PyTuple_Check
(
boxedCode
))
{
RELEASE_ASSERT
(
!
globals
,
""
);
...
...
src/codegen/irgen/hooks.h
View file @
a75d888f
...
...
@@ -40,6 +40,7 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm);
CompiledFunction
*
cfForMachineFunctionName
(
const
std
::
string
&
);
extern
"C"
Box
*
exec
(
Box
*
boxedCode
,
Box
*
globals
,
Box
*
locals
,
FutureFlags
caller_future_flags
);
extern
"C"
Box
*
execfile
(
Box
*
fn
,
Box
*
globals
,
Box
*
locals
);
extern
"C"
Box
*
eval
(
Box
*
boxedCode
,
Box
*
globals
,
Box
*
locals
);
extern
"C"
Box
*
compile
(
Box
*
source
,
Box
*
filename
,
Box
*
mode
,
Box
**
_args
/* flags, dont_inherit */
);
}
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
a75d888f
...
...
@@ -1161,40 +1161,6 @@ Box* powFunc(Box* x, Box* y, Box* z) {
return
rtn
;
}
Box
*
execfile
(
Box
*
_fn
)
{
// The "globals" and "locals" arguments aren't implemented for now
if
(
!
PyString_Check
(
_fn
))
{
raiseExcHelper
(
TypeError
,
"must be string, not %s"
,
getTypeName
(
_fn
));
}
BoxedString
*
fn
=
static_cast
<
BoxedString
*>
(
_fn
);
#if LLVMREV < 217625
bool
exists
;
llvm_error_code
code
=
llvm
::
sys
::
fs
::
exists
(
fn
->
s
,
exists
);
#if LLVMREV < 210072
ASSERT
(
code
==
0
,
"%s: %s"
,
code
.
message
().
c_str
(),
fn
->
s
.
c_str
());
#else
assert
(
!
code
);
#endif
#else
bool
exists
=
llvm
::
sys
::
fs
::
exists
(
std
::
string
(
fn
->
s
()));
#endif
if
(
!
exists
)
raiseExcHelper
(
IOError
,
"No such file or directory: '%s'"
,
fn
->
data
());
// Run directly inside the current module:
AST_Module
*
ast
=
caching_parse_file
(
fn
->
data
());
ASSERT
(
getTopPythonFunction
()
->
source
->
scoping
->
areGlobalsFromModule
(),
"need to pass custom globals in"
);
compileAndRunModule
(
ast
,
getCurrentModule
());
return
None
;
}
Box
*
print
(
BoxedTuple
*
args
,
BoxedDict
*
kwargs
)
{
assert
(
args
->
cls
==
tuple_cls
);
assert
(
!
kwargs
||
kwargs
->
cls
==
dict_cls
);
...
...
@@ -1622,8 +1588,10 @@ void setupBuiltins() {
boxRTFunction
((
void
*
)
coerceFunc
,
UNKNOWN
,
2
,
0
,
false
,
false
),
"coerce"
));
builtins_module
->
giveAttr
(
"divmod"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
divmod
,
UNKNOWN
,
2
),
"divmod"
));
builtins_module
->
giveAttr
(
"execfile"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
execfile
,
UNKNOWN
,
1
),
"execfile"
));
builtins_module
->
giveAttr
(
"execfile"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
execfile
,
UNKNOWN
,
3
,
2
,
false
,
false
),
"execfile"
,
{
NULL
,
NULL
}));
CLFunction
*
compile_func
=
createRTFunction
(
5
,
2
,
false
,
false
,
ParamNames
({
"source"
,
"filename"
,
"mode"
,
"flags"
,
"dont_inherit"
},
""
,
""
));
...
...
test/tests/execfile_test.py
View file @
a75d888f
# expected: fail
# - we throw some very weird error here
try
:
execfile
(
"doesnt_exist.py"
)
except
IOError
,
e
:
print
e
print
type
(
e
)
import
os
fn
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'execfile_target.py'
)
...
...
@@ -14,3 +11,9 @@ execfile(fn)
print
test_name
print
type
(
execfile_target
)
g
=
{}
l
=
{}
execfile
(
fn
,
g
,
l
)
print
sorted
(
g
.
keys
())
print
sorted
(
l
.
keys
())
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