diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-20 20:32:50 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-20 20:37:01 +0200 |
commit | a80ff04fe7458b8ed8e948619b3700b720832ec2 (patch) | |
tree | 8f78e879e523c609c36475bf14bde8043c2719fb /py | |
parent | f0cfb8cb45cb1fc91c77fae98f5452b7f7865392 (diff) | |
download | micropython-a80ff04fe7458b8ed8e948619b3700b720832ec2.tar.gz micropython-a80ff04fe7458b8ed8e948619b3700b720832ec2.zip |
Add dummy bytes() constructor.
Currently, MicroPython strings are mix between CPython byte and unicode
strings. So, conversion is null so far. This dummy implementation is
intended for compatibility with CPython (so, same code can run on both).
Diffstat (limited to 'py')
-rw-r--r-- | py/builtin.c | 12 | ||||
-rw-r--r-- | py/builtin.h | 1 | ||||
-rw-r--r-- | py/mpqstrraw.h | 1 | ||||
-rw-r--r-- | py/runtime.c | 1 |
4 files changed, 15 insertions, 0 deletions
diff --git a/py/builtin.c b/py/builtin.c index f102aa5885..13463ada69 100644 --- a/py/builtin.c +++ b/py/builtin.c @@ -347,3 +347,15 @@ static mp_obj_t mp_builtin_str(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_str_obj, mp_builtin_str); + +// TODO: This should be type, this is just quick CPython compat hack +static mp_obj_t mp_builtin_bytes(uint n_args, const mp_obj_t *args) { + if (!MP_OBJ_IS_QSTR(args[0]) && !MP_OBJ_IS_TYPE(args[0], &str_type)) { + assert(0); + } + // Currently, MicroPython strings are mix between CPython byte and unicode + // strings. So, conversion is null so far. + return args[0]; +} + +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_bytes_obj, 1, 3, mp_builtin_bytes); diff --git a/py/builtin.h b/py/builtin.h index 050a2161c1..4257de5bdb 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -5,6 +5,7 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin___repl_print___obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_abs_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_all_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_any_obj); +MP_DECLARE_CONST_FUN_OBJ(mp_builtin_bytes_obj); // Temporary hack MP_DECLARE_CONST_FUN_OBJ(mp_builtin_callable_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_chr_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_divmod_obj); diff --git a/py/mpqstrraw.h b/py/mpqstrraw.h index 10b1fc0d39..9bc01c5851 100644 --- a/py/mpqstrraw.h +++ b/py/mpqstrraw.h @@ -40,6 +40,7 @@ Q(any) Q(array) Q(bool) Q(bytearray) +Q(bytes) Q(callable) Q(chr) Q(complex) diff --git a/py/runtime.c b/py/runtime.c index d8fc3ff6e4..72347aff80 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -130,6 +130,7 @@ void rt_init(void) { mp_map_add_qstr(&map_builtins, MP_QSTR_abs, (mp_obj_t)&mp_builtin_abs_obj); mp_map_add_qstr(&map_builtins, MP_QSTR_all, (mp_obj_t)&mp_builtin_all_obj); mp_map_add_qstr(&map_builtins, MP_QSTR_any, (mp_obj_t)&mp_builtin_any_obj); + mp_map_add_qstr(&map_builtins, MP_QSTR_bytes, (mp_obj_t)&mp_builtin_bytes_obj); mp_map_add_qstr(&map_builtins, MP_QSTR_callable, (mp_obj_t)&mp_builtin_callable_obj); mp_map_add_qstr(&map_builtins, MP_QSTR_chr, (mp_obj_t)&mp_builtin_chr_obj); mp_map_add_qstr(&map_builtins, MP_QSTR_divmod, (mp_obj_t)&mp_builtin_divmod_obj); |