Re: Need help with PD source (again)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Vincent wrote:
> 
> Can anyone help me get a "continue" statement implemented in the
> PD source code for my modded interpreter? I thought this would of
> been an easy task, but it doesnt seem to be after all. The idea came
> when people starting mentioning the "next" statement on this message
> board, so that is what got me interested.
> 
> For those who dont know what this keyword is:
> 
> A "continue" statement would be for "for" & "while" loops that causes
> the next iteration of the loop to begin instantly. A "for" loop will
> continue by incrementing and testing its loop index. A "while" loop
> will continue with a test of its conditional.
> 
> Any help would be appriciated and ofcourse acknowledged.
> 
> 
> Btw Pete Lomax, I decided on using Daryl Border's conflict resolution
> system (though I had to fix a major bug with it first) instead of
> "import", but I just wanted to thank you for your help anyway smile.

Hopefully, this will put you on the right track.  I recommend taking a 
look at the output of the front end, to see what you need to do.  I use
dis.ex (comes with OOEU), which is where I got the output below.  Basically,
you'll need to output the appropriate END loop op, then repair the 
cg_stack so that it can be done again (I haven't investigated what, exactly,
you need to do for each type of loop).  For example, consider the following
Euphoria code:
with trace
for i = 1 to 3 do
	if i = 2 then
		puts(1,"continue")
	end if
	? i
end for

for i = 1 to 3 by 0.5 do
	if i = 2 then
		puts(1,"continue")
	end if
	? i	
end for

This gets turned into:
SubProgram [_toplevel_:00101]
     1: 058 2                            # STARTLINE: 2 <<for i = 1 to 3 do>>
3: 125 104 105 104 101 103 35       # FOR_I: inc [LIT 1:104], lim [LIT
     3:105],
#     initial [LIT 1:104], lv [i:103],
                                         jmp 0035
    10: 087 103                          # DISPLAY_VAR: [i:103] 
    12: 058 3                            # STARTLINE: 3 <<if i = 2 then>>
14: 121 103 106 23                   # IFW [i:103] = [LIT 2:106] goto 0018
    else
                                         #     goto 0023
    18: 058 4                            # STARTLINE: 4 <<puts(1,"continue")>>
20: 044 104 108                      # PUTS: [LIT 1:104], [LIT
    "continue":108]
    23: 058 6                            # STARTLINE: 6 <<? i>>
    25: 036 104 103                      # QPRINT: [i:103]
    28: 058 7                            # STARTLINE: 7 <<end for>>
30: 054 10 105 103 104               # ENDFOR_INT_UP1: top 0010, lim: [LIT
    3:105],
                                         #     lv [i:103]
    35: 090 103                          # ERASE_SYMBOL: [i:103] 
37: 058 9                            # STARTLINE: 9 <<for i = 1 to 3 by 0.5
    do>>
39: 021 110 105 104 101 109 71       # FOR: inc [LIT 0.5:110], lim [LIT
    3:105],
#     initial [LIT 1:104], lv [i:109],
                                         jmp 0071
    46: 087 109                          # DISPLAY_VAR: [i:109] 
    48: 058 10                           # STARTLINE: 10 <<if i = 2 then>>
50: 104 109 106 59                   # IFW [i:109] = [LIT 2:106] goto 0054
    else
                                         #     goto 0059
    54: 058 11                           # STARTLINE: 11 <<puts(1,"continue")>>
56: 044 104 108                      # PUTS: [LIT 1:104], [LIT
    "continue":108]
    59: 058 13                           # STARTLINE: 13 <<? i	>>
    61: 036 104 109                      # QPRINT: [i:109]
    64: 058 14                           # STARTLINE: 14 <<end for>>
66: 039 46 105 109 110               # ENDFOR_GENERAL: top 0046 lim [LIT
    3:105],
                                         #     inc [i:109], lv [LIT 0.5:110]
    71: 090 109                          # ERASE_SYMBOL: [i:109] 
    73: 034                              # RETURNT:
End SubProgram [_toplevel_:00101]

So it's those ENDFOR_INT_UP1's and ENDFOR_GENERAL's that you need to 
reproduce.

Matt Lewis

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu