Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
a8d404e0
Commit
a8d404e0
authored
Feb 12, 2014
by
Damien George
Browse files
Merge branch 'master' of github.com:micropython/micropython
parents
099a9cb5
2aa217b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/builtinevex.c
View file @
a8d404e0
...
...
@@ -57,8 +57,26 @@ STATIC mp_obj_t mp_builtin_eval(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_builtin_eval_obj
,
mp_builtin_eval
);
STATIC
mp_obj_t
mp_builtin_exec
(
mp_obj_t
o_in
)
{
return
parse_compile_execute
(
o_in
,
MP_PARSE_FILE_INPUT
);
STATIC
mp_obj_t
mp_builtin_exec
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
// Unconditional getting/setting assumes that these operations
// are cheap, which is the case when this comment was written.
mp_map_t
*
old_globals
=
rt_globals_get
();
mp_map_t
*
old_locals
=
rt_locals_get
();
if
(
n_args
>
1
)
{
mp_obj_t
globals
=
args
[
1
];
mp_obj_t
locals
;
if
(
n_args
>
2
)
{
locals
=
args
[
2
];
}
else
{
locals
=
globals
;
}
rt_globals_set
(
mp_obj_dict_get_map
(
globals
));
rt_locals_set
(
mp_obj_dict_get_map
(
locals
));
}
mp_obj_t
res
=
parse_compile_execute
(
args
[
0
],
MP_PARSE_FILE_INPUT
);
rt_globals_set
(
old_globals
);
rt_locals_set
(
old_locals
);
return
res
;
}
MP_DEFINE_CONST_FUN_OBJ_
1
(
mp_builtin_exec_obj
,
mp_builtin_exec
);
MP_DEFINE_CONST_FUN_OBJ_
VAR_BETWEEN
(
mp_builtin_exec_obj
,
1
,
3
,
mp_builtin_exec
);
tests/basics/exec1.py
0 → 100644
View file @
a8d404e0
print
(
exec
(
"def foo(): return 42"
))
print
(
foo
())
d
=
{}
exec
(
"def bar(): return 84"
,
d
)
print
(
d
[
"bar"
]())
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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