@@ -331,27 +331,29 @@ def freeze(self, parent_name):
331331 # TODO
332332 raise FreezeError (self , 'freezing of object %r is not implemented' % (obj ,))
333333
334- # generate constant table
335- print ('STATIC const mp_rom_obj_t const_table_data_%s[%u] = {'
336- % (self .escaped_name , len (self .qstrs ) + len (self .objs ) + len (self .raw_codes )))
337- for qst in self .qstrs :
338- print (' MP_ROM_QSTR(%s),' % global_qstrs [qst ].qstr_id )
339- for i in range (len (self .objs )):
340- if type (self .objs [i ]) is float :
341- print ('#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B' )
342- print (' MP_ROM_PTR(&const_obj_%s_%u),' % (self .escaped_name , i ))
343- print ('#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C' )
344- n = struct .unpack ('<I' , struct .pack ('<f' , self .objs [i ]))[0 ]
345- n = ((n & ~ 0x3 ) | 2 ) + 0x80800000
346- print (' (mp_rom_obj_t)(0x%08x),' % (n ,))
347- print ('#else' )
348- print ('#error "MICROPY_OBJ_REPR_D not supported with floats in frozen mpy files"' )
349- print ('#endif' )
350- else :
351- print (' MP_ROM_PTR(&const_obj_%s_%u),' % (self .escaped_name , i ))
352- for rc in self .raw_codes :
353- print (' MP_ROM_PTR(&raw_code_%s),' % rc .escaped_name )
354- print ('};' )
334+ # generate constant table, if it has any entries
335+ const_table_len = len (self .qstrs ) + len (self .objs ) + len (self .raw_codes )
336+ if const_table_len :
337+ print ('STATIC const mp_rom_obj_t const_table_data_%s[%u] = {'
338+ % (self .escaped_name , const_table_len ))
339+ for qst in self .qstrs :
340+ print (' MP_ROM_QSTR(%s),' % global_qstrs [qst ].qstr_id )
341+ for i in range (len (self .objs )):
342+ if type (self .objs [i ]) is float :
343+ print ('#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B' )
344+ print (' MP_ROM_PTR(&const_obj_%s_%u),' % (self .escaped_name , i ))
345+ print ('#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C' )
346+ n = struct .unpack ('<I' , struct .pack ('<f' , self .objs [i ]))[0 ]
347+ n = ((n & ~ 0x3 ) | 2 ) + 0x80800000
348+ print (' (mp_rom_obj_t)(0x%08x),' % (n ,))
349+ print ('#else' )
350+ print ('#error "MICROPY_OBJ_REPR_D not supported with floats in frozen mpy files"' )
351+ print ('#endif' )
352+ else :
353+ print (' MP_ROM_PTR(&const_obj_%s_%u),' % (self .escaped_name , i ))
354+ for rc in self .raw_codes :
355+ print (' MP_ROM_PTR(&raw_code_%s),' % rc .escaped_name )
356+ print ('};' )
355357
356358 # generate module
357359 if self .simple_name .str != '<module>' :
@@ -362,7 +364,10 @@ def freeze(self, parent_name):
362364 print (' .n_pos_args = %u,' % self .prelude [3 ])
363365 print (' .data.u_byte = {' )
364366 print (' .bytecode = bytecode_data_%s,' % self .escaped_name )
365- print (' .const_table = (mp_uint_t*)const_table_data_%s,' % self .escaped_name )
367+ if const_table_len :
368+ print (' .const_table = (mp_uint_t*)const_table_data_%s,' % self .escaped_name )
369+ else :
370+ print (' .const_table = NULL,' )
366371 print (' #if MICROPY_PERSISTENT_CODE_SAVE' )
367372 print (' .bc_len = %u,' % len (self .bytecode ))
368373 print (' .n_obj = %u,' % len (self .objs ))
0 commit comments