@@ -1092,6 +1092,17 @@ def visit_ARRAYDECL(self, node):
10921092 if self .O_LEVEL > 1 :
10931093 return
10941094
1095+ bound_ptrs = [] # Bound tables pointers (empty if not used)
1096+ lbound_label = entry .mangled + '.__LBOUND__'
1097+ ubound_label = entry .mangled + '.__UBOUND__'
1098+
1099+ if entry .lbound_used or entry .ubound_used :
1100+ bound_ptrs = ['0' , '0' ] # NULL by default
1101+ if entry .lbound_used :
1102+ bound_ptrs [0 ] = lbound_label
1103+ if entry .ubound_used :
1104+ bound_ptrs [1 ] = ubound_label
1105+
10951106 data_label = entry .data_label
10961107 idx_table_label = backend .tmp_label ()
10971108 l = ['%04X' % (len (node .bounds ) - 1 )] # Number of dimensions - 1
@@ -1118,21 +1129,23 @@ def visit_ARRAYDECL(self, node):
11181129
11191130 if entry .addr :
11201131 self .ic_varx (entry .data_ptr_label , gl .PTR_TYPE , [self .traverse_const (entry .addr )])
1132+ if bound_ptrs :
1133+ self .ic_data (gl .PTR_TYPE , bound_ptrs )
11211134 else :
11221135 self .ic_varx (entry .data_ptr_label , gl .PTR_TYPE , [data_label ])
1136+ if bound_ptrs :
1137+ self .ic_data (gl .PTR_TYPE , bound_ptrs )
11231138 self .ic_vard (data_label , arr_data )
11241139
11251140 self .ic_vard (idx_table_label , l )
11261141
11271142 if entry .lbound_used :
1128- l = ['%04X' % len (node .bounds )] + \
1129- ['%04X' % bound .lower for bound in node .bounds ]
1130- self .ic_vard ('__LBOUND__.' + entry .mangled , l )
1143+ l = ['%04X' % bound .lower for bound in node .bounds ]
1144+ self .ic_vard (lbound_label , l )
11311145
11321146 if entry .ubound_used :
1133- l = ['%04X' % len (node .bounds )] + \
1134- ['%04X' % bound .upper for bound in node .bounds ]
1135- self .ic_vard ('__UBOUND__.' + entry .mangled , l )
1147+ l = ['%04X' % bound .upper for bound in node .bounds ]
1148+ self .ic_vard (ubound_label , l )
11361149
11371150
11381151class UnaryOpTranslator (TranslatorVisitor ):
@@ -1284,19 +1297,29 @@ def visit_SQR(self, node):
12841297 # endregion
12851298
12861299 def visit_LBOUND (self , node ):
1287- entry = node .operands [0 ]
1288- self .ic_param (gl .BOUND_TYPE , '#__LBOUND__.' + entry .mangled )
12891300 yield node .operands [1 ]
1290- self .ic_fparam (gl .BOUND_TYPE , optemps .new_t ())
1291- self .ic_call ('__BOUND' , self .TYPE (gl .BOUND_TYPE ).size )
1301+ self .ic_param (gl .BOUND_TYPE , node .operands [1 ].mangled )
1302+ entry = node .operands [0 ]
1303+ if entry .scope == SCOPE .global_ :
1304+ self .ic_fparam (gl .PTR_TYPE , '#{}' .format (entry .mangled ))
1305+ elif entry .scope == SCOPE .parameter :
1306+ self .ic_fparam (entry .t , entry .offset )
1307+ elif entry .scope == SCOPE .local :
1308+ self .ic_fparam (entry .t , - entry .offset )
1309+ self .ic_call ('__LBOUND' , self .TYPE (gl .BOUND_TYPE ).size )
12921310 backend .REQUIRES .add ('bound.asm' )
12931311
12941312 def visit_UBOUND (self , node ):
1295- entry = node .operands [0 ]
1296- self .ic_param (gl .BOUND_TYPE , '#__UBOUND__.' + entry .mangled )
12971313 yield node .operands [1 ]
1298- self .ic_fparam (gl .BOUND_TYPE , optemps .new_t ())
1299- self .ic_call ('__BOUND' , self .TYPE (gl .BOUND_TYPE ).size )
1314+ self .ic_param (gl .BOUND_TYPE , node .operands [1 ].mangled )
1315+ entry = node .operands [0 ]
1316+ if entry .scope == SCOPE .global_ :
1317+ self .ic_fparam (gl .PTR_TYPE , '#{}' .format (entry .mangled ))
1318+ elif entry .scope == SCOPE .parameter :
1319+ self .ic_fparam (entry .t , entry .offset )
1320+ elif entry .scope == SCOPE .local :
1321+ self .ic_fparam (entry .t , - entry .offset )
1322+ self .ic_call ('__UBOUND' , self .TYPE (gl .BOUND_TYPE ).size )
13001323 backend .REQUIRES .add ('bound.asm' )
13011324
13021325 def visit_USR_STR (self , node ):
0 commit comments