Language::Befunge::LaheySpace.3pm

Langue: en

Version: 2008-01-22 (mandriva - 01/05/08)

Section: 3 (Bibliothèques de fonctions)

NAME

Language::Befunge::LaheySpace - a 2-dimensional LaheySpace representation.

SYNOPSIS

         # create a 2-dimensional LaheySpace.
         my $torus = Language::Befunge::LaheySpace->new();
         $torus->clear();
         $torus->store(<<EOF);
         12345
         67890
         EOF
 
 

Note you usually don't need to use this module directly. Language::Befunge::Interpreter uses it internally, for 2-dimensional storage. For non-2-dimensional storage, see Language::Befunge::LaheySpace::Generic.

DESCRIPTION

CONSTRUCTOR


new( )

Creates a new Lahey Space.

PUBLIC METHODS


clear( )

Clear the torus.

store( code, [vector] )

Store the given code at the specified coordinates. If the coordinates are omitted, then the code is stored at the Origin(0, 0) coordinates.

Return the size of the code inserted, as a vector.

The code is a string, representing a block of Funge code. Rows are separated by newlines.

store_binary( code, [vector] )

Store the given code at the specified coordinates. If the coordinates are omitted, then the code is stored at the Origin(0, 0) coordinates.

Return the size of the code inserted, as a vector.

This is binary insertion, that is, EOL and FF sequences are stored in Funge-space instead of causing the dimension counters to be reset and incremented.

get_char( vector )

Return the character stored in the torus at the specified location. If the value is not between 0 and 255 (inclusive), get_char will return a string that looks like ``<np-0x4500>''.

/!\ As in Befunge, code and data share the same playfield, the character returned can be either an instruction or raw data. No guarantee is made that the return value is printable.

get_value( vector )

Return the number stored in the torus at the specified location. If the value hasn't yet been set, it defaults to the ordinal value of a space (ie, #32).

/!\ As in Befunge, code and data share the same playfield, the number returned can be either an instruction or a data (or even both... Eh, that's Befunge! :o) ).

set_value( vector, value )

Write the supplied value in the torus at the specified location.

/!\ As in Befunge, code and data share the same playfield, the number stored can be either an instruction or a data (or even both... Eh, that's Befunge! :o) ).

move_ip_forward( ip )

Move the given ip forward, according to its delta.

rectangle( pos, size )

Return a string containing the data/code in the rectangle defined by the supplied vectors.

labels_lookup( )

Parse the Lahey space to find sequences such as ";:(\w[^\s;])[^;]*;" and return a hash reference whose keys are the labels and the values an anonymous array with four values: a vector describing the absolute position of the character just after the trailing ";", and a vector describing the velocity that lead to this label.

This method will only look in the four cardinal directions.

This allow to define some labels in the source code, to be used by "Inline::Befunge" (and maybe some exstensions).

PRIVATE METHODS


_set_min( x, y )

Set the current minimum coordinates. If the supplied values are bigger than the actual minimum, then nothing is done.

_set_max( x, y )

Set the current maximum coordinates. If the supplied values are smaller than the actual maximum, then nothing is done.

_enlarge_x( dx )

Enlarge the torus on its x coordinate. If the delta is positive, add columns after the last column; if negative, before the first column; if nul, nothing is done.

_enlarge_y( dy )

Enlarge the torus on its y coordinate. If the delta is positive, add lines after the last one; if negative, before the first line; if nul, nothing is done.

_out_of_bounds( vector )

Return true if a location is out of bounds.

_labels_try( x, y, dx, dy )

Try in the specified direction if the funge space matches a label definition. Return undef if it wasn't a label definition, or the name of the label if it was a valid label.

BUGS

The funge-space representation (a 2-D array) is incredibly wasteful. Given the difficulty of writing large befunge programs, this should not be noticeable.

SEE ALSO

Language::Befunge.

AUTHOR

Jerome Quelin, <jquelin@cpan.org> Copyright (c) 2001-2008 Jerome Quelin, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.