321 blockstack[g_BlockStackCursor].type = BLOCKTYPE_FOR; |
321 blockstack[g_BlockStackCursor].type = BLOCKTYPE_FOR; |
322 continue; |
322 continue; |
323 } |
323 } |
324 |
324 |
325 // ============================================================ |
325 // ============================================================ |
|
326 // Do/while loop |
|
327 if (!token.icompare ("do")) { |
|
328 MUST_NOT_TOPLEVEL |
|
329 PushBlockStack (); |
|
330 MustNext ("{"); |
|
331 |
|
332 // Store the marks and incrementor |
|
333 blockstack[g_BlockStackCursor].mark1 = w->AddMark (MARKTYPE_INTERNAL, ""); |
|
334 blockstack[g_BlockStackCursor].type = BLOCKTYPE_DO; |
|
335 continue; |
|
336 } |
|
337 |
|
338 // ============================================================ |
326 if (!token.compare ("}")) { |
339 if (!token.compare ("}")) { |
327 // Closing brace |
340 // Closing brace |
328 |
341 |
329 // If we're in the block stack, we're descending down from it now |
342 // If we're in the block stack, we're descending down from it now |
330 if (g_BlockStackCursor > 0) { |
343 if (g_BlockStackCursor > 0) { |
343 w->Write (DH_GOTO); |
356 w->Write (DH_GOTO); |
344 w->AddReference (info->mark1); |
357 w->AddReference (info->mark1); |
345 |
358 |
346 // Move the closing mark here since we're at the end of the while loop |
359 // Move the closing mark here since we're at the end of the while loop |
347 w->MoveMark (info->mark2); |
360 w->MoveMark (info->mark2); |
|
361 break; |
|
362 case BLOCKTYPE_DO: |
|
363 MustNext ("while"); |
|
364 MustNext ("("); |
|
365 MustNext (); |
|
366 DataBuffer* expr = ParseExpression (TYPE_INT); |
|
367 MustNext (")"); |
|
368 MustNext (";"); |
|
369 |
|
370 // If the condition runs true, go back to the start. |
|
371 w->WriteBuffer (expr); |
|
372 w->Write<long> (DH_IFGOTO); |
|
373 w->AddReference (info->mark1); |
|
374 break; |
348 } |
375 } |
349 |
376 |
350 // Descend down the stack |
377 // Descend down the stack |
351 g_BlockStackCursor--; |
378 g_BlockStackCursor--; |
352 continue; |
379 continue; |
611 b->Write<word> (g->index); |
638 b->Write<word> (g->index); |
612 } else { |
639 } else { |
613 // If nothing else, check for literal |
640 // If nothing else, check for literal |
614 switch (reqtype) { |
641 switch (reqtype) { |
615 case TYPE_VOID: |
642 case TYPE_VOID: |
616 ParserError ("bad syntax"); |
643 ParserError ("unknown identifier `%s` (expected keyword, function or variable)", token.chars()); |
617 break; |
644 break; |
618 case TYPE_INT: { |
645 case TYPE_INT: { |
619 MustNumber (true); |
646 MustNumber (true); |
620 |
647 |
621 // All values are written unsigned - thus we need to write the value's |
648 // All values are written unsigned - thus we need to write the value's |