Changeset 5008
- Timestamp:
- 06/26/05 19:19:20 (4 years ago)
- svk:copy_cache_prev:
- 6856
- Files:
-
- 4 modified
-
src/Pugs/Compile.hs (modified) (1 diff)
-
src/Pugs/Eval.hs (modified) (1 diff)
-
src/perl6/Prelude.pm (modified) (1 diff)
-
t/oo/syntax-but.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Compile.hs
r4955 r5008 342 342 let op = "&infix:" ++ init syn 343 343 compile $ Syn "=" [lhs, App (Var op) Nothing [lhs, exp]] 344 compile (Syn "but" [obj, block]) = 345 compile $ App (Var "&Pugs::Internals::but_block") Nothing [obj, block] 344 346 compile exp = compError exp 345 347 -
src/Pugs/Eval.hs
r4992 r5008 339 339 , subCont = cont 340 340 } 341 342 reduceSyn "but" [obj, block] = do 343 evalExp $ App (Var "&Pugs::Internals::but_block") Nothing [obj, block] 341 344 342 345 reduceSyn name [cond, bodyIf, bodyElse] -
src/perl6/Prelude.pm
r5006 r5008 181 181 $ret; 182 182 } 183 184 sub Pugs::Internals::but_block ($obj, Code $code) { 185 $code($obj); 186 $obj; 187 } -
t/oo/syntax-but.t
r5006 r5008 17 17 # }; 18 18 19 plan 4;19 plan 7; 20 20 21 class SampleClass { has $.var } 22 21 # Without an own class 23 22 { 24 23 my $was_in_but_block; 25 24 my $topic_in_but_block; 26 25 27 my $ obj = eval 'SampleClass.newbut {26 my $num = 3 but { 28 27 $was_in_but_block++; 29 $topic_in_but_block++; 28 $topic_in_but_block = $_; 29 23; 30 }; 31 32 is $num, 3, "syntax but worked on a literal"; 33 ok $was_in_but_block, "syntax but on a literal was executed"; 34 is $topic_in_but_block, 3, "topic in syntax but on a literal was correct"; 35 } 36 37 # With an own class 38 { 39 class SampleClass { has $.attr } 40 41 my $was_in_but_block; 42 my $topic_in_but_block; 43 44 my $obj = SampleClass.new but { 45 $was_in_but_block++; 46 $topic_in_but_block = $_; 30 47 .attr = 42; 31 48 23; 32 } ';49 }; 33 50 34 51 ok $was_in_but_block, 'syntax but ($obj but {...}) was executed'; 35 52 cmp_ok $topic_in_but_block, &infix:<=:=>, $obj, 36 53 'topic in syntax but ($obj but {...}) was correct'; 37 is try { $obj.attr }, 42, "attribute setting worked correctly in syntax but"; 38 cmp_ok $obj, &infix:<!=>, 23, "syntax but returned the original object"; 54 my $attr = try { $obj.attr }; 55 is $attr, 42, "attribute setting worked correctly in syntax but"; 56 cmp_ok $obj, &infix:<~~>, SampleClass, "syntax but returned the original object"; 39 57 }
