Changeset 7901
- Timestamp:
- 11/07/05 20:38:21 (3 years ago)
- Files:
-
- 5 modified
-
src/Pugs/AST/Scope.hs (modified) (1 diff)
-
src/Pugs/Lexer.hs (modified) (1 diff)
-
src/Pugs/Parser.hs (modified) (1 diff)
-
t/builtins/numify.t (modified) (2 diffs)
-
t/var/caller.t (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/AST/Scope.hs
r6432 r7901 9 9 | SLet -- ^ Hypotheticalised (reverted upon failure) 10 10 | STemp -- ^ Temporary (reverted at scope exit) 11 | SEnv -- ^ Environment (declared with @env@) 11 12 | SMy -- ^ Lexical 12 13 | SOur -- ^ Package -
src/Pugs/Lexer.hs
r7752 r7901 275 275 readScope "let" = SLet 276 276 readScope "temp" = STemp 277 readScope "env" = SEnv 277 278 readScope _ = SGlobal 278 279 -
src/Pugs/Parser.hs
r7848 r7901 1977 1977 1978 1978 ruleTwigil :: RuleParser String 1979 ruleTwigil = option "" . choice . map string $ words " ^ * ? . : "1979 ruleTwigil = option "" . choice . map string $ words " ^ * ? . : + " 1980 1980 1981 1981 ruleMatchPos :: RuleParser String -
t/builtins/numify.t
r6894 r7901 4 4 use Test; 5 5 6 plan 37;6 plan 40; 7 7 8 8 is(int('-1.999'), -1, "int('-1.999') is -1"); … … 11 11 is(int('0o678'), 0o67, "int('0o678') is 0o67"); 12 12 is(int('3e4d5'), 3e4, "int('3e4d5') is 3e4"); 13 14 # Per Larry: http://www.nntp.perl.org/group/perl.perl6.compiler/1134 15 is(+'0012', 12, "+'0012' is 12"); 16 is(+'0000', 0, "+'0000' is 0"); 17 is(+'000a', 0, "+'000a' is 0 (illegal number)"); 13 18 14 19 is(+'1.9e3', 1900, "+'1.9e3' is 1900"); -
t/var/caller.t
r7663 r7901 4 4 use Test; 5 5 6 plan 8;6 plan 17; 7 7 8 8 { 9 my $a is env= 9;9 env $a = 9; 10 10 my $sub = sub { $CALLER::a }; 11 11 … … 17 17 18 18 { 19 my $a is env= 9;19 env $a = 9; 20 20 my $sub2 = sub { $CALLER::a }; 21 21 my $sub1 = sub { 22 my $a is env= 10;22 env $a = 10; 23 23 $sub2(); 24 24 }; 25 25 26 26 { 27 my$a = 11;27 env $a = 11; 28 28 is $sub1(), 10, '$CALLER:: with nested subs works'; 29 }30 }31 32 {33 my $a is env = 9;34 my $sub2 = sub { $CALLER::a };35 my $sub1 = sub ($a is env) {36 $sub2();37 };38 39 {40 my $a = 11;41 is $sub1(15), 15, '$CALLER:: works when accessing subparams, too';42 29 } 43 30 } … … 46 33 my $get_caller = sub { return sub { $CALLER::CALLER::a } }; 47 34 my $sub1 = sub { 48 my $a is env= 3;35 env $a = 3; 49 36 $get_caller(); 50 37 }; 51 38 my $sub2 = sub { 52 my $a is env= 5;39 env $a = 5; 53 40 $get_caller(); 54 41 }; … … 65 52 # L<S02/"Names" /The CALLER package refers to the lexical scope/> 66 53 { 67 # $_ is always implicitly declared " isenv".54 # $_ is always implicitly declared "env". 68 55 my sub foo () { $CALLER::_ } 69 56 my sub bar () { … … 73 60 74 61 $_ = 23; 75 is bar(), 42, '$_ is implicitly declared " isenv" (1)';62 is bar(), 42, '$_ is implicitly declared "env" (1)'; 76 63 } 77 64 78 65 { 79 # $_ is always implicitly declared " isenv".66 # $_ is always implicitly declared "env". 80 67 # (And, BTW, $_ is lexical.) 81 68 my sub foo () { $_ = 17; $CALLER::_ } … … 86 73 87 74 $_ = 23; 88 is bar(), 42, '$_ is implicitly declared " isenv" (2)';75 is bar(), 42, '$_ is implicitly declared "env" (2)'; 89 76 } 90 77 91 78 { 92 79 # ...but other vars are not 93 my sub foo { my $abc = 17; $CALLER:: _}80 my sub foo { my $abc = 17; $CALLER::abc } 94 81 my sub bar { 95 82 my $abc = 42; … … 99 86 my $abs = 23; 100 87 dies_ok { bar() }, 101 'vars not declared "is env" are not accessible via $CALLER::_'; 88 'vars not declared "env" are not accessible via $CALLER::'; 89 } 90 91 # Vars declared with env() default to being rw in the creating scope and 92 # readonly when accessed with $CALLER::. 93 { 94 env $foo = 42; 95 $foo++; 96 is $foo, 43, "env() vars are rw in the creating scope (1)"; 97 } 98 99 { 100 env $foo = 42; 101 { $foo++ } 102 is $foo, 43, "env() vars are rw in the creating scope (2)"; 103 } 104 105 { 106 my sub modify { $CALLER::foo++ } 107 env $foo = 42; 108 dies_ok { modify() }, 'env() vars are ro when accessed with $CALLER::'; 109 } 110 111 { 112 my sub modify { $CALLER::_++ } 113 $_ = 42; 114 lives_ok { modify() }, '$_ is implicitly rw (1)'; 115 is $_, 43, '$_ is implicitly rw (2)'; 116 } 117 118 { 119 my sub modify { $CALLER::foo++ } 120 env $foo is rw = 42; 121 lives_ok { modify() }, 122 'env() vars declared "is rw" are rw when accessed with $CALLER:: (1)'; 123 is $foo, 43, 124 'env() vars declared "is rw" are rw when accessed with $CALLER:: (2)'; 125 } 126 127 =begin underspecced 128 129 # Is $+foo really short for $CALLER::foo? S02 doesn't make this 100% clear. 130 131 { 132 my sub get_foo { try { $+foo } } 133 env $foo = 42; 134 135 is get_foo(), 42, '$+ is short for $CALLER::'; 136 } 137 138 =end underspecced 139 140 =cut 141 142 # Rebinding caller's variables -- legal? 143 { 144 my $other_var = 23; 145 my sub rebind_foo { $CALLER::foo := $other_var } 146 env $foo = 42; 147 148 lives_ok { rebind_foo() }, 'rebinding $CALLER:: variables works (1)'; 149 is $foo, 23, 'rebinding $CALLER:: variables works (2)'; 150 $other_var++; 151 is $foo, 24, 'rebinding $CALLER:: variables works (3)'; 102 152 } 103 153
