lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>An year ago, prompted by a similar request here in lua-l, I wrote a simple
>patch for luac that did the right thing for the code below:

My main problem is how to implement a GOSUB that can return to
anywhere in the script (except to functions). The actual jump to the
label's PC is no problem ... that works fine already. The issue is
what information do I need to preserve to be able to return later, e.g.

for k=1,10 do
	gosub label
	print(k)
end

label:
print "hello"
a = 5; b = 6; c = 7 -- do something
funccall()   -- call a function
array[a * b] = 10;  -- array access
_return  -- now back to the for-loop

With my current implementation, the "gosub label" call does an OP_JMP
to the label's PC, prints "hello", does some stuff and then invokes an OP_JMP
back to "print(k)". But now "k" has an incorrect value! That's why I assume that
I need to restore some other things when returning from a label. But I don't
know what! 

-Andreas