diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 972ede8325..a7c3d8f918 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -42,6 +42,7 @@ else: # end compatibility code import sys +import struct from collections import namedtuple sys.path.append('../py') @@ -315,9 +316,10 @@ class RawCode: '{.neg=%u, .fixed_dig=1, .alloc=%u, .len=%u, .dig=(uint%u_t[]){%s}}};' % (obj_name, neg, ndigs, ndigs, bits_per_dig, digs)) elif type(obj) is float: - # works for REPR A and B only + print('#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B') print('STATIC const mp_obj_float_t %s = {{&mp_type_float}, %.16g};' % (obj_name, obj)) + print('#endif') else: # TODO raise FreezeError(self, 'freezing of object %r is not implemented' % (obj,)) @@ -328,7 +330,18 @@ class RawCode: for qst in self.qstrs: print(' (mp_uint_t)MP_OBJ_NEW_QSTR(%s),' % global_qstrs[qst].qstr_id) for i in range(len(self.objs)): - print(' (mp_uint_t)&const_obj_%s_%u,' % (self.escaped_name, i)) + if type(self.objs[i]) is float: + print('#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B') + print(' (mp_uint_t)&const_obj_%s_%u,' % (self.escaped_name, i)) + print('#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C') + n = struct.unpack('