@@ -32,8 +32,9 @@ function astNewMEM _
3232 end if
3333
3434 '' when clearing/moving more than IR_MEMBLOCK_MAXLEN bytes, take
35- '' the adress-of and let emit() do the rest
36- if ( lgt > blkmaxlen ) then
35+ '' the adress-of and let emit() do the rest, or if blkmaxlen = 0,
36+ '' then emit() always handles it, even when lgt=0
37+ if ( (lgt > blkmaxlen) or (blkmaxlen = 0 ) ) then
3738 l = astNewADDROF( l )
3839
3940 if ( op = AST_OP_MEMMOVE ) then
@@ -60,34 +61,39 @@ private function hCallCtorList _
6061 byval subtype as FBSYMBOL ptr _
6162 ) as ASTNODE ptr
6263
63- dim as FBSYMBOL ptr cnt = any, label = any, iter = any
64+ dim as FBSYMBOL ptr cnt = any, label = any, exitlabel = any, iter = any
6465 dim as ASTNODE ptr tree = any
6566
66- cnt = symbAddTempVar( FB_DATATYPE_INTEGER )
67+ cnt = symbAddTempVar( FB_DATATYPE_UINT )
6768 label = symbAddLabel( NULL )
69+ exitlabel = symbAddLabel( NULL )
6870 iter = symbAddTempVar( typeAddrOf( dtype ), subtype )
6971
7072 '' iter = @vector[0]
7173 tree = astBuildVarAssign( iter, astNewVAR( tmp ), AST_OPOPT_ISINI )
7274
73- '' for cnt = 0 to elements-1
75+ '' while( cnt )
7476 '' Note: Using a non-flushing LABEL here because the LABEL node will
7577 '' end up as part of an expression tree, not as a "standalone statement"
76- tree = astBuildForBegin ( tree, cnt, label, 0 , FALSE / ' non-flushing '/ )
78+ tree = astBuildWhileCounterBegin ( tree, cnt, label, exitlabel, elementsexpr , FALSE / ' non-flushing '/ )
7779
7880 '' ctor( *iter )
7981 tree = astNewLINK( tree, astBuildCtorCall( subtype, astBuildVarDeref( iter ) ) )
8082
8183 '' iter += 1
8284 tree = astNewLINK( tree, astBuildVarInc( iter, 1 ) )
8385
84- '' next
85- tree = astBuildForEnd ( tree, cnt, label, elementsexpr )
86+ '' wend
87+ tree = astBuildWhileCounterEnd ( tree, cnt, label, exitlabel, FALSE )
8688
8789 '' Wrap into LOOP node so astCloneTree() can clone the label and update
8890 '' the loop code, because it's part of the new[] expression, and not
8991 '' a standalone statement.
90- function = astNewLOOP( label, tree )
92+ tree = astNewLOOP( label, tree )
93+
94+ tree = astNewLOOP( exitlabel, tree )
95+
96+ function = tree
9197end function
9298
9399private function hElements _
@@ -130,6 +136,7 @@ function astBuildNewOp _
130136
131137 dim as ASTNODE ptr lenexpr = any, tree = any
132138 dim as integer save_elmts = any, init = any, elementstreecount = any
139+ dim as FBSYMBOL ptr exitlabel = any
133140
134141 init = INIT_NONE
135142 tree = NULL
@@ -199,7 +206,7 @@ function astBuildNewOp _
199206 if ( save_elmts ) then
200207 '' length + sizeof( integer ) (to store the vector size)
201208 lenexpr = astNewBOP( AST_OP_ADD, lenexpr, _
202- astNewCONSTi( typeGetSize( FB_DATATYPE_INTEGER ), FB_DATATYPE_UINT ) )
209+ astNewCONSTi( typeGetSize( FB_DATATYPE_UINT ), FB_DATATYPE_UINT ) )
203210 end if
204211
205212 newexpr = rtlMemNewOp( op, lenexpr, dtype, subtype )
@@ -211,20 +218,27 @@ function astBuildNewOp _
211218 '' tempptr = new( len )
212219 tree = astNewLINK( tree, astBuildVarAssign( tmp, newexpr, AST_OPOPT_ISINI ) )
213220
221+ '' if( tempptr <> NULL ) then
222+ exitlabel = symbAddLabel( NULL )
223+
224+ '' handle like IIF, we don't want dtors called if tempptr was never allocated
225+ tree = astNewLINK( tree, _
226+ astBuildBranch( astNewBOP( AST_OP_NE, astNewVAR( tmp ), astNewCONSTi( 0 ) ), exitlabel, FALSE , TRUE ) )
227+
214228 '' save elements count?
215229 if ( save_elmts ) then
216230 '' *tempptr = elements
217231 tree = astNewLINK( tree, _
218232 astNewASSIGN( _
219- astNewDEREF( astNewVAR( tmp, , typeAddrOf( FB_DATATYPE_INTEGER ) ) ), _
233+ astNewDEREF( astNewVAR( tmp, , typeAddrOf( FB_DATATYPE_UINT ) ) ), _
220234 hElements( elementsexpr, elementstreecount ), _
221235 AST_OPOPT_ISINI ) )
222236
223- '' tempptr += len( integer )
237+ '' tempptr += len( uinteger )
224238 tree = astNewLINK( tree, _
225239 astNewSelfBOP( AST_OP_ADD_SELF, _
226240 astNewVAR( tmp, , typeAddrOf( FB_DATATYPE_VOID ) ), _
227- astNewCONSTi( typeGetSize( FB_DATATYPE_INTEGER ) ), _
241+ astNewCONSTi( typeGetSize( FB_DATATYPE_UINT ) ), _
228242 NULL ) )
229243 end if
230244
@@ -257,29 +271,40 @@ function astBuildNewOp _
257271
258272 end select
259273
260- function = astNewLINK( tree, initexpr )
274+ '' *tempptr = initializers
275+ tree = astNewLINK( tree, initexpr )
276+
277+ '' end if
278+ tree = astNewLINK( tree, astNewLABEL( exitlabel, FALSE ) )
279+
280+ '' because this is an expression, exitlabel must be cloned with a new label
281+ '' instead of just copied. astNewLOOP() allows this (but naming could be better).
282+ tree = astNewLOOP( exitlabel, tree )
283+
284+ function = tree
261285end function
262286
263287private function hCallDtorList( byval ptrexpr as ASTNODE ptr ) as ASTNODE ptr
264- dim as FBSYMBOL ptr cnt = any, label = any, iter = any, elmts = any
288+ dim as FBSYMBOL ptr cnt = any, label = any, exitlabel = any, iter = any, elmts = any
265289 dim as ASTNODE ptr tree = any, expr = any
266290
267291 cnt = symbAddTempVar( FB_DATATYPE_INTEGER )
268292 label = symbAddLabel( NULL )
293+ exitlabel = symbAddLabel( NULL )
269294 iter = symbAddTempVar( ptrexpr->dtype, ptrexpr->subtype )
270295 elmts = symbAddTempVar( FB_DATATYPE_INTEGER )
271296
272297 '' DELETE[]'s counter is at: cast(integer ptr, vector)[-1]
273298
274- '' elmts = *cast( integer ptr, cast( any ptr, vector ) + -sizeof( integer ) )
299+ '' elmts = *cast( uinteger ptr, cast( any ptr, vector ) + -sizeof( uinteger ) )
275300 '' (using AST_CONVOPT_DONTCHKPTR to support derived UDT pointers)
276301 tree = astBuildVarAssign( _
277302 elmts, _
278303 astNewDEREF( _
279- astNewCONV( typeAddrOf( FB_DATATYPE_INTEGER ), NULL, _
304+ astNewCONV( typeAddrOf( FB_DATATYPE_UINT ), NULL, _
280305 astNewBOP( AST_OP_ADD, _
281306 astCloneTree( ptrexpr ), _
282- astNewCONSTi( -typeGetSize( FB_DATATYPE_INTEGER ) ) ), _
307+ astNewCONSTi( -typeGetSize( FB_DATATYPE_UINT ) ) ), _
283308 AST_CONVOPT_DONTCHKPTR ) ), _
284309 AST_OPOPT_ISINI )
285310
@@ -291,17 +316,17 @@ private function hCallDtorList( byval ptrexpr as ASTNODE ptr ) as ASTNODE ptr
291316 AST_OPOPT_DEFAULT or AST_OPOPT_DOPTRARITH ), _
292317 AST_OPOPT_ISINI ) )
293318
294- '' for cnt = 0 to elmts-1
295- tree = astBuildForBegin ( tree, cnt, label, 0 )
319+ '' while( counter )
320+ tree = astBuildWhileCounterBegin ( tree, cnt, label, exitlabel, astNewVAR( elmts ) )
296321
297322 '' iter -= 1
298323 tree = astNewLINK( tree, astBuildVarInc( iter, - 1 ) )
299324
300325 '' dtor( *iter )
301326 tree = astNewLINK( tree, astBuildVarDtorCall( astBuildVarDeref( iter ) ) )
302327
303- '' next
304- tree = astBuildForEnd ( tree, cnt, label, astNewVAR( elmts ) )
328+ '' wend
329+ tree = astBuildWhileCounterEnd ( tree, cnt, label, exitlabel )
305330
306331 function = tree
307332end function
0 commit comments