Language::Befunge::IP - an Instruction Pointer for a Befunge-98 program.
This is the class implementing the Instruction Pointers. An Instruction Pointer (aka IP) has a stack, and a stack of stacks that can be manipulated via the methods of the class.
We need a class, since this is a concurrent Befunge, so we can have more than one IP travelling on the Lahey space.
Create a new Instruction Pointer, which operates in a universe of the given $dimensions. If $dimensions is not specified, it defaults to 2 (befunge world).
$dimensions
Clone the current Instruction Pointer with all its stacks, position, delta, etc. Change its unique ID.
The following is a list of attributes of a Language::Befunge::IP object. For each of them, a method get_foobar and set_foobar exists.
get_foobar
set_foobar
The unique ID of the IP (an integer). Don't set the ID yourself.
The number of dimensions this IP operates in (an integer). This is read-only.
The current coordinates of the IP (a Language::Befunge::Vector object).
Language::Befunge::Vector
The velocity of the IP (a Language::Befunge::Vector object).
The coordinates of the storage offset of the IP (a Language::Befunge::Vector object).
The library private storage space (a hash reference). Don't set this yourself. FIXME: not supposed to be accessible
The string_mode of the IP (a boolean).
Whether the IP should be terminated (a boolean).
The current stack of loaded libraries (an array reference). Don't set this yourself. FIXME: not supposed to be accessible
The stack of stack of the IP (an array reference). Don't set this yourself. FIXME: not supposed to be accessible
The current stack (er, TOSS) of the IP (an array reference). Don't set this yourself. FIXME: not supposed to be accessible
Get or set the SOSS.
In this section, I speak about the stack. In fact, this is the TOSS - that is, the Top Of the Stack Stack.
In Befunge-98, standard stack operations occur transparently on the TOSS (as if there were only one stack, as in Befunge-93).
Return the number of elements in the stack.
Push a value on top of the stack.
Push a vector on top of the stack. The x coordinate is pushed first.
Push a list of argument on top of the stack (the first argument will be the deeper one). Convert each argument: a number is pushed as is, whereas a string is pushed as a 0gnirts.
/!\ Do not push references or weird arguments: this method supports only numbers (positive and negative) and strings.
Pop a value from the stack. If the stack is empty, no error occurs and the method acts as if it popped a 0.
Pop multiple values from the stack. If the stack becomes empty, the remainder of the returned values will be 0.
Pop a vector from the stack. Returns a Vector object.
Pop a 0gnirts string from the stack.
Clear the stack.
Return the offsetth value of the TOSS, counting from top of the TOSS. The offset is interpreted as a negative value, that is, a call with an offset of 2 or -2 would return the second value on top of the TOSS.
offset
2
-2
This section discusses about the stack stack. We can speak here about TOSS (Top Of Stack Stack) and SOSS (second on stack stack).
Return the number of stacks in the stack stack. This of course does not include the TOSS itself.
Push the TOSS on the stack stack and create a new stack, aimed to be the new TOSS. Once created, transfer count elements from the SOSS (the former TOSS) to the TOSS. Transfer here means move - and not copy -, furthermore, order is preserved.
count
If count is negative, then count zeroes are pushed on the new TOSS.
Move count elements from TOSS to SOSS, discard TOSS and make the SOSS become the new TOSS. Order of elems is preserved.
Transfer count elements from SOSS to TOSS, or from TOSS to SOSS if count is negative; the transfer is done via pop/push.
The order is not preserved, it is reversed.
Return a list with all the sizes of the stacks in the stack stack (including the TOSS), from the TOSS to the BOSS.
Return the number of elements in SOSS.
Push a value on top of the SOSS.
Pop multiple values from the SOSS. If the stack becomes empty, the remainder of the returned values will be 0.
Push a vector on top of the SOSS.
Pop a value from the SOSS. If the stack is empty, no error occurs and the method acts as if it popped a 0.
Pop a vector from the SOSS. If the stack is empty, no error occurs and the method acts as if it popped a 0. returns a Vector.
Clear the SOSS.
Implements the > instruction. Force the IP to travel east.
>
Implements the < instruction. Force the IP to travel west.
<
Implements the ^ instruction. Force the IP to travel north.
^
Not valid for Unefunge.
Implements the v instruction. Force the IP to travel south.
v
Implements the h instruction. Force the IP to travel up.
h
Not valid for Unefunge or Befunge.
Implements the l instruction. Force the IP to travel down.
l
Implements the ? instruction. Cause the IP to travel in a random cardinal direction (in Befunge's case, one of: north, south, east or west).
?
Implements the [ instruction. Rotate by 90 degrees on the left the delta of the IP which encounters this instruction.
[
Not valid for Unefunge. For Trefunge and greater, only affects the X and Y axes.
Implements the ] instruction. Rotate by 90 degrees on the right the delta of the IP which encounters this instruction.
]
Not valid for Unefunge. For Trefunge and higher dimensions, only affects the X and Y axes.
Implements the r instruction. Reverse the direction of the IP, that is, multiply the IP's delta by -1.
r
Load the given library semantics. The parameter is an extension object (a library instance).
Unload the given library semantics. The parameter is the library name.
Return the library name if it was correctly unloaded, undef otherwise.
/!\ If the library has been loaded twice, this method will only unload the most recent library. Ie, if an IP has loaded the libraries ( FOO, BAR, FOO, BAZ ) and one calls unload( "FOO" ), then the IP will follow the semantics of BAZ, then BAR, then <FOO> (!).
FOO
BAR
BAZ
unload( "FOO" )
Store or fetch a value in a private space. This private space is reserved for libraries that need to store internal values.
Since in Perl references are plain scalars, one can store a reference to an array or even a hash.
Language::Befunge.
Jerome Quelin, <jquelin@cpan.org>
Copyright (c) 2001-2009 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.
To install Language::Befunge, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Language::Befunge
CPAN shell
perl -MCPAN -e shell install Language::Befunge
For more information on module installation, please visit the detailed CPAN module installation guide.