5 has next_op => (is => 'ro', required => 1);
7 has return_stack => (is => 'ro', required => 1);
9 has by_id => (is => 'ro', required => 1);
11 has scope => (is => 'ro', required => 1);
13 has last_choice => (is => 'ro', required => 1);
16 my ($self, $name) = @_;
17 $self->by_id->{$self->scope->{$name}};
20 sub bind_stream_then {
21 my ($self, $var, $stream, $then) = @_;
22 warn "Binding ".$var->id." to $stream";
23 my $bound = $var->with_stream($stream);
25 by_id => { %{$self->by_id}, $var->id => $bound },
27 )->mark_choice($bound);
31 my ($self, $var) = @_;
33 last_choice => [ $self, $var ]
39 my ($state, $var) = ($self);
40 while (($state, $var) = @{$state->last_choice}) {
41 $var->bound_value; $var->clear_bound_value;
42 return $state->mark_choice($var) unless $var->bound_stream->is_exhausted;
48 my ($self, $then) = @_;
49 $self->new(%$self, next_op => $then);
54 while (my $op = $state->next_op) {
55 $state = $op->run($state);