summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rwxr-xr-xtools/mpy-tool.py17
1 files changed, 15 insertions, 2 deletions
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('<I', struct.pack('<f', self.objs[i]))[0]
+ n = ((n & ~0x3) | 2) + 0x80800000
+ print(' (mp_uint_t)0x%08x,' % (n,))
+ print('#else')
+ print('#error "MICROPY_OBJ_REPR_D not supported with floats in frozen mpy files"')
+ print('#endif')
+ else:
+ print(' (mp_uint_t)&const_obj_%s_%u,' % (self.escaped_name, i))
for rc in self.raw_codes:
print(' (mp_uint_t)&raw_code_%s,' % rc.escaped_name)
print('};')