tools/mpy-tool.py: Support freezing of complex numbers.

pull/2387/head
Damien George 2016-09-03 00:19:02 +10:00
rodzic 41ec22632d
commit c51c883cc8
1 zmienionych plików z 12 dodań i 0 usunięć

Wyświetl plik

@ -320,6 +320,9 @@ class RawCode:
print('STATIC const mp_obj_float_t %s = {{&mp_type_float}, %.16g};'
% (obj_name, obj))
print('#endif')
elif type(obj) is complex:
print('STATIC const mp_obj_complex_t %s = {{&mp_type_complex}, %.16g, %.16g};'
% (obj_name, obj.real, obj.imag))
else:
# TODO
raise FreezeError(self, 'freezing of object %r is not implemented' % (obj,))
@ -485,6 +488,15 @@ def freeze_mpy(base_qstrs, raw_codes):
print('#endif')
print()
print('#if MICROPY_PY_BUILTINS_COMPLEX')
print('typedef struct _mp_obj_complex_t {')
print(' mp_obj_base_t base;')
print(' mp_float_t real;')
print(' mp_float_t imag;')
print('} mp_obj_complex_t;')
print('#endif')
print()
print('enum {')
for i in range(len(new)):
if i == 0: