Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[viv] Add $<x> = { code } to reduce dependency on mutable cursors
  • Loading branch information
sorear committed Feb 11, 2011
1 parent 0ef3d73 commit 4608239
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions CursorBase.pmc
Expand Up @@ -597,6 +597,28 @@ sub cursor_bind { my $self = shift; # this is parent's match cursor
bless \%r, ref $self; # return new match cursor for parent
}

sub cursor_bind_value { my $self = shift; # this is parent's match cursor
my $binding = shift;
my $value = shift;
delete $self->{_fate};

$self->deb("cursor_bind_value $binding") if DEBUG & DEBUG::cursors;
my @caps;
@caps = @{$self->{'~CAPS'}} if $self->{'~CAPS'}; # must copy elems
my %r = %$self;
if (ref $r{$binding} eq 'ARRAY') {
push(@{$r{$binding}}, $value);
}
else {
$r{$binding} = $value;
}
push @caps, $binding, $value
unless $binding eq 'PRE' or $binding eq 'POST';
$r{'~CAPS'} = \@caps;
$r{_xact} = $self->{_xact};
bless \%r, ref $self; # return new match cursor for parent
}

sub cursor_fate { my $self = shift;
my $pkg = shift;
my $name = shift;
Expand Down Expand Up @@ -1334,6 +1356,15 @@ sub _SUBSUMEr { my $self = shift;
$self->cursor_bind($names, $var)->retm();
}

sub _SUBSUMEblock { my $self = shift;
my $name = shift;
my $block = shift;
no warnings 'recursion';

local $CTX = $self->callm($name) if DEBUG & DEBUG::trace_call;
$self->cursor_bind_value($name, $block->($self))->retm();
}

sub _EXACT_rev { my $self = shift;
my $s = shift() // '';
my @ints = unpack("U*", $s);
Expand Down
3 changes: 3 additions & 0 deletions viv
Expand Up @@ -3929,6 +3929,9 @@ END
local $::BINDINSIDE = $var;
return $$self{atom}->walk;
}
if ($$self{atom}->isa('RE_block') && $$self{atom}{context} eq 'void') {
return DEEP::raw("\$C->_SUBSUMEblock('" . $var . "', sub {\n" . ::indent("my \$C = shift;\n" . $$self{atom}{body}) . "})", precut => 1);
}
my $re = $$self{atom}->walk;
$self->bind($re, $var);
}
Expand Down

0 comments on commit 4608239

Please sign in to comment.