Author: pmichaud Date: Sat Jan 3 06:53:45 2009 New Revision: 34882 Modified: branches/rvar/languages/perl6/src/builtins/guts.pir branches/rvar/languages/perl6/src/parser/actions.pm
Log: [rakudo]: Refactor public accessor handling. Modified: branches/rvar/languages/perl6/src/builtins/guts.pir ============================================================================== --- branches/rvar/languages/perl6/src/builtins/guts.pir (original) +++ branches/rvar/languages/perl6/src/builtins/guts.pir Sat Jan 3 06:53:45 2009 @@ -450,12 +450,6 @@ goto twigil_done twigil_public: substr name, 1, 1, '!' - .const 'Sub' accessor = '!default_accessor' - $P0 = clone accessor - $P1 = box name - setprop $P0, 'name', $P1 - $S0 = substr name, 2 - metaclass.'add_method'($S0, $P0) twigil_done: # Add the attribute to the metaclass. @@ -479,17 +473,6 @@ .end -.sub '!default_accessor' :anon :method - .local pmc interp, accessor - interp = getinterp - accessor = interp['sub'] - $P0 = getprop 'name', accessor - $S0 = $P0 - $P1 = getattribute self, $S0 - .return ($P1) -.end - - =item !keyword_class(name) Internal helper method to create a class. Modified: branches/rvar/languages/perl6/src/parser/actions.pm ============================================================================== --- branches/rvar/languages/perl6/src/parser/actions.pm (original) +++ branches/rvar/languages/perl6/src/parser/actions.pm Sat Jan 3 06:53:45 2009 @@ -1410,6 +1410,8 @@ method scope_declarator($/) { + our @?BLOCK; + my $block := @?BLOCK[0]; my $sym := ~$<sym>; my $past := $( $<scoped> ); my $scope := 'lexical'; @@ -1425,22 +1427,29 @@ if $_.isa(PAST::Var) { my $var := $_; - my $type; - if +@($var<type>) { $type := $var<type>[0]; } # FIXME - # This is a variable declaration, so we set the scope in - # the block. The symbol entry also tells us the - # implementation type of the variable (itype), any - # initial value for the variable (viviself), and - # any type constraints (type). - our @?BLOCK; - @?BLOCK[0].symbol( $var.name(), :scope($scope) ); + # the block's symbol table as well as the variable itself. + $block.symbol( $var.name(), :scope($scope) ); $var.scope($scope); $var.isdecl(1); if $scope eq 'package' { $var.lvalue(1); } my $init_value := $var.viviself(); + my $type; + if +@($var<type>) { $type := $var<type>[0]; } # FIXME + # If the var has a '.' twigil, we need to create an + # accessor method for it in the block (class/grammar/role) + if $var<twigil> eq '.' { + my $method := PAST::Block.new( :blocktype('method') ); + $method.name( substr($var.name(), 2) ); + $method.push( PAST::Var.new( :name($var.name()) ) ); + $block[0].push($method); + } + if $scope eq 'attribute' { + # Attribute declaration. Add code to the beginning + # of the block (really class/grammar/role) to + # create the attribute. our $?METACLASS; my $has := PAST::Op.new( :name('!meta_attribute'), $?METACLASS, $var.name(), $var<itype> ); @@ -1449,7 +1458,7 @@ $init_value.named('init_value'); $has.push($init_value); } - @?BLOCK[0].push( $has ); + $block[0].push( $has ); } else { # $scope eq 'package' | 'lexical' @@ -1542,7 +1551,7 @@ my $varname := $sigil ~ $twigil ~ $name; # If no twigil, but varname is 'attribute' in outer scope, - # it's really a private attribute and needs a '!' twigil + # it's really a private attribute and implies a '!' twigil if !$twigil { my $sym := outer_symbol($varname); if $sym && $sym<scope> eq 'attribute' { @@ -1613,6 +1622,7 @@ # retrieved by <variable_declarator> if we're called from there. if $twigil eq '.' { my $vardecl := $var; + $vardecl.name( $sigil ~ '!' ~ $name ); $var := PAST::Op.new( :node($/), :pasttype('callmethod'), :name($name), PAST::Var.new( :name('self'), :scope('lexical') )