Language::Befunge::Interpreter.3pm

Langue: en

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

Section: 3 (Bibliothèques de fonctions)

CONSTRUCTOR


new( [filename, ] [ Key => Value, ... ] )

Create a new Befunge interpreter. As an optional first argument, you can pass it a filename to read Funge code from (default: blank torus). All other arguments are key=>value pairs. The following keys are accepted, with their default values shown:

     Dimensions => 2,
     Syntax     => 'befunge98',
     Storage    => 'laheyspace'
 
 

ACCESSORS

The following is a list of attributes of a Language::Befunge object. For each of them, a method "get_foobar" and "set_foobar" exists, which does what you can imagine - and if you can't, then i wonder why you are reading this! :-)
get_curip() / set_curip()
the current Instruction Pointer processed (a L::B::IP object)
get_DEBUG() / set_DEBUG()
wether the interpreter should output debug messages (a boolean)
get_dimensions() / set_dimensions()
the number of dimensions this interpreter works in.
get_file() / set_file()
the script filename (a string)
get_handprint() / set_handprint()
the handprint of the interpreter
get_ips() / set_ips()
the current set of IPs travelling in the Lahey space (an array reference)
get_newips() / set_newips()
the set of IPs that will travel in the Lahey space after the current tick (an array reference)
get_ops() / set_ops()
the current supported operations set.
get_params() / set_params()
the parameters of the script (an array reference)
get_retval() / set_retval()
the current return value of the interpreter (an integer)
get_torus() / set_torus()
the current Lahey space (a L::B::LaheySpace object)

PUBLIC METHODS


Utilities

move_curip( [regex] )
Move the current IP according to its delta on the LaheySpace topology.

If a regex ( a "qr//" object ) is specified, then IP will move as long as the pointed character match the supplied regex.

Example: given the code ";foobar;" (assuming the IP points on the first ";") and the regex "qr/[^;]/", the IP will move in order to point on the "r".

abort( reason )
Abort the interpreter with the given reason, as well as the current file and coordinate of the offending instruction.
debug( LIST )
Issue a warning if the interpreter has DEBUG enabled.

Code and Data Storage

read_file( filename )
Read a file (given as argument) and store its code.

Side effect: clear the previous code.

store_code( code )
Store the given code in the Lahey space.

Side effect: clear the previous code.

Run methods

run_code( [params] )
Run the current code. That is, create a new Instruction Pointer and move it around the code.

Return the exit code of the program.

next_tick( )
Finish the current tick and stop just before the next tick.
process_ip( )
Process the current ip.

TODO

o
Write standard libraries.

BUGS

Although this module comes with a full set of tests, maybe there are subtle bugs - or maybe even I misinterpreted the Funge-98 specs. Please report them to me.

There are some bugs anyway, but they come from the specs:

o
About the 18th cell pushed by the "y" instruction: Funge specs just tell to push onto the stack the size of the stacks, but nothing is said about how user will retrieve the number of stacks.
o
About the load semantics. Once a library is loaded, the interpreter is to put onto the TOSS the fingerprint of the just-loaded library. But nothing is said if the fingerprint is bigger than the maximum cell width (here, 4 bytes). This means that libraries can't have a name bigger than 0x80000000, ie, more than four letters with the first one smaller than "P" ("chr(80)").

Since perl is not so rigid, one can build libraries with more than four letters, but perl will issue a warning about non-portability of numbers greater than 0xffffffff.

ACKNOWLEDGEMENTS

I would like to thank Chris Pressey, creator of Befunge, who gave a whole new dimension to both coding and obfuscating.

SEE ALSO

Language::Befunge

AUTHOR

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.