Commit bb33cc66 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

Properly print MP_OBJ_QSTR objects.

parent 2c7a1b2a
...@@ -44,6 +44,8 @@ void printf_wrapper(void *env, const char *fmt, ...) { ...@@ -44,6 +44,8 @@ void printf_wrapper(void *env, const char *fmt, ...) {
void mp_obj_print_helper(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) { void mp_obj_print_helper(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
if (MP_OBJ_IS_SMALL_INT(o_in)) { if (MP_OBJ_IS_SMALL_INT(o_in)) {
print(env, "%d", (int)MP_OBJ_SMALL_INT_VALUE(o_in)); print(env, "%d", (int)MP_OBJ_SMALL_INT_VALUE(o_in));
} else if (MP_OBJ_IS_QSTR(o_in)) {
mp_obj_str_print_qstr(print, env, MP_OBJ_QSTR_VALUE(o_in), kind);
} else { } else {
mp_obj_base_t *o = o_in; mp_obj_base_t *o = o_in;
if (o->type->print != NULL) { if (o->type->print != NULL) {
......
...@@ -280,6 +280,7 @@ void mp_obj_exception_get_traceback(mp_obj_t self_in, machine_uint_t *n, machine ...@@ -280,6 +280,7 @@ void mp_obj_exception_get_traceback(mp_obj_t self_in, machine_uint_t *n, machine
// str // str
extern const mp_obj_type_t str_type; extern const mp_obj_type_t str_type;
qstr mp_obj_str_get(mp_obj_t self_in); qstr mp_obj_str_get(mp_obj_t self_in);
void mp_obj_str_print_qstr(void (*print)(void *env, const char *fmt, ...), void *env, qstr q, mp_print_kind_t kind);
#if MICROPY_ENABLE_FLOAT #if MICROPY_ENABLE_FLOAT
// float // float
......
...@@ -22,16 +22,20 @@ static mp_obj_t mp_obj_new_str_iterator(mp_obj_str_t *str, int cur); ...@@ -22,16 +22,20 @@ static mp_obj_t mp_obj_new_str_iterator(mp_obj_str_t *str, int cur);
/******************************************************************************/ /******************************************************************************/
/* str */ /* str */
void str_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { void mp_obj_str_print_qstr(void (*print)(void *env, const char *fmt, ...), void *env, qstr q, mp_print_kind_t kind) {
mp_obj_str_t *self = self_in;
if (kind == PRINT_STR) { if (kind == PRINT_STR) {
print(env, "%s", qstr_str(self->qstr)); print(env, "%s", qstr_str(q));
} else { } else {
// TODO need to escape chars etc // TODO need to escape chars etc
print(env, "'%s'", qstr_str(self->qstr)); print(env, "'%s'", qstr_str(q));
} }
} }
void str_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
mp_obj_str_t *self = self_in;
mp_obj_str_print_qstr(print, env, self->qstr, kind);
}
mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_obj_str_t *lhs = lhs_in; mp_obj_str_t *lhs = lhs_in;
const char *lhs_str = qstr_str(lhs->qstr); const char *lhs_str = qstr_str(lhs->qstr);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment