Changeset 6376
- Timestamp:
- 08/20/05 15:47:35 (3 years ago)
- svk:copy_cache_prev:
- 8581
- Files:
-
- 1 added
- 15 modified
-
examples/hop6/LICENSE.txt (modified) (2 props)
-
examples/hop6/Lexer.pm (modified) (2 props)
-
examples/hop6/Parser.pm (modified) (2 props)
-
examples/hop6/Stream.pm (modified) (2 props)
-
examples/hop6/expr-parser.p6 (modified) (2 props)
-
examples/hop6/it2stream.p6 (modified) (2 props)
-
perl5/PIL2JS/README (modified) (1 diff)
-
perl5/PIL2JS/lib/PIL.pm (modified) (4 diffs)
-
perl5/PIL2JS/lib/PIL/PNil.pm (modified) (1 diff)
-
perl5/PIL2JS/lib/PIL/PVar.pm (modified) (1 diff)
-
perl5/PIL2JS/lib/PIL/Subs.pm (modified) (5 diffs)
-
perl5/PIL2JS/lib6/Prelude/JS.pm (modified) (1 diff)
-
perl5/PIL2JS/lib6/Prelude/JS/Continuations.pm (added)
-
perl5/PIL2JS/libjs/PIL2JS.js (modified) (4 diffs)
-
perl5/Perl6-MetaModel/t/14_AUTOLOAD.t (modified) (2 props)
-
t/unspecced/cont.t (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
examples/hop6/LICENSE.txt
- Property svn:mime-type set to text/plain; charset=UTF-8
- Property svn:eol-style set to native
-
examples/hop6/Lexer.pm
- Property svn:mime-type set to text/plain; charset=UTF-8
- Property svn:eol-style set to native
-
examples/hop6/Parser.pm
- Property svn:mime-type set to text/plain; charset=UTF-8
- Property svn:eol-style set to native
-
examples/hop6/Stream.pm
- Property svn:mime-type set to text/plain; charset=UTF-8
- Property svn:eol-style set to native
-
examples/hop6/expr-parser.p6
- Property svn:mime-type set to text/plain; charset=UTF-8
- Property svn:eol-style set to native
-
examples/hop6/it2stream.p6
- Property svn:mime-type set to text/plain; charset=UTF-8
- Property svn:eol-style set to native
-
perl5/PIL2JS/README
r6330 r6376 147 147 148 148 Additionally to the arguments passed by the user, the first argument is always 149 a boxed C<PIL2JS.Context> object. Methods expect C<$?SELF> as their second149 an unboxed C<PIL2JS.Context> object. Methods expect C<$?SELF> as their second 150 150 argument. 151 151 -
perl5/PIL2JS/lib/PIL.pm
r6315 r6376 18 18 # Are we in a sublike thing? If yes, what sublevel does that thing have? 19 19 our $IN_SUBLIKE = undef; 20 our @IN_SUBLIKES; 20 21 21 22 # What's the name of the sub we're currently in? … … 23 24 24 25 # Our current pos? 25 our $CUR_POS = bless [ "<unknown>", (0) x 4 ] => "PIL::MkPos"; 26 our $CUR_POS = bless { 27 posName => "<unknown>", 28 posBeginLine => 0, 29 posBeginColumn => 0, 30 posEndLine => 0, 31 posEndColumn => 0, 32 } => "PIL::MkPos"; 26 33 27 34 # Are we in pilGlob? … … 181 188 "\n// End of initialization of global vars and exportation of subs.\n"; 182 189 183 return sprintf <<EOF, $decl_js, add_indent( 2, join "\n", @glob_js, $init_js, $main_js);190 return sprintf <<EOF, $decl_js, add_indent(3, join "\n", @glob_js, $init_js, $main_js); 184 191 %s 185 192 PIL2JS.catch_all_exceptions(function () { 186 PIL2JS.runloop(function () { 187 var PIL2JS = AlsoPIL2JS_SpeedupHack; 188 var pad = {}; PIL2JS_subpads.push(pad); 189 pad['\$?POSITION'] = _24main_3a_3a_3fPOSITION; 190 pad['\$_'] = _24main_3a_3a_; 193 PIL2JS.catch_end_exception(function() { 194 PIL2JS.runloop(function () { 195 var PIL2JS = AlsoPIL2JS_SpeedupHack; 196 var pad = {}; PIL2JS_subpads.push(pad); 197 pad['\$?POSITION'] = _24main_3a_3a_3fPOSITION; 198 pad['\$_'] = _24main_3a_3a_; 191 199 192 200 %s 201 }); 193 202 }); 194 203 }); … … 207 216 208 217 sub as_js { 209 return sprintf "new PIL2JS. Box.Constant(new PIL2JS.Context({ main: %s, type: %s }))",218 return sprintf "new PIL2JS.Context({ main: %s, type: %s })", 210 219 PIL::doublequote($_[0]->main), 211 220 defined $_[0]->type -
perl5/PIL2JS/lib/PIL/PNil.pm
r6270 r6376 11 11 12 12 sub as_js { 13 return "" unless $PIL::IN_SUBLIKE; 13 # This is so even programs using function converted by PIL2JS.cps2normal can 14 # correctly terminate. 15 return "throw new PIL2JS.ControlException.end" unless $PIL::IN_SUBLIKE; 14 16 15 17 my $cxt = "PIL2JS.Context.ItemAny"; -
perl5/PIL2JS/lib/PIL/PVar.pm
r6276 r6376 7 7 die unless keys %{ $_[0] } == 1; 8 8 die if ref(my $name = $_[0]->{pVarName}); 9 local $_; 9 10 10 11 if($name eq "&return") { 11 12 PIL::fail("Can't return outside a subroutine!") 12 unless $PIL::IN_SUBLIKE >= PIL::SUBROUTINE; 13 unless grep { $_ >= PIL::SUBROUTINE } @PIL::IN_SUBLIKES; 14 # XXX hack? 15 return bless { 16 pVarName => PIL::RawJS->new("PIL2JS.generic_return(subreturncc)") 17 } => "PIL::PVar"; 18 } elsif($name eq "&?CALLER_CONTINUATION") { 19 PIL::fail("There's no &?CALLER_CONTINUATION outside a subroutine!") 20 unless grep { $_ >= PIL::SUBROUTINE } @PIL::IN_SUBLIKES; 13 21 # XXX hack? 14 22 return bless { -
perl5/PIL2JS/lib/PIL/Subs.pm
r6315 r6376 23 23 $self->{pSubType} = bless [] => "PIL::$self->{pSubType}"; # minor hack 24 24 25 local $PIL::IN_SUBLIKE = $self->{pSubType}->as_constant; 25 local $PIL::IN_SUBLIKE = $self->{pSubType}->as_constant; 26 local @PIL::IN_SUBLIKES = (@PIL::IN_SUBLIKES, $self->{pSubType}->as_constant); 26 27 27 28 return bless { … … 43 44 44 45 local $PIL::IN_SUBLIKE = $self->{pSubType}->as_constant; 46 local @PIL::IN_SUBLIKES = (@PIL::IN_SUBLIKES, $self->{pSubType}->as_constant); 45 47 local $PIL::CUR_SUBNAME = $self->{pSubName}; 46 48 … … 132 134 $self->{pType} = bless [] => "PIL::$self->{pType}"; # minor hack 133 135 134 local $PIL::IN_SUBLIKE = $self->{pType}->as_constant; 136 local $PIL::IN_SUBLIKE = $self->{pType}->as_constant; 137 local @PIL::IN_SUBLIKES = (@PIL::IN_SUBLIKES, $self->{pType}->as_constant); 135 138 136 139 # &PIL::Params::fixup returns the fixed PIL::Params and the fixed … … 155 158 156 159 local $PIL::IN_SUBLIKE = $self->{pType}->as_constant; 160 local @PIL::IN_SUBLIKES = (@PIL::IN_SUBLIKES, $self->{pType}->as_constant); 157 161 local $PIL::CUR_SUBNAME = "<anonymous@{[$PIL::CUR_SUBNAME ? ' in ' . $PIL::CUR_SUBNAME : '']}>"; 158 162 … … 201 205 my $self = shift; 202 206 local $PIL::IN_SUBLIKE = PIL::SUBTHUNK; 207 local @PIL::IN_SUBLIKES = (@PIL::IN_SUBLIKES, PIL::SUBTHUNK); 203 208 local $PIL::CUR_SUBNAME = "<thunk@{[$PIL::CUR_SUBNAME ? ' in ' . $PIL::CUR_SUBNAME : '']}>"; 204 209 -
perl5/PIL2JS/lib6/Prelude/JS.pm
r6317 r6376 15 15 16 16 use Prelude::JS::Code; 17 use Prelude::JS::Continuations; 17 18 use Prelude::JS::ControlFlow; 18 19 use Prelude::JS::IO; -
perl5/PIL2JS/libjs/PIL2JS.js
r6330 r6376 182 182 (this.uid == undefined && other.uid == undefined && this.FETCH() == other.FETCH()) 183 183 ) { 184 PIL2JS.die("Binding would create a bind cycle!"); 184 // PIL2JS.die("Binding would create a bind cycle!"); 185 // Bind cycles are actually legal. 185 186 } 186 187 … … 659 660 PIL2JS.ControlException.redo.prototype.toString = 660 661 function () { return "Can't \"redo\" outside a loop block!" }; 662 PIL2JS.ControlException.end = function () {}; 661 663 662 664 // PIL2JS.generic_return -- generates a function, which, when invoked, will … … 784 786 }; 785 787 786 PIL2JS.Context.Void = new PIL2JS. Box.Constant(new PIL2JS.Context({ main: "void" }));787 PIL2JS.Context.ItemAny = new PIL2JS. Box.Constant(new PIL2JS.Context({ main: "item", type: "Any" }));788 PIL2JS.Context.SlurpyAny = new PIL2JS. Box.Constant(new PIL2JS.Context({ main: "slurpy", type: "Any" }));788 PIL2JS.Context.Void = new PIL2JS.Context({ main: "void" }); 789 PIL2JS.Context.ItemAny = new PIL2JS.Context({ main: "item", type: "Any" }); 790 PIL2JS.Context.SlurpyAny = new PIL2JS.Context({ main: "slurpy", type: "Any" }); 789 791 790 792 PIL2JS.print_exception = function (err) { … … 804 806 try { code() } catch(err) { 805 807 PIL2JS.print_exception(err); 808 } 809 }; 810 PIL2JS.catch_end_exception = function (code) { 811 try { code() } catch(err) { 812 if(err instanceof PIL2JS.ControlException.end) { 813 return; 814 } else { 815 throw err; 816 } 806 817 } 807 818 }; -
perl5/Perl6-MetaModel/t/14_AUTOLOAD.t
- Property svn:mime-type set to text/plain; charset=UTF-8
- Property svn:eol-style set to native
-
t/unspecced/cont.t
r4600 r6376 10 10 =cut 11 11 12 plan 1 3;12 plan 14; 13 13 14 14 sub simple1() returns Int { … … 18 18 is(simple1(), 2, 'using ec instead of return'); 19 19 20 sub simple2( $n) {20 sub simple2(Num $n) { 21 21 if ($n == 5) { 22 22 &?CALLER_CONTINUATION(1); … … 35 35 is(closure1(), 5, 'closure uses ec to escape', :todo); 36 36 37 sub call_argument( $f) {38 return $f( );37 sub call_argument(Code $f, $arg) { 38 return $f($arg); 39 39 } 40 sub foo( $f) returns Int {41 call_argument($f );40 sub foo(Code $f) returns Int { 41 call_argument($f, 8); 42 42 return 3; 43 43 } 44 sub passing1 returns Int {44 sub passing1 () returns Int { 45 45 foo(&?CALLER_CONTINUATION); 46 46 return 2; 47 47 } 48 eval_is('passing1()', 8, 'ec passed as an argument', :todo);48 is(try { passing1() }, 8, 'ec passed as an argument', :todo); 49 49 50 sub is_five( $n,$f) {50 sub is_five(Num $n, Code $f) { 51 51 if ($n == 5) { 52 52 $f(1); … … 54 54 return 0; 55 55 } 56 sub passing2_not_cont( $n) {56 sub passing2_not_cont(Num $n) { 57 57 my $a = 9; 58 58 is_five($n, sub { $a = 1 }); 59 59 return $a; 60 60 } 61 sub passing2( $n) {61 sub passing2(Num $n) { 62 62 is_five($n, &?CALLER_CONTINUATION); 63 63 return 9; 64 64 } 65 sub passing2_closure( $n) {65 sub passing2_closure(Num $n) { 66 66 my $c = &?CALLER_CONTINUATION; 67 67 is_five($n, sub { $c(1) }); 68 68 return 9; 69 69 } 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 ');70 is(passing2_not_cont(5), 1, 'is_five w/o ec (1)'); 71 is(passing2_not_cont(2), 9, 'is_five w/o ec (2)'); 72 is(passing2(5), 1, 'is_five passing ec itself (1)', :todo); 73 is(passing2(2), 9, 'is_five passing ec itself (2)'); 74 is(passing2_closure(5), 1, 'is_five passing ec via closure (1)', :todo); 75 is(passing2_closure(2), 9, 'is_five passing ec via closure (2)'); 76 76 77 77 sub callconty() { … … 79 79 return 1; 80 80 } 81 sub conty( $c) {81 sub conty(Code $c) { 82 82 $c(2); 83 return 3; 83 84 } 84 85 is(callconty(), 2, 'continuation bug', :todo<bug>); … … 86 87 # Now test complicated full continuations got from the same place. 87 88 88 sub callcc (Code &block) { &block(&?CALLER_CONTINUATION) } 89 { 90 sub callcc (Code &block) { &block(&?CALLER_CONTINUATION) } 89 91 90 my $cnt;91 my $counter = 0;92 my $cont; 93 my $counter = 0; 92 94 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 }
