Hello.

>> I enjoy Parrot and tried to write new two opcodes -- suspend and resume.
>> suspend opcode is to halt interpreter and resume opcode is to restart
>> interpreter from where it suspended.
> Hmm. How does the C<resume> opcode execute, when the runloop was left?
> No test case there. What would be the usage of suspend/resume?

suspend and resume opcode are related two interpreters - one is the
parent, the other is the child.
The usage is following:

1. The parent interpreter creates child a ParrotInterpreter object.
2. The parent interpreter runs the child interpreter with runinterp opcode.
3. The child interpreter suspends by itself with suspend opcode.
4. The parent interpreter resumes the child interpreter with resume opcode.

suspend opcode has no operand.
resume opcode needs one operand to resume ParrotInterpreter PMC.

I write down test cases below. Please excuse the following long text.
Thank you.

--- suspend.t ---
#! perl -w

=head1 NAME

suspend.t - Suspend test

=head1 SYNOPSIS

        % perl -Ilib suspend.t

=head1 DESCRIPTION

Tests suspend opcode.

=cut

use Parrot::Test tests => 3;

pir_output_is(<< 'CODE', << 'OUTPUT', "suspend main interpreter");
.sub main @MAIN
    loadlib P0, "phtest_ops"
    print "suspend\n"
    suspend
    print "not reached\n"
.end
CODE
suspend
OUTPUT

pir_output_is(<< 'CODE', << 'OUTPUT', "suspend in sub");
.sub main @MAIN
    loadlib P0, "phtest_ops"
    .local pmc interp
    interp = new .ParrotInterpreter
    print "0\n"
    runinterp interp, LABEL1
    print "1\n"
    resume interp
    print "2\n"
    end
LABEL1:
    test()
    end
.end

.sub test
    print "3\n"
    suspend
    print "4\n"
.end
CODE
0
3
1
4
2
OUTPUT

pir_output_is(<< 'CODE', << 'OUTPUT', "suspend in sub in sub");
.sub main @MAIN
    loadlib P0, "phtest_ops"
    .local pmc interp
    interp = new .ParrotInterpreter
    print "0\n"
    runinterp interp, LABEL1
    print "1\n"
    resume interp
    print "2\n"
    end
LABEL1:
    test()
    end
.end

.sub test
    print "3\n"
    test2()
    print "4\n"
.end

.sub test2
    print "5\n"
    suspend
    print "6\n"
.end
CODE
0
3
5
1
6
4
2
OUTPUT

1;


Reply via email to