Skip to content
Snippets Groups Projects
Commit c51c883c authored by Damien George's avatar Damien George
Browse files

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

parent 41ec2263
No related branches found
No related tags found
No related merge requests found
...@@ -320,6 +320,9 @@ class RawCode: ...@@ -320,6 +320,9 @@ class RawCode:
print('STATIC const mp_obj_float_t %s = {{&mp_type_float}, %.16g};' print('STATIC const mp_obj_float_t %s = {{&mp_type_float}, %.16g};'
% (obj_name, obj)) % (obj_name, obj))
print('#endif') 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: else:
# TODO # TODO
raise FreezeError(self, 'freezing of object %r is not implemented' % (obj,)) raise FreezeError(self, 'freezing of object %r is not implemented' % (obj,))
...@@ -485,6 +488,15 @@ def freeze_mpy(base_qstrs, raw_codes): ...@@ -485,6 +488,15 @@ def freeze_mpy(base_qstrs, raw_codes):
print('#endif') print('#endif')
print() 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 {') print('enum {')
for i in range(len(new)): for i in range(len(new)):
if i == 0: if i == 0:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment