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.
This commit is contained in:
Damien George 2014-03-30 13:35:08 +01:00
parent 09d207785c
commit d17926db71
71 changed files with 983 additions and 978 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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) {

View File

@ -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
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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;
case RT_BINARY_OP_INPLACE_ADD: printf("INPLACE_ADD\n"); break;
case RT_BINARY_OP_INPLACE_SUBTRACT: printf("INPLACE_SUBTRACT\n"); break;
case RT_BINARY_OP_INPLACE_MULTIPLY: printf("INPLACE_MULTIPLY\n"); break;
case RT_BINARY_OP_INPLACE_FLOOR_DIVIDE: printf("INPLACE_FLOOR_DIVIDE\n"); break;
case RT_BINARY_OP_INPLACE_TRUE_DIVIDE: printf("INPLACE_TRUE_DIVIDE\n"); break;
case RT_BINARY_OP_INPLACE_MODULO: printf("INPLACE_MODULO\n"); break;
case RT_BINARY_OP_INPLACE_POWER: printf("INPLACE_POWER\n"); break;
case RT_BINARY_OP_LESS: printf("COMPARE_OP <\n"); break;
case RT_BINARY_OP_MORE: printf("COMPARE_OP >\n"); break;
case RT_BINARY_OP_EQUAL: printf("COMPARE_OP ==\n"); break;
case RT_BINARY_OP_LESS_EQUAL: printf("COMPARE_OP <=\n"); break;
case RT_BINARY_OP_MORE_EQUAL: printf("COMPARE_OP >=\n"); break;
case RT_BINARY_OP_NOT_EQUAL: printf("COMPARE_OP !=\n"); break;
case RT_BINARY_OP_IN: printf("COMPARE_OP in\n"); break;
case RT_BINARY_OP_IS: printf("COMPARE_OP is\n"); break;
case RT_BINARY_OP_EXCEPTION_MATCH: printf("COMPARE_OP exception match\n"); break;
case RT_BINARY_OP_NOT_IN: printf("COMPARE_OP not in\n"); break;
case RT_BINARY_OP_IS_NOT: printf("COMPARE_OP is not\n"); break;
case MP_BINARY_OP_SUBSCR: printf("BINARY_SUBSCR\n"); break;
case MP_BINARY_OP_OR: printf("BINARY_OR\n"); break;
case MP_BINARY_OP_XOR: printf("BINARY_XOR\n"); break;
case MP_BINARY_OP_AND: printf("BINARY_AND\n"); break;
case MP_BINARY_OP_LSHIFT: printf("BINARY_LSHIFT\n"); break;
case MP_BINARY_OP_RSHIFT: printf("BINARY_RSHIFT\n"); break;
case MP_BINARY_OP_ADD: printf("BINARY_ADD\n"); break;
case MP_BINARY_OP_SUBTRACT: printf("BINARY_SUBTRACT\n"); break;
case MP_BINARY_OP_MULTIPLY: printf("BINARY_MULTIPLY\n"); break;
case MP_BINARY_OP_FLOOR_DIVIDE: printf("BINARY_FLOOR_DIVIDE\n"); break;
case MP_BINARY_OP_TRUE_DIVIDE: printf("BINARY_TRUE_DIVIDE\n"); break;
case MP_BINARY_OP_MODULO: printf("BINARY_MODULO\n"); break;
case MP_BINARY_OP_POWER: printf("BINARY_POWER\n"); break;
case MP_BINARY_OP_INPLACE_OR: printf("INPLACE_OR\n"); break;
case MP_BINARY_OP_INPLACE_XOR: printf("INPLACE_XOR\n"); break;
case MP_BINARY_OP_INPLACE_AND: printf("INPLACE_AND\n"); break;
case MP_BINARY_OP_INPLACE_LSHIFT: printf("INPLACE_LSHIFT\n"); break;
case MP_BINARY_OP_INPLACE_RSHIFT: printf("INPLACE_RSHIFT\n"); break;
case MP_BINARY_OP_INPLACE_ADD: printf("INPLACE_ADD\n"); break;
case MP_BINARY_OP_INPLACE_SUBTRACT: printf("INPLACE_SUBTRACT\n"); break;
case MP_BINARY_OP_INPLACE_MULTIPLY: printf("INPLACE_MULTIPLY\n"); break;
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: printf("INPLACE_FLOOR_DIVIDE\n"); break;
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE: printf("INPLACE_TRUE_DIVIDE\n"); break;
case MP_BINARY_OP_INPLACE_MODULO: printf("INPLACE_MODULO\n"); break;
case MP_BINARY_OP_INPLACE_POWER: printf("INPLACE_POWER\n"); break;
case MP_BINARY_OP_LESS: printf("COMPARE_OP <\n"); break;
case MP_BINARY_OP_MORE: printf("COMPARE_OP >\n"); break;
case MP_BINARY_OP_EQUAL: printf("COMPARE_OP ==\n"); break;
case MP_BINARY_OP_LESS_EQUAL: printf("COMPARE_OP <=\n"); break;
case MP_BINARY_OP_MORE_EQUAL: printf("COMPARE_OP >=\n"); break;
case MP_BINARY_OP_NOT_EQUAL: printf("COMPARE_OP !=\n"); break;
case MP_BINARY_OP_IN: printf("COMPARE_OP in\n"); break;
case MP_BINARY_OP_IS: printf("COMPARE_OP is\n"); break;
case MP_BINARY_OP_EXCEPTION_MATCH: printf("COMPARE_OP exception match\n"); break;
case MP_BINARY_OP_NOT_IN: printf("COMPARE_OP not in\n"); break;
case MP_BINARY_OP_IS_NOT: printf("COMPARE_OP is not\n"); break;
default: assert(0);
}
}

View File

