Re: Need help with PD source (again)
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Apr 04, 2005
- 422 views
Pete Lomax wrote: > > > > Matt Lewis wrote: > > So it's those ENDFOR_INT_UP1's and ENDFOR_GENERAL's that you need to > > reproduce. > > You would need additional goto's after them, to properly exit the > loop, should you be on the last iteration. I think you would be better > off jumping to the existing endfor/endwhile statement instead. > Branch straightening might tidy things up automatically, with luck. That seems wasteful (execution-wise) and requires changing the back end, anyway. It was actually pretty simple to do. I basically had to create a couple of stacks to remember the loop type, variable and the backpatch addresses, and added a continue statement. In the for-loop case, I just added an exit right after the ENDFOR statement (ENDWHILE just jumps back to the while statement for evaluation). Here's what the new routine looks like:
procedure Continue_statement() token tok integer bp1, bp2 sequence s if preprocess then CompileErr("continue not allowed in preprocessing") end if if not loop_stack[$] then CompileErr( "continue must be inside of loop" ) elsif loop_stack[$] = FOR then StartSourceLine(TRUE) op_info1 = loop_sym_stack[$] op_info2 = loop_bp_stack[$] + 1 s = Pop() & Pop() Push( s[2] ) Push( s[1] ) emit_op(ENDFOR_GENERAL) -- will be set at runtime by FOR op Push( s[2] ) Push( s[1] ) emit_op(EXIT) AppendXList(length(Code)+1) emit_forward_addr() -- to be back-patched tok = next_token() putback(tok) elsif loop_stack[$] = WHILE then bp1 = loop_bp_stack[$][1] bp2 = loop_bp_stack[$][1] StartSourceLine(TRUE) emit_op(ENDWHILE) emit_addr(bp1) end if end procedure
> How about duplicating AppendXList/PatchXList in parser.e? I don't know what you mean by this... Matt Lewis