Skip to content

Commit

Permalink
Rename rt_* to mp_*.
Browse files Browse the repository at this point in the history
Mostly just a global search and replace.  Except rt_is_true which
becomes mp_obj_is_true.

Still would like to tidy up some of the names, but this will do for now.
  • Loading branch information
dpgeorge committed Mar 30, 2014
1 parent 09d2077 commit d17926d
Show file tree
Hide file tree
Showing 71 changed files with 988 additions and 983 deletions.
50 changes: 25 additions & 25 deletions py/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ STATIC mp_obj_t mp_builtin___build_class__(uint n_args, const mp_obj_t *args) {
assert(2 <= n_args);

// we differ from CPython: we set the new __locals__ object here
mp_map_t *old_locals = rt_locals_get();
mp_map_t *old_locals = mp_locals_get();
mp_obj_t class_locals = mp_obj_new_dict(0);
rt_locals_set(mp_obj_dict_get_map(class_locals));
mp_locals_set(mp_obj_dict_get_map(class_locals));

// call the class code
mp_obj_t cell = rt_call_function_1(args[0], (mp_obj_t)0xdeadbeef);
mp_obj_t cell = mp_call_function_1(args[0], (mp_obj_t)0xdeadbeef);

// restore old __locals__ object
rt_locals_set(old_locals);
mp_locals_set(old_locals);

// get the class type (meta object) from the base objects
mp_obj_t meta;
Expand All @@ -49,7 +49,7 @@ STATIC mp_obj_t mp_builtin___build_class__(uint n_args, const mp_obj_t *args) {
meta_args[0] = args[1]; // class name
meta_args[1] = mp_obj_new_tuple(n_args - 2, args + 2); // tuple of bases
meta_args[2] = class_locals; // dict of members
mp_obj_t new_class = rt_call_function_n_kw(meta, 3, 0, meta_args);
mp_obj_t new_class = mp_call_function_n_kw(meta, 3, 0, meta_args);

// store into cell if neede
if (cell != mp_const_none) {
Expand Down Expand Up @@ -101,10 +101,10 @@ mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_abs_obj, mp_builtin_abs);

STATIC mp_obj_t mp_builtin_all(mp_obj_t o_in) {
mp_obj_t iterable = rt_getiter(o_in);
mp_obj_t iterable = mp_getiter(o_in);
mp_obj_t item;
while ((item = rt_iternext(iterable)) != MP_OBJ_NULL) {
if (!rt_is_true(item)) {
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
if (!mp_obj_is_true(item)) {
return mp_const_false;
}
}
Expand All @@ -114,10 +114,10 @@ STATIC mp_obj_t mp_builtin_all(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_all_obj, mp_builtin_all);

STATIC mp_obj_t mp_builtin_any(mp_obj_t o_in) {
mp_obj_t iterable = rt_getiter(o_in);
mp_obj_t iterable = mp_getiter(o_in);
mp_obj_t item;
while ((item = rt_iternext(iterable)) != MP_OBJ_NULL) {
if (rt_is_true(item)) {
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
if (mp_obj_is_true(item)) {
return mp_const_true;
}
}
Expand Down Expand Up @@ -154,7 +154,7 @@ STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) {
mp_map_t *map = NULL;
if (n_args == 0) {
// make a list of names in the local name space
map = rt_locals_get();
map = mp_locals_get();
} else { // n_args == 1
// make a list of names in the given object
if (MP_OBJ_IS_TYPE(args[0], &mp_type_module)) {
Expand Down Expand Up @@ -193,7 +193,7 @@ STATIC mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) {
mp_obj_t args[2];
args[0] = MP_OBJ_NEW_SMALL_INT(i1 / i2);
args[1] = MP_OBJ_NEW_SMALL_INT(i1 % i2);
return rt_build_tuple(2, args);
return mp_build_tuple(2, args);
} else {
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "unsupported operand type(s) for divmod(): '%s' and '%s'", mp_obj_get_type_str(o1_in), mp_obj_get_type_str(o2_in)));
}
Expand All @@ -209,7 +209,7 @@ STATIC mp_obj_t mp_builtin_hash(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hash_obj, mp_builtin_hash);

STATIC mp_obj_t mp_builtin_iter(mp_obj_t o_in) {
return rt_getiter(o_in);
return mp_getiter(o_in);
}

MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_iter_obj, mp_builtin_iter);
Expand All @@ -228,10 +228,10 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_len_obj, mp_builtin_len);
STATIC mp_obj_t mp_builtin_max(uint n_args, const mp_obj_t *args) {
if (n_args == 1) {
// given an iterable
mp_obj_t iterable = rt_getiter(args[0]);
mp_obj_t iterable = mp_getiter(args[0]);
mp_obj_t max_obj = NULL;
mp_obj_t item;
while ((item = rt_iternext(iterable)) != MP_OBJ_NULL) {
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
if (max_obj == NULL || mp_obj_less(max_obj, item)) {
max_obj = item;
}
Expand All @@ -257,10 +257,10 @@ MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin_max_obj, 1, mp_builtin_max);
STATIC mp_obj_t mp_builtin_min(uint n_args, const mp_obj_t *args) {
if (n_args == 1) {
// given an iterable
mp_obj_t iterable = rt_getiter(args[0]);
mp_obj_t iterable = mp_getiter(args[0]);
mp_obj_t min_obj = NULL;
mp_obj_t item;
while ((item = rt_iternext(iterable)) != MP_OBJ_NULL) {
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
if (min_obj == NULL || mp_obj_less(item, min_obj)) {
min_obj = item;
}
Expand All @@ -284,7 +284,7 @@ STATIC mp_obj_t mp_builtin_min(uint n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin_min_obj, 1, mp_builtin_min);

STATIC mp_obj_t mp_builtin_next(mp_obj_t o) {
mp_obj_t ret = rt_iternext_allow_raise(o);
mp_obj_t ret = mp_iternext_allow_raise(o);
if (ret == MP_OBJ_NULL) {
nlr_jump(mp_obj_new_exception(&mp_type_StopIteration));
} else {
Expand All @@ -311,8 +311,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord);
STATIC mp_obj_t mp_builtin_pow(uint n_args, const mp_obj_t *args) {
assert(2 <= n_args && n_args <= 3);
switch (n_args) {
case 2: return rt_binary_op(RT_BINARY_OP_POWER, args[0], args[1]);
default: return rt_binary_op(RT_BINARY_OP_MODULO, rt_binary_op(RT_BINARY_OP_POWER, args[0], args[1]), args[2]); // TODO optimise...
case 2: return mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]);
default: return mp_binary_op(MP_BINARY_OP_MODULO, mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]), args[2]); // TODO optimise...
}
}

Expand Down Expand Up @@ -359,10 +359,10 @@ STATIC mp_obj_t mp_builtin_sum(uint n_args, const mp_obj_t *args) {
case 1: value = mp_obj_new_int(0); break;
default: value = args[1]; break;
}
mp_obj_t iterable = rt_getiter(args[0]);
mp_obj_t iterable = mp_getiter(args[0]);
mp_obj_t item;
while ((item = rt_iternext(iterable)) != MP_OBJ_NULL) {
value = rt_binary_op(RT_BINARY_OP_ADD, value, item);
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
value = mp_binary_op(MP_BINARY_OP_ADD, value, item);
}
return value;
}
Expand Down Expand Up @@ -391,7 +391,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_id_obj, mp_builtin_id);

STATIC mp_obj_t mp_builtin_getattr(mp_obj_t o_in, mp_obj_t attr) {
assert(MP_OBJ_IS_QSTR(attr));
return rt_load_attr(o_in, MP_OBJ_QSTR_VALUE(attr));
return mp_load_attr(o_in, MP_OBJ_QSTR_VALUE(attr));
}

MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_getattr_obj, mp_builtin_getattr);
14 changes: 7 additions & 7 deletions py/builtinevex.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ STATIC mp_obj_t parse_compile_execute(mp_obj_t o_in, mp_parse_input_kind_t parse
}

// complied successfully, execute it
return rt_call_function_0(module_fun);
return mp_call_function_0(module_fun);
}

STATIC mp_obj_t mp_builtin_eval(mp_obj_t o_in) {
Expand All @@ -55,8 +55,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_eval_obj, mp_builtin_eval);
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();
mp_map_t *old_globals = mp_globals_get();
mp_map_t *old_locals = mp_locals_get();
if (n_args > 1) {
mp_obj_t globals = args[1];
mp_obj_t locals;
Expand All @@ -65,13 +65,13 @@ STATIC mp_obj_t mp_builtin_exec(uint n_args, const mp_obj_t *args) {
} else {
locals = globals;
}
rt_globals_set(mp_obj_dict_get_map(globals));
rt_locals_set(mp_obj_dict_get_map(locals));
mp_globals_set(mp_obj_dict_get_map(globals));
mp_locals_set(mp_obj_dict_get_map(locals));
}
mp_obj_t res = parse_compile_execute(args[0], MP_PARSE_FILE_INPUT);
// TODO if the above call throws an exception, then we never get to reset the globals/locals
rt_globals_set(old_globals);
rt_locals_set(old_locals);
mp_globals_set(old_globals);
mp_locals_set(old_locals);
return res;
}

