@@ -94,7 +94,7 @@ def visit_LABEL(self, node):
9494 self .ic_label (node .mangled )
9595
9696 def visit_CONST (self , node ):
97- yield node .t
97+ yield node .symbol
9898
9999 def visit_VAR (self , node ):
100100 __DEBUG__ (
@@ -977,7 +977,7 @@ def loop_cont_label(self, loop_type):
977977 raise InvalidLoopError (loop_type )
978978
979979 @classmethod
980- def default_value (cls , type_ , expr ): # TODO: This function must be moved to api.xx
980+ def default_value (cls , type_ : symbols . TYPE , expr ) -> list [ str ] : # TODO: This function must be moved to api.xx
981981 """Returns a list of bytes (as hexadecimal 2 char string)"""
982982 assert isinstance (type_ , symbols .TYPE )
983983 assert type_ .is_basic
@@ -986,44 +986,37 @@ def default_value(cls, type_, expr): # TODO: This function must be moved to api
986986 if expr .token in ("CONSTEXPR" , "CONST" ): # a constant expression like @label + 1
987987 if type_ in (cls .TYPE (TYPE .float ), cls .TYPE (TYPE .string )):
988988 error (expr .lineno , f"Can't convert non-numeric value to { type_ .name } at compile time" )
989- return ["<ERROR>" ]
989+ return ["<ERROR>" ] # dummy placeholder so the compilation continues
990990
991991 val = Translator .traverse_const (expr )
992992 if type_ .size == 1 : # U/byte
993993 if expr .type_ .size != 1 :
994- return ["#({0 }) & 0xFF" . format ( val ) ]
994+ return [f "#({ val } ) & 0xFF" ]
995995 else :
996- return ["#{0}" . format ( val ) ]
996+ return [f "#{ val } " ]
997997
998998 if type_ .size == 2 : # U/integer
999999 if expr .type_ .size != 2 :
1000- return ["##({0 }) & 0xFFFF" . format ( val ) ]
1000+ return [f "##({ val } ) & 0xFFFF" ]
10011001 else :
1002- return ["##{0}" . format ( val ) ]
1002+ return [f "##{ val } " ]
10031003
10041004 if type_ == cls .TYPE (TYPE .fixed ):
1005- return ["0000" , "##({0 }) & 0xFFFF" . format ( val ) ]
1005+ return ["0000" , f "##({ val } ) & 0xFFFF" ]
10061006
10071007 # U/Long
1008- return ["##({0 }) & 0xFFFF" . format ( val ), "##(({0 }) >> 16) & 0xFFFF" . format ( val ) ]
1008+ return [f "##({ val } ) & 0xFFFF", f "##(({ val } ) >> 16) & 0xFFFF" ]
10091009
10101010 if type_ == cls .TYPE (TYPE .float ):
10111011 C , DE , HL = _float (expr .value )
10121012 C = C [:- 1 ] # Remove 'h' suffix
1013- if len (C ) > 2 :
1014- C = C [- 2 :]
1013+ C = C [- 2 :]
10151014
10161015 DE = DE [:- 1 ] # Remove 'h' suffix
1017- if len (DE ) > 4 :
1018- DE = DE [- 4 :]
1019- elif len (DE ) < 3 :
1020- DE = "00" + DE
1016+ DE = ("00" + DE )[- 4 :]
10211017
10221018 HL = HL [:- 1 ] # Remove 'h' suffix
1023- if len (HL ) > 4 :
1024- HL = HL [- 4 :]
1025- elif len (HL ) < 3 :
1026- HL = "00" + HL
1019+ HL = ("00" + HL )[- 4 :]
10271020
10281021 return [C , DE [- 2 :], DE [:- 2 ], HL [- 2 :], HL [:- 2 ]]
10291022
@@ -1032,8 +1025,8 @@ def default_value(cls, type_, expr): # TODO: This function must be moved to api
10321025 else :
10331026 value = int (expr .value )
10341027
1035- result = [value , value >> 8 , value >> 16 , value >> 24 ]
1036- result = ["%02X" % (v & 0xFF ) for v in result ]
1028+ values = [value , value >> 8 , value >> 16 , value >> 24 ]
1029+ result = ["%02X" % (v & 0xFF ) for v in values ]
10371030 return result [: type_ .size ]
10381031
10391032 @staticmethod
@@ -1459,7 +1452,10 @@ def visit_FUNCTION(self, node):
14591452 if node .convention == CONVENTION .stdcall :
14601453 for local_var in node .local_symbol_table .values ():
14611454 scope = local_var .scope
1462- if local_var .type_ == self .TYPE (TYPE .string ): # Only if it's string we free it
1455+ if local_var .type_ == self .TYPE (TYPE .string ):
1456+ if local_var .class_ == CLASS .const :
1457+ continue
1458+ # Only if it's string we free it
14631459 if local_var .class_ != CLASS .array : # Ok just free it
14641460 if scope == SCOPE .local or (scope == SCOPE .parameter and not local_var .byref ):
14651461 if not preserve_hl :
@@ -1469,8 +1465,6 @@ def visit_FUNCTION(self, node):
14691465 offset = - local_var .offset if scope == SCOPE .local else local_var .offset
14701466 self .ic_fpload (TYPE .string , local_var .t , offset )
14711467 self .runtime_call (RuntimeLabel .MEM_FREE , 0 )
1472- elif local_var .class_ == CLASS .const :
1473- continue
14741468 else : # This is an array of strings, we must free it unless it's a by_ref array
14751469 if scope == SCOPE .local or (scope == SCOPE .parameter and not local_var .byref ):
14761470 if not preserve_hl :
0 commit comments