Re: WISHLIST.TXT
- Posted by Kat <gertie at PELL.NET> Aug 23, 2002
- 439 views
On 23 Aug 2002, at 11:55, C. K. Lester wrote: > > > :restartloop: > > -- initvars > > for loop = 1 to something do > > --code > > if whatever1 then goto restartloop end if > > if whatever2 then goto endloop end if > > if whatever3 then goto resumeloop end if > > --code > > :resumeloop: > > -- possible code > > end for > > :endloop: > > I've never gotten involved in any arguments regarding goto because I really > don't care. I don't use them... wouldn't use them... etc... But, I don't care > if > they're part of the language, as long as code without gotos doesn't suffer. > > Kat, my question is, would there be some extra garbage collection required > if you jump out of a loop that hasn't completed? In your example above, when > whatever2 is true, would the interpreter know that you've exited the loop and > will never return? Does the interpreter even need to know that? I'm just > thinking that stuff would be left hanging, and that doesn't seem very > efficient > to me unless the interpreter is smart enough to know where you've gone and > what > you've left undone. The way i see it, the loop is treated like a local function in Eu (it was in turbo pascal), which is why you don't haveto declare the loop variable. Any jump to *outside* this function will generate default cleanup code exactly as it does now. Forward jumps are easy to add, backwards jumps to *before* the loop start are more difficult, it's a few more steps (exit loop, cleanup, reinit the loop var, find the target (that's easy, we passed over it before, we know where it is), and jmp there with everything else unchanged. The fun part is the loops are simply exited, triggering the same cleanup as now exists, in the compiled code,, i assume the interpreter is smart enough too. This way of treating the loops allowed another neat trick in TP: the embedded procedure or function. Which would fullfill another request made in this thread, a request made before a few times too: a 3rd level of var scope. In Pascal, i can do this (pseudocode): procedure 1() declare vars for procedure 1() function 2() -- vars' scope is procedure 1() end function2 procedure 4() -- vars' scope is procedure 1() end procedure procedure 1()'s code here call function 2() more procedure 1()'s code here call procedure 4() more procedure 1()'s code here procedure 1()'s code here call function 2() end procedure 1() For scoping problems, this was ideal, and in the disassembler, it looked a lot like the loop's machine code, anything in the loop was scoped to the calling procedure as well. Also, see: Karl's Bach / Bliss in the archives. > Just curious, Curious is good. Kat