@@ -55,22 +55,22 @@ def visit_FUNCTION(self, node):
5555 # if self.O_LEVEL > 1:
5656 # return
5757
58+ if local_var .class_ == CLASS .const or local_var .scope == SCOPE .parameter :
59+ continue
60+
5861 if local_var .class_ == CLASS .array and local_var .scope == SCOPE .local :
59- bound_ptrs = [] # Bound tables pointers (empty if not used)
6062 lbound_label = local_var .mangled + ".__LBOUND__"
6163 ubound_label = local_var .mangled + ".__UBOUND__"
64+ lbound_needed = not local_var .is_zero_based and local_var .is_dynamically_accessed
6265
63- if local_var .lbound_used or local_var .ubound_used :
64- bound_ptrs = ["0" , "0" ] # NULL by default
65- if local_var .lbound_used :
66- bound_ptrs [0 ] = lbound_label
67- if local_var .ubound_used :
68- bound_ptrs [1 ] = ubound_label
66+ bound_ptrs = [lbound_label if lbound_needed else "0" , "0" ]
67+ if local_var .ubound_used :
68+ bound_ptrs [1 ] = ubound_label
6969
70- if bound_ptrs :
70+ if bound_ptrs != [ "0" , "0" ] :
7171 OPTIONS ["__DEFINES" ].value ["__ZXB_USE_LOCAL_ARRAY_WITH_BOUNDS__" ] = ""
7272
73- if local_var . lbound_used :
73+ if lbound_needed :
7474 l = ["%04X" % bound .lower for bound in local_var .bounds ]
7575 bound_tables .append (LabelledData (lbound_label , l ))
7676
@@ -89,8 +89,7 @@ def visit_FUNCTION(self, node):
8989 if local_var .default_value is not None :
9090 r .extend (self .array_default_value (local_var .type_ , local_var .default_value ))
9191 self .ic_larrd (local_var .offset , q , local_var .size , r , bound_ptrs ) # Initializes array bounds
92- elif local_var .class_ == CLASS .const or local_var .scope == SCOPE .parameter :
93- continue
92+
9493 else : # Local vars always defaults to 0, so if 0 we do nothing
9594 if (
9695 local_var .token != "FUNCTION"
@@ -119,6 +118,7 @@ def visit_FUNCTION(self, node):
119118 if local_var .type_ == self .TYPE (TYPE .string ):
120119 if local_var .class_ == CLASS .const or local_var .token == "FUNCTION" :
121120 continue
121+
122122 # Only if it's string we free it
123123 if local_var .class_ != CLASS .array : # Ok just free it
124124 if scope == SCOPE .local or (scope == SCOPE .parameter and not local_var .byref ):
0 commit comments