@ -190,7 +190,7 @@ void mp_emit_glue_assign_inline_asm_code(uint unique_code_id, void *fun, uint le
#endif
}
mp_obj_t rt_make_function_from_id(uint unique_code_id, bool free_unique_code, mp_obj_t def_args) {
mp_obj_t mp_make_function_from_id(uint unique_code_id, bool free_unique_code, mp_obj_t def_args) {
DEBUG_OP_printf("make_function_from_id %d\n", unique_code_id);
if (unique_code_id >= unique_codes_total) {
// illegal code id
@ -205,7 +205,7 @@ mp_obj_t rt_make_function_from_id(uint unique_code_id, bool free_unique_code, mp
fun = mp_obj_new_fun_bc(c->scope_flags, c->arg_names, c->n_args, def_args, c->u_byte.code);
break;
case MP_CODE_NATIVE:
fun = rt_make_function_n(c->n_args, c->u_native.fun);
fun = mp_make_function_n(c->n_args, c->u_native.fun);
break;
case MP_CODE_INLINE_ASM:
fun = mp_obj_new_fun_asm(c->n_args, c->u_inline_asm.fun);
@ -231,10 +231,10 @@ mp_obj_t rt_make_function_from_id(uint unique_code_id, bool free_unique_code, mp
return fun;
}
mp_obj_t rt_make_closure_from_id(uint unique_code_id, mp_obj_t closure_tuple, mp_obj_t def_args) {
mp_obj_t mp_make_closure_from_id(uint unique_code_id, mp_obj_t closure_tuple, mp_obj_t def_args) {
DEBUG_OP_printf("make_closure_from_id %d\n", unique_code_id);
// make function object
mp_obj_t ffun = rt_make_function_from_id(unique_code_id, false, def_args);
mp_obj_t ffun = mp_make_function_from_id(unique_code_id, false, def_args);
// wrap function in closure object
return mp_obj_new_closure(ffun, closure_tuple);
}

View File

@ -251,7 +251,7 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
}
}
asm_thumb_mov_reg_i32(emit->as, REG_R7, (machine_uint_t)rt_fun_table);
asm_thumb_mov_reg_i32(emit->as, REG_R7, (machine_uint_t)mp_fun_table);
#endif
}
@ -512,33 +512,33 @@ STATIC void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, int reg_dest, i
adjust_stack(emit, n_push);
}
STATIC void emit_call(emit_t *emit, rt_fun_kind_t fun_kind, void *fun) {
STATIC void emit_call(emit_t *emit, mp_fun_kind_t fun_kind, void *fun) {
need_reg_all(emit);
#if N_X64
asm_x64_call_ind(emit->as, fun, REG_RAX);
#elif N_THUMB
asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3);
asm_thumb_bl_ind(emit->as, mp_fun_table[fun_kind], fun_kind, REG_R3);
#endif
}
STATIC void emit_call_with_imm_arg(emit_t *emit, rt_fun_kind_t fun_kind, void *fun, machine_int_t arg_val, int arg_reg) {
STATIC void emit_call_with_imm_arg(emit_t *emit, mp_fun_kind_t fun_kind, void *fun, machine_int_t arg_val, int arg_reg) {
need_reg_all(emit);
ASM_MOV_IMM_TO_REG(arg_val, arg_reg);
#if N_X64
asm_x64_call_ind(emit->as, fun, REG_RAX);
#elif N_THUMB
asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3);
asm_thumb_bl_ind(emit->as, mp_fun_table[fun_kind], fun_kind, REG_R3);
#endif
}
STATIC void emit_call_with_2_imm_args(emit_t *emit, rt_fun_kind_t fun_kind, void *fun, machine_int_t arg_val1, int arg_reg1, machine_int_t arg_val2, int arg_reg2) {
STATIC void emit_call_with_2_imm_args(emit_t *emit, mp_fun_kind_t fun_kind, void *fun, machine_int_t arg_val1, int arg_reg1, machine_int_t arg_val2, int arg_reg2) {
need_reg_all(emit);
ASM_MOV_IMM_TO_REG(arg_val1, arg_reg1);
ASM_MOV_IMM_TO_REG(arg_val2, arg_reg2);
#if N_X64
asm_x64_call_ind(emit->as, fun, REG_RAX);
#elif N_THUMB
asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3);
asm_thumb_bl_ind(emit->as, mp_fun_table[fun_kind], fun_kind, REG_R3);
#endif
}
@ -633,7 +633,7 @@ STATIC void emit_native_load_const_int(emit_t *emit, qstr qstr) {
STATIC void emit_native_load_const_dec(emit_t *emit, qstr qstr) {
// for viper, a float/complex is just a Python object
emit_native_pre(emit);
emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_DEC, rt_load_const_dec, qstr, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_LOAD_CONST_DEC, mp_load_const_dec, qstr, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
@ -642,7 +642,7 @@ STATIC void emit_native_load_const_id(emit_t *emit, qstr qstr) {
if (emit->do_viper_types) {
assert(0);
} else {
emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_STR, rt_load_const_str, qstr, REG_ARG_1); // TODO
emit_call_with_imm_arg(emit, MP_F_LOAD_CONST_STR, mp_load_const_str, qstr, REG_ARG_1); // TODO
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
}
@ -655,7 +655,7 @@ STATIC void emit_native_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
assert(0);
emit_post_push_imm(emit, VTYPE_PTR, (machine_uint_t)qstr_str(qstr));
} else {
emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_STR, rt_load_const_str, qstr, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_LOAD_CONST_STR, mp_load_const_str, qstr, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
}
@ -707,13 +707,13 @@ STATIC void emit_native_load_closure(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_native_load_name(emit_t *emit, qstr qstr) {
emit_native_pre(emit);
emit_call_with_imm_arg(emit, RT_F_LOAD_NAME, rt_load_name, qstr, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_LOAD_NAME, mp_load_name, qstr, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
STATIC void emit_native_load_global(emit_t *emit, qstr qstr) {
emit_native_pre(emit);
emit_call_with_imm_arg(emit, RT_F_LOAD_GLOBAL, rt_load_global, qstr, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_LOAD_GLOBAL, mp_load_global, qstr, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
@ -721,11 +721,11 @@ STATIC void emit_native_load_attr(emit_t *emit, qstr qstr) {
// depends on type of subject:
// - integer, function, pointer to integers: error
// - pointer to structure: get member, quite easy
// - Python object: call rt_load_attr, and needs to be typed to convert result
// - Python object: call mp_load_attr, and needs to be typed to convert result
vtype_kind_t vtype_base;
emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base
assert(vtype_base == VTYPE_PYOBJ);
emit_call_with_imm_arg(emit, RT_F_LOAD_ATTR, rt_load_attr, qstr, REG_ARG_2); // arg2 = attribute name
emit_call_with_imm_arg(emit, MP_F_LOAD_ATTR, mp_load_attr, qstr, REG_ARG_2); // arg2 = attribute name
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
@ -734,12 +734,12 @@ STATIC void emit_native_load_method(emit_t *emit, qstr qstr) {
emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base
assert(vtype_base == VTYPE_PYOBJ);
emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_3, 2); // arg3 = dest ptr
emit_call_with_imm_arg(emit, RT_F_LOAD_METHOD, rt_load_method, qstr, REG_ARG_2); // arg2 = method name
emit_call_with_imm_arg(emit, MP_F_LOAD_METHOD, mp_load_method, qstr, REG_ARG_2); // arg2 = method name
}
STATIC void emit_native_load_build_class(emit_t *emit) {
emit_native_pre(emit);
emit_call(emit, RT_F_LOAD_BUILD_CLASS, rt_load_build_class);
emit_call(emit, MP_F_LOAD_BUILD_CLASS, mp_load_build_class);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
@ -783,11 +783,11 @@ STATIC void emit_native_store_deref(emit_t *emit, qstr qstr, int local_num) {
}
STATIC void emit_native_store_name(emit_t *emit, qstr qstr) {
// rt_store_name, but needs conversion of object (maybe have rt_viper_store_name(obj, type))
// mp_store_name, but needs conversion of object (maybe have mp_viper_store_name(obj, type))
vtype_kind_t vtype;
emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
assert(vtype == VTYPE_PYOBJ);
emit_call_with_imm_arg(emit, RT_F_STORE_NAME, rt_store_name, qstr, REG_ARG_1); // arg1 = name
emit_call_with_imm_arg(emit, MP_F_STORE_NAME, mp_store_name, qstr, REG_ARG_1); // arg1 = name
emit_post(emit);
}
@ -801,7 +801,7 @@ STATIC void emit_native_store_attr(emit_t *emit, qstr qstr) {
emit_pre_pop_reg_reg(emit, &vtype_base, REG_ARG_1, &vtype_val, REG_ARG_3); // arg1 = base, arg3 = value
assert(vtype_base == VTYPE_PYOBJ);
assert(vtype_val == VTYPE_PYOBJ);
emit_call_with_imm_arg(emit, RT_F_STORE_ATTR, rt_store_attr, qstr, REG_ARG_2); // arg2 = attribute name
emit_call_with_imm_arg(emit, MP_F_STORE_ATTR, mp_store_attr, qstr, REG_ARG_2); // arg2 = attribute name
emit_post(emit);
}
@ -815,7 +815,7 @@ STATIC void emit_native_store_subscr(emit_t *emit) {
assert(vtype_index == VTYPE_PYOBJ);
assert(vtype_base == VTYPE_PYOBJ);
assert(vtype_value == VTYPE_PYOBJ);
emit_call(emit, RT_F_STORE_SUBSCR, rt_store_subscr);
emit_call(emit, MP_F_STORE_SUBSCR, mp_store_subscr);
}
STATIC void emit_native_store_locals(emit_t *emit) {
@ -838,13 +838,13 @@ STATIC void emit_native_delete_deref(emit_t *emit, qstr qstr, int local_num) {
STATIC void emit_native_delete_name(emit_t *emit, qstr qstr) {
// not implemented
// use rt_delete_name
// use mp_delete_name
assert(0);
}
STATIC void emit_native_delete_global(emit_t *emit, qstr qstr) {
// not implemented
// use rt_delete_global
// use mp_delete_global
assert(0);
}
@ -904,7 +904,7 @@ STATIC void emit_native_pop_jump_pre_helper(emit_t *emit, int label) {
emit_pre_pop_reg(emit, &vtype, REG_RET);
} else if (vtype == VTYPE_PYOBJ) {
emit_pre_pop_reg(emit, &vtype, REG_ARG_1);
emit_call(emit, RT_F_IS_TRUE, rt_is_true);
emit_call(emit, MP_F_OBJ_IS_TRUE, mp_obj_is_true);
} else {
printf("ViperTypeError: expecting a bool or pyobj, got %d\n", vtype);
assert(0);
@ -977,7 +977,7 @@ STATIC void emit_native_get_iter(emit_t *emit) {
vtype_kind_t vtype;
emit_pre_pop_reg(emit, &vtype, REG_ARG_1);
assert(vtype == VTYPE_PYOBJ);
emit_call(emit, RT_F_GETITER, rt_getiter);
emit_call(emit, MP_F_GETITER, mp_getiter);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
@ -986,7 +986,7 @@ STATIC void emit_native_for_iter(emit_t *emit, int label) {
vtype_kind_t vtype;
emit_access_stack(emit, 1, &vtype, REG_ARG_1);
assert(vtype == VTYPE_PYOBJ);
emit_call(emit, RT_F_ITERNEXT, rt_iternext);
emit_call(emit, MP_F_ITERNEXT, mp_iternext);
ASM_MOV_IMM_TO_REG((machine_uint_t)MP_OBJ_NULL, REG_TEMP1);
#if N_X64
asm_x64_cmp_r64_with_r64(emit->as, REG_RET, REG_TEMP1);
@ -1014,26 +1014,26 @@ STATIC void emit_native_pop_except(emit_t *emit) {
assert(0);
}
STATIC void emit_native_unary_op(emit_t *emit, rt_unary_op_t op) {
STATIC void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) {
vtype_kind_t vtype;
emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
assert(vtype == VTYPE_PYOBJ);
emit_call_with_imm_arg(emit, RT_F_UNARY_OP, rt_unary_op, op, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_UNARY_OP, mp_unary_op, op, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
STATIC void emit_native_binary_op(emit_t *emit, rt_binary_op_t op) {
STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
vtype_kind_t vtype_lhs, vtype_rhs;
emit_pre_pop_reg_reg(emit, &vtype_rhs, REG_ARG_3, &vtype_lhs, REG_ARG_2);
if (vtype_lhs == VTYPE_INT && vtype_rhs == VTYPE_INT) {
if (op == RT_BINARY_OP_ADD || op == RT_BINARY_OP_INPLACE_ADD) {
if (op == MP_BINARY_OP_ADD || op == MP_BINARY_OP_INPLACE_ADD) {
#if N_X64
asm_x64_add_r64_to_r64(emit->as, REG_ARG_3, REG_ARG_2);
#elif N_THUMB
asm_thumb_add_reg_reg_reg(emit->as, REG_ARG_2, REG_ARG_2, REG_ARG_3);
#endif
emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
} else if (op == RT_BINARY_OP_LESS) {
} else if (op == MP_BINARY_OP_LESS) {
#if N_X64
asm_x64_xor_r64_to_r64(emit->as, REG_RET, REG_RET);
asm_x64_cmp_r64_with_r64(emit->as, REG_ARG_3, REG_ARG_2);
@ -1050,7 +1050,7 @@ STATIC void emit_native_binary_op(emit_t *emit, rt_binary_op_t op) {
assert(0);
}
} else if (vtype_lhs == VTYPE_PYOBJ && vtype_rhs == VTYPE_PYOBJ) {
emit_call_with_imm_arg(emit, RT_F_BINARY_OP, rt_binary_op, op, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_BINARY_OP, mp_binary_op, op, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
} else {
printf("ViperTypeError: can't do binary op between types %d and %d\n", vtype_lhs, vtype_rhs);
@ -1063,14 +1063,14 @@ STATIC void emit_native_build_tuple(emit_t *emit, int n_args) {
// if wrapped in byte_array, or something, allocates memory and fills it
emit_native_pre(emit);
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items
emit_call_with_imm_arg(emit, RT_F_BUILD_TUPLE, rt_build_tuple, n_args, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_BUILD_TUPLE, mp_build_tuple, n_args, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new tuple
}
STATIC void emit_native_build_list(emit_t *emit, int n_args) {
emit_native_pre(emit);
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items
emit_call_with_imm_arg(emit, RT_F_BUILD_LIST, rt_build_list, n_args, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_BUILD_LIST, mp_build_list, n_args, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new list
}
@ -1081,13 +1081,13 @@ STATIC void emit_native_list_append(emit_t *emit, int list_index) {
emit_access_stack(emit, list_index, &vtype_list, REG_ARG_1);
assert(vtype_list == VTYPE_PYOBJ);
assert(vtype_item == VTYPE_PYOBJ);
emit_call(emit, RT_F_LIST_APPEND, rt_list_append);
emit_call(emit, MP_F_LIST_APPEND, mp_list_append);
emit_post(emit);
}
STATIC void emit_native_build_map(emit_t *emit, int n_args) {
emit_native_pre(emit);
emit_call_with_imm_arg(emit, RT_F_BUILD_MAP, rt_build_map, n_args, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_BUILD_MAP, mp_build_map, n_args, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new map
}
@ -1097,7 +1097,7 @@ STATIC void emit_native_store_map(emit_t *emit) {
assert(vtype_key == VTYPE_PYOBJ);
assert(vtype_value == VTYPE_PYOBJ);
assert(vtype_map == VTYPE_PYOBJ);
emit_call(emit, RT_F_STORE_MAP, rt_store_map);
emit_call(emit, MP_F_STORE_MAP, mp_store_map);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // map
}
@ -1109,14 +1109,14 @@ STATIC void emit_native_map_add(emit_t *emit, int map_index) {
assert(vtype_map == VTYPE_PYOBJ);
assert(vtype_key == VTYPE_PYOBJ);
assert(vtype_value == VTYPE_PYOBJ);
emit_call(emit, RT_F_STORE_MAP, rt_store_map);
emit_call(emit, MP_F_STORE_MAP, mp_store_map);
emit_post(emit);
}
STATIC void emit_native_build_set(emit_t *emit, int n_args) {
emit_native_pre(emit);
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items
emit_call_with_imm_arg(emit, RT_F_BUILD_SET, rt_build_set, n_args, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_BUILD_SET, mp_build_set, n_args, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new set
}
@ -1127,7 +1127,7 @@ STATIC void emit_native_set_add(emit_t *emit, int set_index) {
emit_access_stack(emit, set_index, &vtype_set, REG_ARG_1);
assert(vtype_set == VTYPE_PYOBJ);
assert(vtype_item == VTYPE_PYOBJ);
emit_call(emit, RT_F_STORE_SET, rt_store_set);
emit_call(emit, MP_F_STORE_SET, mp_store_set);
emit_post(emit);
}
@ -1146,7 +1146,7 @@ STATIC void emit_native_make_function(emit_t *emit, scope_t *scope, int n_dict_p
// call runtime, with type info for args, or don't support dict/default params, or only support Python objects for them
assert(n_default_params == 0 && n_dict_params == 0);
emit_native_pre(emit);
emit_call_with_imm_arg(emit, RT_F_MAKE_FUNCTION_FROM_ID, rt_make_function_from_id, scope->unique_code_id, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_MAKE_FUNCTION_FROM_ID, mp_make_function_from_id, scope->unique_code_id, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
@ -1165,20 +1165,20 @@ STATIC void emit_native_call_function(emit_t *emit, int n_positional, int n_keyw
vtype_kind_t vtype_fun;
emit_pre_pop_reg(emit, &vtype_fun, REG_ARG_1); // the function
assert(vtype_fun == VTYPE_PYOBJ);
emit_call(emit, RT_F_CALL_FUNCTION_0, rt_call_function_0);
emit_call(emit, MP_F_CALL_FUNCTION_0, mp_call_function_0);
} else if (n_positional == 1) {
vtype_kind_t vtype_fun, vtype_arg1;
emit_pre_pop_reg_reg(emit, &vtype_arg1, REG_ARG_2, &vtype_fun, REG_ARG_1); // the single argument, the function
assert(vtype_fun == VTYPE_PYOBJ);
assert(vtype_arg1 == VTYPE_PYOBJ);
emit_call(emit, RT_F_CALL_FUNCTION_1, rt_call_function_1);
emit_call(emit, MP_F_CALL_FUNCTION_1, mp_call_function_1);
} else if (n_positional == 2) {
vtype_kind_t vtype_fun, vtype_arg1, vtype_arg2;
emit_pre_pop_reg_reg_reg(emit, &vtype_arg2, REG_ARG_3, &vtype_arg1, REG_ARG_2, &vtype_fun, REG_ARG_1); // the second argument, the first argument, the function
assert(vtype_fun == VTYPE_PYOBJ);
assert(vtype_arg1 == VTYPE_PYOBJ);
assert(vtype_arg2 == VTYPE_PYOBJ);
emit_call(emit, RT_F_CALL_FUNCTION_2, rt_call_function_2);
emit_call(emit, MP_F_CALL_FUNCTION_2, mp_call_function_2);
} else {
*/
@ -1189,7 +1189,7 @@ STATIC void emit_native_call_function(emit_t *emit, int n_positional, int n_keyw
vtype_kind_t vtype_fun;
emit_pre_pop_reg(emit, &vtype_fun, REG_ARG_1); // the function
assert(vtype_fun == VTYPE_PYOBJ);
emit_call_with_imm_arg(emit, RT_F_CALL_FUNCTION_N_KW_FOR_NATIVE, rt_call_function_n_kw_for_native, n_positional, REG_ARG_2);
emit_call_with_imm_arg(emit, MP_F_CALL_FUNCTION_N_KW_FOR_NATIVE, mp_call_function_n_kw_for_native, n_positional, REG_ARG_2);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
@ -1202,20 +1202,20 @@ STATIC void emit_native_call_method(emit_t *emit, int n_positional, int n_keywor
emit_pre_pop_reg_reg(emit, &vtype_self, REG_ARG_2, &vtype_meth, REG_ARG_1); // the self object (or NULL), the method
assert(vtype_meth == VTYPE_PYOBJ);
assert(vtype_self == VTYPE_PYOBJ);
emit_call(emit, RT_F_CALL_METHOD_1, rt_call_method_1);
emit_call(emit, MP_F_CALL_METHOD_1, mp_call_method_1);
} else if (n_positional == 1) {
vtype_kind_t vtype_meth, vtype_self, vtype_arg1;
emit_pre_pop_reg_reg_reg(emit, &vtype_arg1, REG_ARG_3, &vtype_self, REG_ARG_2, &vtype_meth, REG_ARG_1); // the first argument, the self object (or NULL), the method
assert(vtype_meth == VTYPE_PYOBJ);
assert(vtype_self == VTYPE_PYOBJ);
assert(vtype_arg1 == VTYPE_PYOBJ);
emit_call(emit, RT_F_CALL_METHOD_2, rt_call_method_2);
emit_call(emit, MP_F_CALL_METHOD_2, mp_call_method_2);
} else {
*/
emit_native_pre(emit);
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_3, n_positional + 2); // pointer to items, including meth and self
emit_call_with_2_imm_args(emit, RT_F_CALL_METHOD_N_KW, rt_call_method_n_kw, n_positional, REG_ARG_1, n_keyword, REG_ARG_2);
emit_call_with_2_imm_args(emit, MP_F_CALL_METHOD_N_KW, mp_call_method_n_kw, n_positional, REG_ARG_1, n_keyword, REG_ARG_2);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}

View File

@ -67,6 +67,39 @@ void mp_obj_print_exception(mp_obj_t exc) {
printf("\n");
}
int mp_obj_is_true(mp_obj_t arg) {
if (arg == mp_const_false) {
return 0;
} else if (arg == mp_const_true) {
return 1;
} else if (arg == mp_const_none) {
return 0;
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
if (MP_OBJ_SMALL_INT_VALUE(arg) == 0) {
return 0;
} else {
return 1;
}
} else {
mp_obj_type_t *type = mp_obj_get_type(arg);
if (type->unary_op != NULL) {
mp_obj_t result = type->unary_op(MP_UNARY_OP_BOOL, arg);
if (result != MP_OBJ_NULL) {
return result == mp_const_true;
}
}
mp_obj_t len = mp_obj_len_maybe(arg);
if (len != MP_OBJ_NULL) {
// obj has a length, truth determined if len != 0
return len != MP_OBJ_NEW_SMALL_INT(0);
} else {
// any other obj is true per Python semantics
return 1;
}
}
}
bool mp_obj_is_callable(mp_obj_t o_in) {
return mp_obj_get_type(o_in)->call != NULL;
}
@ -121,7 +154,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
// If o2 is long int, dispatch to its virtual methods
mp_obj_base_t *o = o2;
if (o->type->binary_op != NULL) {
mp_obj_t r = o->type->binary_op(RT_BINARY_OP_EQUAL, o2, o1);
mp_obj_t r = o->type->binary_op(MP_BINARY_OP_EQUAL, o2, o1);
return r == mp_const_true ? true : false;
}
}
@ -132,7 +165,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
} else {
mp_obj_base_t *o = o1;
if (o->type->binary_op != NULL) {
mp_obj_t r = o->type->binary_op(RT_BINARY_OP_EQUAL, o1, o2);
mp_obj_t r = o->type->binary_op(MP_BINARY_OP_EQUAL, o1, o2);
if (r != MP_OBJ_NULL) {
return r == mp_const_true ? true : false;
}
@ -271,7 +304,7 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
} else {
mp_obj_type_t *type = mp_obj_get_type(o_in);
if (type->unary_op != NULL) {
return type->unary_op(RT_UNARY_OP_LEN, o_in);
return type->unary_op(MP_UNARY_OP_LEN, o_in);
} else {
return MP_OBJ_NULL;
}

View File

@ -308,6 +308,7 @@ void mp_obj_print_helper(void (*print)(void *env, const char *fmt, ...), void *e
void mp_obj_print(mp_obj_t o, mp_print_kind_t kind);
void mp_obj_print_exception(mp_obj_t exc);
int mp_obj_is_true(mp_obj_t arg);
bool mp_obj_is_callable(mp_obj_t o_in);
machine_int_t mp_obj_hash(mp_obj_t o_in);
bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2);

View File

@ -61,10 +61,10 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
mp_obj_array_t *array = array_new(typecode, len);
mp_obj_t iterable = rt_getiter(initializer);
mp_obj_t iterable = mp_getiter(initializer);
mp_obj_t item;
int i = 0;
while ((item = rt_iternext(iterable)) != MP_OBJ_NULL) {
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
if (len == 0) {
array_append(array, item);
} else {
@ -99,8 +99,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_bytearray_obj, mp_builtin_bytearray);
STATIC mp_obj_t array_unary_op(int op, mp_obj_t o_in) {
mp_obj_array_t *o = o_in;
switch (op) {
case RT_UNARY_OP_BOOL: return MP_BOOL(o->len != 0);
case RT_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(o->len);
case MP_UNARY_OP_BOOL: return MP_BOOL(o->len != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(o->len);
default: return MP_OBJ_NULL; // op not supported
}
}
@ -108,7 +108,7 @@ STATIC mp_obj_t array_unary_op(int op, mp_obj_t o_in) {
STATIC mp_obj_t array_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
mp_obj_array_t *o = lhs;
switch (op) {
case RT_BINARY_OP_SUBSCR:
case MP_BINARY_OP_SUBSCR:
{
uint index = mp_get_index(o->base.type, o->len, rhs, false);
return mp_binary_get_val(o->typecode, o->items, index);

View File

@ -26,7 +26,7 @@ STATIC mp_obj_t bool_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
switch (n_args) {
case 0: return mp_const_false;
case 1: if (rt_is_true(args[0])) { return mp_const_true; } else { return mp_const_false; }
case 1: if (mp_obj_is_true(args[0])) { return mp_const_true; } else { return mp_const_false; }
default: nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "bool takes at most 1 argument, %d given", n_args));
}
}
@ -34,10 +34,10 @@ STATIC mp_obj_t bool_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
STATIC mp_obj_t bool_unary_op(int op, mp_obj_t o_in) {
machine_int_t value = ((mp_obj_bool_t*)o_in)->value;
switch (op) {
case RT_UNARY_OP_BOOL: return o_in;
case RT_UNARY_OP_POSITIVE: return MP_OBJ_NEW_SMALL_INT(value);
case RT_UNARY_OP_NEGATIVE: return MP_OBJ_NEW_SMALL_INT(-value);
case RT_UNARY_OP_INVERT:
case MP_UNARY_OP_BOOL: return o_in;
case MP_UNARY_OP_POSITIVE: return MP_OBJ_NEW_SMALL_INT(value);
case MP_UNARY_OP_NEGATIVE: return MP_OBJ_NEW_SMALL_INT(-value);
case MP_UNARY_OP_INVERT:
default: // no other cases
return MP_OBJ_NEW_SMALL_INT(~value);
}

View File

@ -24,13 +24,13 @@ mp_obj_t bound_meth_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_
mp_obj_t args2[5];
args2[0] = self->self;
memcpy(args2 + 1, args, n_total * sizeof(mp_obj_t));
return rt_call_function_n_kw(self->meth, n_args + 1, n_kw, &args2[0]);
return mp_call_function_n_kw(self->meth, n_args + 1, n_kw, &args2[0]);
} else {
// use heap to allocate temporary args array
mp_obj_t *args2 = m_new(mp_obj_t, 1 + n_total);
args2[0] = self->self;
memcpy(args2 + 1, args, n_total * sizeof(mp_obj_t));
mp_obj_t res = rt_call_function_n_kw(self->meth, n_args + 1, n_kw, &args2[0]);
mp_obj_t res = mp_call_function_n_kw(self->meth, n_args + 1, n_kw, &args2[0]);
m_del(mp_obj_t, args2, 1 + n_total);
return res;
}

View File

@ -25,13 +25,13 @@ mp_obj_t closure_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *
mp_obj_t args2[5];
memcpy(args2, self->closed, self->n_closed * sizeof(mp_obj_t));
memcpy(args2 + self->n_closed, args, (n_args + 2 * n_kw) * sizeof(mp_obj_t));
return rt_call_function_n_kw(self->fun, self->n_closed + n_args, n_kw, args2);
return mp_call_function_n_kw(self->fun, self->n_closed + n_args, n_kw, args2);
} else {
// use heap to allocate temporary args array
mp_obj_t *args2 = m_new(mp_obj_t, n_total);
memcpy(args2, self->closed, self->n_closed * sizeof(mp_obj_t));
memcpy(args2 + self->n_closed, args, (n_args + 2 * n_kw) * sizeof(mp_obj_t));
mp_obj_t res = rt_call_function_n_kw(self->fun, self->n_closed + n_args, n_kw, args2);
mp_obj_t res = mp_call_function_n_kw(self->fun, self->n_closed + n_args, n_kw, args2);
m_del(mp_obj_t, args2, n_total);
return res;
}

View File

@ -94,9 +94,9 @@ STATIC mp_obj_t complex_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
STATIC mp_obj_t complex_unary_op(int op, mp_obj_t o_in) {
mp_obj_complex_t *o = o_in;
switch (op) {
case RT_UNARY_OP_BOOL: return MP_BOOL(o->real != 0 || o->imag != 0);
case RT_UNARY_OP_POSITIVE: return o_in;
case RT_UNARY_OP_NEGATIVE: return mp_obj_new_complex(-o->real, -o->imag);
case MP_UNARY_OP_BOOL: return MP_BOOL(o->real != 0 || o->imag != 0);
case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_complex(-o->real, -o->imag);
default: return MP_OBJ_NULL; // op not supported
}
}
@ -134,18 +134,18 @@ mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_im
mp_float_t rhs_real, rhs_imag;
mp_obj_get_complex(rhs_in, &rhs_real, &rhs_imag); // can be any type, this function will convert to float (if possible)
switch (op) {
case RT_BINARY_OP_ADD:
case RT_BINARY_OP_INPLACE_ADD:
case MP_BINARY_OP_ADD:
case MP_BINARY_OP_INPLACE_ADD:
lhs_real += rhs_real;
lhs_imag += rhs_imag;
break;
case RT_BINARY_OP_SUBTRACT:
case RT_BINARY_OP_INPLACE_SUBTRACT:
case MP_BINARY_OP_SUBTRACT:
case MP_BINARY_OP_INPLACE_SUBTRACT:
lhs_real -= rhs_real;
lhs_imag -= rhs_imag;
break;
case RT_BINARY_OP_MULTIPLY:
case RT_BINARY_OP_INPLACE_MULTIPLY:
case MP_BINARY_OP_MULTIPLY:
case MP_BINARY_OP_INPLACE_MULTIPLY:
{
mp_float_t real = lhs_real * rhs_real - lhs_imag * rhs_imag;
lhs_imag = lhs_real * rhs_imag + lhs_imag * rhs_real;
@ -153,12 +153,12 @@ mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_im
break;
}
/* TODO floor(?) the value
case RT_BINARY_OP_FLOOR_DIVIDE:
case RT_BINARY_OP_INPLACE_FLOOR_DIVIDE: val = lhs_val / rhs_val; break;
case MP_BINARY_OP_FLOOR_DIVIDE:
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: val = lhs_val / rhs_val; break;
*/
/* TODO
case RT_BINARY_OP_TRUE_DIVIDE:
case RT_BINARY_OP_INPLACE_TRUE_DIVIDE: val = lhs_val / rhs_val; break;
case MP_BINARY_OP_TRUE_DIVIDE:
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE: val = lhs_val / rhs_val; break;
*/
return NULL; // op not supported
}

View File

@ -34,14 +34,14 @@ STATIC void dict_print(void (*print)(void *env, const char *fmt, ...), void *env
STATIC mp_obj_t dict_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
// TODO create from an iterable!
return rt_build_map(0);
return mp_build_map(0);
}
STATIC mp_obj_t dict_unary_op(int op, mp_obj_t self_in) {
mp_obj_dict_t *self = self_in;
switch (op) {
case RT_UNARY_OP_BOOL: return MP_BOOL(self->map.used != 0);
case RT_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((machine_int_t)self->map.used);
case MP_UNARY_OP_BOOL: return MP_BOOL(self->map.used != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((machine_int_t)self->map.used);
default: return MP_OBJ_NULL; // op not supported for None
}
}
@ -49,7 +49,7 @@ STATIC mp_obj_t dict_unary_op(int op, mp_obj_t self_in) {
STATIC mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_obj_dict_t *o = lhs_in;
switch (op) {
case RT_BINARY_OP_SUBSCR:
case MP_BINARY_OP_SUBSCR:
{
// dict load
mp_map_elem_t *elem = mp_map_lookup(&o->map, rhs_in, MP_MAP_LOOKUP);
@ -59,7 +59,7 @@ STATIC mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return elem->value;
}
}
case RT_BINARY_OP_IN:
case MP_BINARY_OP_IN:
{
mp_map_elem_t *elem = mp_map_lookup(&o->map, rhs_in, MP_MAP_LOOKUP);
return MP_BOOL(elem != NULL);
@ -149,7 +149,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_copy_obj, dict_copy);
// this is a classmethod
STATIC mp_obj_t dict_fromkeys(uint n_args, const mp_obj_t *args) {
assert(2 <= n_args && n_args <= 3);
mp_obj_t iter = rt_getiter(args[1]);
mp_obj_t iter = mp_getiter(args[1]);
mp_obj_t len = mp_obj_len_maybe(iter);
mp_obj_t value = mp_const_none;
mp_obj_t next = NULL;
@ -166,7 +166,7 @@ STATIC mp_obj_t dict_fromkeys(uint n_args, const mp_obj_t *args) {
self = mp_obj_new_dict(MP_OBJ_SMALL_INT_VALUE(len));
}
while ((next = rt_iternext(iter)) != MP_OBJ_NULL) {
while ((next = mp_iternext(iter)) != MP_OBJ_NULL) {
mp_map_lookup(&self->map, next, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value;
}
@ -259,13 +259,13 @@ STATIC mp_obj_t dict_update(mp_obj_t self_in, mp_obj_t iterable) {
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_dict));
mp_obj_dict_t *self = self_in;
/* TODO: check for the "keys" method */
mp_obj_t iter = rt_getiter(iterable);
mp_obj_t iter = mp_getiter(iterable);
mp_obj_t next = NULL;
while ((next = rt_iternext(iter)) != MP_OBJ_NULL) {
mp_obj_t inneriter = rt_getiter(next);
mp_obj_t key = rt_iternext(inneriter);
mp_obj_t value = rt_iternext(inneriter);
mp_obj_t stop = rt_iternext(inneriter);
while ((next = mp_iternext(iter)) != MP_OBJ_NULL) {
mp_obj_t inneriter = mp_getiter(next);
mp_obj_t key = mp_iternext(inneriter);
mp_obj_t value = mp_iternext(inneriter);
mp_obj_t stop = mp_iternext(inneriter);
if (key == MP_OBJ_NULL
|| value == MP_OBJ_NULL
|| stop != MP_OBJ_NULL) {
@ -372,7 +372,7 @@ STATIC mp_obj_t dict_view_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
/* only supported for the 'keys' kind until sets and dicts are refactored */
mp_obj_dict_view_t *o = lhs_in;
if (o->kind != MP_DICT_VIEW_KEYS) return NULL;
if (op != RT_BINARY_OP_IN) return NULL;
if (op != MP_BINARY_OP_IN) return NULL;
return dict_binary_op(op, o->dict, rhs_in);
}

View File

@ -21,7 +21,7 @@ STATIC mp_obj_t enumerate_make_new(mp_obj_t type_in, uint n_args, uint n_kw, con
assert(n_args > 0);
mp_obj_enumerate_t *o = m_new_obj(mp_obj_enumerate_t);
o->base.type = &mp_type_enumerate;
o->iter = rt_getiter(args[0]);
o->iter = mp_getiter(args[0]);
o->cur = n_args > 1 ? mp_obj_get_int(args[1]) : 0;
return o;
}
@ -37,7 +37,7 @@ const mp_obj_type_t mp_type_enumerate = {
STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in) {
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_enumerate));
mp_obj_enumerate_t *self = self_in;
mp_obj_t next = rt_iternext(self->iter);
mp_obj_t next = mp_iternext(self->iter);
if (next == MP_OBJ_NULL) {
return MP_OBJ_NULL;
} else {

View File

@ -244,7 +244,7 @@ bool mp_obj_is_exception_instance(mp_obj_t self_in) {
// exception type.
bool mp_obj_exception_match(mp_obj_t exc, const mp_obj_type_t *exc_type) {
// TODO: move implementation from RT_BINARY_OP_EXCEPTION_MATCH here.
return rt_binary_op(RT_BINARY_OP_EXCEPTION_MATCH, exc, (mp_obj_t)exc_type) == mp_const_true;
return mp_binary_op(MP_BINARY_OP_EXCEPTION_MATCH, exc, (mp_obj_t)exc_type) == mp_const_true;
}
void mp_obj_exception_clear_traceback(mp_obj_t self_in) {

View File

@ -22,7 +22,7 @@ STATIC mp_obj_t filter_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
mp_obj_filter_t *o = m_new_obj(mp_obj_filter_t);
o->base.type = &mp_type_filter;
o->fun = args[0];
o->iter = rt_getiter(args[1]);
o->iter = mp_getiter(args[1]);
return o;
}
@ -30,14 +30,14 @@ STATIC mp_obj_t filter_iternext(mp_obj_t self_in) {
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_filter));
mp_obj_filter_t *self = self_in;
mp_obj_t next;
while ((next = rt_iternext(self->iter)) != MP_OBJ_NULL) {
while ((next = mp_iternext(self->iter)) != MP_OBJ_NULL) {
mp_obj_t val;
if (self->fun != mp_const_none) {
val = rt_call_function_n_kw(self->fun, 1, 0, &next);
val = mp_call_function_n_kw(self->fun, 1, 0, &next);
} else {
val = next;
}
if (rt_is_true(val)) {
if (mp_obj_is_true(val)) {
return next;
}
}

View File

@ -56,9 +56,9 @@ STATIC mp_obj_t float_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
STATIC mp_obj_t float_unary_op(int op, mp_obj_t o_in) {
mp_obj_float_t *o = o_in;
switch (op) {
case RT_UNARY_OP_BOOL: return MP_BOOL(o->value != 0);
case RT_UNARY_OP_POSITIVE: return o_in;
case RT_UNARY_OP_NEGATIVE: return mp_obj_new_float(-o->value);
case MP_UNARY_OP_BOOL: return MP_BOOL(o->value != 0);
case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_float(-o->value);
default: return NULL; // op not supported
}
}
@ -97,27 +97,27 @@ mp_float_t mp_obj_float_get(mp_obj_t self_in) {
mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs_in) {
mp_float_t rhs_val = mp_obj_get_float(rhs_in); // can be any type, this function will convert to float (if possible)
switch (op) {
case RT_BINARY_OP_ADD:
case RT_BINARY_OP_INPLACE_ADD: lhs_val += rhs_val; break;
case RT_BINARY_OP_SUBTRACT:
case RT_BINARY_OP_INPLACE_SUBTRACT: lhs_val -= rhs_val; break;
case RT_BINARY_OP_MULTIPLY:
case RT_BINARY_OP_INPLACE_MULTIPLY: lhs_val *= rhs_val; break;
case MP_BINARY_OP_ADD:
case MP_BINARY_OP_INPLACE_ADD: lhs_val += rhs_val; break;
case MP_BINARY_OP_SUBTRACT:
case MP_BINARY_OP_INPLACE_SUBTRACT: lhs_val -= rhs_val; break;
case MP_BINARY_OP_MULTIPLY:
case MP_BINARY_OP_INPLACE_MULTIPLY: lhs_val *= rhs_val; break;
/* TODO floor(?) the value
case RT_BINARY_OP_FLOOR_DIVIDE:
case RT_BINARY_OP_INPLACE_FLOOR_DIVIDE: val = lhs_val / rhs_val; break;
case MP_BINARY_OP_FLOOR_DIVIDE:
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: val = lhs_val / rhs_val; break;
*/
case RT_BINARY_OP_TRUE_DIVIDE:
case RT_BINARY_OP_INPLACE_TRUE_DIVIDE:
case MP_BINARY_OP_TRUE_DIVIDE:
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE:
lhs_val /= rhs_val;
if (isinf(lhs_val)){ // check for division by zero
nlr_jump(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "float division by zero"));
}
break;
case RT_BINARY_OP_LESS: return MP_BOOL(lhs_val < rhs_val);
case RT_BINARY_OP_MORE: return MP_BOOL(lhs_val > rhs_val);
case RT_BINARY_OP_LESS_EQUAL: return MP_BOOL(lhs_val <= rhs_val);
case RT_BINARY_OP_MORE_EQUAL: return MP_BOOL(lhs_val >= rhs_val);
case MP_BINARY_OP_LESS: return MP_BOOL(lhs_val < rhs_val);
case MP_BINARY_OP_MORE: return MP_BOOL(lhs_val > rhs_val);
case MP_BINARY_OP_LESS_EQUAL: return MP_BOOL(lhs_val <= rhs_val);
case MP_BINARY_OP_MORE_EQUAL: return MP_BOOL(lhs_val >= rhs_val);
return NULL; // op not supported
}

View File

@ -26,10 +26,10 @@
// mp_obj_fun_native_t defined in obj.h
STATIC void check_nargs(mp_obj_fun_native_t *self, int n_args, int n_kw) {
rt_check_nargs(n_args, self->n_args_min, self->n_args_max, n_kw, self->is_kw);
mp_check_nargs(n_args, self->n_args_min, self->n_args_max, n_kw, self->is_kw);
}
void rt_check_nargs(int n_args, machine_uint_t n_args_min, machine_uint_t n_args_max, int n_kw, bool is_kw) {
void mp_check_nargs(int n_args, machine_uint_t n_args_min, machine_uint_t n_args_max, int n_kw, bool is_kw) {
if (n_kw && !is_kw) {
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError,
"function does not take keyword arguments"));
@ -106,7 +106,7 @@ const mp_obj_type_t mp_type_fun_native = {
};
// fun must have the correct signature for n_args fixed arguments
mp_obj_t rt_make_function_n(int n_args, void *fun) {
mp_obj_t mp_make_function_n(int n_args, void *fun) {
mp_obj_fun_native_t *o = m_new_obj(mp_obj_fun_native_t);
o->base.type = &mp_type_fun_native;
o->is_kw = false;
@ -116,7 +116,7 @@ mp_obj_t rt_make_function_n(int n_args, void *fun) {
return o;
}
mp_obj_t rt_make_function_var(int n_args_min, mp_fun_var_t fun) {
mp_obj_t mp_make_function_var(int n_args_min, mp_fun_var_t fun) {
mp_obj_fun_native_t *o = m_new_obj(mp_obj_fun_native_t);
o->base.type = &mp_type_fun_native;
o->is_kw = false;
@ -127,7 +127,7 @@ mp_obj_t rt_make_function_var(int n_args_min, mp_fun_var_t fun) {
}
// min and max are inclusive
mp_obj_t rt_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var_t fun) {
mp_obj_t mp_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var_t fun) {
mp_obj_fun_native_t *o = m_new_obj(mp_obj_fun_native_t);
o->base.type = &mp_type_fun_native;
o->is_kw = false;
@ -278,14 +278,14 @@ continue2:;
}
}
mp_map_t *old_globals = rt_globals_get();
rt_globals_set(self->globals);
mp_map_t *old_globals = mp_globals_get();
mp_globals_set(self->globals);
mp_obj_t result;
DEBUG_printf("Calling: args=%p, n_args=%d, extra_args=%p, n_extra_args=%d\n", args, n_args, extra_args, n_extra_args);
dump_args(args, n_args);
dump_args(extra_args, n_extra_args);
mp_vm_return_kind_t vm_return_kind = mp_execute_byte_code(self->bytecode, args, n_args, extra_args, n_extra_args, &result);
rt_globals_set(old_globals);
mp_globals_set(old_globals);
if (vm_return_kind == MP_VM_RETURN_NORMAL) {
return result;
@ -319,7 +319,7 @@ mp_obj_t mp_obj_new_fun_bc(uint scope_flags, qstr *args, uint n_args, mp_obj_t d
}
mp_obj_fun_bc_t *o = m_new_obj_var(mp_obj_fun_bc_t, mp_obj_t, n_extra_args);
o->base.type = &mp_type_fun_bc;
o->globals = rt_globals_get();
o->globals = mp_globals_get();
o->args = args;
o->n_args = n_args;
o->n_def_args = n_def_args;

View File

@ -162,7 +162,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(gen_instance_send_obj, gen_instance_send);
STATIC mp_obj_t gen_instance_close(mp_obj_t self_in);
STATIC mp_obj_t gen_instance_throw(uint n_args, const mp_obj_t *args) {
mp_obj_t exc = (n_args == 2) ? args[1] : args[2];
exc = rt_make_raise_obj(exc);
exc = mp_make_raise_obj(exc);
if (mp_obj_is_subclass_fast(mp_obj_get_type(exc), &mp_type_GeneratorExit)) {
// Throwing GeneratorExit is equivalent of calling close aka
// GeneratorExit should be handled specially

View File

@ -19,7 +19,7 @@ STATIC mp_obj_t it_iternext(mp_obj_t self_in) {
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
// try to get next item
mp_obj_t value = rt_call_method_n_kw(1, 0, self->args);
mp_obj_t value = mp_call_method_n_kw(1, 0, self->args);
self->args[2] = MP_OBJ_NEW_SMALL_INT(MP_OBJ_SMALL_INT_VALUE(self->args[2]) + 1);
nlr_pop();
return value;
@ -41,7 +41,7 @@ STATIC const mp_obj_type_t it_type = {
.iternext = it_iternext
};
// args are those returned from rt_load_method_maybe (ie either an attribute or a method)
// args are those returned from mp_load_method_maybe (ie either an attribute or a method)
mp_obj_t mp_obj_new_getitem_iter(mp_obj_t *args) {
mp_obj_getitem_iter_t *o = m_new_obj(mp_obj_getitem_iter_t);
o->base.type = &it_type;

View File

@ -32,10 +32,10 @@ void int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj
mp_obj_t int_unary_op(int op, mp_obj_t o_in) {
mp_obj_int_t *o = o_in;
switch (op) {
case RT_UNARY_OP_BOOL: return MP_BOOL(o->val != 0);
case RT_UNARY_OP_POSITIVE: return o_in;
case RT_UNARY_OP_NEGATIVE: return mp_obj_new_int_from_ll(-o->val);
case RT_UNARY_OP_INVERT: return mp_obj_new_int_from_ll(~o->val);
case MP_UNARY_OP_BOOL: return MP_BOOL(o->val != 0);
case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_int_from_ll(-o->val);
case MP_UNARY_OP_INVERT: return mp_obj_new_int_from_ll(~o->val);
default: return NULL; // op not supported
}
}
@ -61,50 +61,50 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
}
switch (op) {
case RT_BINARY_OP_ADD:
case RT_BINARY_OP_INPLACE_ADD:
case MP_BINARY_OP_ADD:
case MP_BINARY_OP_INPLACE_ADD:
return mp_obj_new_int_from_ll(lhs_val + rhs_val);
case RT_BINARY_OP_SUBTRACT:
case RT_BINARY_OP_INPLACE_SUBTRACT:
case MP_BINARY_OP_SUBTRACT:
case MP_BINARY_OP_INPLACE_SUBTRACT:
return mp_obj_new_int_from_ll(lhs_val - rhs_val);
case RT_BINARY_OP_MULTIPLY:
case RT_BINARY_OP_INPLACE_MULTIPLY:
case MP_BINARY_OP_MULTIPLY:
case MP_BINARY_OP_INPLACE_MULTIPLY:
return mp_obj_new_int_from_ll(lhs_val * rhs_val);
case RT_BINARY_OP_FLOOR_DIVIDE:
case RT_BINARY_OP_INPLACE_FLOOR_DIVIDE:
case MP_BINARY_OP_FLOOR_DIVIDE:
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
return mp_obj_new_int_from_ll(lhs_val / rhs_val);
case RT_BINARY_OP_MODULO:
case RT_BINARY_OP_INPLACE_MODULO:
case MP_BINARY_OP_MODULO:
case MP_BINARY_OP_INPLACE_MODULO:
return mp_obj_new_int_from_ll(lhs_val % rhs_val);
case RT_BINARY_OP_AND:
case RT_BINARY_OP_INPLACE_AND:
case MP_BINARY_OP_AND:
case MP_BINARY_OP_INPLACE_AND:
return mp_obj_new_int_from_ll(lhs_val & rhs_val);
case RT_BINARY_OP_OR:
case RT_BINARY_OP_INPLACE_OR:
case MP_BINARY_OP_OR:
case MP_BINARY_OP_INPLACE_OR:
return mp_obj_new_int_from_ll(lhs_val | rhs_val);
case RT_BINARY_OP_XOR:
case RT_BINARY_OP_INPLACE_XOR:
case MP_BINARY_OP_XOR:
case MP_BINARY_OP_INPLACE_XOR:
return mp_obj_new_int_from_ll(lhs_val ^ rhs_val);
case RT_BINARY_OP_LSHIFT:
case RT_BINARY_OP_INPLACE_LSHIFT:
case MP_BINARY_OP_LSHIFT:
case MP_BINARY_OP_INPLACE_LSHIFT:
return mp_obj_new_int_from_ll(lhs_val << (int)rhs_val);
case RT_BINARY_OP_RSHIFT:
case RT_BINARY_OP_INPLACE_RSHIFT:
case MP_BINARY_OP_RSHIFT:
case MP_BINARY_OP_INPLACE_RSHIFT:
return mp_obj_new_int_from_ll(lhs_val >> (int)rhs_val);
case RT_BINARY_OP_LESS:
case MP_BINARY_OP_LESS:
return MP_BOOL(lhs_val < rhs_val);
case RT_BINARY_OP_MORE:
case MP_BINARY_OP_MORE:
return MP_BOOL(lhs_val > rhs_val);
case RT_BINARY_OP_LESS_EQUAL:
case MP_BINARY_OP_LESS_EQUAL:
return MP_BOOL(lhs_val <= rhs_val);
case RT_BINARY_OP_MORE_EQUAL:
case MP_BINARY_OP_MORE_EQUAL:
return MP_BOOL(lhs_val >= rhs_val);
case RT_BINARY_OP_EQUAL:
case MP_BINARY_OP_EQUAL:
return MP_BOOL(lhs_val == rhs_val);
case RT_BINARY_OP_NOT_EQUAL:
case MP_BINARY_OP_NOT_EQUAL:
return MP_BOOL(lhs_val != rhs_val);
default:

View File

@ -36,10 +36,10 @@ void int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj
mp_obj_t int_unary_op(int op, mp_obj_t o_in) {
mp_obj_int_t *o = o_in;
switch (op) {
case RT_UNARY_OP_BOOL: return MP_BOOL(!mpz_is_zero(&o->mpz));
case RT_UNARY_OP_POSITIVE: return o_in;
case RT_UNARY_OP_NEGATIVE: { mp_obj_int_t *o2 = mp_obj_int_new_mpz(); mpz_neg_inpl(&o2->mpz, &o->mpz); return o2; }
case RT_UNARY_OP_INVERT: { mp_obj_int_t *o2 = mp_obj_int_new_mpz(); mpz_not_inpl(&o2->mpz, &o->mpz); return o2; }
case MP_UNARY_OP_BOOL: return MP_BOOL(!mpz_is_zero(&o->mpz));
case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: { mp_obj_int_t *o2 = mp_obj_int_new_mpz(); mpz_neg_inpl(&o2->mpz, &o->mpz); return o2; }
case MP_UNARY_OP_INVERT: { mp_obj_int_t *o2 = mp_obj_int_new_mpz(); mpz_not_inpl(&o2->mpz, &o->mpz); return o2; }
default: return NULL; // op not supported
}
}
@ -61,7 +61,7 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return MP_OBJ_NULL;
}
// if rhs is small int, then lhs was not (otherwise rt_binary_op handles it)
// if rhs is small int, then lhs was not (otherwise mp_binary_op handles it)
if (MP_OBJ_IS_SMALL_INT(rhs_in)) {
mpz_init_fixed_from_int(&z_int, z_int_dig, MPZ_NUM_DIG_FOR_INT, MP_OBJ_SMALL_INT_VALUE(rhs_in));
zrhs = &z_int;
@ -80,30 +80,30 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
if (0) {
#if MICROPY_ENABLE_FLOAT
} else if (op == RT_BINARY_OP_TRUE_DIVIDE || op == RT_BINARY_OP_INPLACE_TRUE_DIVIDE) {
} else if (op == MP_BINARY_OP_TRUE_DIVIDE || op == MP_BINARY_OP_INPLACE_TRUE_DIVIDE) {
mp_float_t flhs = mpz_as_float(zlhs);
mp_float_t frhs = mpz_as_float(zrhs);
return mp_obj_new_float(flhs / frhs);
#endif
} else if (op <= RT_BINARY_OP_INPLACE_POWER) {
} else if (op <= MP_BINARY_OP_INPLACE_POWER) {
mp_obj_int_t *res = mp_obj_int_new_mpz();
switch (op) {
case RT_BINARY_OP_ADD:
case RT_BINARY_OP_INPLACE_ADD:
case MP_BINARY_OP_ADD:
case MP_BINARY_OP_INPLACE_ADD:
mpz_add_inpl(&res->mpz, zlhs, zrhs);
break;
case RT_BINARY_OP_SUBTRACT:
case RT_BINARY_OP_INPLACE_SUBTRACT:
case MP_BINARY_OP_SUBTRACT:
case MP_BINARY_OP_INPLACE_SUBTRACT:
mpz_sub_inpl(&res->mpz, zlhs, zrhs);
break;
case RT_BINARY_OP_MULTIPLY:
case RT_BINARY_OP_INPLACE_MULTIPLY:
case MP_BINARY_OP_MULTIPLY:
case MP_BINARY_OP_INPLACE_MULTIPLY:
mpz_mul_inpl(&res->mpz, zlhs, zrhs);
break;
case RT_BINARY_OP_FLOOR_DIVIDE:
case RT_BINARY_OP_INPLACE_FLOOR_DIVIDE: {
case MP_BINARY_OP_FLOOR_DIVIDE:
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: {
mpz_t rem; mpz_init_zero(&rem);
mpz_divmod_inpl(&res->mpz, &rem, zlhs, zrhs);
if (zlhs->neg != zrhs->neg) {
@ -115,8 +115,8 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mpz_deinit(&rem);
break;
}
case RT_BINARY_OP_MODULO:
case RT_BINARY_OP_INPLACE_MODULO: {
case MP_BINARY_OP_MODULO:
case MP_BINARY_OP_INPLACE_MODULO: {
mpz_t quo; mpz_init_zero(&quo);
mpz_divmod_inpl(&quo, &res->mpz, zlhs, zrhs);
mpz_deinit(&quo);
@ -127,29 +127,29 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
break;
}
case RT_BINARY_OP_AND:
case RT_BINARY_OP_INPLACE_AND:
case MP_BINARY_OP_AND:
case MP_BINARY_OP_INPLACE_AND:
mpz_and_inpl(&res->mpz, zlhs, zrhs);
break;
case RT_BINARY_OP_OR:
case RT_BINARY_OP_INPLACE_OR:
case MP_BINARY_OP_OR:
case MP_BINARY_OP_INPLACE_OR:
mpz_or_inpl(&res->mpz, zlhs, zrhs);
break;
case RT_BINARY_OP_XOR:
case RT_BINARY_OP_INPLACE_XOR:
case MP_BINARY_OP_XOR:
case MP_BINARY_OP_INPLACE_XOR:
mpz_xor_inpl(&res->mpz, zlhs, zrhs);
break;
case RT_BINARY_OP_LSHIFT:
case RT_BINARY_OP_INPLACE_LSHIFT:
case RT_BINARY_OP_RSHIFT:
case RT_BINARY_OP_INPLACE_RSHIFT: {
case MP_BINARY_OP_LSHIFT:
case MP_BINARY_OP_INPLACE_LSHIFT:
case MP_BINARY_OP_RSHIFT:
case MP_BINARY_OP_INPLACE_RSHIFT: {
// TODO check conversion overflow
machine_int_t irhs = mpz_as_int(zrhs);
if (irhs < 0) {
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count"));
}
if (op == RT_BINARY_OP_LSHIFT || op == RT_BINARY_OP_INPLACE_LSHIFT) {
if (op == MP_BINARY_OP_LSHIFT || op == MP_BINARY_OP_INPLACE_LSHIFT) {
mpz_shl_inpl(&res->mpz, zlhs, irhs);
} else {
mpz_shr_inpl(&res->mpz, zlhs, irhs);
@ -157,8 +157,8 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
break;
}
case RT_BINARY_OP_POWER:
case RT_BINARY_OP_INPLACE_POWER:
case MP_BINARY_OP_POWER:
case MP_BINARY_OP_INPLACE_POWER:
mpz_pow_inpl(&res->mpz, zlhs, zrhs);
break;
@ -171,17 +171,17 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
} else {
int cmp = mpz_cmp(zlhs, zrhs);
switch (op) {
case RT_BINARY_OP_LESS:
case MP_BINARY_OP_LESS:
return MP_BOOL(cmp < 0);
case RT_BINARY_OP_MORE:
case MP_BINARY_OP_MORE:
return MP_BOOL(cmp > 0);
case RT_BINARY_OP_LESS_EQUAL:
case MP_BINARY_OP_LESS_EQUAL:
return MP_BOOL(cmp <= 0);
case RT_BINARY_OP_MORE_EQUAL:
case MP_BINARY_OP_MORE_EQUAL:
return MP_BOOL(cmp >= 0);
case RT_BINARY_OP_EQUAL:
case MP_BINARY_OP_EQUAL:
return MP_BOOL(cmp == 0);
case RT_BINARY_OP_NOT_EQUAL:
case MP_BINARY_OP_NOT_EQUAL:
return MP_BOOL(cmp != 0);
default:

View File

@ -50,10 +50,10 @@ STATIC mp_obj_t list_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
case 1:
{
// make list from iterable
mp_obj_t iterable = rt_getiter(args[0]);
mp_obj_t iterable = mp_getiter(args[0]);
mp_obj_t list = mp_obj_new_list(0, NULL);
mp_obj_t item;
while ((item = rt_iternext(iterable)) != MP_OBJ_NULL) {
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
mp_obj_list_append(list, item);
}
return list;
@ -65,7 +65,7 @@ STATIC mp_obj_t list_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
return NULL;
}
// Don't pass RT_BINARY_OP_NOT_EQUAL here
// Don't pass MP_BINARY_OP_NOT_EQUAL here
STATIC bool list_cmp_helper(int op, mp_obj_t self_in, mp_obj_t another_in) {
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_list));
if (!MP_OBJ_IS_TYPE(another_in, &mp_type_list)) {
@ -80,8 +80,8 @@ STATIC bool list_cmp_helper(int op, mp_obj_t self_in, mp_obj_t another_in) {
STATIC mp_obj_t list_unary_op(int op, mp_obj_t self_in) {
mp_obj_list_t *self = self_in;
switch (op) {
case RT_UNARY_OP_BOOL: return MP_BOOL(self->len != 0);
case RT_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len);
case MP_UNARY_OP_BOOL: return MP_BOOL(self->len != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len);
default: return MP_OBJ_NULL; // op not supported for None
}
}
@ -89,7 +89,7 @@ STATIC mp_obj_t list_unary_op(int op, mp_obj_t self_in) {
STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
mp_obj_list_t *o = lhs;
switch (op) {
case RT_BINARY_OP_SUBSCR:
case MP_BINARY_OP_SUBSCR:
{
#if MICROPY_ENABLE_SLICE
if (MP_OBJ_IS_TYPE(rhs, &mp_type_slice)) {
@ -105,7 +105,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
uint index = mp_get_index(o->base.type, o->len, rhs, false);
return o->items[index];
}
case RT_BINARY_OP_ADD:
case MP_BINARY_OP_ADD:
{
if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) {
return NULL;
@ -115,7 +115,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
m_seq_cat(s->items, o->items, o->len, p->items, p->len, mp_obj_t);
return s;
}
case RT_BINARY_OP_INPLACE_ADD:
case MP_BINARY_OP_INPLACE_ADD:
{
if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) {
return NULL;
@ -123,7 +123,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
list_extend(lhs, rhs);
return o;
}
case RT_BINARY_OP_MULTIPLY:
case MP_BINARY_OP_MULTIPLY:
{
if (!MP_OBJ_IS_SMALL_INT(rhs)) {
return NULL;
@ -133,14 +133,14 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
mp_seq_multiply(o->items, sizeof(*o->items), o->len, n, s->items);
return s;
}
case RT_BINARY_OP_EQUAL:
case RT_BINARY_OP_LESS:
case RT_BINARY_OP_LESS_EQUAL:
case RT_BINARY_OP_MORE:
case RT_BINARY_OP_MORE_EQUAL:
case MP_BINARY_OP_EQUAL:
case MP_BINARY_OP_LESS:
case MP_BINARY_OP_LESS_EQUAL:
case MP_BINARY_OP_MORE:
case MP_BINARY_OP_MORE_EQUAL:
return MP_BOOL(list_cmp_helper(op, lhs, rhs));
case RT_BINARY_OP_NOT_EQUAL:
return MP_BOOL(!list_cmp_helper(RT_BINARY_OP_EQUAL, lhs, rhs));
case MP_BINARY_OP_NOT_EQUAL:
return MP_BOOL(!list_cmp_helper(MP_BINARY_OP_EQUAL, lhs, rhs));
default:
// op not supported
@ -201,14 +201,14 @@ STATIC mp_obj_t list_pop(uint n_args, const mp_obj_t *args) {
// TODO make this conform to CPython's definition of sort
STATIC void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, bool reversed) {
int op = reversed ? RT_BINARY_OP_MORE : RT_BINARY_OP_LESS;
int op = reversed ? MP_BINARY_OP_MORE : MP_BINARY_OP_LESS;
while (head < tail) {
mp_obj_t *h = head - 1;
mp_obj_t *t = tail;
mp_obj_t v = key_fn == NULL ? tail[0] : rt_call_function_1(key_fn, tail[0]); // get pivot using key_fn
mp_obj_t v = key_fn == NULL ? tail[0] : mp_call_function_1(key_fn, tail[0]); // get pivot using key_fn
for (;;) {
do ++h; while (rt_binary_op(op, key_fn == NULL ? h[0] : rt_call_function_1(key_fn, h[0]), v) == mp_const_true);
do --t; while (h < t && rt_binary_op(op, v, key_fn == NULL ? t[0] : rt_call_function_1(key_fn, t[0])) == mp_const_true);
do ++h; while (mp_binary_op(op, key_fn == NULL ? h[0] : mp_call_function_1(key_fn, h[0]), v) == mp_const_true);
do --t; while (h < t && mp_binary_op(op, v, key_fn == NULL ? t[0] : mp_call_function_1(key_fn, t[0])) == mp_const_true);
if (h >= t) break;
mp_obj_t x = h[0];
h[0] = t[0];
@ -235,7 +235,7 @@ mp_obj_t mp_obj_list_sort(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
mp_map_elem_t *reverse = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(MP_QSTR_reverse), MP_MAP_LOOKUP);
mp_quicksort(self->items, self->items + self->len - 1,
keyfun ? keyfun->value : NULL,
reverse && reverse->value ? rt_is_true(reverse->value) : false);
reverse && reverse->value ? mp_obj_is_true(reverse->value) : false);
}
return mp_const_none; // return None, as per CPython
}

View File

@ -25,7 +25,7 @@ STATIC mp_obj_t map_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
o->n_iters = n_args - 1;
o->fun = args[0];
for (int i = 0; i < n_args - 1; i++) {
o->iters[i] = rt_getiter(args[i + 1]);
o->iters[i] = mp_getiter(args[i + 1]);
}
return o;
}
@ -40,14 +40,14 @@ STATIC mp_obj_t map_iternext(mp_obj_t self_in) {
mp_obj_t *nextses = m_new(mp_obj_t, self->n_iters);
for (int i = 0; i < self->n_iters; i++) {
mp_obj_t next = rt_iternext(self->iters[i]);
mp_obj_t next = mp_iternext(self->iters[i]);
if (next == MP_OBJ_NULL) {
m_del(mp_obj_t, nextses, self->n_iters);
return MP_OBJ_NULL;
}
nextses[i] = next;
}
return rt_call_function_n_kw(self->fun, self->n_iters, 0, nextses);
return mp_call_function_n_kw(self->fun, self->n_iters, 0, nextses);
}
const mp_obj_type_t mp_type_map = {

View File

@ -17,7 +17,7 @@ STATIC void none_print(void (*print)(void *env, const char *fmt, ...), void *env
STATIC mp_obj_t none_unary_op(int op, mp_obj_t o_in) {
switch (op) {
case RT_UNARY_OP_BOOL: return mp_const_false;
case MP_UNARY_OP_BOOL: return mp_const_false;
default: return MP_OBJ_NULL; // op not supported for None
}
}

View File

@ -57,9 +57,9 @@ STATIC mp_obj_t set_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
{
// 1 argument, an iterable from which we make a new set
mp_obj_t set = mp_obj_new_set(0, NULL);
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) {
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
mp_obj_set_store(set, item);
}
return set;
@ -160,9 +160,9 @@ STATIC mp_obj_t set_diff_int(int n_args, const mp_obj_t *args, bool update) {
if (self == other) {
set_clear(self);
} else {
mp_obj_t iter = rt_getiter(other);
mp_obj_t iter = mp_getiter(other);
mp_obj_t next;
while ((next = rt_iternext(iter)) != MP_OBJ_NULL) {
while ((next = mp_iternext(iter)) != MP_OBJ_NULL) {
set_discard(self, next);
}
}
@ -191,9 +191,9 @@ STATIC mp_obj_t set_intersect_int(mp_obj_t self_in, mp_obj_t other, bool update)
mp_obj_set_t *self = self_in;
mp_obj_set_t *out = mp_obj_new_set(0, NULL);
mp_obj_t iter = rt_getiter(other);
mp_obj_t iter = mp_getiter(other);
mp_obj_t next;
while ((next = rt_iternext(iter)) != MP_OBJ_NULL) {
while ((next = mp_iternext(iter)) != MP_OBJ_NULL) {
if (mp_set_lookup(&self->set, next, MP_MAP_LOOKUP)) {
set_add(out, next);
}
@ -223,9 +223,9 @@ STATIC mp_obj_t set_isdisjoint(mp_obj_t self_in, mp_obj_t other) {
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set));
mp_obj_set_t *self = self_in;
mp_obj_t iter = rt_getiter(other);
mp_obj_t iter = mp_getiter(other);
mp_obj_t next;
while ((next = rt_iternext(iter)) != MP_OBJ_NULL) {
while ((next = mp_iternext(iter)) != MP_OBJ_NULL) {
if (mp_set_lookup(&self->set, next, MP_MAP_LOOKUP)) {
return mp_const_false;
}
@ -330,9 +330,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_remove_obj, set_remove);
STATIC mp_obj_t set_symmetric_difference_update(mp_obj_t self_in, mp_obj_t other_in) {
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_set));
mp_obj_set_t *self = self_in;
mp_obj_t iter = rt_getiter(other_in);
mp_obj_t iter = mp_getiter(other_in);
mp_obj_t next;
while ((next = rt_iternext(iter)) != MP_OBJ_NULL) {
while ((next = mp_iternext(iter)) != MP_OBJ_NULL) {
mp_set_lookup(&self->set, next, MP_MAP_LOOKUP_REMOVE_IF_FOUND | MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
}
return mp_const_none;
@ -348,9 +348,9 @@ STATIC mp_obj_t set_symmetric_difference(mp_obj_t self_in, mp_obj_t other_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_symmetric_difference_obj, set_symmetric_difference);
STATIC void set_update_int(mp_obj_set_t *self, mp_obj_t other_in) {
mp_obj_t iter = rt_getiter(other_in);
mp_obj_t iter = mp_getiter(other_in);
mp_obj_t next;
while ((next = rt_iternext(iter)) != MP_OBJ_NULL) {
while ((next = mp_iternext(iter)) != MP_OBJ_NULL) {
mp_set_lookup(&self->set, next, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
}
}
@ -379,35 +379,35 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_union_obj, set_union);
STATIC mp_obj_t set_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
mp_obj_t args[] = {lhs, rhs};
switch (op) {
case RT_BINARY_OP_OR:
case MP_BINARY_OP_OR:
return set_union(lhs, rhs);
case RT_BINARY_OP_XOR:
case MP_BINARY_OP_XOR:
return set_symmetric_difference(lhs, rhs);
case RT_BINARY_OP_AND:
case MP_BINARY_OP_AND:
return set_intersect(lhs, rhs);
case RT_BINARY_OP_SUBTRACT:
case MP_BINARY_OP_SUBTRACT:
return set_diff(2, args);
case RT_BINARY_OP_INPLACE_OR:
case MP_BINARY_OP_INPLACE_OR:
return set_union(lhs, rhs);
case RT_BINARY_OP_INPLACE_XOR:
case MP_BINARY_OP_INPLACE_XOR:
return set_symmetric_difference(lhs, rhs);
case RT_BINARY_OP_INPLACE_AND:
case MP_BINARY_OP_INPLACE_AND:
return set_intersect(lhs, rhs);
case RT_BINARY_OP_INPLACE_SUBTRACT:
case MP_BINARY_OP_INPLACE_SUBTRACT:
return set_diff(2, args);
case RT_BINARY_OP_LESS:
case MP_BINARY_OP_LESS:
return set_issubset_proper(lhs, rhs);
case RT_BINARY_OP_MORE:
case MP_BINARY_OP_MORE:
return set_issuperset_proper(lhs, rhs);
case RT_BINARY_OP_EQUAL:
case MP_BINARY_OP_EQUAL:
return set_equal(lhs, rhs);
case RT_BINARY_OP_LESS_EQUAL:
case MP_BINARY_OP_LESS_EQUAL:
return set_issubset(lhs, rhs);
case RT_BINARY_OP_MORE_EQUAL:
case MP_BINARY_OP_MORE_EQUAL:
return set_issuperset(lhs, rhs);
case RT_BINARY_OP_NOT_EQUAL:
case MP_BINARY_OP_NOT_EQUAL:
return MP_BOOL(set_equal(lhs, rhs) == mp_const_false);
case RT_BINARY_OP_IN:
case MP_BINARY_OP_IN:
{
mp_obj_set_t *o = lhs;
mp_obj_t elem = mp_set_lookup(&o->set, rhs, MP_MAP_LOOKUP);

View File

@ -160,9 +160,9 @@ STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
o = mp_obj_str_builder_start(&mp_type_bytes, len, &data);
}
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) {
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
if (len == -1) {
vstr_add_char(vstr, MP_OBJ_SMALL_INT_VALUE(item));
} else {
@ -215,7 +215,7 @@ STATIC const byte *find_subbytes(const byte *haystack, machine_uint_t hlen, cons
STATIC mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
GET_STR_DATA_LEN(lhs_in, lhs_data, lhs_len);
switch (op) {
case RT_BINARY_OP_SUBSCR:
case MP_BINARY_OP_SUBSCR:
// TODO: need predicate to check for int-like type (bools are such for example)
// ["no", "yes"][1 == 2] is common idiom
if (MP_OBJ_IS_SMALL_INT(rhs_in)) {
@ -239,8 +239,8 @@ STATIC mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "index must be int"));
}
case RT_BINARY_OP_ADD:
case RT_BINARY_OP_INPLACE_ADD:
case MP_BINARY_OP_ADD:
case MP_BINARY_OP_INPLACE_ADD:
if (MP_OBJ_IS_STR(rhs_in)) {
// add 2 strings
@ -264,7 +264,7 @@ STATIC mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
}
break;
case RT_BINARY_OP_IN:
case MP_BINARY_OP_IN:
/* NOTE `a in b` is `b.__contains__(a)` */
if (MP_OBJ_IS_STR(rhs_in)) {
GET_STR_DATA_LEN(rhs_in, rhs_data, rhs_len);
@ -272,7 +272,7 @@ STATIC mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
}
break;
case RT_BINARY_OP_MULTIPLY:
case MP_BINARY_OP_MULTIPLY:
{
if (!MP_OBJ_IS_SMALL_INT(rhs_in)) {
return NULL;
@ -284,13 +284,13 @@ STATIC mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return mp_obj_str_builder_end(s);
}
// These 2 are never passed here, dealt with as a special case in rt_binary_op().
//case RT_BINARY_OP_EQUAL:
//case RT_BINARY_OP_NOT_EQUAL:
case RT_BINARY_OP_LESS:
case RT_BINARY_OP_LESS_EQUAL:
case RT_BINARY_OP_MORE:
case RT_BINARY_OP_MORE_EQUAL:
// These 2 are never passed here, dealt with as a special case in mp_binary_op().
//case MP_BINARY_OP_EQUAL:
//case MP_BINARY_OP_NOT_EQUAL:
case MP_BINARY_OP_LESS:
case MP_BINARY_OP_LESS_EQUAL:
case MP_BINARY_OP_MORE:
case MP_BINARY_OP_MORE_EQUAL:
if (MP_OBJ_IS_STR(rhs_in)) {
GET_STR_DATA_LEN(rhs_in, rhs_data, rhs_len);
return MP_BOOL(mp_seq_cmp_bytes(op, lhs_data, lhs_len, rhs_data, rhs_len));
@ -373,7 +373,7 @@ STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) {
while (s < top && splits != 0) {
start = s;
while (s < top && !is_ws(*s)) s++;
rt_list_append(res, mp_obj_new_str(start, s - start, false));
mp_list_append(res, mp_obj_new_str(start, s - start, false));
if (s >= top) {
break;
}
@ -384,7 +384,7 @@ STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) {
}
if (s < top) {
rt_list_append(res, mp_obj_new_str(s, top - s, false));
mp_list_append(res, mp_obj_new_str(s, top - s, false));
}
return res;

View File

@ -39,8 +39,7 @@ STATIC mp_obj_t tuple_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
// return a empty tuple
return mp_const_empty_tuple;
case 1:
{
case 1: {
// 1 argument, an iterable from which we make a new tuple
if (MP_OBJ_IS_TYPE(args[0], &mp_type_tuple)) {
return args[0];
@ -52,9 +51,9 @@ STATIC mp_obj_t tuple_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
uint len = 0;
mp_obj_t *items = m_new(mp_obj_t, alloc);
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) {
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
if (len >= alloc) {
items = m_renew(mp_obj_t, items, alloc, alloc * 2);
alloc *= 2;
@ -73,7 +72,7 @@ STATIC mp_obj_t tuple_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
}
}
// Don't pass RT_BINARY_OP_NOT_EQUAL here
// Don't pass MP_BINARY_OP_NOT_EQUAL here
STATIC bool tuple_cmp_helper(int op, mp_obj_t self_in, mp_obj_t another_in) {
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_tuple));
if (!MP_OBJ_IS_TYPE(another_in, &mp_type_tuple)) {
@ -88,8 +87,8 @@ STATIC bool tuple_cmp_helper(int op, mp_obj_t self_in, mp_obj_t another_in) {
mp_obj_t tuple_unary_op(int op, mp_obj_t self_in) {
mp_obj_tuple_t *self = self_in;
switch (op) {
case RT_UNARY_OP_BOOL: return MP_BOOL(self->len != 0);
case RT_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len);
case MP_UNARY_OP_BOOL: return MP_BOOL(self->len != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len);
default: return MP_OBJ_NULL; // op not supported for None
}
}
@ -97,7 +96,7 @@ mp_obj_t tuple_unary_op(int op, mp_obj_t self_in) {
mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
mp_obj_tuple_t *o = lhs;
switch (op) {
case RT_BINARY_OP_SUBSCR:
case MP_BINARY_OP_SUBSCR:
{
#if MICROPY_ENABLE_SLICE
if (MP_OBJ_IS_TYPE(rhs, &mp_type_slice)) {
@ -113,7 +112,7 @@ mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
uint index = mp_get_index(o->base.type, o->len, rhs, false);
return o->items[index];
}
case RT_BINARY_OP_ADD:
case MP_BINARY_OP_ADD:
{
if (!mp_obj_is_subclass_fast(mp_obj_get_type(rhs), (mp_obj_t)&mp_type_tuple)) {
return NULL;
@ -123,7 +122,7 @@ mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
m_seq_cat(s->items, o->items, o->len, p->items, p->len, mp_obj_t);
return s;
}
case RT_BINARY_OP_MULTIPLY:
case MP_BINARY_OP_MULTIPLY:
{
if (!MP_OBJ_IS_SMALL_INT(rhs)) {
return NULL;
@ -133,14 +132,14 @@ mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
mp_seq_multiply(o->items, sizeof(*o->items), o->len, n, s->items);
return s;
}
case RT_BINARY_OP_EQUAL:
case RT_BINARY_OP_LESS:
case RT_BINARY_OP_LESS_EQUAL:
case RT_BINARY_OP_MORE:
case RT_BINARY_OP_MORE_EQUAL:
case MP_BINARY_OP_EQUAL:
case MP_BINARY_OP_LESS:
case MP_BINARY_OP_LESS_EQUAL:
case MP_BINARY_OP_MORE:
case MP_BINARY_OP_MORE_EQUAL:
return MP_BOOL(tuple_cmp_helper(op, lhs, rhs));
case RT_BINARY_OP_NOT_EQUAL:
return MP_BOOL(!tuple_cmp_helper(RT_BINARY_OP_EQUAL, lhs, rhs));
case MP_BINARY_OP_NOT_EQUAL:
return MP_BOOL(!tuple_cmp_helper(MP_BINARY_OP_EQUAL, lhs, rhs));
default:
// op not supported

View File

@ -76,7 +76,7 @@ STATIC void class_print(void (*print)(void *env, const char *fmt, ...), void *en
}
if (member != MP_OBJ_NULL) {
mp_obj_t r = rt_call_function_1(member, self_in);
mp_obj_t r = mp_call_function_1(member, self_in);
mp_obj_print_helper(print, env, r, PRINT_STR);
return;
}
@ -98,12 +98,12 @@ STATIC mp_obj_t class_make_new(mp_obj_t self_in, uint n_args, uint n_kw, const m
// call __init__ function
mp_obj_t init_ret;
if (n_args == 0 && n_kw == 0) {
init_ret = rt_call_function_n_kw(init_fn, 1, 0, (mp_obj_t*)&o);
init_ret = mp_call_function_n_kw(init_fn, 1, 0, (mp_obj_t*)&o);
} else {
mp_obj_t *args2 = m_new(mp_obj_t, 1 + n_args + 2 * n_kw);
args2[0] = o;
memcpy(args2 + 1, args, (n_args + 2 * n_kw) * sizeof(mp_obj_t));
init_ret = rt_call_function_n_kw(init_fn, n_args + 1, n_kw, args2);
init_ret = mp_call_function_n_kw(init_fn, n_args + 1, n_kw, args2);
m_del(mp_obj_t, args2, 1 + n_args + 2 * n_kw);
}
if (init_ret != mp_const_none) {
@ -121,12 +121,12 @@ STATIC mp_obj_t class_make_new(mp_obj_t self_in, uint n_args, uint n_kw, const m
}
STATIC const qstr unary_op_method_name[] = {
[RT_UNARY_OP_BOOL] = MP_QSTR___bool__,
[RT_UNARY_OP_LEN] = MP_QSTR___len__,
//[RT_UNARY_OP_POSITIVE,
//[RT_UNARY_OP_NEGATIVE,
//[RT_UNARY_OP_INVERT,
[RT_UNARY_OP_NOT] = MP_QSTR_, // don't need to implement this, used to make sure array has full size
[MP_UNARY_OP_BOOL] = MP_QSTR___bool__,
[MP_UNARY_OP_LEN] = MP_QSTR___len__,
//[MP_UNARY_OP_POSITIVE,
//[MP_UNARY_OP_NEGATIVE,
//[MP_UNARY_OP_INVERT,
[MP_UNARY_OP_NOT] = MP_QSTR_, // don't need to implement this, used to make sure array has full size
};
STATIC mp_obj_t class_unary_op(int op, mp_obj_t self_in) {
@ -137,51 +137,51 @@ STATIC mp_obj_t class_unary_op(int op, mp_obj_t self_in) {
}
mp_obj_t member = mp_obj_class_lookup(self->base.type, op_name);
if (member != MP_OBJ_NULL) {
return rt_call_function_1(member, self_in);
return mp_call_function_1(member, self_in);
} else {
return MP_OBJ_NULL;
}
}
STATIC const qstr binary_op_method_name[] = {
[RT_BINARY_OP_SUBSCR] = MP_QSTR___getitem__,
[MP_BINARY_OP_SUBSCR] = MP_QSTR___getitem__,
/*
RT_BINARY_OP_OR,
RT_BINARY_OP_XOR,
RT_BINARY_OP_AND,
RT_BINARY_OP_LSHIFT,
RT_BINARY_OP_RSHIFT,
MP_BINARY_OP_OR,
MP_BINARY_OP_XOR,
MP_BINARY_OP_AND,
MP_BINARY_OP_LSHIFT,
MP_BINARY_OP_RSHIFT,
*/
[RT_BINARY_OP_ADD] = MP_QSTR___add__,
[RT_BINARY_OP_SUBTRACT] = MP_QSTR___sub__,
[MP_BINARY_OP_ADD] = MP_QSTR___add__,
[MP_BINARY_OP_SUBTRACT] = MP_QSTR___sub__,
/*
RT_BINARY_OP_MULTIPLY,
RT_BINARY_OP_FLOOR_DIVIDE,
RT_BINARY_OP_TRUE_DIVIDE,
RT_BINARY_OP_MODULO,
RT_BINARY_OP_POWER,
RT_BINARY_OP_INPLACE_OR,
RT_BINARY_OP_INPLACE_XOR,
RT_BINARY_OP_INPLACE_AND,
RT_BINARY_OP_INPLACE_LSHIFT,
RT_BINARY_OP_INPLACE_RSHIFT,
RT_BINARY_OP_INPLACE_ADD,
RT_BINARY_OP_INPLACE_SUBTRACT,
RT_BINARY_OP_INPLACE_MULTIPLY,
RT_BINARY_OP_INPLACE_FLOOR_DIVIDE,
RT_BINARY_OP_INPLACE_TRUE_DIVIDE,
RT_BINARY_OP_INPLACE_MODULO,
RT_BINARY_OP_INPLACE_POWER,
RT_BINARY_OP_LESS,
RT_BINARY_OP_MORE,
RT_BINARY_OP_EQUAL,
RT_BINARY_OP_LESS_EQUAL,
RT_BINARY_OP_MORE_EQUAL,
RT_BINARY_OP_NOT_EQUAL,
RT_BINARY_OP_IN,
RT_BINARY_OP_IS,
MP_BINARY_OP_MULTIPLY,
MP_BINARY_OP_FLOOR_DIVIDE,
MP_BINARY_OP_TRUE_DIVIDE,
MP_BINARY_OP_MODULO,
MP_BINARY_OP_POWER,
MP_BINARY_OP_INPLACE_OR,
MP_BINARY_OP_INPLACE_XOR,
MP_BINARY_OP_INPLACE_AND,
MP_BINARY_OP_INPLACE_LSHIFT,
MP_BINARY_OP_INPLACE_RSHIFT,
MP_BINARY_OP_INPLACE_ADD,
MP_BINARY_OP_INPLACE_SUBTRACT,
MP_BINARY_OP_INPLACE_MULTIPLY,
MP_BINARY_OP_INPLACE_FLOOR_DIVIDE,
MP_BINARY_OP_INPLACE_TRUE_DIVIDE,
MP_BINARY_OP_INPLACE_MODULO,
MP_BINARY_OP_INPLACE_POWER,
MP_BINARY_OP_LESS,
MP_BINARY_OP_MORE,
MP_BINARY_OP_EQUAL,
MP_BINARY_OP_LESS_EQUAL,
MP_BINARY_OP_MORE_EQUAL,
MP_BINARY_OP_NOT_EQUAL,
MP_BINARY_OP_IN,
MP_BINARY_OP_IS,
*/
[RT_BINARY_OP_EXCEPTION_MATCH] = MP_QSTR_, // not implemented, used to make sure array has full size
[MP_BINARY_OP_EXCEPTION_MATCH] = MP_QSTR_, // not implemented, used to make sure array has full size
};
STATIC mp_obj_t class_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
@ -192,7 +192,7 @@ STATIC mp_obj_t class_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
}
mp_obj_t member = mp_obj_class_lookup(lhs->base.type, op_name);
if (member != MP_OBJ_NULL) {
return rt_call_function_2(member, lhs_in, rhs_in);
return mp_call_function_2(member, lhs_in, rhs_in);
} else {
return MP_OBJ_NULL;
}
@ -242,7 +242,7 @@ bool class_store_item(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
mp_obj_t member = mp_obj_class_lookup(self->base.type, MP_QSTR___setitem__);
if (member != MP_OBJ_NULL) {
mp_obj_t args[3] = {self_in, index, value};
rt_call_function_n_kw(member, 3, 0, args);
mp_call_function_n_kw(member, 3, 0, args);
return true;
} else {
return false;

View File

@ -20,7 +20,7 @@ STATIC mp_obj_t zip_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
o->base.type = &mp_type_zip;
o->n_iters = n_args;
for (int i = 0; i < n_args; i++) {
o->iters[i] = rt_getiter(args[i]);
o->iters[i] = mp_getiter(args[i]);
}
return o;
}
@ -40,7 +40,7 @@ STATIC mp_obj_t zip_iternext(mp_obj_t self_in) {
mp_obj_tuple_get(o, NULL, &items);
for (int i = 0; i < self->n_iters; i++) {
mp_obj_t next = rt_iternext(self->iters[i]);
mp_obj_t next = mp_iternext(self->iters[i]);
if (next == MP_OBJ_NULL) {
mp_obj_tuple_del(o);
return MP_OBJ_NULL;

View File

@ -37,7 +37,7 @@ STATIC void mp_map_add_qstr(mp_map_t *map, qstr qstr, mp_obj_t value) {
mp_map_lookup(map, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value;
}
void rt_init(void) {
void mp_init(void) {
mp_emit_glue_init();
// locals = globals for outer module (see Objects/frameobject.c/PyFrame_New())
@ -60,86 +60,52 @@ void rt_init(void) {
#endif
// init sys.path
// for efficiency, left to platform-specific startup code
//sys_path = mp_obj_new_list(0, NULL);
//rt_store_attr(m_sys, MP_QSTR_path, sys_path);
//mp_sys_path = mp_obj_new_list(0, NULL);
//mp_store_attr(m_sys, MP_QSTR_path, mp_sys_path);
}
void rt_deinit(void) {
void mp_deinit(void) {
mp_map_free(map_globals);
mp_map_deinit(&map_builtins);
mp_module_deinit();
mp_emit_glue_deinit();
}
int rt_is_true(mp_obj_t arg) {
DEBUG_OP_printf("is true %p\n", arg);
if (arg == mp_const_false) {
return 0;
} else if (arg == mp_const_true) {
return 1;
} else if (arg == mp_const_none) {
return 0;
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
if (MP_OBJ_SMALL_INT_VALUE(arg) == 0) {
return 0;
} else {
return 1;
}
} else {
mp_obj_type_t *type = mp_obj_get_type(arg);
if (type->unary_op != NULL) {
mp_obj_t result = type->unary_op(RT_UNARY_OP_BOOL, arg);
if (result != MP_OBJ_NULL) {
return result == mp_const_true;
}
}
mp_obj_t len = mp_obj_len_maybe(arg);
if (len != MP_OBJ_NULL) {
// obj has a length, truth determined if len != 0
return len != MP_OBJ_NEW_SMALL_INT(0);
} else {
// any other obj is true per Python semantics
return 1;
}
}
}
mp_obj_t rt_list_append(mp_obj_t self_in, mp_obj_t arg) {
mp_obj_t mp_list_append(mp_obj_t self_in, mp_obj_t arg) {
return mp_obj_list_append(self_in, arg);
}
mp_obj_t rt_load_const_dec(qstr qstr) {
mp_obj_t mp_load_const_dec(qstr qstr) {
DEBUG_OP_printf("load '%s'\n", qstr_str(qstr));
uint len;
const byte* data = qstr_data(qstr, &len);
return mp_parse_num_decimal((const char*)data, len, true, false);
}
mp_obj_t rt_load_const_str(qstr qstr) {
mp_obj_t mp_load_const_str(qstr qstr) {
DEBUG_OP_printf("load '%s'\n", qstr_str(qstr));
return MP_OBJ_NEW_QSTR(qstr);
}
mp_obj_t rt_load_const_bytes(qstr qstr) {
mp_obj_t mp_load_const_bytes(qstr qstr) {
DEBUG_OP_printf("load b'%s'\n", qstr_str(qstr));
uint len;
const byte *data = qstr_data(qstr, &len);
return mp_obj_new_bytes(data, len);
}
mp_obj_t rt_load_name(qstr qstr) {
mp_obj_t mp_load_name(qstr qstr) {
// logic: search locals, globals, builtins
DEBUG_OP_printf("load name %s\n", qstr_str(qstr));
mp_map_elem_t *elem = mp_map_lookup(map_locals, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP);
if (elem != NULL) {
return elem->value;
} else {
return rt_load_global(qstr);
return mp_load_global(qstr);
}
}
mp_obj_t rt_load_global(qstr qstr) {
mp_obj_t mp_load_global(qstr qstr) {
// logic: search globals, builtins
DEBUG_OP_printf("load global %s\n", qstr_str(qstr));
mp_map_elem_t *elem = mp_map_lookup(map_globals, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP);
@ -156,7 +122,7 @@ mp_obj_t rt_load_global(qstr qstr) {
return elem->value;
}
mp_obj_t rt_load_build_class(void) {
mp_obj_t mp_load_build_class(void) {
DEBUG_OP_printf("load_build_class\n");
// lookup __build_class__ in dynamic table of builtins first
mp_map_elem_t *elem = mp_map_lookup(&map_builtins, MP_OBJ_NEW_QSTR(MP_QSTR___build_class__), MP_MAP_LOOKUP);
@ -169,47 +135,47 @@ mp_obj_t rt_load_build_class(void) {
}
}
mp_obj_t rt_get_cell(mp_obj_t cell) {
mp_obj_t mp_get_cell(mp_obj_t cell) {
return mp_obj_cell_get(cell);
}
void rt_set_cell(mp_obj_t cell, mp_obj_t val) {
void mp_set_cell(mp_obj_t cell, mp_obj_t val) {
mp_obj_cell_set(cell, val);
}
void rt_store_name(qstr qstr, mp_obj_t obj) {
void mp_store_name(qstr qstr, mp_obj_t obj) {
DEBUG_OP_printf("store name %s <- %p\n", qstr_str(qstr), obj);
mp_map_lookup(map_locals, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = obj;
}
void rt_delete_name(qstr qstr) {
void mp_delete_name(qstr qstr) {
DEBUG_OP_printf("delete name %s\n", qstr_str(qstr));
mp_map_lookup(map_locals, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP_REMOVE_IF_FOUND);
}
void rt_store_global(qstr qstr, mp_obj_t obj) {
void mp_store_global(qstr qstr, mp_obj_t obj) {
DEBUG_OP_printf("store global %s <- %p\n", qstr_str(qstr), obj);
mp_map_lookup(map_globals, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = obj;
}
mp_obj_t rt_unary_op(int op, mp_obj_t arg) {
mp_obj_t mp_unary_op(int op, mp_obj_t arg) {
DEBUG_OP_printf("unary %d %p\n", op, arg);
if (MP_OBJ_IS_SMALL_INT(arg)) {
mp_small_int_t val = MP_OBJ_SMALL_INT_VALUE(arg);
switch (op) {
case RT_UNARY_OP_BOOL:
case MP_UNARY_OP_BOOL:
return MP_BOOL(val != 0);
case RT_UNARY_OP_POSITIVE:
case MP_UNARY_OP_POSITIVE:
return arg;
case RT_UNARY_OP_NEGATIVE:
case MP_UNARY_OP_NEGATIVE:
// check for overflow
if (val == MP_SMALL_INT_MIN) {
return mp_obj_new_int(-val);
} else {
return MP_OBJ_NEW_SMALL_INT(-val);
}
case RT_UNARY_OP_INVERT:
case MP_UNARY_OP_INVERT:
return MP_OBJ_NEW_SMALL_INT(~val);
default:
assert(0);
@ -228,7 +194,7 @@ mp_obj_t rt_unary_op(int op, mp_obj_t arg) {
}
}
mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
DEBUG_OP_printf("binary %d %p %p\n", op, lhs, rhs);
// TODO correctly distinguish inplace operators for mutable objects
@ -241,20 +207,20 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
// note that list does not implement + or +=, so that inplace_concat is reached first for +=
// deal with is
if (op == RT_BINARY_OP_IS) {
if (op == MP_BINARY_OP_IS) {
return MP_BOOL(lhs == rhs);
}
// deal with == and != for all types
if (op == RT_BINARY_OP_EQUAL || op == RT_BINARY_OP_NOT_EQUAL) {
if (op == MP_BINARY_OP_EQUAL || op == MP_BINARY_OP_NOT_EQUAL) {
if (mp_obj_equal(lhs, rhs)) {
if (op == RT_BINARY_OP_EQUAL) {
if (op == MP_BINARY_OP_EQUAL) {
return mp_const_true;
} else {
return mp_const_false;
}
} else {
if (op == RT_BINARY_OP_EQUAL) {
if (op == MP_BINARY_OP_EQUAL) {
return mp_const_false;
} else {
return mp_const_true;
@ -263,7 +229,7 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
}
// deal with exception_match for all types
if (op == RT_BINARY_OP_EXCEPTION_MATCH) {
if (op == MP_BINARY_OP_EXCEPTION_MATCH) {
// rhs must be issubclass(rhs, BaseException)
if (mp_obj_is_exception_type(rhs)) {
// if lhs is an instance of an exception, then extract and use its type
@ -294,14 +260,14 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
// % if lhs=MIN and rhs=-1; result always fits in machine_int_t, then handled by SMALL_INT check
// << checked explicitly
switch (op) {
case RT_BINARY_OP_OR:
case RT_BINARY_OP_INPLACE_OR: lhs_val |= rhs_val; break;
case RT_BINARY_OP_XOR:
case RT_BINARY_OP_INPLACE_XOR: lhs_val ^= rhs_val; break;
case RT_BINARY_OP_AND:
case RT_BINARY_OP_INPLACE_AND: lhs_val &= rhs_val; break;
case RT_BINARY_OP_LSHIFT:
case RT_BINARY_OP_INPLACE_LSHIFT: {
case MP_BINARY_OP_OR:
case MP_BINARY_OP_INPLACE_OR: lhs_val |= rhs_val; break;
case MP_BINARY_OP_XOR:
case MP_BINARY_OP_INPLACE_XOR: lhs_val ^= rhs_val; break;
case MP_BINARY_OP_AND:
case MP_BINARY_OP_INPLACE_AND: lhs_val &= rhs_val; break;
case MP_BINARY_OP_LSHIFT:
case MP_BINARY_OP_INPLACE_LSHIFT: {
if (rhs_val < 0) {
// negative shift not allowed
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count"));
@ -315,8 +281,8 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
}
break;
}
case RT_BINARY_OP_RSHIFT:
case RT_BINARY_OP_INPLACE_RSHIFT:
case MP_BINARY_OP_RSHIFT:
case MP_BINARY_OP_INPLACE_RSHIFT:
if (rhs_val < 0) {
// negative shift not allowed
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count"));
@ -325,12 +291,12 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
lhs_val >>= rhs_val;
}
break;
case RT_BINARY_OP_ADD:
case RT_BINARY_OP_INPLACE_ADD: lhs_val += rhs_val; break;
case RT_BINARY_OP_SUBTRACT:
case RT_BINARY_OP_INPLACE_SUBTRACT: lhs_val -= rhs_val; break;
case RT_BINARY_OP_MULTIPLY:
case RT_BINARY_OP_INPLACE_MULTIPLY: {
case MP_BINARY_OP_ADD:
case MP_BINARY_OP_INPLACE_ADD: lhs_val += rhs_val; break;
case MP_BINARY_OP_SUBTRACT:
case MP_BINARY_OP_INPLACE_SUBTRACT: lhs_val -= rhs_val; break;
case MP_BINARY_OP_MULTIPLY:
case MP_BINARY_OP_INPLACE_MULTIPLY: {
// If long long type exists and is larger than machine_int_t, then
// we can use the following code to perform overflow-checked multiplication.
@ -379,25 +345,25 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
break;
}
case RT_BINARY_OP_FLOOR_DIVIDE:
case RT_BINARY_OP_INPLACE_FLOOR_DIVIDE:
case MP_BINARY_OP_FLOOR_DIVIDE:
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
{
lhs_val = python_floor_divide(lhs_val, rhs_val);
break;
}
#if MICROPY_ENABLE_FLOAT
case RT_BINARY_OP_TRUE_DIVIDE:
case RT_BINARY_OP_INPLACE_TRUE_DIVIDE: return mp_obj_new_float((mp_float_t)lhs_val / (mp_float_t)rhs_val);
case MP_BINARY_OP_TRUE_DIVIDE:
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE: return mp_obj_new_float((mp_float_t)lhs_val / (mp_float_t)rhs_val);
#endif
case RT_BINARY_OP_MODULO:
case RT_BINARY_OP_INPLACE_MODULO:
case MP_BINARY_OP_MODULO:
case MP_BINARY_OP_INPLACE_MODULO:
{
lhs_val = python_modulo(lhs_val, rhs_val);
break;
}
case RT_BINARY_OP_POWER:
case RT_BINARY_OP_INPLACE_POWER:
case MP_BINARY_OP_POWER:
case MP_BINARY_OP_INPLACE_POWER:
if (rhs_val < 0) {
#if MICROPY_ENABLE_FLOAT
lhs = mp_obj_new_float(lhs_val);
@ -418,10 +384,10 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
lhs_val = ans;
}
break;
case RT_BINARY_OP_LESS: return MP_BOOL(lhs_val < rhs_val); break;
case RT_BINARY_OP_MORE: return MP_BOOL(lhs_val > rhs_val); break;
case RT_BINARY_OP_LESS_EQUAL: return MP_BOOL(lhs_val <= rhs_val); break;
case RT_BINARY_OP_MORE_EQUAL: return MP_BOOL(lhs_val >= rhs_val); break;
case MP_BINARY_OP_LESS: return MP_BOOL(lhs_val < rhs_val); break;
case MP_BINARY_OP_MORE: return MP_BOOL(lhs_val > rhs_val); break;
case MP_BINARY_OP_LESS_EQUAL: return MP_BOOL(lhs_val <= rhs_val); break;
case MP_BINARY_OP_MORE_EQUAL: return MP_BOOL(lhs_val >= rhs_val); break;
default: assert(0);
}
@ -445,7 +411,7 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
* NOTE `a in b` is `b.__contains__(a)`, hence why the generic dispatch
* needs to go below with swapped arguments
*/
if (op == RT_BINARY_OP_IN) {
if (op == MP_BINARY_OP_IN) {
mp_obj_type_t *type = mp_obj_get_type(rhs);
if (type->binary_op != NULL) {
mp_obj_t res = type->binary_op(op, rhs, lhs);
@ -456,8 +422,8 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
if (type->getiter != NULL) {
/* second attempt, walk the iterator */
mp_obj_t next = NULL;
mp_obj_t iter = rt_getiter(rhs);
while ((next = rt_iternext(iter)) != MP_OBJ_NULL) {
mp_obj_t iter = mp_getiter(rhs);
while ((next = mp_iternext(iter)) != MP_OBJ_NULL) {
if (mp_obj_equal(next, lhs)) {
return mp_const_true;
}
@ -491,29 +457,29 @@ generic_binary_op:
return mp_const_none;
}
mp_obj_t rt_call_function_0(mp_obj_t fun) {
return rt_call_function_n_kw(fun, 0, 0, NULL);
mp_obj_t mp_call_function_0(mp_obj_t fun) {
return mp_call_function_n_kw(fun, 0, 0, NULL);
}
mp_obj_t rt_call_function_1(mp_obj_t fun, mp_obj_t arg) {
return rt_call_function_n_kw(fun, 1, 0, &arg);
mp_obj_t mp_call_function_1(mp_obj_t fun, mp_obj_t arg) {
return mp_call_function_n_kw(fun, 1, 0, &arg);
}
mp_obj_t rt_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2) {
mp_obj_t mp_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2) {
mp_obj_t args[2];
args[0] = arg1;
args[1] = arg2;
return rt_call_function_n_kw(fun, 2, 0, args);
return mp_call_function_n_kw(fun, 2, 0, args);
}
// wrapper that accepts n_args and n_kw in one argument
// native emitter can only pass at most 3 arguments to a function
mp_obj_t rt_call_function_n_kw_for_native(mp_obj_t fun_in, uint n_args_kw, const mp_obj_t *args) {
return rt_call_function_n_kw(fun_in, n_args_kw & 0xff, (n_args_kw >> 8) & 0xff, args);
mp_obj_t mp_call_function_n_kw_for_native(mp_obj_t fun_in, uint n_args_kw, const mp_obj_t *args) {
return mp_call_function_n_kw(fun_in, n_args_kw & 0xff, (n_args_kw >> 8) & 0xff, args);
}
// args contains, eg: arg0 arg1 key0 value0 key1 value1
mp_obj_t rt_call_function_n_kw(mp_obj_t fun_in, uint n_args, uint n_kw, const mp_obj_t *args) {
mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, uint n_args, uint n_kw, const mp_obj_t *args) {
// TODO improve this: fun object can specify its type and we parse here the arguments,
// passing to the function arrays of fixed and keyword arguments
@ -532,31 +498,31 @@ mp_obj_t rt_call_function_n_kw(mp_obj_t fun_in, uint n_args, uint n_kw, const mp
// args contains: fun self/NULL arg(0) ... arg(n_args-2) arg(n_args-1) kw_key(0) kw_val(0) ... kw_key(n_kw-1) kw_val(n_kw-1)
// if n_args==0 and n_kw==0 then there are only fun and self/NULL
mp_obj_t rt_call_method_n_kw(uint n_args, uint n_kw, const mp_obj_t *args) {
mp_obj_t mp_call_method_n_kw(uint n_args, uint n_kw, const mp_obj_t *args) {
DEBUG_OP_printf("call method (fun=%p, self=%p, n_args=%u, n_kw=%u, args=%p)\n", args[0], args[1], n_args, n_kw, args);
int adjust = (args[1] == NULL) ? 0 : 1;
return rt_call_function_n_kw(args[0], n_args + adjust, n_kw, args + 2 - adjust);
return mp_call_function_n_kw(args[0], n_args + adjust, n_kw, args + 2 - adjust);
}
mp_obj_t rt_build_tuple(int n_args, mp_obj_t *items) {
mp_obj_t mp_build_tuple(int n_args, mp_obj_t *items) {
return mp_obj_new_tuple(n_args, items);
}
mp_obj_t rt_build_list(int n_args, mp_obj_t *items) {
mp_obj_t mp_build_list(int n_args, mp_obj_t *items) {
return mp_obj_new_list(n_args, items);
}
mp_obj_t rt_build_set(int n_args, mp_obj_t *items) {
mp_obj_t mp_build_set(int n_args, mp_obj_t *items) {
return mp_obj_new_set(n_args, items);
}
mp_obj_t rt_store_set(mp_obj_t set, mp_obj_t item) {
mp_obj_t mp_store_set(mp_obj_t set, mp_obj_t item) {
mp_obj_set_store(set, item);
return set;
}
// unpacked items are stored in reverse order into the array pointed to by items
void rt_unpack_sequence(mp_obj_t seq_in, uint num, mp_obj_t *items) {
void mp_unpack_sequence(mp_obj_t seq_in, uint num, mp_obj_t *items) {
uint seq_len;
if (MP_OBJ_IS_TYPE(seq_in, &mp_type_tuple) || MP_OBJ_IS_TYPE(seq_in, &mp_type_list)) {
mp_obj_t *seq_items;
@ -574,16 +540,16 @@ void rt_unpack_sequence(mp_obj_t seq_in, uint num, mp_obj_t *items) {
items[i] = seq_items[num - 1 - i];
}
} else {
mp_obj_t iterable = rt_getiter(seq_in);
mp_obj_t iterable = mp_getiter(seq_in);
for (seq_len = 0; seq_len < num; seq_len++) {
mp_obj_t el = rt_iternext(iterable);
mp_obj_t el = mp_iternext(iterable);
if (el == MP_OBJ_NULL) {
goto too_short;
}
items[num - 1 - seq_len] = el;
}
if (rt_iternext(iterable) != MP_OBJ_NULL) {
if (mp_iternext(iterable) != MP_OBJ_NULL) {
goto too_long;
}
}
@ -595,20 +561,20 @@ too_long:
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "too many values to unpack (expected %d)", num));
}
mp_obj_t rt_build_map(int n_args) {
mp_obj_t mp_build_map(int n_args) {
return mp_obj_new_dict(n_args);
}
mp_obj_t rt_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value) {
mp_obj_t mp_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value) {
// map should always be a dict
return mp_obj_dict_store(map, key, value);
}
mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) {
mp_obj_t mp_load_attr(mp_obj_t base, qstr attr) {
DEBUG_OP_printf("load attr %p.%s\n", base, qstr_str(attr));
// use load_method
mp_obj_t dest[2];
rt_load_method(base, attr, dest);
mp_load_method(base, attr, dest);
if (dest[1] == MP_OBJ_NULL) {
// load_method returned just a normal attribute
return dest[0];
@ -621,7 +587,7 @@ mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) {
// no attribute found, returns: dest[0] == MP_OBJ_NULL, dest[1] == MP_OBJ_NULL
// normal attribute found, returns: dest[0] == <attribute>, dest[1] == MP_OBJ_NULL
// method attribute found, returns: dest[0] == <method>, dest[1] == <self>
STATIC void rt_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest) {
STATIC void mp_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest) {
// clear output to indicate no attribute/method found yet
dest[0] = MP_OBJ_NULL;
dest[1] = MP_OBJ_NULL;
@ -673,10 +639,10 @@ STATIC void rt_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest) {
}
}
void rt_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
DEBUG_OP_printf("load method %p.%s\n", base, qstr_str(attr));
rt_load_method_maybe(base, attr, dest);
mp_load_method_maybe(base, attr, dest);
if (dest[0] == MP_OBJ_NULL) {
// no attribute/method called attr
@ -690,7 +656,7 @@ void rt_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
}
}
void rt_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
DEBUG_OP_printf("store attr %p.%s <- %p\n", base, qstr_str(attr), value);
mp_obj_type_t *type = mp_obj_get_type(base);
if (type->store_attr != NULL) {
@ -701,7 +667,7 @@ void rt_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_AttributeError, "'%s' object has no attribute '%s'", mp_obj_get_type_str(base), qstr_str(attr)));
}
void rt_store_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
void mp_store_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
DEBUG_OP_printf("store subscr %p[%p] <- %p\n", base, index, value);
if (MP_OBJ_IS_TYPE(base, &mp_type_list)) {
// list store
@ -722,19 +688,19 @@ void rt_store_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
}
}
mp_obj_t rt_getiter(mp_obj_t o_in) {
mp_obj_t mp_getiter(mp_obj_t o_in) {
mp_obj_type_t *type = mp_obj_get_type(o_in);
if (type->getiter != NULL) {
return type->getiter(o_in);
} else {
// check for __iter__ method
mp_obj_t dest[2];
rt_load_method_maybe(o_in, MP_QSTR___iter__, dest);
mp_load_method_maybe(o_in, MP_QSTR___iter__, dest);
if (dest[0] != MP_OBJ_NULL) {
// __iter__ exists, call it and return its result
return rt_call_method_n_kw(0, 0, dest);
return mp_call_method_n_kw(0, 0, dest);
} else {
rt_load_method_maybe(o_in, MP_QSTR___getitem__, dest);
mp_load_method_maybe(o_in, MP_QSTR___getitem__, dest);
if (dest[0] != MP_OBJ_NULL) {
// __getitem__ exists, create an iterator
return mp_obj_new_getitem_iter(dest);
@ -748,17 +714,17 @@ mp_obj_t rt_getiter(mp_obj_t o_in) {
// may return MP_OBJ_NULL as an optimisation instead of raise StopIteration()
// may also raise StopIteration()
mp_obj_t rt_iternext_allow_raise(mp_obj_t o_in) {
mp_obj_t mp_iternext_allow_raise(mp_obj_t o_in) {
mp_obj_type_t *type = mp_obj_get_type(o_in);
if (type->iternext != NULL) {
return type->iternext(o_in);
} else {
// check for __next__ method
mp_obj_t dest[2];
rt_load_method_maybe(o_in, MP_QSTR___next__, dest);
mp_load_method_maybe(o_in, MP_QSTR___next__, dest);
if (dest[0] != MP_OBJ_NULL) {
// __next__ exists, call it and return its result
return rt_call_method_n_kw(0, 0, dest);
return mp_call_method_n_kw(0, 0, dest);
} else {
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not an iterator", mp_obj_get_type_str(o_in)));
}
@ -767,19 +733,19 @@ mp_obj_t rt_iternext_allow_raise(mp_obj_t o_in) {
// will always return MP_OBJ_NULL instead of raising StopIteration() (or any subclass thereof)
// may raise other exceptions
mp_obj_t rt_iternext(mp_obj_t o_in) {
mp_obj_t mp_iternext(mp_obj_t o_in) {
mp_obj_type_t *type = mp_obj_get_type(o_in);
if (type->iternext != NULL) {
return type->iternext(o_in);
} else {
// check for __next__ method
mp_obj_t dest[2];
rt_load_method_maybe(o_in, MP_QSTR___next__, dest);
mp_load_method_maybe(o_in, MP_QSTR___next__, dest);
if (dest[0] != MP_OBJ_NULL) {
// __next__ exists, call it and return its result
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
mp_obj_t ret = rt_call_method_n_kw(0, 0, dest);
mp_obj_t ret = mp_call_method_n_kw(0, 0, dest);
nlr_pop();
return ret;
} else {
@ -795,14 +761,14 @@ mp_obj_t rt_iternext(mp_obj_t o_in) {
}
}
mp_obj_t rt_make_raise_obj(mp_obj_t o) {
mp_obj_t mp_make_raise_obj(mp_obj_t o) {
DEBUG_printf("raise %p\n", o);
if (mp_obj_is_exception_type(o)) {
// o is an exception type (it is derived from BaseException (or is BaseException))
// create and return a new exception instance by calling o
// TODO could have an option to disable traceback, then builtin exceptions (eg TypeError)
// could have const instances in ROM which we return here instead
return rt_call_function_n_kw(o, 0, 0, NULL);
return mp_call_function_n_kw(o, 0, 0, NULL);
} else if (mp_obj_is_exception_instance(o)) {
// o is an instance of an exception, so use it as the exception
return o;
@ -812,7 +778,7 @@ mp_obj_t rt_make_raise_obj(mp_obj_t o) {
}
}
mp_obj_t rt_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level) {
mp_obj_t mp_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level) {
DEBUG_printf("import name %s\n", qstr_str(name));
// build args array
@ -827,10 +793,10 @@ mp_obj_t rt_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level) {
return mp_builtin___import__(5, args);
}
mp_obj_t rt_import_from(mp_obj_t module, qstr name) {
mp_obj_t mp_import_from(mp_obj_t module, qstr name) {
DEBUG_printf("import from %p %s\n", module, qstr_str(name));
mp_obj_t x = rt_load_attr(module, name);
mp_obj_t x = mp_load_attr(module, name);
/* TODO convert AttributeError to ImportError
if (fail) {
(ImportError, "cannot import name %s", qstr_str(name), NULL)
@ -839,66 +805,66 @@ mp_obj_t rt_import_from(mp_obj_t module, qstr name) {
return x;
}
void rt_import_all(mp_obj_t module) {
void mp_import_all(mp_obj_t module) {
DEBUG_printf("import all %p\n", module);
mp_map_t *map = mp_obj_module_get_globals(module);
for (uint i = 0; i < map->alloc; i++) {
if (map->table[i].key != MP_OBJ_NULL) {
rt_store_name(MP_OBJ_QSTR_VALUE(map->table[i].key), map->table[i].value);
mp_store_name(MP_OBJ_QSTR_VALUE(map->table[i].key), map->table[i].value);
}
}
}
mp_map_t *rt_locals_get(void) {
mp_map_t *mp_locals_get(void) {
return map_locals;
}
void rt_locals_set(mp_map_t *m) {
DEBUG_OP_printf("rt_locals_set(%p)\n", m);
void mp_locals_set(mp_map_t *m) {
DEBUG_OP_printf("mp_locals_set(%p)\n", m);
map_locals = m;
}
mp_map_t *rt_globals_get(void) {
mp_map_t *mp_globals_get(void) {
return map_globals;
}
void rt_globals_set(mp_map_t *m) {
DEBUG_OP_printf("rt_globals_set(%p)\n", m);
void mp_globals_set(mp_map_t *m) {
DEBUG_OP_printf("mp_globals_set(%p)\n", m);
map_globals = m;
}
// these must correspond to the respective enum
void *const rt_fun_table[RT_F_NUMBER_OF] = {
rt_load_const_dec,
rt_load_const_str,
rt_load_name,
rt_load_global,
rt_load_build_class,
rt_load_attr,
rt_load_method,
rt_store_name,
rt_store_attr,
rt_store_subscr,
rt_is_true,
rt_unary_op,
rt_binary_op,
rt_build_tuple,
rt_build_list,
rt_list_append,
rt_build_map,
rt_store_map,
rt_build_set,
rt_store_set,
rt_make_function_from_id,
rt_call_function_n_kw_for_native,
rt_call_method_n_kw,
rt_getiter,
rt_iternext,
void *const mp_fun_table[MP_F_NUMBER_OF] = {
mp_load_const_dec,
mp_load_const_str,
mp_load_name,
mp_load_global,
mp_load_build_class,
mp_load_attr,
mp_load_method,
mp_store_name,
mp_store_attr,
mp_store_subscr,
mp_obj_is_true,
mp_unary_op,
mp_binary_op,
mp_build_tuple,
mp_build_list,
mp_list_append,
mp_build_map,
mp_store_map,
mp_build_set,
mp_store_set,
mp_make_function_from_id,
mp_call_function_n_kw_for_native,
mp_call_method_n_kw,
mp_getiter,
mp_iternext,
};
/*
void rt_f_vector(rt_fun_kind_t fun_kind) {
(rt_f_table[fun_kind])();
void mp_f_vector(mp_fun_kind_t fun_kind) {
(mp_f_table[fun_kind])();
}
*/

View File

@ -1,58 +1,64 @@
void rt_init(void);
void rt_deinit(void);
void mp_init(void);
void mp_deinit(void);
void rt_check_nargs(int n_args, machine_uint_t n_args_min, machine_uint_t n_args_max, int n_kw, bool is_kw);
void mp_check_nargs(int n_args, machine_uint_t n_args_min, machine_uint_t n_args_max, int n_kw, bool is_kw);
int rt_is_true(mp_obj_t arg);
struct _mp_map_t *mp_locals_get(void);
void mp_locals_set(struct _mp_map_t *m);
struct _mp_map_t *mp_globals_get(void);
void mp_globals_set(struct _mp_map_t *m);
mp_obj_t rt_load_const_dec(qstr qstr);
mp_obj_t rt_load_const_str(qstr qstr);
mp_obj_t rt_load_const_bytes(qstr qstr);
mp_obj_t rt_load_name(qstr qstr);
mp_obj_t rt_load_global(qstr qstr);
mp_obj_t rt_load_build_class(void);
mp_obj_t rt_get_cell(mp_obj_t cell);
void rt_set_cell(mp_obj_t cell, mp_obj_t val);
void rt_store_name(qstr qstr, mp_obj_t obj);
void rt_store_global(qstr qstr, mp_obj_t obj);
void rt_delete_name(qstr qstr);
mp_obj_t rt_unary_op(int op, mp_obj_t arg);
mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs);
mp_obj_t rt_make_function_from_id(uint unique_code_id, bool free_unique_code, mp_obj_t def_args);
mp_obj_t rt_make_function_n(int n_args, void *fun); // fun must have the correct signature for n_args fixed arguments
mp_obj_t rt_make_function_var(int n_args_min, mp_fun_var_t fun);
mp_obj_t rt_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var_t fun); // min and max are inclusive
mp_obj_t rt_make_closure_from_id(uint unique_code_id, mp_obj_t closure_tuple, mp_obj_t def_args);
mp_obj_t rt_call_function_0(mp_obj_t fun);
mp_obj_t rt_call_function_1(mp_obj_t fun, mp_obj_t arg);
mp_obj_t rt_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2);
mp_obj_t rt_call_function_n_kw_for_native(mp_obj_t fun_in, uint n_args_kw, const mp_obj_t *args);
mp_obj_t rt_call_function_n_kw(mp_obj_t fun, uint n_args, uint n_kw, const mp_obj_t *args);
mp_obj_t rt_call_method_n_kw(uint n_args, uint n_kw, const mp_obj_t *args);
mp_obj_t rt_build_tuple(int n_args, mp_obj_t *items);
mp_obj_t rt_build_list(int n_args, mp_obj_t *items);
mp_obj_t rt_list_append(mp_obj_t list, mp_obj_t arg);
mp_obj_t rt_build_set(int n_args, mp_obj_t *items);
mp_obj_t rt_store_set(mp_obj_t set, mp_obj_t item);
void rt_unpack_sequence(mp_obj_t seq, uint num, mp_obj_t *items);
mp_obj_t rt_build_map(int n_args);
mp_obj_t rt_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value);
mp_obj_t rt_load_attr(mp_obj_t base, qstr attr);
void rt_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest);
void rt_store_attr(mp_obj_t base, qstr attr, mp_obj_t val);
void rt_store_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val);
mp_obj_t rt_getiter(mp_obj_t o);
mp_obj_t rt_iternext_allow_raise(mp_obj_t o); // may return MP_OBJ_NULL instead of raising StopIteration()
mp_obj_t rt_iternext(mp_obj_t o); // will always return MP_OBJ_NULL instead of raising StopIteration(...)
mp_obj_t rt_make_raise_obj(mp_obj_t o);
mp_obj_t rt_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level);
mp_obj_t rt_import_from(mp_obj_t module, qstr name);
void rt_import_all(mp_obj_t module);
mp_obj_t mp_load_name(qstr qstr);
mp_obj_t mp_load_global(qstr qstr);
mp_obj_t mp_load_build_class(void);
void mp_store_name(qstr qstr, mp_obj_t obj);
void mp_store_global(qstr qstr, mp_obj_t obj);
void mp_delete_name(qstr qstr);
struct _mp_map_t;
struct _mp_map_t *rt_locals_get(void);
void rt_locals_set(struct _mp_map_t *m);
struct _mp_map_t *rt_globals_get(void);
void rt_globals_set(struct _mp_map_t *m);
struct _mp_map_t *rt_loaded_modules_get(void);
extern mp_obj_t sys_path;
mp_obj_t mp_unary_op(int op, mp_obj_t arg);
mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs);
mp_obj_t mp_load_const_dec(qstr qstr);
mp_obj_t mp_load_const_str(qstr qstr);
mp_obj_t mp_load_const_bytes(qstr qstr);
mp_obj_t mp_get_cell(mp_obj_t cell);
void mp_set_cell(mp_obj_t cell, mp_obj_t val);
mp_obj_t mp_make_function_from_id(uint unique_code_id, bool free_unique_code, mp_obj_t def_args);
mp_obj_t mp_make_function_n(int n_args, void *fun); // fun must have the correct signature for n_args fixed arguments
mp_obj_t mp_make_function_var(int n_args_min, mp_fun_var_t fun);
mp_obj_t mp_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var_t fun); // min and max are inclusive
mp_obj_t mp_make_closure_from_id(uint unique_code_id, mp_obj_t closure_tuple, mp_obj_t def_args);
mp_obj_t mp_call_function_0(mp_obj_t fun);
mp_obj_t mp_call_function_1(mp_obj_t fun, mp_obj_t arg);
mp_obj_t mp_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2);
mp_obj_t mp_call_function_n_kw_for_native(mp_obj_t fun_in, uint n_args_kw, const mp_obj_t *args);
mp_obj_t mp_call_function_n_kw(mp_obj_t fun, uint n_args, uint n_kw, const mp_obj_t *args);
mp_obj_t mp_call_method_n_kw(uint n_args, uint n_kw, const mp_obj_t *args);
mp_obj_t mp_build_tuple(int n_args, mp_obj_t *items);
mp_obj_t mp_build_list(int n_args, mp_obj_t *items);
mp_obj_t mp_list_append(mp_obj_t list, mp_obj_t arg);
mp_obj_t mp_build_set(int n_args, mp_obj_t *items);
mp_obj_t mp_store_set(mp_obj_t set, mp_obj_t item);
void mp_unpack_sequence(mp_obj_t seq, uint num, mp_obj_t *items);
mp_obj_t mp_build_map(int n_args);
mp_obj_t mp_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value);
mp_obj_t mp_load_attr(mp_obj_t base, qstr attr);
void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest);
void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t val);
void mp_store_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val);
mp_obj_t mp_getiter(mp_obj_t o);
mp_obj_t mp_iternext_allow_raise(mp_obj_t o); // may return MP_OBJ_NULL instead of raising StopIteration()
mp_obj_t mp_iternext(mp_obj_t o); // will always return MP_OBJ_NULL instead of raising StopIteration(...)
mp_obj_t mp_make_raise_obj(mp_obj_t o);
extern mp_obj_t mp_sys_path;
struct _mp_map_t *mp_loaded_modules_get(void);
mp_obj_t mp_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level);
mp_obj_t mp_import_from(mp_obj_t module, qstr name);
void mp_import_all(mp_obj_t module);

View File

@ -13,83 +13,83 @@
#define MP_SCOPE_FLAG_NOFREE 0x40
typedef enum {
RT_UNARY_OP_BOOL, // __bool__
RT_UNARY_OP_LEN, // __len__
RT_UNARY_OP_POSITIVE,
RT_UNARY_OP_NEGATIVE,
RT_UNARY_OP_INVERT,
MP_UNARY_OP_BOOL, // __bool__
MP_UNARY_OP_LEN, // __len__
MP_UNARY_OP_POSITIVE,
MP_UNARY_OP_NEGATIVE,
MP_UNARY_OP_INVERT,
// these are not supported by the runtime and must be synthesised by the emitter
RT_UNARY_OP_NOT,
} rt_unary_op_t;
MP_UNARY_OP_NOT,
} mp_unary_op_t;
typedef enum {
RT_BINARY_OP_SUBSCR,
RT_BINARY_OP_OR,
RT_BINARY_OP_XOR,
RT_BINARY_OP_AND,
RT_BINARY_OP_LSHIFT,
RT_BINARY_OP_RSHIFT,
RT_BINARY_OP_ADD,
RT_BINARY_OP_SUBTRACT,
RT_BINARY_OP_MULTIPLY,
RT_BINARY_OP_FLOOR_DIVIDE,
RT_BINARY_OP_TRUE_DIVIDE,
RT_BINARY_OP_MODULO,
RT_BINARY_OP_POWER,
RT_BINARY_OP_INPLACE_OR,
RT_BINARY_OP_INPLACE_XOR,
RT_BINARY_OP_INPLACE_AND,
RT_BINARY_OP_INPLACE_LSHIFT,
RT_BINARY_OP_INPLACE_RSHIFT,
RT_BINARY_OP_INPLACE_ADD,
RT_BINARY_OP_INPLACE_SUBTRACT,
RT_BINARY_OP_INPLACE_MULTIPLY,
RT_BINARY_OP_INPLACE_FLOOR_DIVIDE,
RT_BINARY_OP_INPLACE_TRUE_DIVIDE,
RT_BINARY_OP_INPLACE_MODULO,
RT_BINARY_OP_INPLACE_POWER,
MP_BINARY_OP_SUBSCR,
MP_BINARY_OP_OR,
MP_BINARY_OP_XOR,
MP_BINARY_OP_AND,
MP_BINARY_OP_LSHIFT,
MP_BINARY_OP_RSHIFT,
MP_BINARY_OP_ADD,
MP_BINARY_OP_SUBTRACT,
MP_BINARY_OP_MULTIPLY,
MP_BINARY_OP_FLOOR_DIVIDE,
MP_BINARY_OP_TRUE_DIVIDE,
MP_BINARY_OP_MODULO,
MP_BINARY_OP_POWER,
MP_BINARY_OP_INPLACE_OR,
MP_BINARY_OP_INPLACE_XOR,
MP_BINARY_OP_INPLACE_AND,
MP_BINARY_OP_INPLACE_LSHIFT,
MP_BINARY_OP_INPLACE_RSHIFT,
MP_BINARY_OP_INPLACE_ADD,
MP_BINARY_OP_INPLACE_SUBTRACT,
MP_BINARY_OP_INPLACE_MULTIPLY,
MP_BINARY_OP_INPLACE_FLOOR_DIVIDE,
MP_BINARY_OP_INPLACE_TRUE_DIVIDE,
MP_BINARY_OP_INPLACE_MODULO,
MP_BINARY_OP_INPLACE_POWER,
// these should return a bool
RT_BINARY_OP_LESS,
RT_BINARY_OP_MORE,
RT_BINARY_OP_EQUAL,
RT_BINARY_OP_LESS_EQUAL,
RT_BINARY_OP_MORE_EQUAL,
RT_BINARY_OP_NOT_EQUAL,
RT_BINARY_OP_IN,
RT_BINARY_OP_IS,
RT_BINARY_OP_EXCEPTION_MATCH,
MP_BINARY_OP_LESS,
MP_BINARY_OP_MORE,
MP_BINARY_OP_EQUAL,
MP_BINARY_OP_LESS_EQUAL,
MP_BINARY_OP_MORE_EQUAL,
MP_BINARY_OP_NOT_EQUAL,
MP_BINARY_OP_IN,
MP_BINARY_OP_IS,
MP_BINARY_OP_EXCEPTION_MATCH,
// these are not supported by the runtime and must be synthesised by the emitter
RT_BINARY_OP_NOT_IN,
RT_BINARY_OP_IS_NOT,
} rt_binary_op_t;
MP_BINARY_OP_NOT_IN,
MP_BINARY_OP_IS_NOT,
} mp_binary_op_t;
typedef enum {
RT_F_LOAD_CONST_DEC = 0,
RT_F_LOAD_CONST_STR,
RT_F_LOAD_NAME,
RT_F_LOAD_GLOBAL,
RT_F_LOAD_BUILD_CLASS,
RT_F_LOAD_ATTR,
RT_F_LOAD_METHOD,
RT_F_STORE_NAME,
RT_F_STORE_ATTR,
RT_F_STORE_SUBSCR,
RT_F_IS_TRUE,
RT_F_UNARY_OP,
RT_F_BINARY_OP,
RT_F_BUILD_TUPLE,
RT_F_BUILD_LIST,
RT_F_LIST_APPEND,
RT_F_BUILD_MAP,
RT_F_STORE_MAP,
RT_F_BUILD_SET,
RT_F_STORE_SET,
RT_F_MAKE_FUNCTION_FROM_ID,
RT_F_CALL_FUNCTION_N_KW_FOR_NATIVE,
RT_F_CALL_METHOD_N_KW,
RT_F_GETITER,
RT_F_ITERNEXT,
RT_F_NUMBER_OF,
} rt_fun_kind_t;
MP_F_LOAD_CONST_DEC = 0,
MP_F_LOAD_CONST_STR,
MP_F_LOAD_NAME,
MP_F_LOAD_GLOBAL,
MP_F_LOAD_BUILD_CLASS,
MP_F_LOAD_ATTR,
MP_F_LOAD_METHOD,
MP_F_STORE_NAME,
MP_F_STORE_ATTR,
MP_F_STORE_SUBSCR,
MP_F_OBJ_IS_TRUE,
MP_F_UNARY_OP,
MP_F_BINARY_OP,
MP_F_BUILD_TUPLE,
MP_F_BUILD_LIST,
MP_F_LIST_APPEND,
MP_F_BUILD_MAP,
MP_F_STORE_MAP,
MP_F_BUILD_SET,
MP_F_STORE_SET,
MP_F_MAKE_FUNCTION_FROM_ID,
MP_F_CALL_FUNCTION_N_KW_FOR_NATIVE,
MP_F_CALL_METHOD_N_KW,
MP_F_GETITER,
MP_F_ITERNEXT,
MP_F_NUMBER_OF,
} mp_fun_kind_t;
extern void *const rt_fun_table[RT_F_NUMBER_OF];
extern void *const mp_fun_table[MP_F_NUMBER_OF];

View File

@ -55,16 +55,16 @@ bool m_seq_get_fast_slice_indexes(machine_uint_t len, mp_obj_t slice, machine_ui
}
// Special-case comparison function for sequences of bytes
// Don't pass RT_BINARY_OP_NOT_EQUAL here
// Don't pass MP_BINARY_OP_NOT_EQUAL here
bool mp_seq_cmp_bytes(int op, const byte *data1, uint len1, const byte *data2, uint len2) {
// Let's deal only with > & >=
if (op == RT_BINARY_OP_LESS || op == RT_BINARY_OP_LESS_EQUAL) {
if (op == MP_BINARY_OP_LESS || op == MP_BINARY_OP_LESS_EQUAL) {
SWAP(const byte*, data1, data2);
SWAP(uint, len1, len2);
if (op == RT_BINARY_OP_LESS) {
op = RT_BINARY_OP_MORE;
if (op == MP_BINARY_OP_LESS) {
op = MP_BINARY_OP_MORE;
} else {
op = RT_BINARY_OP_MORE_EQUAL;
op = MP_BINARY_OP_MORE_EQUAL;
}
}
uint min_len = len1 < len2 ? len1 : len2;
@ -83,7 +83,7 @@ bool mp_seq_cmp_bytes(int op, const byte *data1, uint len1, const byte *data2, u
// ... then longer list length wins (we deal only with >)
return false;
}
} else if (op == RT_BINARY_OP_MORE) {
} else if (op == MP_BINARY_OP_MORE) {
// Otherwise, if we have strict relation, equality means failure
return false;
}
@ -91,20 +91,20 @@ bool mp_seq_cmp_bytes(int op, const byte *data1, uint len1, const byte *data2, u
}
// Special-case comparison function for sequences of mp_obj_t
// Don't pass RT_BINARY_OP_NOT_EQUAL here
// Don't pass MP_BINARY_OP_NOT_EQUAL here
bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t *items2, uint len2) {
if (op == RT_BINARY_OP_EQUAL && len1 != len2) {
if (op == MP_BINARY_OP_EQUAL && len1 != len2) {
return false;
}
// Let's deal only with > & >=
if (op == RT_BINARY_OP_LESS || op == RT_BINARY_OP_LESS_EQUAL) {
if (op == MP_BINARY_OP_LESS || op == MP_BINARY_OP_LESS_EQUAL) {
SWAP(const mp_obj_t *, items1, items2);
SWAP(uint, len1, len2);
if (op == RT_BINARY_OP_LESS) {
op = RT_BINARY_OP_MORE;
if (op == MP_BINARY_OP_LESS) {
op = MP_BINARY_OP_MORE;
} else {
op = RT_BINARY_OP_MORE_EQUAL;
op = MP_BINARY_OP_MORE_EQUAL;
}
}
@ -113,10 +113,10 @@ bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t *
bool rel_status;
for (int i = 0; i < len; i++) {
eq_status = mp_obj_equal(items1[i], items2[i]);
if (op == RT_BINARY_OP_EQUAL && !eq_status) {
if (op == MP_BINARY_OP_EQUAL && !eq_status) {
return false;
}
rel_status = (rt_binary_op(op, items1[i], items2[i]) == mp_const_true);
rel_status = (mp_binary_op(op, items1[i], items2[i]) == mp_const_true);
if (!eq_status && !rel_status) {
return false;
}
@ -130,7 +130,7 @@ bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t *
// ... then longer list length wins (we deal only with >)
return false;
}
} else if (op == RT_BINARY_OP_MORE) {
} else if (op == MP_BINARY_OP_MORE) {
// Otherwise, if we have strict relation, equality means failure
return false;
}

104
py/vm.c
View File

@ -157,7 +157,7 @@ outer_dispatch_loop:
if (inject_exc != MP_OBJ_NULL && *ip != MP_BC_YIELD_FROM) {
mp_obj_t t = inject_exc;
inject_exc = MP_OBJ_NULL;
nlr_jump(rt_make_raise_obj(t));
nlr_jump(mp_make_raise_obj(t));
}
// loop to execute byte code
for (;;) {
@ -201,22 +201,22 @@ dispatch_loop:
case MP_BC_LOAD_CONST_DEC:
DECODE_QSTR;
PUSH(rt_load_const_dec(qst));
PUSH(mp_load_const_dec(qst));
break;
case MP_BC_LOAD_CONST_ID:
DECODE_QSTR;
PUSH(rt_load_const_str(qst)); // TODO
PUSH(mp_load_const_str(qst)); // TODO
break;
case MP_BC_LOAD_CONST_BYTES:
DECODE_QSTR;
PUSH(rt_load_const_bytes(qst));
PUSH(mp_load_const_bytes(qst));
break;
case MP_BC_LOAD_CONST_STRING:
DECODE_QSTR;
PUSH(rt_load_const_str(qst));
PUSH(mp_load_const_str(qst));
break;
case MP_BC_LOAD_FAST_0:
@ -238,32 +238,32 @@ dispatch_loop:
case MP_BC_LOAD_DEREF:
DECODE_UINT;
PUSH(rt_get_cell(fastn[-unum]));
PUSH(mp_get_cell(fastn[-unum]));
break;
case MP_BC_LOAD_NAME:
DECODE_QSTR;
PUSH(rt_load_name(qst));
PUSH(mp_load_name(qst));
break;
case MP_BC_LOAD_GLOBAL:
DECODE_QSTR;
PUSH(rt_load_global(qst));
PUSH(mp_load_global(qst));
break;
case MP_BC_LOAD_ATTR:
DECODE_QSTR;
SET_TOP(rt_load_attr(TOP(), qst));
SET_TOP(mp_load_attr(TOP(), qst));
break;
case MP_BC_LOAD_METHOD:
DECODE_QSTR;
rt_load_method(*sp, qst, sp);
mp_load_method(*sp, qst, sp);
sp += 1;
break;
case MP_BC_LOAD_BUILD_CLASS:
PUSH(rt_load_build_class());
PUSH(mp_load_build_class());
break;
case MP_BC_STORE_FAST_0:
@ -285,33 +285,33 @@ dispatch_loop:
case MP_BC_STORE_DEREF:
DECODE_UINT;
rt_set_cell(fastn[-unum], POP());
mp_set_cell(fastn[-unum], POP());
break;
case MP_BC_STORE_NAME:
DECODE_QSTR;
rt_store_name(qst, POP());
mp_store_name(qst, POP());
break;
case MP_BC_STORE_GLOBAL:
DECODE_QSTR;
rt_store_global(qst, POP());
mp_store_global(qst, POP());
break;
case MP_BC_STORE_ATTR:
DECODE_QSTR;
rt_store_attr(sp[0], qst, sp[-1]);
mp_store_attr(sp[0], qst, sp[-1]);
sp -= 2;
break;
case MP_BC_STORE_SUBSCR:
rt_store_subscr(sp[-1], sp[0], sp[-2]);
mp_store_subscr(sp[-1], sp[0], sp[-2]);
sp -= 3;
break;
case MP_BC_DELETE_NAME:
DECODE_QSTR;
rt_delete_name(qst);
mp_delete_name(qst);
break;
case MP_BC_DUP_TOP:
@ -349,21 +349,21 @@ dispatch_loop:
case MP_BC_POP_JUMP_IF_TRUE:
DECODE_SLABEL;
if (rt_is_true(POP())) {
if (mp_obj_is_true(POP())) {
ip += unum;
}
break;
case MP_BC_POP_JUMP_IF_FALSE:
DECODE_SLABEL;
if (!rt_is_true(POP())) {
if (!mp_obj_is_true(POP())) {
ip += unum;
}
break;
case MP_BC_JUMP_IF_TRUE_OR_POP:
DECODE_SLABEL;
if (rt_is_true(TOP())) {
if (mp_obj_is_true(TOP())) {
ip += unum;
} else {
sp--;
@ -372,7 +372,7 @@ dispatch_loop:
case MP_BC_JUMP_IF_FALSE_OR_POP:
DECODE_SLABEL;
if (rt_is_true(TOP())) {
if (mp_obj_is_true(TOP())) {
sp--;
} else {
ip += unum;
@ -388,9 +388,9 @@ dispatch_loop:
case MP_BC_SETUP_WITH:
obj1 = TOP();
SET_TOP(rt_load_attr(obj1, MP_QSTR___exit__));
rt_load_method(obj1, MP_QSTR___enter__, sp + 1);
obj2 = rt_call_method_n_kw(0, 0, sp + 1);
SET_TOP(mp_load_attr(obj1, MP_QSTR___exit__));
mp_load_method(obj1, MP_QSTR___enter__, sp + 1);
obj2 = mp_call_method_n_kw(0, 0, sp + 1);
PUSH_EXC_BLOCK();
PUSH(obj2);
break;
@ -405,19 +405,19 @@ dispatch_loop:
sp--;
obj1 = TOP();
SET_TOP(mp_const_none);
obj2 = rt_call_function_n_kw(obj1, 3, 0, no_exc);
obj2 = mp_call_function_n_kw(obj1, 3, 0, no_exc);
} else if (MP_OBJ_IS_SMALL_INT(TOP())) {
mp_obj_t cause = POP();
switch (MP_OBJ_SMALL_INT_VALUE(cause)) {
case UNWIND_RETURN: {
mp_obj_t retval = POP();
obj2 = rt_call_function_n_kw(TOP(), 3, 0, no_exc);
obj2 = mp_call_function_n_kw(TOP(), 3, 0, no_exc);
SET_TOP(retval);
PUSH(cause);
break;
}
case UNWIND_JUMP: {
obj2 = rt_call_function_n_kw(sp[-2], 3, 0, no_exc);
obj2 = mp_call_function_n_kw(sp[-2], 3, 0, no_exc);
// Pop __exit__ boundmethod at sp[-2]
sp[-2] = sp[-1];
sp[-1] = sp[0];
@ -429,14 +429,14 @@ dispatch_loop:
}
} else if (mp_obj_is_exception_type(TOP())) {
mp_obj_t args[3] = {sp[0], sp[-1], sp[-2]};
obj2 = rt_call_function_n_kw(sp[-3], 3, 0, args);
obj2 = mp_call_function_n_kw(sp[-3], 3, 0, args);
// Pop __exit__ boundmethod at sp[-3]
// TODO: Once semantics is proven, optimize for case when obj2 == True
sp[-3] = sp[-2];
sp[-2] = sp[-1];
sp[-1] = sp[0];
sp--;
if (rt_is_true(obj2)) {
if (mp_obj_is_true(obj2)) {
// This is what CPython does
//PUSH(MP_OBJ_NEW_SMALL_INT(UNWIND_SILENCED));
// But what we need to do is - pop exception from value stack...
@ -514,12 +514,12 @@ unwind_jump:
break;
case MP_BC_GET_ITER:
SET_TOP(rt_getiter(TOP()));
SET_TOP(mp_getiter(TOP()));
break;
case MP_BC_FOR_ITER:
DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward
obj1 = rt_iternext_allow_raise(TOP());
obj1 = mp_iternext_allow_raise(TOP());
if (obj1 == MP_OBJ_NULL) {
--sp; // pop the exhausted iterator
ip += unum; // jump to after for-block
@ -557,62 +557,62 @@ unwind_jump:
case MP_BC_UNARY_OP:
unum = *ip++;
SET_TOP(rt_unary_op(unum, TOP()));
SET_TOP(mp_unary_op(unum, TOP()));
break;
case MP_BC_BINARY_OP:
unum = *ip++;
obj2 = POP();
obj1 = TOP();
SET_TOP(rt_binary_op(unum, obj1, obj2));
SET_TOP(mp_binary_op(unum, obj1, obj2));
break;
case MP_BC_BUILD_TUPLE:
DECODE_UINT;
sp -= unum - 1;
SET_TOP(rt_build_tuple(unum, sp));
SET_TOP(mp_build_tuple(unum, sp));
break;
case MP_BC_BUILD_LIST:
DECODE_UINT;
sp -= unum - 1;
SET_TOP(rt_build_list(unum, sp));
SET_TOP(mp_build_list(unum, sp));
break;
case MP_BC_LIST_APPEND:
DECODE_UINT;
// I think it's guaranteed by the compiler that sp[unum] is a list
rt_list_append(sp[-unum], sp[0]);
mp_list_append(sp[-unum], sp[0]);
sp--;
break;
case MP_BC_BUILD_MAP:
DECODE_UINT;
PUSH(rt_build_map(unum));
PUSH(mp_build_map(unum));
break;
case MP_BC_STORE_MAP:
sp -= 2;
rt_store_map(sp[0], sp[2], sp[1]);
mp_store_map(sp[0], sp[2], sp[1]);
break;
case MP_BC_MAP_ADD:
DECODE_UINT;
// I think it's guaranteed by the compiler that sp[-unum - 1] is a map
rt_store_map(sp[-unum - 1], sp[0], sp[-1]);
mp_store_map(sp[-unum - 1], sp[0], sp[-1]);
sp -= 2;
break;
case MP_BC_BUILD_SET:
DECODE_UINT;
sp -= unum - 1;
SET_TOP(rt_build_set(unum, sp));
SET_TOP(mp_build_set(unum, sp));
break;
case MP_BC_SET_ADD:
DECODE_UINT;
// I think it's guaranteed by the compiler that sp[-unum] is a set
rt_store_set(sp[-unum], sp[0]);
mp_store_set(sp[-unum], sp[0]);
sp--;
break;
@ -632,29 +632,29 @@ unwind_jump:
case MP_BC_UNPACK_SEQUENCE:
DECODE_UINT;
rt_unpack_sequence(sp[0], unum, sp);
mp_unpack_sequence(sp[0], unum, sp);
sp += unum - 1;
break;
case MP_BC_MAKE_FUNCTION:
DECODE_UINT;
PUSH(rt_make_function_from_id(unum, false, MP_OBJ_NULL));
PUSH(mp_make_function_from_id(unum, false, MP_OBJ_NULL));
break;
case MP_BC_MAKE_FUNCTION_DEFARGS:
DECODE_UINT;
SET_TOP(rt_make_function_from_id(unum, false, TOP()));
SET_TOP(mp_make_function_from_id(unum, false, TOP()));
break;
case MP_BC_MAKE_CLOSURE:
DECODE_UINT;
SET_TOP(rt_make_closure_from_id(unum, TOP(), MP_OBJ_NULL));
SET_TOP(mp_make_closure_from_id(unum, TOP(), MP_OBJ_NULL));
break;
case MP_BC_MAKE_CLOSURE_DEFARGS:
DECODE_UINT;
obj1 = POP();
SET_TOP(rt_make_closure_from_id(unum, obj1, TOP()));
SET_TOP(mp_make_closure_from_id(unum, obj1, TOP()));
break;
case MP_BC_CALL_FUNCTION:
@ -662,7 +662,7 @@ unwind_jump:
// unum & 0xff == n_positional
// (unum >> 8) & 0xff == n_keyword
sp -= (unum & 0xff) + ((unum >> 7) & 0x1fe);
SET_TOP(rt_call_function_n_kw(*sp, unum & 0xff, (unum >> 8) & 0xff, sp + 1));
SET_TOP(mp_call_function_n_kw(*sp, unum & 0xff, (unum >> 8) & 0xff, sp + 1));
break;
case MP_BC_CALL_METHOD:
@ -670,7 +670,7 @@ unwind_jump:
// unum & 0xff == n_positional
// (unum >> 8) & 0xff == n_keyword
sp -= (unum & 0xff) + ((unum >> 7) & 0x1fe) + 1;
SET_TOP(rt_call_method_n_kw(unum & 0xff, (unum >> 8) & 0xff, sp));
SET_TOP(mp_call_method_n_kw(unum & 0xff, (unum >> 8) & 0xff, sp));
break;
case MP_BC_RETURN_VALUE:
@ -714,7 +714,7 @@ unwind_return:
} else {
obj1 = POP();
}
nlr_jump(rt_make_raise_obj(obj1));
nlr_jump(mp_make_raise_obj(obj1));
case MP_BC_YIELD_VALUE:
yield:
@ -778,17 +778,17 @@ yield:
case MP_BC_IMPORT_NAME:
DECODE_QSTR;
obj1 = POP();
SET_TOP(rt_import_name(qst, obj1, TOP()));
SET_TOP(mp_import_name(qst, obj1, TOP()));
break;
case MP_BC_IMPORT_FROM:
DECODE_QSTR;
obj1 = rt_import_from(TOP(), qst);
obj1 = mp_import_from(TOP(), qst);
PUSH(obj1);
break;
case MP_BC_IMPORT_STAR:
rt_import_all(POP());
mp_import_all(POP());
break;
default:

View File

@ -268,7 +268,7 @@ mp_obj_t pyb_accel_read(void) {
data[2] = mp_obj_new_int(accel_buf[2] + accel_buf[5] + accel_buf[8] + accel_buf[11]);
data[3] = mp_obj_new_int(jolt_info);
return rt_build_tuple(4, data);
return mp_build_tuple(4, data);
}
MP_DEFINE_CONST_FUN_OBJ_0(pyb_accel_read_obj, pyb_accel_read);
@ -283,7 +283,7 @@ mp_obj_t pyb_accel_read_all(void) {
}
data[10] = mp_obj_new_int(accel_read_nack());
return rt_build_tuple(11, data);
return mp_build_tuple(11, data);
}
MP_DEFINE_CONST_FUN_OBJ_0(pyb_accel_read_all_obj, pyb_accel_read_all);

View File

@ -284,7 +284,7 @@ static void exti_load_attr(mp_obj_t self_in, qstr attr_qstr, mp_obj_t *dest) {
static mp_obj_t exti_call(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
// type_in == exti_obj_type
rt_check_nargs(n_args, 4, 4, n_kw, 0);
mp_check_nargs(n_args, 4, 4, n_kw, 0);
exti_obj_t *self = m_new_obj(exti_obj_t);
self->base.type = type_in;
@ -336,7 +336,7 @@ static void Handle_EXTI_Irq(uint32_t line) {
if (line < EXTI_NUM_VECTORS) {
exti_vector_t *v = &exti_vector[line];
if (v->callback_obj != mp_const_none) {
rt_call_function_1(v->callback_obj, MP_OBJ_NEW_SMALL_INT(line));
mp_call_function_1(v->callback_obj, MP_OBJ_NEW_SMALL_INT(line));
}
}
}

View File

@ -46,7 +46,7 @@ mp_obj_t pyb_gpio(uint n_args, mp_obj_t *args) {
}
} else {
// set pin
if (rt_is_true(args[1])) {
if (mp_obj_is_true(args[1])) {
// set pin high
port->BSRRL = pin_mask;
} else {

View File

@ -209,7 +209,7 @@ mp_obj_t lcd_print(mp_obj_t text) {
mp_obj_t lcd_light(mp_obj_t value) {
#if defined(PYB_LCD_BL_PORT)
if (rt_is_true(value)) {
if (mp_obj_is_true(value)) {
PYB_LCD_BL_PORT->BSRRL = PYB_LCD_BL_PIN; // set pin high to turn backlight on
} else {
PYB_LCD_BL_PORT->BSRRH = PYB_LCD_BL_PIN; // set pin low to turn backlight off
@ -288,14 +288,14 @@ static mp_obj_t pyb_lcd_init(void) {
// Micro Python interface
mp_obj_t o = mp_obj_new_type(MP_QSTR_LCD, mp_const_empty_tuple, mp_obj_new_dict(0));
rt_store_attr(o, qstr_from_str("lcd8"), rt_make_function_n(2, lcd_draw_pixel_8));
rt_store_attr(o, qstr_from_str("clear"), rt_make_function_n(0, lcd_pix_clear));
rt_store_attr(o, qstr_from_str("get"), rt_make_function_n(2, lcd_pix_get));
rt_store_attr(o, qstr_from_str("set"), rt_make_function_n(2, lcd_pix_set));
rt_store_attr(o, qstr_from_str("reset"), rt_make_function_n(2, lcd_pix_reset));
rt_store_attr(o, qstr_from_str("show"), rt_make_function_n(0, lcd_pix_show));
rt_store_attr(o, qstr_from_str("text"), rt_make_function_n(1, lcd_print));
rt_store_attr(o, qstr_from_str("light"), rt_make_function_n(1, lcd_light));
mp_store_attr(o, qstr_from_str("lcd8"), mp_make_function_n(2, lcd_draw_pixel_8));
mp_store_attr(o, qstr_from_str("clear"), mp_make_function_n(0, lcd_pix_clear));
mp_store_attr(o, qstr_from_str("get"), mp_make_function_n(2, lcd_pix_get));
mp_store_attr(o, qstr_from_str("set"), mp_make_function_n(2, lcd_pix_set));
mp_store_attr(o, qstr_from_str("reset"), mp_make_function_n(2, lcd_pix_reset));
mp_store_attr(o, qstr_from_str("show"), mp_make_function_n(0, lcd_pix_show));
mp_store_attr(o, qstr_from_str("text"), mp_make_function_n(1, lcd_print));
mp_store_attr(o, qstr_from_str("light"), mp_make_function_n(1, lcd_light));
mp_lcd = o;
return o;
}
@ -304,7 +304,7 @@ static MP_DEFINE_CONST_FUN_OBJ_0(pyb_lcd_init_obj, pyb_lcd_init);
void lcd_init(void) {
mp_lcd = MP_OBJ_NULL;
rt_store_name(qstr_from_str("LCD"), (mp_obj_t)&pyb_lcd_init_obj);
mp_store_name(qstr_from_str("LCD"), (mp_obj_t)&pyb_lcd_init_obj);
}
void lcd_print_str(const char *str) {

View File

@ -233,12 +233,12 @@ soft_reset:
// Micro Python init
qstr_init();
rt_init();
mp_init();
mp_obj_t def_path[3];
def_path[0] = MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_);
def_path[1] = MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_src);
def_path[2] = MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_lib);
sys_path = mp_obj_new_list(3, def_path);
mp_sys_path = mp_obj_new_list(3, def_path);
exti_init();
@ -270,8 +270,8 @@ soft_reset:
pin_map_init();
// add some functions to the builtin Python namespace
rt_store_name(MP_QSTR_help, rt_make_function_n(0, pyb_help));
rt_store_name(MP_QSTR_open, rt_make_function_n(2, pyb_io_open));
mp_store_name(MP_QSTR_help, mp_make_function_n(0, pyb_help));
mp_store_name(MP_QSTR_open, mp_make_function_n(2, pyb_io_open));
// load the pyb module
mp_module_register(MP_QSTR_pyb, (mp_obj_t)&pyb_module);

View File

@ -69,7 +69,7 @@ static void pin_map_obj_print(void (*print)(void *env, const char *fmt, ...), vo
static mp_obj_t pin_map_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args) {
pin_map_obj_t *self = self_in;
rt_check_nargs(n_args, 1, 2, n_kw, false);
mp_check_nargs(n_args, 1, 2, n_kw, false);
if (n_args > 1) {
if (!self->map_dict) {
@ -96,7 +96,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_map_obj_mapper_obj, 1, 2, pin_map
static mp_obj_t pin_map_obj_debug(uint n_args, mp_obj_t *args) {
pin_map_obj_t *self = args[0];
if (n_args > 1) {
self->debug = rt_is_true(args[1]);
self->debug = mp_obj_is_true(args[1]);
return mp_const_none;
}
return MP_BOOL(self->debug);
@ -162,7 +162,7 @@ const pin_obj_t *pin_map_user_obj(mp_obj_t user_obj) {
}
if (pin_map_obj.mapper) {
pin_obj = rt_call_function_1(pin_map_obj.mapper, user_obj);
pin_obj = mp_call_function_1(pin_map_obj.mapper, user_obj);
if (pin_obj != mp_const_none) {
if (!MP_OBJ_IS_TYPE(pin_obj, &pin_obj_type)) {
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin.mapper didn't return a Pin object"));

View File

@ -154,7 +154,7 @@ bool parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, bo
uint32_t start = sys_tick_counter;
if (nlr_push(&nlr) == 0) {
usb_vcp_set_interrupt_char(VCP_CHAR_CTRL_C); // allow ctrl-C to interrupt us
rt_call_function_0(module_fun);
mp_call_function_0(module_fun);
usb_vcp_set_interrupt_char(VCP_CHAR_NONE); // disable interrupt
nlr_pop();
ret = true;
@ -238,8 +238,8 @@ raw_repl_reset:
void pyexec_repl(void) {
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
// in host mode, we enable the LCD for the repl
mp_obj_t lcd_o = rt_call_function_0(rt_load_name(qstr_from_str("LCD")));
rt_call_function_1(rt_load_attr(lcd_o, qstr_from_str("light")), mp_const_true);
mp_obj_t lcd_o = mp_call_function_0(mp_load_name(qstr_from_str("LCD")));
mp_call_function_1(mp_load_attr(lcd_o, qstr_from_str("light")), mp_const_true);
#endif
stdout_tx_str("Micro Python build <git hash> on 25/1/2014; " MICROPY_HW_BOARD_NAME " with STM32F405RG\r\n");

View File

@ -173,7 +173,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(sd_present_obj, sd_present);
static mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) {
bool result;
if (rt_is_true(state)) {
if (mp_obj_is_true(state)) {
result = sdcard_power_on();
} else {
sdcard_power_off();

View File

@ -74,11 +74,11 @@ void timer_init(void) {
// Python interface
mp_obj_t m = mp_obj_new_module(QSTR_FROM_STR_STATIC("timer"));
rt_store_attr(m, QSTR_FROM_STR_STATIC("callback"), rt_make_function_n(1, timer_py_set_callback));
rt_store_attr(m, QSTR_FROM_STR_STATIC("period"), rt_make_function_n(1, timer_py_set_period));
rt_store_attr(m, QSTR_FROM_STR_STATIC("prescaler"), rt_make_function_n(1, timer_py_set_prescaler));
rt_store_attr(m, QSTR_FROM_STR_STATIC("value"), rt_make_function_n(0, timer_py_get_value));
rt_store_name(QSTR_FROM_STR_STATIC("timer"), m);
mp_store_attr(m, QSTR_FROM_STR_STATIC("callback"), mp_make_function_n(1, timer_py_set_callback));
mp_store_attr(m, QSTR_FROM_STR_STATIC("period"), mp_make_function_n(1, timer_py_set_period));
mp_store_attr(m, QSTR_FROM_STR_STATIC("prescaler"), mp_make_function_n(1, timer_py_set_prescaler));
mp_store_attr(m, QSTR_FROM_STR_STATIC("value"), mp_make_function_n(0, timer_py_get_value));
mp_store_name(QSTR_FROM_STR_STATIC("timer"), m);
}
void timer_interrupt(void) {
@ -86,7 +86,7 @@ void timer_interrupt(void) {
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
// XXX what to do if the GC is in the middle of running??
rt_call_function_0(timer_py_callback);
mp_call_function_0(timer_py_callback);
nlr_pop();
} else {
// uncaught exception

View File

@ -33,7 +33,7 @@ static mp_obj_t switch_user_callback_obj;
static mp_obj_t switch_callback(mp_obj_t line) {
if (switch_user_callback_obj != mp_const_none) {
rt_call_function_0(switch_user_callback_obj);
mp_call_function_0(switch_user_callback_obj);
}
return mp_const_none;
}

View File

@ -76,7 +76,7 @@ STATIC pyb_accel_obj_t pyb_accel_obj;
STATIC mp_obj_t pyb_accel_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
// check arguments
rt_check_nargs(n_args, 0, 0, n_kw, false);
mp_check_nargs(n_args, 0, 0, n_kw, false);
// init accel object
pyb_accel_obj.base.type = &pyb_accel_type;
@ -135,7 +135,7 @@ STATIC mp_obj_t pyb_accel_filtered_xyz(mp_obj_t self_in) {
tuple[i] = mp_obj_new_int(val);
}
return rt_build_tuple(3, tuple);
return mp_build_tuple(3, tuple);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_filtered_xyz_obj, pyb_accel_filtered_xyz);

View File

@ -119,7 +119,7 @@ STATIC void adc_print(void (*print)(void *env, const char *fmt, ...), void *env,
STATIC mp_obj_t adc_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
// check number of arguments
rt_check_nargs(n_args, 1, 1, n_kw, false);
mp_check_nargs(n_args, 1, 1, n_kw, false);
// 1st argument is the pin name
mp_obj_t pin_obj = args[0];

View File

@ -65,7 +65,7 @@ STATIC pyb_dac_obj_t pyb_dac_channel_2 = {{&pyb_dac_type}, DAC_CHANNEL_2, DMA1_S
STATIC mp_obj_t pyb_dac_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
// check arguments
rt_check_nargs(n_args, 1, 1, n_kw, false);
mp_check_nargs(n_args, 1, 1, n_kw, false);
machine_int_t dac_id = mp_obj_get_int(args[0]);
uint32_t pin;

View File

@ -264,7 +264,7 @@ STATIC MP_DEFINE_CONST_DICT(exti_locals_dict, exti_locals_dict_table);
STATIC mp_obj_t exti_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
// type_in == exti_obj_type
rt_check_nargs(n_args, 4, 4, n_kw, false);
mp_check_nargs(n_args, 4, 4, n_kw, false);
exti_obj_t *self = m_new_obj(exti_obj_t);
self->base.type = type_in;
@ -305,7 +305,7 @@ void Handle_EXTI_Irq(uint32_t line) {
exti_vector_t *v = &exti_vector[line];
if (v->callback_obj != mp_const_none) {
// TODO need to wrap this in an nlr_buf; really need a general function for this
rt_call_function_1(v->callback_obj, MP_OBJ_NEW_SMALL_INT(line));
mp_call_function_1(v->callback_obj, MP_OBJ_NEW_SMALL_INT(line));
}
}
}

View File

@ -27,7 +27,7 @@ mp_obj_t pyb_gpio(uint n_args, mp_obj_t *args) {
}
// set pin
HAL_GPIO_WritePin(pin->gpio, pin->pin_mask, rt_is_true(args[1]));
HAL_GPIO_WritePin(pin->gpio, pin->pin_mask, mp_obj_is_true(args[1]));
return mp_const_none;
}

View File

@ -80,7 +80,7 @@ STATIC pyb_i2c_obj_t pyb_i2c_obj[PYB_NUM_I2C] = {{{&pyb_i2c_type}, &I2cHandle_X}
STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
// check arguments
rt_check_nargs(n_args, 1, 1, n_kw, false);
mp_check_nargs(n_args, 1, 1, n_kw, false);
// get i2c number
machine_int_t i2c_id = mp_obj_get_int(args[0]) - 1;

View File

@ -214,7 +214,7 @@ mp_obj_t lcd_print(mp_obj_t text) {
mp_obj_t lcd_light(mp_obj_t value) {
#if defined(PYB_LCD_BL_PORT)
if (rt_is_true(value)) {
if (mp_obj_is_true(value)) {
PYB_LCD_BL_PORT->BSRRL = PYB_LCD_BL_PIN; // set pin high to turn backlight on
} else {
PYB_LCD_BL_PORT->BSRRH = PYB_LCD_BL_PIN; // set pin low to turn backlight off
@ -291,14 +291,14 @@ static mp_obj_t pyb_lcd_init(void) {
// Micro Python interface
mp_obj_t o = mp_obj_new_type(MP_QSTR_LCD, mp_const_empty_tuple, mp_obj_new_dict(0));
rt_store_attr(o, qstr_from_str("lcd8"), rt_make_function_n(2, lcd_draw_pixel_8));
rt_store_attr(o, qstr_from_str("clear"), rt_make_function_n(0, lcd_pix_clear));
rt_store_attr(o, qstr_from_str("get"), rt_make_function_n(2, lcd_pix_get));
rt_store_attr(o, qstr_from_str("set"), rt_make_function_n(2, lcd_pix_set));
rt_store_attr(o, qstr_from_str("reset"), rt_make_function_n(2, lcd_pix_reset));
rt_store_attr(o, qstr_from_str("show"), rt_make_function_n(0, lcd_pix_show));
rt_store_attr(o, qstr_from_str("text"), rt_make_function_n(1, lcd_print));
rt_store_attr(o, qstr_from_str("light"), rt_make_function_n(1, lcd_light));
mp_store_attr(o, qstr_from_str("lcd8"), mp_make_function_n(2, lcd_draw_pixel_8));
mp_store_attr(o, qstr_from_str("clear"), mp_make_function_n(0, lcd_pix_clear));
mp_store_attr(o, qstr_from_str("get"), mp_make_function_n(2, lcd_pix_get));
mp_store_attr(o, qstr_from_str("set"), mp_make_function_n(2, lcd_pix_set));
mp_store_attr(o, qstr_from_str("reset"), mp_make_function_n(2, lcd_pix_reset));
mp_store_attr(o, qstr_from_str("show"), mp_make_function_n(0, lcd_pix_show));
mp_store_attr(o, qstr_from_str("text"), mp_make_function_n(1, lcd_print));
mp_store_attr(o, qstr_from_str("light"), mp_make_function_n(1, lcd_light));
mp_lcd = o;
return o;
}
@ -307,7 +307,7 @@ static MP_DEFINE_CONST_FUN_OBJ_0(pyb_lcd_init_obj, pyb_lcd_init);
void lcd_init(void) {
mp_lcd = MP_OBJ_NULL;
rt_store_name(qstr_from_str("LCD"), (mp_obj_t)&pyb_lcd_init_obj);
mp_store_name(qstr_from_str("LCD"), (mp_obj_t)&pyb_lcd_init_obj);
}
void lcd_print_str(const char *str) {

View File

@ -208,7 +208,7 @@ void led_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp
STATIC mp_obj_t led_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
// check arguments
rt_check_nargs(n_args, 1, 1, n_kw, false);
mp_check_nargs(n_args, 1, 1, n_kw, false);
// get led number
machine_int_t led_id = mp_obj_get_int(args[0]) - 1;

View File

@ -251,12 +251,12 @@ soft_reset:
// Micro Python init
qstr_init();
rt_init();
mp_init();
mp_obj_t def_path[3];
def_path[0] = MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_);
def_path[1] = MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_src);
def_path[2] = MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_lib);
sys_path = mp_obj_new_list(3, def_path);
mp_sys_path = mp_obj_new_list(3, def_path);
readline_init();

View File

@ -69,7 +69,7 @@ static void pin_map_obj_print(void (*print)(void *env, const char *fmt, ...), vo
static mp_obj_t pin_map_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args) {
pin_map_obj_t *self = self_in;
rt_check_nargs(n_args, 1, 2, n_kw, false);
mp_check_nargs(n_args, 1, 2, n_kw, false);
if (n_args > 1) {
if (!self->map_dict) {
@ -96,7 +96,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_map_obj_mapper_obj, 1, 2, pin_map
static mp_obj_t pin_map_obj_debug(uint n_args, mp_obj_t *args) {
pin_map_obj_t *self = args[0];
if (n_args > 1) {
self->debug = rt_is_true(args[1]);
self->debug = mp_obj_is_true(args[1]);
return mp_const_none;
}
return MP_BOOL(self->debug);
@ -162,7 +162,7 @@ const pin_obj_t *pin_map_user_obj(mp_obj_t user_obj) {
}
if (pin_map_obj.mapper) {
pin_obj = rt_call_function_1(pin_map_obj.mapper, user_obj);
pin_obj = mp_call_function_1(pin_map_obj.mapper, user_obj);
if (pin_obj != mp_const_none) {
if (!MP_OBJ_IS_TYPE(pin_obj, &pin_obj_type)) {
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin.mapper didn't return a Pin object"));

View File

@ -55,7 +55,7 @@ bool parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, bo
uint32_t start = HAL_GetTick();
if (nlr_push(&nlr) == 0) {
usb_vcp_set_interrupt_char(VCP_CHAR_CTRL_C); // allow ctrl-C to interrupt us
rt_call_function_0(module_fun);
mp_call_function_0(module_fun);
usb_vcp_set_interrupt_char(VCP_CHAR_NONE); // disable interrupt
nlr_pop();
ret = true;
@ -151,8 +151,8 @@ int pyexec_friendly_repl(void) {
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
// in host mode, we enable the LCD for the repl
mp_obj_t lcd_o = rt_call_function_0(rt_load_name(qstr_from_str("LCD")));
rt_call_function_1(rt_load_attr(lcd_o, qstr_from_str("light")), mp_const_true);
mp_obj_t lcd_o = mp_call_function_0(mp_load_name(qstr_from_str("LCD")));
mp_call_function_1(mp_load_attr(lcd_o, qstr_from_str("light")), mp_const_true);
#endif
friendly_repl_reset:

View File

@ -209,7 +209,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(sd_present_obj, sd_present);
static mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) {
bool result;
if (rt_is_true(state)) {
if (mp_obj_is_true(state)) {
result = sdcard_power_on();
} else {
sdcard_power_off();

View File

@ -157,7 +157,7 @@ STATIC void pyb_servo_print(void (*print)(void *env, const char *fmt, ...), void
STATIC mp_obj_t pyb_servo_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
// check arguments
rt_check_nargs(n_args, 1, 1, n_kw, false);
mp_check_nargs(n_args, 1, 1, n_kw, false);
// get servo number
machine_int_t servo_id = mp_obj_get_int(args[0]) - 1;

View File

@ -33,7 +33,7 @@ static mp_obj_t switch_user_callback_obj;
static mp_obj_t switch_callback(mp_obj_t line) {
if (switch_user_callback_obj != mp_const_none) {
rt_call_function_0(switch_user_callback_obj);
mp_call_function_0(switch_user_callback_obj);
}
return mp_const_none;
}

View File

@ -186,7 +186,7 @@ mp_obj_t pyb_gpio(int n_args, mp_obj_t *args) {
// set pin
pinMode(pin, OUTPUT);
digitalWrite(pin, rt_is_true(args[1]));
digitalWrite(pin, mp_obj_is_true(args[1]));
return mp_const_none;
pin_error:
@ -237,7 +237,7 @@ mp_obj_t pyb_delay(mp_obj_t count) {
}
mp_obj_t pyb_led(mp_obj_t state) {
led_state(PYB_LED_BUILTIN, rt_is_true(state));
led_state(PYB_LED_BUILTIN, mp_obj_is_true(state));
return state;
}
@ -368,7 +368,7 @@ bool do_file(const char *filename) {
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
rt_call_function_0(module_fun);
mp_call_function_0(module_fun);
nlr_pop();
return true;
} else {
@ -427,7 +427,7 @@ void do_repl(void) {
nlr_buf_t nlr;
uint32_t start = micros();
if (nlr_push(&nlr) == 0) {
rt_call_function_0(module_fun);
mp_call_function_0(module_fun);
nlr_pop();
// optional timing
if (0) {
@ -468,28 +468,28 @@ soft_reset:
gc_init(&_heap_start, (void*)HEAP_END);
qstr_init();
rt_init();
mp_init();
// add some functions to the python namespace
{
rt_store_name(MP_QSTR_help, rt_make_function_n(0, pyb_help));
mp_store_name(MP_QSTR_help, mp_make_function_n(0, pyb_help));
mp_obj_t m = mp_obj_new_module(MP_QSTR_pyb);
rt_store_attr(m, MP_QSTR_info, rt_make_function_n(0, pyb_info));
rt_store_attr(m, MP_QSTR_source_dir, rt_make_function_n(1, pyb_source_dir));
rt_store_attr(m, MP_QSTR_main, rt_make_function_n(1, pyb_main));
rt_store_attr(m, MP_QSTR_gc, rt_make_function_n(0, pyb_gc));
rt_store_attr(m, MP_QSTR_delay, rt_make_function_n(1, pyb_delay));
rt_store_attr(m, MP_QSTR_led, rt_make_function_n(1, pyb_led));
rt_store_attr(m, MP_QSTR_Led, rt_make_function_n(1, pyb_Led));
rt_store_attr(m, MP_QSTR_analogRead, rt_make_function_n(1, pyb_analog_read));
rt_store_attr(m, MP_QSTR_analogWrite, rt_make_function_n(2, pyb_analog_write));
rt_store_attr(m, MP_QSTR_analogWriteResolution, rt_make_function_n(1, pyb_analog_write_resolution));
rt_store_attr(m, MP_QSTR_analogWriteFrequency, rt_make_function_n(2, pyb_analog_write_frequency));
mp_store_attr(m, MP_QSTR_info, mp_make_function_n(0, pyb_info));
mp_store_attr(m, MP_QSTR_source_dir, mp_make_function_n(1, pyb_source_dir));
mp_store_attr(m, MP_QSTR_main, mp_make_function_n(1, pyb_main));
mp_store_attr(m, MP_QSTR_gc, mp_make_function_n(0, pyb_gc));
mp_store_attr(m, MP_QSTR_delay, mp_make_function_n(1, pyb_delay));
mp_store_attr(m, MP_QSTR_led, mp_make_function_n(1, pyb_led));
mp_store_attr(m, MP_QSTR_Led, mp_make_function_n(1, pyb_Led));
mp_store_attr(m, MP_QSTR_analogRead, mp_make_function_n(1, pyb_analog_read));
mp_store_attr(m, MP_QSTR_analogWrite, mp_make_function_n(2, pyb_analog_write));
mp_store_attr(m, MP_QSTR_analogWriteResolution, mp_make_function_n(1, pyb_analog_write_resolution));
mp_store_attr(m, MP_QSTR_analogWriteFrequency, mp_make_function_n(2, pyb_analog_write_frequency));
rt_store_attr(m, MP_QSTR_gpio, (mp_obj_t)&pyb_gpio_obj);
rt_store_attr(m, MP_QSTR_Servo, rt_make_function_n(0, pyb_Servo));
rt_store_name(MP_QSTR_pyb, m);
rt_store_name(MP_QSTR_run, rt_make_function_n(1, pyb_run));
mp_store_attr(m, MP_QSTR_gpio, (mp_obj_t)&pyb_gpio_obj);
mp_store_attr(m, MP_QSTR_Servo, mp_make_function_n(0, pyb_Servo));
mp_store_name(MP_QSTR_pyb, m);
mp_store_name(MP_QSTR_run, mp_make_function_n(1, pyb_run));
}
printf("About execute /boot.py\n");

View File

@ -61,7 +61,7 @@ void do_file(const char *file) {
int main(int argc, char **argv) {
qstr_init();
rt_init();
mp_init();
if (argc == 2) {
do_file(argv[1]);
@ -69,7 +69,7 @@ int main(int argc, char **argv) {
printf("usage: py [<file>]\n");
return 1;
}
rt_deinit();
mp_deinit();
return 0;
}

View File

@ -128,10 +128,10 @@ STATIC mp_obj_t ffimod_func(uint n_args, const mp_obj_t *args) {
o->func = sym;
o->rettype = *rettype;
mp_obj_t iterable = rt_getiter(args[3]);
mp_obj_t iterable = mp_getiter(args[3]);
mp_obj_t item;
int i = 0;
while ((item = rt_iternext(iterable)) != MP_OBJ_NULL) {
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
o->params[i++] = get_ffi_type(item);
}
@ -149,7 +149,7 @@ STATIC void call_py_func(ffi_cif *cif, void *ret, void** args, mp_obj_t func) {
for (int i = 0; i < cif->nargs; i++) {
pyargs[i] = mp_obj_new_int(*(int*)args[i]);
}
mp_obj_t res = rt_call_function_n_kw(func, cif->nargs, 0, pyargs);
mp_obj_t res = mp_call_function_n_kw(func, cif->nargs, 0, pyargs);
*(ffi_arg*)ret = mp_obj_int_get(res);
}
@ -165,10 +165,10 @@ STATIC mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t
o->rettype = *rettype;
mp_obj_t iterable = rt_getiter(paramtypes_in);
mp_obj_t iterable = mp_getiter(paramtypes_in);
mp_obj_t item;
int i = 0;
while ((item = rt_iternext(iterable)) != MP_OBJ_NULL) {
while ((item = mp_iternext(iterable)) != MP_OBJ_NULL) {
o->params[i++] = get_ffi_type(item);
}
@ -348,8 +348,8 @@ MP_DEFINE_CONST_FUN_OBJ_2(mod_ffi_as_bytearray_obj, mod_ffi_as_bytearray);
void ffi_init() {
mp_obj_t m = mp_obj_new_module(QSTR_FROM_STR_STATIC("ffi"));
rt_store_attr(m, MP_QSTR_open, (mp_obj_t)&mod_ffi_open_obj);
rt_store_attr(m, QSTR_FROM_STR_STATIC("callback"), (mp_obj_t)&mod_ffi_callback_obj);
mp_store_attr(m, MP_QSTR_open, (mp_obj_t)&mod_ffi_open_obj);
mp_store_attr(m, QSTR_FROM_STR_STATIC("callback"), (mp_obj_t)&mod_ffi_callback_obj);
// there would be as_bytes, but bytes currently is value, not reference type!
rt_store_attr(m, QSTR_FROM_STR_STATIC("as_bytearray"), (mp_obj_t)&mod_ffi_as_bytearray_obj);
mp_store_attr(m, QSTR_FROM_STR_STATIC("as_bytearray"), (mp_obj_t)&mod_ffi_as_bytearray_obj);
}

View File

@ -140,7 +140,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_open_obj, 1, 2, mp_builtin_open);
void file_init() {
mp_obj_t m_sys = mp_obj_new_module(MP_QSTR_sys);
rt_store_attr(m_sys, MP_QSTR_stdin, fdfile_new(STDIN_FILENO));
rt_store_attr(m_sys, MP_QSTR_stdout, fdfile_new(STDOUT_FILENO));
rt_store_attr(m_sys, MP_QSTR_stderr, fdfile_new(STDERR_FILENO));
mp_store_attr(m_sys, MP_QSTR_stdin, fdfile_new(STDIN_FILENO));
mp_store_attr(m_sys, MP_QSTR_stdout, fdfile_new(STDOUT_FILENO));
mp_store_attr(m_sys, MP_QSTR_stderr, fdfile_new(STDERR_FILENO));
}

View File

@ -85,7 +85,7 @@ static void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind
// 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 {
// uncaught exception
@ -278,7 +278,7 @@ int main(int argc, char **argv) {
#endif
qstr_init();
rt_init();
mp_init();
char *home = getenv("HOME");
char *path = getenv("MICROPYPATH");
@ -292,9 +292,9 @@ int main(int argc, char **argv) {
p++;
}
}
sys_path = mp_obj_new_list(path_num, NULL);
mp_sys_path = mp_obj_new_list(path_num, NULL);
mp_obj_t *path_items;
mp_obj_list_get(sys_path, &path_num, &path_items);
mp_obj_list_get(mp_sys_path, &path_num, &path_items);
path_items[0] = MP_OBJ_NEW_QSTR(MP_QSTR_);
char *p = path;
for (int i = 1; i < path_num; i++) {
@ -315,15 +315,15 @@ int main(int argc, char **argv) {
}
mp_obj_t m_sys = mp_obj_new_module(MP_QSTR_sys);
rt_store_attr(m_sys, MP_QSTR_path, sys_path);
mp_store_attr(m_sys, MP_QSTR_path, mp_sys_path);
mp_obj_t py_argv = mp_obj_new_list(0, NULL);
rt_store_attr(m_sys, MP_QSTR_argv, py_argv);
mp_store_attr(m_sys, MP_QSTR_argv, py_argv);
rt_store_name(qstr_from_str("test"), test_obj_new(42));
rt_store_name(qstr_from_str("mem_info"), rt_make_function_n(0, mem_info));
rt_store_name(qstr_from_str("qstr_info"), rt_make_function_n(0, qstr_info));
mp_store_name(qstr_from_str("test"), test_obj_new(42));
mp_store_name(qstr_from_str("mem_info"), mp_make_function_n(0, mem_info));
mp_store_name(qstr_from_str("qstr_info"), mp_make_function_n(0, qstr_info));
#if MICROPY_ENABLE_GC
rt_store_name(qstr_from_str("gc"), (mp_obj_t)&pyb_gc_obj);
mp_store_name(qstr_from_str("gc"), (mp_obj_t)&pyb_gc_obj);
#endif
file_init();
@ -344,8 +344,8 @@ int main(int argc, char **argv) {
// test_obj.attr = 42
mp_obj_t test_class_type, test_class_instance;
test_class_type = mp_obj_new_type(QSTR_FROM_STR_STATIC("TestClass"), mp_const_empty_tuple, mp_obj_new_dict(0));
rt_store_name(QSTR_FROM_STR_STATIC("test_obj"), test_class_instance = rt_call_function_0(test_class_type));
rt_store_attr(test_class_instance, QSTR_FROM_STR_STATIC("attr"), mp_obj_new_int(42));
mp_store_name(QSTR_FROM_STR_STATIC("test_obj"), test_class_instance = mp_call_function_0(test_class_type));
mp_store_attr(test_class_instance, QSTR_FROM_STR_STATIC("attr"), mp_obj_new_int(42));
/*
printf("bytes:\n");
@ -378,7 +378,7 @@ int main(int argc, char **argv) {
free(basedir);
}
for (int i = a; i < argc; i++) {
rt_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
mp_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
}
do_file(argv[a]);
executed = true;
@ -390,7 +390,7 @@ int main(int argc, char **argv) {
do_repl();
}
rt_deinit();
mp_deinit();
//printf("total bytes = %d\n", m_get_total_bytes_allocated());
return 0;

View File

@ -314,7 +314,7 @@ static mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) {
}
assert(addr);
mp_obj_t list = rt_build_list(0, NULL);
mp_obj_t list = mp_build_list(0, NULL);
for (; addr; addr = addr->ai_next) {
mp_obj_tuple_t *t = mp_obj_new_tuple(5, NULL);
t->items[0] = MP_OBJ_NEW_SMALL_INT((machine_int_t)addr->ai_family);
@ -328,7 +328,7 @@ static mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) {
t->items[3] = mp_const_none;
}
t->items[4] = mp_obj_new_bytearray(addr->ai_addrlen, addr->ai_addr);
rt_list_append(list, t);
mp_list_append(list, t);
}
return list;
}
@ -366,15 +366,15 @@ static const struct sym_entry {
void microsocket_init() {
mp_obj_t m = mp_obj_new_module(MP_QSTR_microsocket);
rt_store_attr(m, MP_QSTR_socket, (mp_obj_t)&microsocket_type);
mp_store_attr(m, MP_QSTR_socket, (mp_obj_t)&microsocket_type);
#if MICROPY_SOCKET_EXTRA
rt_store_attr(m, MP_QSTR_sockaddr_in, (mp_obj_t)&sockaddr_in_type);
rt_store_attr(m, MP_QSTR_htons, (mp_obj_t)&mod_socket_htons_obj);
rt_store_attr(m, MP_QSTR_inet_aton, (mp_obj_t)&mod_socket_inet_aton_obj);
rt_store_attr(m, MP_QSTR_gethostbyname, (mp_obj_t)&mod_socket_gethostbyname_obj);
mp_store_attr(m, MP_QSTR_sockaddr_in, (mp_obj_t)&sockaddr_in_type);
mp_store_attr(m, MP_QSTR_htons, (mp_obj_t)&mod_socket_htons_obj);
mp_store_attr(m, MP_QSTR_inet_aton, (mp_obj_t)&mod_socket_inet_aton_obj);
mp_store_attr(m, MP_QSTR_gethostbyname, (mp_obj_t)&mod_socket_gethostbyname_obj);
#endif
rt_store_attr(m, MP_QSTR_getaddrinfo, (mp_obj_t)&mod_socket_getaddrinfo_obj);
mp_store_attr(m, MP_QSTR_getaddrinfo, (mp_obj_t)&mod_socket_getaddrinfo_obj);
for (const struct sym_entry *p = constants; p->sym != NULL; p++) {
rt_store_attr(m, QSTR_FROM_STR_STATIC(p->sym), MP_OBJ_NEW_SMALL_INT((machine_int_t)p->val));
mp_store_attr(m, QSTR_FROM_STR_STATIC(p->sym), MP_OBJ_NEW_SMALL_INT((machine_int_t)p->val));
}
}

View File

@ -43,7 +43,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_obj, mod_time_sleep);
void time_init() {
mp_obj_t m = mp_obj_new_module(QSTR_FROM_STR_STATIC("time"));
rt_store_attr(m, QSTR_FROM_STR_STATIC("time"), (mp_obj_t)&mod_time_time_obj);
rt_store_attr(m, QSTR_FROM_STR_STATIC("clock"), (mp_obj_t)&mod_time_clock_obj);
rt_store_attr(m, QSTR_FROM_STR_STATIC("sleep"), (mp_obj_t)&mod_time_sleep_obj);
mp_store_attr(m, QSTR_FROM_STR_STATIC("time"), (mp_obj_t)&mod_time_time_obj);
mp_store_attr(m, QSTR_FROM_STR_STATIC("clock"), (mp_obj_t)&mod_time_clock_obj);
mp_store_attr(m, QSTR_FROM_STR_STATIC("sleep"), (mp_obj_t)&mod_time_sleep_obj);
}

View File

@ -69,7 +69,7 @@ static void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind
// 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 {
// uncaught exception
@ -183,14 +183,14 @@ mp_obj_t qstr_info(void) {
int main(int argc, char **argv) {
qstr_init();
rt_init();
mp_init();
mp_obj_t m_sys = mp_obj_new_module(MP_QSTR_sys);
mp_obj_t py_argv = mp_obj_new_list(0, NULL);
rt_store_attr(m_sys, MP_QSTR_argv, py_argv);
mp_store_attr(m_sys, MP_QSTR_argv, py_argv);
rt_store_name(qstr_from_str("mem_info"), rt_make_function_n(0, mem_info));
rt_store_name(qstr_from_str("qstr_info"), rt_make_function_n(0, qstr_info));
mp_store_name(qstr_from_str("mem_info"), mp_make_function_n(0, mem_info));
mp_store_name(qstr_from_str("qstr_info"), mp_make_function_n(0, qstr_info));
file_init();
@ -217,7 +217,7 @@ int main(int argc, char **argv) {
}
} else {
for (int i = a; i < argc; i++) {
rt_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
mp_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
}
do_file(argv[a]);
break;
@ -225,7 +225,7 @@ int main(int argc, char **argv) {
}
}
rt_deinit();
mp_deinit();
//printf("total bytes = %d\n", m_get_total_bytes_allocated());
return 0;