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

Rename rt_* to mp_*.

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.
parent 09d20778
......@@ -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;
......@@ -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) {
......@@ -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;
}
}
......@@ -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;
}
}
......@@ -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)) {
......@@ -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)));
}
......@@ -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);
......@@ -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;
}
......@@ -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;
}
......@@ -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 {
......@@ -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...
}
}
......@@ -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;
}
......@@ -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);
......@@ -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) {
......@@ -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;
......@@ -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;
}
......
......@@ -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));
......@@ -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 {
......@@ -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;
......@@ -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));
}
......@@ -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) {
......@@ -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) {
......
......@@ -602,7 +602,7 @@ void c_assign_power(compiler_t *comp, mp_parse_node_struct_t *pns, assign_kind_t
compile_node(comp, pns1->nodes[0]);
if (assign_kind == ASSIGN_AUG_LOAD) {
EMIT(dup_top_two);
EMIT_ARG(binary_op, RT_BINARY_OP_SUBSCR);
EMIT_ARG(binary_op, MP_BINARY_OP_SUBSCR);
} else {
EMIT(store_subscr);
}
......@@ -1531,7 +1531,7 @@ void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t pn_var,
// compile: var += step
c_assign(comp, pn_var, ASSIGN_AUG_LOAD);
compile_node(comp, pn_step);
EMIT_ARG(binary_op, RT_BINARY_OP_INPLACE_ADD);
EMIT_ARG(binary_op, MP_BINARY_OP_INPLACE_ADD);
c_assign(comp, pn_var, ASSIGN_AUG_STORE);
EMIT_ARG(label_assign, entry_label);
......@@ -1541,9 +1541,9 @@ void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t pn_var,
compile_node(comp, pn_end);
assert(MP_PARSE_NODE_IS_SMALL_INT(pn_step));
if (MP_PARSE_NODE_LEAF_SMALL_INT(pn_step) >= 0) {
EMIT_ARG(binary_op, RT_BINARY_OP_LESS);
EMIT_ARG(binary_op, MP_BINARY_OP_LESS);
} else {
EMIT_ARG(binary_op, RT_BINARY_OP_MORE);
EMIT_ARG(binary_op, MP_BINARY_OP_MORE);
}
EMIT_ARG(pop_jump_if_true, top_label);
......@@ -1680,7 +1680,7 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except,
}
EMIT(dup_top);
compile_node(comp, pns_exception_expr);
EMIT_ARG(binary_op, RT_BINARY_OP_EXCEPTION_MATCH);
EMIT_ARG(binary_op, MP_BINARY_OP_EXCEPTION_MATCH);
EMIT_ARG(pop_jump_if_false, end_finally_label);
}
......@@ -1848,21 +1848,21 @@ void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
c_assign(comp, pns->nodes[0], ASSIGN_AUG_LOAD); // lhs load for aug assign
compile_node(comp, pns1->nodes[1]); // rhs
assert(MP_PARSE_NODE_IS_TOKEN(pns1->nodes[0]));
rt_binary_op_t op;
mp_binary_op_t op;
switch (MP_PARSE_NODE_LEAF_ARG(pns1->nodes[0])) {
case MP_TOKEN_DEL_PIPE_EQUAL: op = RT_BINARY_OP_INPLACE_OR; break;
case MP_TOKEN_DEL_CARET_EQUAL: op = RT_BINARY_OP_INPLACE_XOR; break;
case MP_TOKEN_DEL_AMPERSAND_EQUAL: op = RT_BINARY_OP_INPLACE_AND; break;
case MP_TOKEN_DEL_DBL_LESS_EQUAL: op = RT_BINARY_OP_INPLACE_LSHIFT; break;
case MP_TOKEN_DEL_DBL_MORE_EQUAL: op = RT_BINARY_OP_INPLACE_RSHIFT; break;
case MP_TOKEN_DEL_PLUS_EQUAL: op = RT_BINARY_OP_INPLACE_ADD; break;
case MP_TOKEN_DEL_MINUS_EQUAL: op = RT_BINARY_OP_INPLACE_SUBTRACT; break;
case MP_TOKEN_DEL_STAR_EQUAL: op = RT_BINARY_OP_INPLACE_MULTIPLY; break;
case MP_TOKEN_DEL_DBL_SLASH_EQUAL: op = RT_BINARY_OP_INPLACE_FLOOR_DIVIDE; break;
case MP_TOKEN_DEL_SLASH_EQUAL: op = RT_BINARY_OP_INPLACE_TRUE_DIVIDE; break;
case MP_TOKEN_DEL_PERCENT_EQUAL: op = RT_BINARY_OP_INPLACE_MODULO; break;
case MP_TOKEN_DEL_DBL_STAR_EQUAL: op = RT_BINARY_OP_INPLACE_POWER; break;
default: assert(0); op = RT_BINARY_OP_INPLACE_OR; // shouldn't happen
case MP_TOKEN_DEL_PIPE_EQUAL: op = MP_BINARY_OP_INPLACE_OR; break;
case MP_TOKEN_DEL_CARET_EQUAL: op = MP_BINARY_OP_INPLACE_XOR; break;
case MP_TOKEN_DEL_AMPERSAND_EQUAL: op = MP_BINARY_OP_INPLACE_AND; break;
case MP_TOKEN_DEL_DBL_LESS_EQUAL: op = MP_BINARY_OP_INPLACE_LSHIFT; break;
case MP_TOKEN_DEL_DBL_MORE_EQUAL: op = MP_BINARY_OP_INPLACE_RSHIFT; break;
case MP_TOKEN_DEL_PLUS_EQUAL: op = MP_BINARY_OP_INPLACE_ADD; break;
case MP_TOKEN_DEL_MINUS_EQUAL: op = MP_BINARY_OP_INPLACE_SUBTRACT; break;
case MP_TOKEN_DEL_STAR_EQUAL: op = MP_BINARY_OP_INPLACE_MULTIPLY; break;
case MP_TOKEN_DEL_DBL_SLASH_EQUAL: op = MP_BINARY_OP_INPLACE_FLOOR_DIVIDE; break;
case MP_TOKEN_DEL_SLASH_EQUAL: op = MP_BINARY_OP_INPLACE_TRUE_DIVIDE; break;
case MP_TOKEN_DEL_PERCENT_EQUAL: op = MP_BINARY_OP_INPLACE_MODULO; break;
case MP_TOKEN_DEL_DBL_STAR_EQUAL: op = MP_BINARY_OP_INPLACE_POWER; break;
default: assert(0); op = MP_BINARY_OP_INPLACE_OR; // shouldn't happen
}
EMIT_ARG(binary_op, op);
c_assign(comp, pns->nodes[0], ASSIGN_AUG_STORE); // lhs store for aug assign
......@@ -1919,7 +1919,7 @@ void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
}
void c_binary_op(compiler_t *comp, mp_parse_node_struct_t *pns, rt_binary_op_t binary_op) {
void c_binary_op(compiler_t *comp, mp_parse_node_struct_t *pns, mp_binary_op_t binary_op) {
int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
compile_node(comp, pns->nodes[0]);
for (int i = 1; i < num_nodes; i += 1) {
......@@ -1989,7 +1989,7 @@ void compile_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
void compile_not_test_2(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_node(comp, pns->nodes[0]);
EMIT_ARG(unary_op, RT_UNARY_OP_NOT);
EMIT_ARG(unary_op, MP_UNARY_OP_NOT);
}
void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) {
......@@ -2008,28 +2008,28 @@ void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT(rot_three);
}
if (MP_PARSE_NODE_IS_TOKEN(pns->nodes[i])) {
rt_binary_op_t op;
mp_binary_op_t op;
switch (MP_PARSE_NODE_LEAF_ARG(pns->nodes[i])) {
case MP_TOKEN_OP_LESS: op = RT_BINARY_OP_LESS; break;
case MP_TOKEN_OP_MORE: op = RT_BINARY_OP_MORE; break;
case MP_TOKEN_OP_DBL_EQUAL: op = RT_BINARY_OP_EQUAL; break;
case MP_TOKEN_OP_LESS_EQUAL: op = RT_BINARY_OP_LESS_EQUAL; break;
case MP_TOKEN_OP_MORE_EQUAL: op = RT_BINARY_OP_MORE_EQUAL; break;
case MP_TOKEN_OP_NOT_EQUAL: op = RT_BINARY_OP_NOT_EQUAL; break;
case MP_TOKEN_KW_IN: op = RT_BINARY_OP_IN; break;
default: assert(0); op = RT_BINARY_OP_LESS; // shouldn't happen
case MP_TOKEN_OP_LESS: op = MP_BINARY_OP_LESS; break;
case MP_TOKEN_OP_MORE: op = MP_BINARY_OP_MORE; break;
case MP_TOKEN_OP_DBL_EQUAL: op = MP_BINARY_OP_EQUAL; break;
case MP_TOKEN_OP_LESS_EQUAL: op = MP_BINARY_OP_LESS_EQUAL; break;
case MP_TOKEN_OP_MORE_EQUAL: op = MP_BINARY_OP_MORE_EQUAL; break;
case MP_TOKEN_OP_NOT_EQUAL: op = MP_BINARY_OP_NOT_EQUAL; break;
case MP_TOKEN_KW_IN: op = MP_BINARY_OP_IN; break;
default: assert(0); op = MP_BINARY_OP_LESS; // shouldn't happen
}
EMIT_ARG(binary_op, op);
} else if (MP_PARSE_NODE_IS_STRUCT(pns->nodes[i])) {
mp_parse_node_struct_t *pns2 = (mp_parse_node_struct_t*)pns->nodes[i];
int kind = MP_PARSE_NODE_STRUCT_KIND(pns2);
if (kind == PN_comp_op_not_in) {
EMIT_ARG(binary_op, RT_BINARY_OP_NOT_IN);
EMIT_ARG(binary_op, MP_BINARY_OP_NOT_IN);
} else if (kind == PN_comp_op_is) {
if (MP_PARSE_NODE_IS_NULL(pns2->nodes[0])) {
EMIT_ARG(binary_op, RT_BINARY_OP_IS);
EMIT_ARG(binary_op, MP_BINARY_OP_IS);
} else {
EMIT_ARG(binary_op, RT_BINARY_OP_IS_NOT);
EMIT_ARG(binary_op, MP_BINARY_OP_IS_NOT);
}
} else {
// shouldn't happen
......@@ -2062,15 +2062,15 @@ void compile_star_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
void compile_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
c_binary_op(comp, pns, RT_BINARY_OP_OR);
c_binary_op(comp, pns, MP_BINARY_OP_OR);
}
void compile_xor_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
c_binary_op(comp, pns, RT_BINARY_OP_XOR);
c_binary_op(comp, pns, MP_BINARY_OP_XOR);
}
void compile_and_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
c_binary_op(comp, pns, RT_BINARY_OP_AND);
c_binary_op(comp, pns, MP_BINARY_OP_AND);
}
void compile_shift_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
......@@ -2079,9 +2079,9 @@ void compile_shift_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
for (int i = 1; i + 1 < num_nodes; i += 2) {
compile_node(comp, pns->nodes[i + 1]);
if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_DBL_LESS)) {
EMIT_ARG(binary_op, RT_BINARY_OP_LSHIFT);
EMIT_ARG(binary_op, MP_BINARY_OP_LSHIFT);
} else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_DBL_MORE)) {
EMIT_ARG(binary_op, RT_BINARY_OP_RSHIFT);
EMIT_ARG(binary_op, MP_BINARY_OP_RSHIFT);
} else {
// shouldn't happen
assert(0);
......@@ -2095,9 +2095,9 @@ void compile_arith_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
for (int i = 1; i + 1 < num_nodes; i += 2) {
compile_node(comp, pns->nodes[i + 1]);
if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_PLUS)) {
EMIT_ARG(binary_op, RT_BINARY_OP_ADD);
EMIT_ARG(binary_op, MP_BINARY_OP_ADD);
} else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_MINUS)) {
EMIT_ARG(binary_op, RT_BINARY_OP_SUBTRACT);
EMIT_ARG(binary_op, MP_BINARY_OP_SUBTRACT);
} else {
// shouldn't happen
assert(0);
......@@ -2111,13 +2111,13 @@ void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) {
for (int i = 1; i + 1 < num_nodes; i += 2) {
compile_node(comp, pns->nodes[i + 1]);
if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_STAR)) {
EMIT_ARG(binary_op, RT_BINARY_OP_MULTIPLY);
EMIT_ARG(binary_op, MP_BINARY_OP_MULTIPLY);
} else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_DBL_SLASH)) {
EMIT_ARG(binary_op, RT_BINARY_OP_FLOOR_DIVIDE);
EMIT_ARG(binary_op, MP_BINARY_OP_FLOOR_DIVIDE);
} else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_SLASH)) {
EMIT_ARG(binary_op, RT_BINARY_OP_TRUE_DIVIDE);
EMIT_ARG(binary_op, MP_BINARY_OP_TRUE_DIVIDE);
} else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[i], MP_TOKEN_OP_PERCENT)) {
EMIT_ARG(binary_op, RT_BINARY_OP_MODULO);
EMIT_ARG(binary_op, MP_BINARY_OP_MODULO);
} else {
// shouldn't happen
assert(0);
......@@ -2128,11 +2128,11 @@ void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) {
void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_node(comp, pns->nodes[1]);
if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[0], MP_TOKEN_OP_PLUS)) {
EMIT_ARG(unary_op, RT_UNARY_OP_POSITIVE);
EMIT_ARG(unary_op, MP_UNARY_OP_POSITIVE);
} else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[0], MP_TOKEN_OP_MINUS)) {
EMIT_ARG(unary_op, RT_UNARY_OP_NEGATIVE);
EMIT_ARG(unary_op, MP_UNARY_OP_NEGATIVE);
} else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[0], MP_TOKEN_OP_TILDE)) {
EMIT_ARG(unary_op, RT_UNARY_OP_INVERT);
EMIT_ARG(unary_op, MP_UNARY_OP_INVERT);
} else {
// shouldn't happen
assert(0);
......@@ -2219,7 +2219,7 @@ void compile_power_trailers(compiler_t *comp, mp_parse_node_struct_t *pns) {
void compile_power_dbl_star(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_node(comp, pns->nodes[0]);
EMIT_ARG(binary_op, RT_BINARY_OP_POWER);
EMIT_ARG(binary_op, MP_BINARY_OP_POWER);
}
void compile_atom_string(compiler_t *comp, mp_parse_node_struct_t *pns) {
......@@ -2444,7 +2444,7 @@ void compile_trailer_paren(compiler_t *comp, mp_parse_node_struct_t *pns) {
void compile_trailer_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) {
// object who's index we want is on top of stack
compile_node(comp, pns->nodes[0]); // the index
EMIT_ARG(binary_op, RT_BINARY_OP_SUBSCR);
EMIT_ARG(binary_op, MP_BINARY_OP_SUBSCR);
}
void compile_trailer_period(compiler_t *comp, mp_parse_node_struct_t *pns) {
......@@ -3317,7 +3317,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, bool is_repl) {
#else
// return function that executes the outer module
// we can free the unique_code slot because no-one has reference to this unique_code_id anymore
return rt_make_function_from_id(unique_code_id, true, MP_OBJ_NULL);
return mp_make_function_from_id(unique_code_id, true, MP_OBJ_NULL);
#endif
}
}
......@@ -84,8 +84,8 @@ typedef struct _emit_method_table_t {
void (*for_iter_end)(emit_t *emit);
void (*pop_block)(emit_t *emit);
void (*pop_except)(emit_t *emit);
void (*unary_op)(emit_t *emit, rt_unary_op_t op);
void (*binary_op)(emit_t *emit, rt_binary_op_t op);
void (*unary_op)(emit_t *emit, mp_unary_op_t op);
void (*binary_op)(emit_t *emit, mp_binary_op_t op);
void (*build_tuple)(emit_t *emit, int n_args);
void (*build_list)(emit_t *emit, int n_args);
void (*list_append)(emit_t *emit, int list_stack_index);
......
......@@ -632,10 +632,10 @@ STATIC void emit_bc_pop_except(emit_t *emit) {
emit_write_byte_code_byte(emit, MP_BC_POP_EXCEPT);
}
STATIC void emit_bc_unary_op(emit_t *emit, rt_unary_op_t op) {
if (op == RT_UNARY_OP_NOT) {
STATIC void emit_bc_unary_op(emit_t *emit, mp_unary_op_t op) {
if (op == MP_UNARY_OP_NOT) {
emit_bc_pre(emit, 0);
emit_write_byte_code_byte_byte(emit, MP_BC_UNARY_OP, RT_UNARY_OP_BOOL);
emit_write_byte_code_byte_byte(emit, MP_BC_UNARY_OP, MP_UNARY_OP_BOOL);
emit_bc_pre(emit, 0);
emit_write_byte_code_byte(emit, MP_BC_NOT);
} else {
......@@ -644,14 +644,14 @@ STATIC void emit_bc_unary_op(emit_t *emit, rt_unary_op_t op) {
}
}
STATIC void emit_bc_binary_op(emit_t *emit, rt_binary_op_t op) {
STATIC void emit_bc_binary_op(emit_t *emit, mp_binary_op_t op) {
bool invert = false;
if (op == RT_BINARY_OP_NOT_IN) {
if (op == MP_BINARY_OP_NOT_IN) {
invert = true;
op = RT_BINARY_OP_IN;
} else if (op == RT_BINARY_OP_IS_NOT) {
op = MP_BINARY_OP_IN;
} else if (op == MP_BINARY_OP_IS_NOT) {
invert = true;
op = RT_BINARY_OP_IS;
op = MP_BINARY_OP_IS;
}
emit_bc_pre(emit, -1);
emit_write_byte_code_byte_byte(emit, MP_BC_BINARY_OP, op);
......
......@@ -541,21 +541,21 @@ STATIC void emit_cpy_pop_except(emit_t *emit) {
}
}
STATIC void emit_cpy_unary_op(emit_t *emit, rt_unary_op_t op) {
STATIC void emit_cpy_unary_op(emit_t *emit, mp_unary_op_t op) {
emit_pre(emit, 0, 1);
if (emit->pass == PASS_3) {
switch (op) {
case RT_UNARY_OP_POSITIVE: printf("UNARY_POSITIVE\n"); break;
case RT_UNARY_OP_NEGATIVE: printf("UNARY_NEGATIVE\n"); break;
case RT_UNARY_OP_INVERT: printf("UNARY_INVERT\n"); break;
case RT_UNARY_OP_NOT: printf("UNARY_NOT\n"); break;
case MP_UNARY_OP_POSITIVE: printf("UNARY_POSITIVE\n"); break;
case MP_UNARY_OP_NEGATIVE: printf("UNARY_NEGATIVE\n"); break;
case MP_UNARY_OP_INVERT: printf("UNARY_INVERT\n"); break;
case MP_UNARY_OP_NOT: printf("UNARY_NOT\n"); break;
default: assert(0);
}
}
}
STATIC void emit_cpy_binary_op(emit_t *emit, rt_binary_op_t op) {
if (op <= RT_BINARY_OP_INPLACE_POWER) {
STATIC void emit_cpy_binary_op(emit_t *emit, mp_binary_op_t op) {
if (op <= MP_BINARY_OP_INPLACE_POWER) {
// CPython uses a byte code for each binary op
emit_pre(emit, -1, 1);
} else {
......@@ -564,42 +564,42 @@ STATIC void emit_cpy_binary_op(emit_t *emit, rt_binary_op_t op) {
}
if (emit->pass == PASS_3) {
switch (op) {
case RT_BINARY_OP_SUBSCR: printf("BINARY_SUBSCR\n"); break;
case RT_BINARY_OP_OR: printf("BINARY_OR\n"); break;
case RT_BINARY_OP_XOR: printf("BINARY_XOR\n"); break;
case RT_BINARY_OP_AND: printf("BINARY_AND\n"); break;
case RT_BINARY_OP_LSHIFT: printf("BINARY_LSHIFT\n"); break;
case RT_BINARY_OP_RSHIFT: printf("BINARY_RSHIFT\n"); break;
case RT_BINARY_OP_ADD: printf("BINARY_ADD\n"); break;
case RT_BINARY_OP_SUBTRACT: printf("BINARY_SUBTRACT\n"); break;
case RT_BINARY_OP_MULTIPLY: printf("BINARY_MULTIPLY\n"); break;
case RT_BINARY_OP_FLOOR_DIVIDE: printf("BINARY_FLOOR_DIVIDE\n"); break;
case RT_BINARY_OP_TRUE_DIVIDE: printf("BINARY_TRUE_DIVIDE\n"); break;
case RT_BINARY_OP_MODULO: printf("BINARY_MODULO\n"); break;
case RT_BINARY_OP_POWER: printf("BINARY_POWER\n"); break;
case RT_BINARY_OP_INPLACE_OR: printf("INPLACE_OR\n"); break;
case RT_BINARY_OP_INPLACE_XOR: printf("INPLACE_XOR\n"); break;
case RT_BINARY_OP_INPLACE_AND: printf("INPLACE_AND\n"); break;
case RT_BINARY_OP_INPLACE_LSHIFT: printf("INPLACE_LSHIFT\n"); break;
case RT_BINARY_OP_INPLACE_RSHIFT: printf("INPLACE_RSHIFT\n"); break;