Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[nrx] implement /a||b/ form
  • Loading branch information
sorear committed Sep 5, 2010
1 parent ce9e29e commit 066f98c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/CodeGen.pm
Expand Up @@ -624,7 +624,7 @@ use 5.010;
sub rxpushb {
my ($self, $tag, $label) = @_;
push @{ $self->buffer }, " th.rx.PushBacktrack(" . qm($tag) .
", \@\@L$label);\n";
", " . ($label ? "\@\@L$label" : "-1") . ");\n";
}

sub return {
Expand Down
30 changes: 17 additions & 13 deletions src/RxOp.pm
Expand Up @@ -13,6 +13,9 @@ use CgOp;

sub opzyg { map { $_->opzyg } @{ $_[0]->zyg } }

my $nlabel = 0;
sub label { "b" . ($nlabel++) }

__PACKAGE__->meta->make_immutable;
no Moose;
}
Expand Down Expand Up @@ -152,22 +155,23 @@ use CgOp;

# zyg * N

sub op {
my ($self, $cn, $cont) = @_;
sub code {
my ($self, $body) = @_;

my $cni = Niecza::Actions->gensym;
my @terms;
push @terms, $self->_close_k($cn, $cont);
for (@{ $self->zyg }) {
push @terms, Op::CallSub->new(
invocant => $self->_close_k($_->op($cn,
Op::CallSub->new(
invocant => Op::Lexical->new(name => $terms[0]->var),
positionals => [ Op::Lexical->new(name => $cn) ]))),
positionals => [ Op::Lexical->new(name => $cni) ]);
my @ends = map { $self->label } @{ $self->zyg };
my @code;
my $n = @{ $self->zyg };

for (my $i = 0; $i < $n; $i++) {
push @code, CgOp::rxpushb("SEQALT",
($i == $n - 1) ? undef : $ends[$i]);
push @code, $self->zyg->[$i]->code($body);
push @code, CgOp::goto($ends[$n-1]) unless $i == $n-1;
push @code, CgOp::label($ends[$i]);
}

$cni, Op::StatementList->new(children => \@terms);
push @code, CgOp::rxpushb("ENDSEQALT");
@code;
}

sub lad { $_[0]->zyg->[0]->lad }
Expand Down
6 changes: 4 additions & 2 deletions test2.pl
Expand Up @@ -32,8 +32,10 @@
}
}
is +("x" ~~ /x/), 1, "x ~~ /x/";
is +("y" ~~ /x/), 0, "y !~~ /x/";
is +("x" ~~ /x||y/), 1, "x ~~ /x||y/";
is +("y" ~~ /x||y/), 1, "y ~~ /x||y/";
is +("z" ~~ /x||y/), 0, "z !~~ /x||y/";
is +(/x||x/(Cursor.new("x"))), 2, "x ~~ /x||x/ (2x) ";
#is +rxt(Cursor.new("x")), 1, "/x||y/ ~~ x";
#is +rxt(Cursor.new("y")), 1, "/x||y/ ~~ y";
Expand Down

0 comments on commit 066f98c

Please sign in to comment.