Skip to content
Browse files

Implement .^ meta-calls

  • Loading branch information...
1 parent b1f1f63 commit 2dc1686db08ac64f8b1d49cea6cfa1b1a2bc107e @sorear committed Jul 18, 2010
Showing with 47 additions and 0 deletions.
  1. +10 −0 CgOp.pm
  2. +14 −0 Niecza/Actions.pm
  3. +23 −0 Op.pm
View
10 CgOp.pm
@@ -337,6 +337,16 @@ use warnings;
check => $_[2],
body => $_[3]);
}
+
+ my $nextlet = 0;
+ sub let {
+ my ($head, $type, $bodyf) = @_;
+ my $v = 'let!' . ($nextlet++);
+ my $body = $bodyf->(nil([rawlexget => $v, 0 ]));
+
+ nil(lextypes($v,$type), $head, [ rawlexput => $v, 0 ], $body,
+ null($type), [ rawlexput => $v, 0 ]);
+ }
}
1;
View
14 Niecza/Actions.pm
@@ -267,6 +267,11 @@ sub POSTFIX { my ($cl, $M) = @_;
$M->{_ast} = Op::Interrogative->new(
receiver => $M->{arg}{_ast},
name => $op->{name});
+ } elsif ($op->{metamethod}) {
+ $M->{_ast} = Op::CallMetaMethod->new(
+ receiver => $M->{arg}{_ast},
+ name => $op->{metamethod},
+ positionals => $op->{args} // []);
} elsif ($op->{name}) {
$M->{_ast} = Op::CallMethod->new(
receiver => $M->{arg}{_ast},
@@ -349,6 +354,15 @@ sub dotty__S_Dot { my ($cl, $M) = @_;
$M->{_ast} = $M->{dottyop}{_ast};
}
+sub dotty__S_DotStar { my ($cl, $M) = @_;
+ if ($M->{sym} eq '.^' && $M->{dottyop}{_ast}{name}) {
+ $M->{_ast} = { metamethod => $M->{dottyop}{_ast}{name},
+ args => $M->{dottyop}{_ast}{args} };
+ } else {
+ $M->sorry('NYI dottyop form ' . $M->{sym});
+ }
+}
+
sub coloncircumfix { my ($cl, $M) = @_;
$M->{_ast} = $M->{circumfix}{_ast};
$M->{qpvalue} = $M->{circumfix}{qpvalue};
View
23 Op.pm
@@ -111,6 +111,29 @@ use CgOp;
no Moose;
}
+# or maybe we should provide Op::Let and let Actions do the desugaring?
+{
+ package Op::CallMetaMethod;
+ use Moose;
+ extends 'Op';
+
+ has receiver => (isa => 'Op', is => 'ro', required => 1);
+ has positionals => (isa => 'ArrayRef[Op]', is => 'ro',
+ default => sub { [] });
+ has name => (isa => 'Str', is => 'ro', required => 1);
+
+ sub code {
+ my ($self, $body) = @_;
+ CgOp::let($self->receiver->code($body), 'Variable', sub {
+ CgOp::methodcall(CgOp::newscalar(CgOp::how(CgOp::fetch($_[0]))),
+ $self->name, $_[0], map { $_->code($body) }
+ @{ $self->positionals })});
+ }
+
+ __PACKAGE__->meta->make_immutable;
+ no Moose;
+}
+
{
package Op::Interrogative;
use Moose;

0 comments on commit 2dc1686

Please sign in to comment.
Something went wrong with that request. Please try again.