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
39afd252
Commit
39afd252
authored
Mar 26, 2015
by
Travis Hance
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
basic implementation of `exec code in dict`
parent
ed5f850c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
14 deletions
+46
-14
src/codegen/ast_interpreter.cpp
src/codegen/ast_interpreter.cpp
+4
-4
src/codegen/irgen/hooks.cpp
src/codegen/irgen/hooks.cpp
+12
-3
src/codegen/irgen/hooks.h
src/codegen/irgen/hooks.h
+1
-1
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+20
-6
test/tests/exec_in_basic_test.py
test/tests/exec_in_basic_test.py
+9
-0
No files found.
src/codegen/ast_interpreter.cpp
View file @
39afd252
...
...
@@ -888,12 +888,12 @@ Value ASTInterpreter::visit_print(AST_Print* node) {
}
Value
ASTInterpreter
::
visit_exec
(
AST_Exec
*
node
)
{
RELEASE_ASSERT
(
!
node
->
globals
,
"do not support exec with globals or locals yet"
);
assert
(
!
node
->
locals
);
// TODO implement the locals and globals arguments
Box
*
code
=
visit_expr
(
node
->
body
).
o
;
exec
(
code
);
Box
*
globals
=
node
->
globals
==
NULL
?
NULL
:
visit_expr
(
node
->
globals
).
o
;
Box
*
locals
=
node
->
locals
==
NULL
?
NULL
:
visit_expr
(
node
->
locals
).
o
;
exec
(
code
,
globals
,
locals
);
return
Value
();
}
...
...
src/codegen/irgen/hooks.cpp
View file @
39afd252
...
...
@@ -379,8 +379,17 @@ Box* eval(Box* boxedCode) {
return
evalOrExec
<
AST_Expression
>
(
parsedExpr
,
body
,
module
,
boxedLocals
);
}
Box
*
exec
(
Box
*
boxedCode
)
{
Box
*
boxedLocals
=
fastLocalsToBoxedLocals
();
Box
*
exec
(
Box
*
boxedCode
,
Box
*
globals
,
Box
*
locals
)
{
// TODO boxedCode is allowed to be a tuple
// TODO need to handle passing in globals
if
(
locals
==
NULL
)
{
locals
=
globals
;
}
if
(
locals
==
NULL
)
{
locals
=
fastLocalsToBoxedLocals
();
}
BoxedModule
*
module
=
getCurrentModule
();
// TODO same issues as in `eval`
...
...
@@ -390,7 +399,7 @@ Box* exec(Box* boxedCode) {
AST_Suite
*
parsedSuite
=
new
AST_Suite
(
std
::
move
(
parsedModule
->
interned_strings
));
parsedSuite
->
body
=
parsedModule
->
body
;
return
evalOrExec
<
AST_Suite
>
(
parsedSuite
,
parsedSuite
->
body
,
module
,
boxedL
ocals
);
return
evalOrExec
<
AST_Suite
>
(
parsedSuite
,
parsedSuite
->
body
,
module
,
l
ocals
);
}
// If a function version keeps failing its speculations, kill it (remove it
...
...
src/codegen/irgen/hooks.h
View file @
39afd252
...
...
@@ -37,7 +37,7 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm);
// will we always want to generate unique function names? (ie will this function always be reasonable?)
CompiledFunction
*
cfForMachineFunctionName
(
const
std
::
string
&
);
extern
"C"
Box
*
exec
(
Box
*
boxedCode
);
extern
"C"
Box
*
exec
(
Box
*
boxedCode
,
Box
*
globals
,
Box
*
locals
);
extern
"C"
Box
*
eval
(
Box
*
boxedCode
);
}
...
...
src/codegen/irgen/irgenerator.cpp
View file @
39afd252
...
...
@@ -1711,15 +1711,29 @@ private:
}
void
doExec
(
AST_Exec
*
node
,
UnwindInfo
unw_info
)
{
// TODO locals and globals
RELEASE_ASSERT
(
!
node
->
globals
,
"do not support exec with globals or locals yet"
);
assert
(
!
node
->
locals
);
CompilerVariable
*
body
=
evalExpr
(
node
->
body
,
unw_info
);
ConcreteCompilerVariable
*
cbody
=
body
->
makeConverted
(
emitter
,
body
->
getBoxType
()
);
llvm
::
Value
*
vbody
=
body
->
makeConverted
(
emitter
,
body
->
getBoxType
())
->
getValue
(
);
body
->
decvref
(
emitter
);
emitter
.
createCall
(
unw_info
,
g
.
funcs
.
exec
,
cbody
->
getValue
());
llvm
::
Value
*
vglobals
;
if
(
node
->
globals
)
{
CompilerVariable
*
globals
=
evalExpr
(
node
->
globals
,
unw_info
);
vglobals
=
globals
->
makeConverted
(
emitter
,
globals
->
getBoxType
())
->
getValue
();
globals
->
decvref
(
emitter
);
}
else
{
vglobals
=
embedConstantPtr
(
NULL
,
g
.
llvm_value_type_ptr
);
}
llvm
::
Value
*
vlocals
;
if
(
node
->
locals
)
{
CompilerVariable
*
locals
=
evalExpr
(
node
->
locals
,
unw_info
);
vlocals
=
locals
->
makeConverted
(
emitter
,
locals
->
getBoxType
())
->
getValue
();
locals
->
decvref
(
emitter
);
}
else
{
vlocals
=
embedConstantPtr
(
NULL
,
g
.
llvm_value_type_ptr
);
}
emitter
.
createCall3
(
unw_info
,
g
.
funcs
.
exec
,
vbody
,
vglobals
,
vlocals
);
}
void
doPrint
(
AST_Print
*
node
,
UnwindInfo
unw_info
)
{
...
...
test/tests/exec_in_basic_test.py
0 → 100644
View file @
39afd252
d
=
{}
exec
"a = 5"
in
d
print
d
[
'a'
]
def
f
():
d2
=
{}
exec
"b = 6"
in
d2
print
d2
[
'b'
]
f
()
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