Skip to content

Commit

Permalink
Preparations for positional/associative delegate.
Browse files Browse the repository at this point in the history
This work will eliminate some of the v-table use that is in the way of
certain bits of porting work, but should also provide some other wins.
  • Loading branch information
jnthn committed Feb 9, 2013
1 parent f7eb701 commit 7133fa1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/NQP/Actions.pm
Expand Up @@ -709,6 +709,7 @@ class NQP::Actions is HLL::Actions {
my $sigil := $<variable><sigil>;
my $name := $past.name;
my $BLOCK := $*W.cur_lexpad();
my $*DECLARAND_ATTR;
if $name && $BLOCK.symbol($name) {
$/.CURSOR.panic("Redeclaration of symbol ", $name);
}
Expand All @@ -735,7 +736,7 @@ class NQP::Actions is HLL::Actions {
}

# Add it.
$*W.pkg_add_attribute($*PACKAGE, %*HOW{$*PKGDECL ~ '-attr'},
$*DECLARAND_ATTR := $*W.pkg_add_attribute($*PACKAGE, %*HOW{$*PKGDECL ~ '-attr'},
%lit_args, %obj_args);

$past := QAST::Stmts.new();
Expand Down Expand Up @@ -1179,6 +1180,12 @@ class NQP::Actions is HLL::Actions {
$*W.pkg_add_parrot_vtable_handler_mapping($package, $name, ~$match<variable>);
};
}
elsif $<longname> eq 'positional_delegate' {
$*DECLARAND_ATTR.positional_delegate(1);
}
elsif $<longname> eq 'associative_delegate' {
$*DECLARAND_ATTR.associative_delegate(1);
}
elsif $<longname> eq 'export' {
make -> $match {
my $ast := $match.ast;
Expand Down
1 change: 1 addition & 0 deletions src/NQP/World.pm
Expand Up @@ -409,6 +409,7 @@ class NQP::World is HLL::World {
method pkg_add_attribute($obj, $meta_attr, %lit_args, %obj_args) {
my $attr := $meta_attr.new(|%lit_args, |%obj_args);
$obj.HOW.add_attribute($obj, $attr);
$attr
}

# Adds a method to the meta-object.
Expand Down
18 changes: 18 additions & 0 deletions src/how/NQPAttribute.pm
Expand Up @@ -5,6 +5,8 @@ knowhow NQPAttribute {
has $!box_target;
has $!default;
has $!has_default;
has $!positional_delegate;
has $!associative_delegate;

method new(:$name!, :$box_target, *%extra) {
my $attr := nqp::create(self);
Expand Down Expand Up @@ -46,6 +48,22 @@ knowhow NQPAttribute {
method auto_viv_container() {
$!has_default ?? $!default !! nqp::null()
}

method set_positional_delegate($value) {
$!positional_delegate := $value;
}

method set_associative_delegate($value) {
$!associative_delegate := $value;
}

method positional_delegate() {
!nqp::isnull($!positional_delegate) && $!positional_delegate ?? 1 !! 0
}

method associative_delegate() {
!nqp::isnull($!associative_delegate) && $!associative_delegate ?? 1 !! 0
}

method compose($obj) {
$obj
Expand Down
6 changes: 6 additions & 0 deletions src/how/NQPClassHOW.pm
Expand Up @@ -277,6 +277,12 @@ knowhow NQPClassHOW {
if nqp::can($attr, 'auto_viv_container') {
%attr_info<auto_viv_container> := $attr.auto_viv_container;
}
if $attr.positional_delegate {
%attr_info<positional_delegate> := 1;
}
if $attr.associative_delegate {
%attr_info<associative_delegate> := 1;
}
nqp::push(@attrs, %attr_info);
}

Expand Down

0 comments on commit 7133fa1

Please sign in to comment.