parser.cxx

changeset 42
5cd91fd1526c
parent 41
47e686c96d8f
child 43
1b35c9985989
equal deleted inserted replaced
41:47e686c96d8f 42:5cd91fd1526c
236 continue; 236 continue;
237 } 237 }
238 238
239 // While 239 // While
240 if (!token.compare ("while")) { 240 if (!token.compare ("while")) {
241 printf ("begin while loop\n");
242 MUST_NOT_TOPLEVEL 241 MUST_NOT_TOPLEVEL
243 PushBlockStack (); 242 PushBlockStack ();
244 243
245 // While loops need two marks - one at the start of the loop and one at the 244 // While loops need two marks - one at the start of the loop and one at the
246 // end. The condition is checked at the very start of the loop, if it fails, 245 // end. The condition is checked at the very start of the loop, if it fails,
277 // If we're in the block stack, we're descending down from it now 276 // If we're in the block stack, we're descending down from it now
278 if (g_BlockStackCursor > 0) { 277 if (g_BlockStackCursor > 0) {
279 BlockInformation* info = &blockstack[g_BlockStackCursor]; 278 BlockInformation* info = &blockstack[g_BlockStackCursor];
280 switch (info->type) { 279 switch (info->type) {
281 case BLOCKTYPE_IF: 280 case BLOCKTYPE_IF:
282 printf ("end if\n");
283 // Adjust the closing mark. 281 // Adjust the closing mark.
284 w->MoveMark (info->mark1); 282 w->MoveMark (info->mark1);
285 break; 283 break;
286 case BLOCKTYPE_WHILE: 284 case BLOCKTYPE_WHILE:
287 printf ("end while loop\n");
288
289 // Write down the instruction to go back to the start of the loop 285 // Write down the instruction to go back to the start of the loop
290 w->Write (DH_GOTO); 286 w->Write (DH_GOTO);
291 w->AddReference (info->mark1); 287 w->AddReference (info->mark1);
292 288
293 // Move the closing mark here since we're at the end of the while loop 289 // Move the closing mark here since we're at the end of the while loop
294 w->MoveMark (info->mark2); 290 w->MoveMark (info->mark2);
295
296 // Offset it by 4 since the parser doesn't like having marks directly afte refs
297 w->OffsetMark (info->mark2, sizeof (word)*2);
298 } 291 }
299 292
300 // Descend down the stack 293 // Descend down the stack
301 g_BlockStackCursor--; 294 g_BlockStackCursor--;
302 continue; 295 continue;
622 615
623 return retbuf; 616 return retbuf;
624 } 617 }
625 618
626 void ScriptReader::PushBlockStack () { 619 void ScriptReader::PushBlockStack () {
620 g_BlockStackCursor++;
627 BlockInformation* info = &blockstack[g_BlockStackCursor]; 621 BlockInformation* info = &blockstack[g_BlockStackCursor];
628 info->type = 0; 622 info->type = 0;
629 info->mark1 = 0; 623 info->mark1 = 0;
630 info->mark2 = 0; 624 info->mark2 = 0;
631 g_BlockStackCursor++; 625 }
632 }

mercurial