Commit ca476798 authored by Damien George's avatar Damien George
Browse files

py: Implement builtin exec.

parent 4acb2452
......@@ -11,6 +11,7 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin_chr_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_dir_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_divmod_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_eval_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_exec_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_hash_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_id_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_isinstance_obj);
......
......@@ -19,7 +19,7 @@
#include "map.h"
#include "builtin.h"
static mp_obj_t mp_builtin_eval(mp_obj_t o_in) {
static mp_obj_t parse_compile_execute(mp_obj_t o_in, mp_parse_input_kind_t parse_input_kind) {
uint str_len;
const byte *str = mp_obj_str_get_data(o_in, &str_len);
......@@ -30,7 +30,7 @@ static mp_obj_t mp_builtin_eval(mp_obj_t o_in) {
// parse the string
qstr parse_exc_id;
const char *parse_exc_msg;
mp_parse_node_t pn = mp_parse(lex, MP_PARSE_EVAL_INPUT, &parse_exc_id, &parse_exc_msg);
mp_parse_node_t pn = mp_parse(lex, parse_input_kind, &parse_exc_id, &parse_exc_msg);
mp_lexer_free(lex);
if (pn == MP_PARSE_NODE_NULL) {
......@@ -51,4 +51,14 @@ static mp_obj_t mp_builtin_eval(mp_obj_t o_in) {
return rt_call_function_0(module_fun);
}
static mp_obj_t mp_builtin_eval(mp_obj_t o_in) {
return parse_compile_execute(o_in, MP_PARSE_EVAL_INPUT);
}
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);
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_exec_obj, mp_builtin_exec);
......@@ -65,7 +65,7 @@ PY_O_BASENAME = \
stream.o \
builtin.o \
builtinimport.o \
builtineval.o \
builtinevex.o \
builtinmp.o \
vm.o \
showbc.o \
......
......@@ -55,6 +55,7 @@ Q(dir)
Q(divmod)
Q(enumerate)
Q(eval)
Q(exec)
Q(filter)
Q(float)
Q(hash)
......
......@@ -144,6 +144,7 @@ void rt_init(void) {
mp_map_add_qstr(&map_builtins, MP_QSTR_dir, (mp_obj_t)&mp_builtin_dir_obj);
mp_map_add_qstr(&map_builtins, MP_QSTR_divmod, (mp_obj_t)&mp_builtin_divmod_obj);
mp_map_add_qstr(&map_builtins, MP_QSTR_eval, (mp_obj_t)&mp_builtin_eval_obj);
mp_map_add_qstr(&map_builtins, MP_QSTR_exec, (mp_obj_t)&mp_builtin_exec_obj);
mp_map_add_qstr(&map_builtins, MP_QSTR_hash, (mp_obj_t)&mp_builtin_hash_obj);
mp_map_add_qstr(&map_builtins, MP_QSTR_id, (mp_obj_t)&mp_builtin_id_obj);
mp_map_add_qstr(&map_builtins, MP_QSTR_isinstance, (mp_obj_t)&mp_builtin_isinstance_obj);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment