my ($self, $var, $stream, $then) = @_;
warn "Binding ".$var->id." to $stream";
my $bound = $var->with_stream($stream);
- $self->new(%$self,
+ $self->but(
by_id => { %{$self->by_id}, $var->id => $bound },
next_op => $then
)->mark_choice($bound);
sub mark_choice {
my ($self, $var) = @_;
- $self->new(%$self,
- last_choice => [ $self, $var ]
- );
+ $self->but(last_choice => [ $self, $var ]);
}
sub backtrack {
sub then {
my ($self, $then) = @_;
- $self->new(%$self, next_op => $then);
+ $self->but(next_op => $then);
}
sub run {
$_[0]->then(DX::Op::FromCode->new(code => sub { $_[1]->backtrack }));
}
+sub but {
+ my ($self, @but) = @_;
+ $self->new(%$self, @but);
+}
+
1;
my ($self, $state) = @_;
my @stack = @{$state->return_stack};
my $top = pop @stack;
- $state->new(%$state, return_stack => \@stack, next_op => $top);
+ $state->but(return_stack => \@stack, next_op => $top);
}
));
my $save_scope = $state->scope;
my %scope = (S => $save_scope->{S});
my $ret_op = FromCode->new(
- code => sub { $_[1]->new(%{$_[1]}, scope => $save_scope, next_op => $_[0]->next) },
+ code => sub { $_[1]->but(scope => $save_scope, next_op => $_[0]->next) },
next => $self->next,
);
- $state->new(%$state,
+ $state->but(
scope => \%scope,
return_stack => [ @rst, $ret_op ],
next_op => $inner_op