Skip to content

Commit

Permalink
Get handles wired up and working. Patch mostly by maard++ with a few …
Browse files Browse the repository at this point in the history
…tweaks from me.
  • Loading branch information
jnthn committed Jun 19, 2010
1 parent edb8be9 commit 478bde3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/Perl6/Actions.pm
Expand Up @@ -921,6 +921,10 @@ sub declare_variable($/, $past, $sigil, $twigil, $desigilname, $trait_list) {
%attr_info<type> := $*TYPENAME;
%attr_info<accessor> := $twigil eq '.' ?? 1 !! 0;
%attr_info<rw> := $trait_list && has_compiler_trait_with_val($trait_list, '&trait_mod:<is>', 'rw') ?? 1 !! 0;
my $has_handles := has_compiler_trait($trait_list, '&trait_mod:<handles>');
if $has_handles {
%attr_info<handles> := $has_handles[0];
}
@PACKAGE[0].attributes.push(%attr_info);

# If no twigil, note $foo is an alias to $!foo.
Expand Down
4 changes: 4 additions & 0 deletions src/Perl6/Compiler/Package.pm
Expand Up @@ -177,6 +177,10 @@ method finish($block) {
$_<build>.named('build');
$attr.push($_<build>);
}
if $_<handles> {
$_<handles>.named('handles');
$attr.push($_<handles>);
}
if $_<type> ~~ PAST::Node {
$_<type>.named('type');
$attr.push($_<type>);
Expand Down
24 changes: 12 additions & 12 deletions src/glue/handles.pm
@@ -1,20 +1,20 @@
our sub add_handles_method_helper($metaclass, $attr, $meth-name, $meth-rename = $meth-name) {
$metaclass.add_method($metaclass, $meth-name, (method (|$c) {
pir::getattribute__PPS(self, $attr)."$meth-rename"(|$c);
}).clone() );
}
class Rakudo::Guts {
sub add_handles_method_helper(Mu $metaclass, $attr, $meth_name, $meth_rename = $meth_name) {
$metaclass.add_method($metaclass, $meth_name, (method (|$c) {
pir::getattribute__PPS(self, $attr)."$meth_rename"(|$c);
}).clone());
}

our sub add_handles_method($metaclass, $attr_name, $expr) {
for ($expr) -> $x {
given $x {
when Str { add_handles_method_helper($metaclass, $attr_name, $x); }
method add_handles_method(Mu $metaclass, $attr_name, $expr) {
given $expr {
when Str { add_handles_method_helper($metaclass, $attr_name, $expr); }
when Parcel {
for $x.list -> $x { add_handles_method_helper($metaclass, $attr_name, $x); }
for $expr.list -> $x { add_handles_method($metaclass, $attr_name, $x); }
}
when Pair {
add_handles_method_helper($metaclass, $attr_name, $x.key, $x.value);
add_handles_method_helper($metaclass, $attr_name, $expr.key, $expr.value);
}
default { die sprintf("add_handles_method can't handle %s in list", $x.WHAT); }
default { die sprintf("add_handles_method can't handle %s in list", $expr.WHAT); }
}
}
}
5 changes: 4 additions & 1 deletion src/metamodel/Attribute.nqp
Expand Up @@ -83,7 +83,10 @@ method compose($package) {
$package.add_method($package, $meth_name, $meth);
}

# XXX Handles...
# If we've a handles, pass it along to the handles setup helper.
if $!handles {
Rakudo::Guts.add_handles_method($package, $!name, $!handles);
}
}

# vim: ft=perl6

0 comments on commit 478bde3

Please sign in to comment.