Acme-Aheui

 view release on metacpan or  search on metacpan

lib/Acme/Aheui.pm  view on Meta::CPAN

}

sub _loop_steps {
    my ($self) = @_;

    while (1) {
        my $codespace = $self->{_codespace};
        my ($x, $y) = ($self->{_x}, $self->{_y});

        if ($x > $#{$$codespace[$y]}) {
            $self->_move_cursor();
            next;
        }

        my $c = $$codespace[$y][$x];

        if (!$c || $c->{cho} == -1) {
            $self->_move_cursor();
            next;
        }

        my $cho = $c->{cho};
        my $jung = $c->{jung};
        my $jong = $c->{jong};
        my $si = $self->{_stack_index};

        my ($dx, $dy) = $self->_get_deltas_upon_jung($jung);
        $self->{_dx} = $dx;

lib/Acme/Aheui.pm  view on Meta::CPAN

                    $self->{_dx} = -($self->{_dx});
                    $self->{_dy} = -($self->{_dy});
                }
            }
            elsif ($cho == 18) { # ã…Ž
                my $ret = $self->_pop($si) || 0;
                return $ret;
            }
        }

        $self->_move_cursor();
    }
}

sub _move_cursor {
    my ($self) = @_;
    my $codespace = $self->{_codespace};

    $self->{_x} += $self->{_dx};
    $self->{_y} += $self->{_dy};

    my $last_row_index = $#{ $codespace };
    if ($self->{_y} < 0) {
        $self->{_y} = $last_row_index;
    }

t/01_aheui.t  view on Meta::CPAN


    is( $$interpreter{_codespace}[2][1]{cho}, -1 );
    is( $$interpreter{_codespace}[2][1]{jung}, -1 );
    is( $$interpreter{_codespace}[2][1]{jong}, -1 );

    is( $$interpreter{_codespace}[2][2]{cho}, -1 );
    is( $$interpreter{_codespace}[2][2]{jung}, -1 );
    is( $$interpreter{_codespace}[2][2]{jong}, -1 );
}

{ # move cursor
    my $source = <<'__SOURCE__';
가나다
라마
바사아자차
ì¹´
타파하
__SOURCE__
    
    my $interpreter = Acme::Aheui->new( source => $source );
    is( $interpreter->{_x}, 0 );
    is( $interpreter->{_y}, 0 );
    is( $interpreter->{_dx}, 0 );
    is( $interpreter->{_dy}, 1 );

    $interpreter->{_dx} = 1;
    $interpreter->{_dy} = 0;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [1, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [1, 0] );

    $interpreter->{_dx} = -1;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [1, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );

    $interpreter->{_dx} = 0;
    $interpreter->{_dy} = 1;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 1] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 2] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 3] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 1] );

    $interpreter->{_dy} = -1;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );

    $interpreter->{_dx} = 2;
    $interpreter->{_dy} = 0;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 4] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 4] );

    $interpreter->{_dx} = -2;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 4] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );

    $interpreter->{_dx} = 0;
    $interpreter->{_dy} = 2;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 2] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );

    $interpreter->{_dy} = -2;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 2] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
}

{ # storages

    my $counter = 0;
    sub test_stack {
        my ($interpreter, $storage_index) = @_;

        # a push and a pop



( run in 0.261 second using v1.01-cache-2.11-cpan-4d50c553e7e )