NAME

Language::Befunge::Interpreter - an interpreter for Language::Befunge

VERSION

version 5.000

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_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_storage()

the LB::Storage object containing the playfield.

get_wrapping()

the LB::Wrapping object driving wrapping policy. Private.

PUBLIC METHODS

Utilities

move_ip( $ip [, $regex] )

Move the $ip according to its delta on the storage.

If $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.

set_input( $string )

Preload the input buffer with the given value.

get_input( )

Fetch a character of input from the input buffer, or else, directly from stdin.

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.

AUTHOR

Jerome Quelin

COPYRIGHT AND LICENSE

This software is copyright (c) 2003 by Jerome Quelin.

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