Changeset 6376 for t/unspecced/cont.t

Show
Ignore:
Timestamp:
08/20/05 15:47:35 (3 years ago)
Author:
iblech
svk:copy_cache_prev:
8581
Message:

* Usual svn props.
* PIL2JS: &?CALLER_CONTINUATION.

  • t/unspecced/cont.t: Added some type annotations and a new test. PIL2JS passes 14/14 with 6 unexpected succeedings. :)
  • PIL, PIL2JS.js: PIL2JS.cps2normal now works correctly with functions which reach the end of the program (this can happen, for example, with continuations :)). Previously, the program flow was restarted after the call to PIL2JS.cps2normal, resulting in certain regions running twice.
  • PIL, PIL::PVar, PIL::Subs: sub foo { {return}() } didn't compile, because PIL2JS only kept track of the current subtype, not of all subs it's currently in. Fixed.

* PIL2JS: PIL, PIL2JS.js, README: Context objects are now unboxed -- boxing was

never needed. Should give a small speedup.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • t/unspecced/cont.t

    r4600 r6376  
    1010=cut 
    1111 
    12 plan 13; 
     12plan 14; 
    1313 
    1414sub simple1() returns Int { 
     
    1818is(simple1(), 2, 'using ec instead of return'); 
    1919 
    20 sub simple2($n) { 
     20sub simple2(Num $n) { 
    2121  if ($n == 5) { 
    2222    &?CALLER_CONTINUATION(1); 
     
    3535is(closure1(), 5, 'closure uses ec to escape', :todo); 
    3636 
    37 sub call_argument($f) { 
    38   return $f(); 
     37sub call_argument(Code $f, $arg) { 
     38  return $f($arg); 
    3939} 
    40 sub foo($f) returns Int { 
    41   call_argument($f); 
     40sub foo(Code $f) returns Int { 
     41  call_argument($f, 8); 
    4242  return 3; 
    4343} 
    44 sub passing1 returns Int { 
     44sub passing1 () returns Int { 
    4545  foo(&?CALLER_CONTINUATION); 
    4646  return 2; 
    4747} 
    48 eval_is('passing1()', 8, 'ec passed as an argument', :todo); 
     48is(try { passing1() }, 8, 'ec passed as an argument', :todo); 
    4949 
    50 sub is_five($n, $f) { 
     50sub is_five(Num $n, Code $f) { 
    5151  if ($n == 5) { 
    5252    $f(1); 
     
    5454  return 0; 
    5555} 
    56 sub passing2_not_cont($n) { 
     56sub passing2_not_cont(Num $n) { 
    5757  my $a = 9; 
    5858  is_five($n, sub { $a = 1 }); 
    5959  return $a; 
    6060} 
    61 sub passing2($n) { 
     61sub passing2(Num $n) { 
    6262  is_five($n, &?CALLER_CONTINUATION); 
    6363  return 9; 
    6464} 
    65 sub passing2_closure($n) { 
     65sub passing2_closure(Num $n) { 
    6666  my $c = &?CALLER_CONTINUATION; 
    6767  is_five($n, sub { $c(1) }); 
    6868  return 9; 
    6969} 
    70 is(passing2_not_cont(5), 1, 'is_five w/o ec'); 
    71 is(passing2_not_cont(2), 9, 'is_five w/o ec'); 
    72 is(passing2(5), 1, 'is_five passing ec itself', :todo); 
    73 is(passing2(2), 9, 'is_five passing ec itself'); 
    74 is(passing2_closure(5), 1, 'is_five passing ec via closure', :todo); 
    75 is(passing2_closure(2), 9, 'is_five passing ec via closure'); 
     70is(passing2_not_cont(5), 1, 'is_five w/o ec (1)'); 
     71is(passing2_not_cont(2), 9, 'is_five w/o ec (2)'); 
     72is(passing2(5), 1, 'is_five passing ec itself (1)', :todo); 
     73is(passing2(2), 9, 'is_five passing ec itself (2)'); 
     74is(passing2_closure(5), 1, 'is_five passing ec via closure (1)', :todo); 
     75is(passing2_closure(2), 9, 'is_five passing ec via closure (2)'); 
    7676 
    7777sub callconty() { 
     
    7979    return 1; 
    8080} 
    81 sub conty($c) { 
     81sub conty(Code $c) { 
    8282    $c(2); 
     83    return 3; 
    8384} 
    8485is(callconty(), 2, 'continuation bug', :todo<bug>); 
     
    8687# Now test complicated full continuations got from the same place. 
    8788 
    88 sub callcc (Code &block) {  &block(&?CALLER_CONTINUATION) } 
     89{ 
     90  sub callcc (Code &block) {  &block(&?CALLER_CONTINUATION) } 
    8991 
    90 my $cnt; 
    91 my $counter = 0; 
     92  my $cont; 
     93  my $counter = 0; 
    9294 
    93 callcc -> $cc { $cnt = $cc }; 
    94 $counter++; 
    95 ok 1, "$counter times through the loop"; 
    96 $cnt(undef) unless $counter == 3; 
    97 is($counter, 3, "Looping with a full continuation", :todo<feature>); 
     95  callcc -> $cc { $cont = $cc }; 
     96  $counter++; 
     97  $cont(undef) unless $counter == 3; 
     98  is($counter, 3, "Looping with a full continuation", :todo<feature>); 
     99} 
     100 
     101# Really evil: Store continuations in an aggregate 
     102{ 
     103  my %conts; 
     104  my $foo = sub { %conts<foo> = &?CALLER_CONTINUATION; return "normalfoo" }; 
     105  my $bar = sub { %conts<bar> = &?CALLER_CONTINUATION; return "normalbar" }; 
     106 
     107  my $history; 
     108  my $counter = 0; 
     109 
     110  $history ~= $foo(); $history ~= "foo$counter"; $counter++; 
     111  $history ~= $bar(); $history ~= "bar$counter"; $counter++; 
     112  %conts<foo>("secondfoo") if $counter <= 2; 
     113  %conts<bar>("secondbar") if $counter <= 4; 
     114 
     115  is 
     116    $history, 
     117    "normalfoofoo0normalbarbar1secondfoofoo2normalbarbar3secondbarbar4", 
     118    "continuations stored in an aggregate with loops"; 
     119}