Language::Befunge::LaheySpace::Generic.3pm

Langue: en

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

Section: 3 (Bibliothèques de fonctions)

NAME

Language::Befunge::LaheySpace::Generic - a generic N-dimensional LaheySpace.

SYNOPSIS

     # create a 3-dimensional LaheySpace.
     my $torus = Language::Befunge::LaheySpace::Generic->new(3);
     $torus->clear();
     $torus->store(<<"EOF");
     12345
     67890
     \fabcde
     fghij
     EOF
 
 

Note you usually don't need to use this module directly. Language::Befunge::Interpreter uses it internally, for non-2-dimensional storage. For 2-dimensional storage, Language::Befunge::LaheySpace is used instead, because it is more efficient.

DESCRIPTION

This module implements a traditional Lahey space.

CONSTRUCTOR


new( dimensions )

Creates a new Lahey Space.

PUBLIC METHODS


clear( )

Clear the torus.

store( code, [vector] )

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

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. Planes are separated by form feeds. A complete list of separators follows:

     Axis    Delimiter
     X       (none)
     Y       \n
     Z       \f
     4       \0
 
 

The new-line and form-feed delimiters are in the Funge98 spec. However, there is no standardized separator for dimensions above Z. Currently, dimensions 4 and above use \0, \0\0, \0\0\0, etc. These are dangerously ambiguous, but are the only way I can think of to retain reverse compatibility. Suggestions for better delimiters are welcome. (Using XML would be really ugly, I'd prefer not to.)

store_binary( code, [vectir] )

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. The data is stored all in one row.

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 Funge, 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 Funge, code and data share the same playfield, the number returned can be either an instruction or a data (or even both... Eh, that's Funge! :o) ).

set_value( vector, value )

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

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

move_ip_forward( ip )

Move the given ip forward, according to its delta.

wrap( position, delta )

Handle LaheySpace wrapping, if necessary.

rectangle( start, size )

Return a string containing the data/code in the specified rectangle.

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 two vectors: 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 cardinal directions; west, east, north, south, up, down and so forth.

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

get_min()

Returns a Vector object, pointing at the beginning of the torus. If nothing has been stored to a negative offset, this Vector will point at the origin (0,0).

get_max()

Returns a Vector object, pointing at the end of the torus. This is usually the largest position which has been written to.

PRIVATE METHODS


_enlarge( v )

Expand the torus to include the provided point.

_out_of_bounds( $vector )


_out_of_bounds( $vector )

Return true if a location is out of bounds.

_labels_try( start, delta )

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.

_rasterize( vector )

Return the next vector in raster order. To enumerate the entire storage area, the caller should pass in $$self{min} the first time, and keep looping until the return value == $$self{max}.

BUGS

None known. Please inform me if you find one.

SEE ALSO

Language::Befunge::LaheySpace, Language::Befunge.

AUTHOR

Mark Glines, <infinoid@cpan.org> Jerome Quelin, <jquelin@cpan.org>

Development is discussed on <language-befunge@mongueurs.net>

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.