Without running it I'm guessing that it prints out something like
456=789
456=456
123=123
And on running it, I see that I'm right.
Remember that invoking a continuation does nothing to the existing
register state (which is as it should be).
So why does it work like this?
Letting IMCC handle calling _func saves all the registers and sets P1
to a RetContinuation that points to _func's return point (which is sort
of inside the _func() line because of the stuff IMCC does on a function
return).
_func then sets P16-18 to 4-6 respectively and you make the
continuation.
Calling _do_something saves all the registers and sets P1 to
(essentially) _end
_do_something sets P16-18 to 7-9 then jumps through the continuation
back to _end.
Which prints out '456=789' because P16-18 haven't been restored
Then it returns. Returning invokes P1, which is currently set to point
to _end. However, returning using .pcc_*_return also restores the
registers, which means P16-18 now contain 4-6, so it prints out
456=456 and returns through P1, which now boints back to the original
place that _func was called from.
Easy.
One part of your problem (The state of P16-18) is, therefore, a bug in
your program. The other part seems to be a bug in the current
implementation of Continuation.
A new Continuation should grab the current P1 continuation. If you
later invoke that Continuation, it should make the jump and reset
P1. Until that's done, all we have is a heavyweight goto.
>> Hi,
>>
>> does the attached test use the Continuation in a correct way?
>> The test failes, what am I doing wrong?
> Without running it I'm guessing that it prints out something like
> 456=789
> 456=456
> 123=123
Why would it print 3 lines?
> Easy.
Brrr.
> One part of your problem (The state of P16-18) is, therefore, a bug in
> your program. The other part seems to be a bug in the current
> implementation of Continuation.
Yep.
> A new Continuation should grab the current P1 continuation. If you
> later invoke that Continuation, it should make the jump and reset
> P1. Until that's done, all we have is a heavyweight goto.
I don't get that. Below is a stripped down version of Jens program. There
are 2 ways of invokeing the return continuation:
invoke conti
or
conti()
The former is more or less ignored by imcc, the latter is recognized as
a regular function call: registers are preserved and a flag
"sub_calls_a_sub" is set, so that e.g. the return continuation is
preserved around the call. These variants give different output.
How schould it really work?
.sub _main
.local int a
a = 1
_func()
print a
print " main\n"
end
.end
.sub _func
.local pmc conti
.local int a
a = 4
conti = newcont _end
_do_something( conti )
_end:
print a
print " _func\n"
.end
.sub _do_something
.param pmc conti
.local int a
a = 7
# invoke conti # (1)
conti() # (2)
print "error!\n"
.end
Thanks,
leo
> Piers Cawley <pdca...@bofh.org.uk> wrote:
>> Jens Rieks <par...@jensbeimsurfen.de> writes:
>
>>> Hi,
>>>
>>> does the attached test use the Continuation in a correct way?
>>> The test failes, what am I doing wrong?
>
>> Without running it I'm guessing that it prints out something like
>
>> 456=789
>> 456=456
>> 123=123
>
> Why would it print 3 lines?
Actually, it doesn't, I was going mad and mixing it up with the problem
I've been having with ParrotUnit, which does bad things with returning...