py: Add native json printing using existing print framework.

Also add start of ujson module with dumps implemented.  Enabled in unix
and stmhal ports.  Test passes on both.
This commit is contained in:
Damien George
2014-09-17 22:56:34 +01:00
parent 8a9b999f1c
commit 612045f53f
18 changed files with 227 additions and 15 deletions

View File

@@ -49,12 +49,15 @@ STATIC mp_obj_t list_pop(mp_uint_t n_args, const mp_obj_t *args);
STATIC void list_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
mp_obj_list_t *o = o_in;
if (!(MICROPY_PY_UJSON && kind == PRINT_JSON)) {
kind = PRINT_REPR;
}
print(env, "[");
for (mp_uint_t i = 0; i < o->len; i++) {
if (i > 0) {
print(env, ", ");
}
mp_obj_print_helper(print, env, o->items[i], PRINT_REPR);
mp_obj_print_helper(print, env, o->items[i], kind);
}
print(env, "]");
}