Expand Down
36 changes: 18 additions & 18 deletions py/builtinimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define PATH_SEP_CHAR '/'

mp_obj_t sys_path;
mp_obj_t mp_sys_path;

mp_import_stat_t stat_dir_or_file(vstr_t *path) {
//printf("stat %s\n", vstr_str(path));
Expand All @@ -42,12 +42,12 @@ mp_import_stat_t find_file(const char *file_str, uint file_len, vstr_t *dest) {
// extract the list of paths
uint path_num = 0;
mp_obj_t *path_items;
if (sys_path != MP_OBJ_NULL) {
mp_obj_list_get(sys_path, &path_num, &path_items);
if (mp_sys_path != MP_OBJ_NULL) {
mp_obj_list_get(mp_sys_path, &path_num, &path_items);
}

if (path_num == 0) {
// sys_path is empty, so just use the given file name
// mp_sys_path is empty, so just use the given file name
vstr_add_strn(dest, file_str, file_len);
return stat_dir_or_file(dest);
} else {
Expand Down Expand Up @@ -84,12 +84,12 @@ void do_load(mp_obj_t module_obj, vstr_t *file) {
qstr source_name = mp_lexer_source_name(lex);

// save the old context
mp_map_t *old_locals = rt_locals_get();
mp_map_t *old_globals = rt_globals_get();
mp_map_t *old_locals = mp_locals_get();
mp_map_t *old_globals = mp_globals_get();

// set the new context
rt_locals_set(mp_obj_module_get_globals(module_obj));
rt_globals_set(mp_obj_module_get_globals(module_obj));
mp_locals_set(mp_obj_module_get_globals(module_obj));
mp_globals_set(mp_obj_module_get_globals(module_obj));

// parse the imported script
mp_parse_error_kind_t parse_error_kind;
Expand All @@ -98,8 +98,8 @@ void do_load(mp_obj_t module_obj, vstr_t *file) {

if (pn == MP_PARSE_NODE_NULL) {
// parse error; clean up and raise exception
rt_locals_set(old_locals);
rt_globals_set(old_globals);
mp_locals_set(old_locals);
mp_globals_set(old_globals);
nlr_jump(mp_parse_make_exception(parse_error_kind));
}

Expand All @@ -109,24 +109,24 @@ void do_load(mp_obj_t module_obj, vstr_t *file) {

if (module_fun == mp_const_none) {
// TODO handle compile error correctly
rt_locals_set(old_locals);
rt_globals_set(old_globals);
mp_locals_set(old_locals);
mp_globals_set(old_globals);
return;
}

// complied successfully, execute it
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
rt_call_function_0(module_fun);
mp_call_function_0(module_fun);
nlr_pop();
} else {
// exception; restore context and re-raise same exception
rt_locals_set(old_locals);
rt_globals_set(old_globals);
mp_locals_set(old_locals);
mp_globals_set(old_globals);
nlr_jump(nlr.ret_val);
}
rt_locals_set(old_locals);
rt_globals_set(old_globals);
mp_locals_set(old_locals);
mp_globals_set(old_globals);
}

mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
Expand Down Expand Up @@ -228,7 +228,7 @@ mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
}
if (outer_module_obj != MP_OBJ_NULL) {
qstr s = qstr_from_strn(mod_str + last, i - last);
rt_store_attr(outer_module_obj, s, module_obj);
mp_store_attr(outer_module_obj, s, module_obj);
}
outer_module_obj = module_obj;
if (top_module_obj == MP_OBJ_NULL) {
Expand Down
Loading

0 comments on commit d17926d

Please sign in to comment.