Language::Nouse - Perl interpreter for the nouse language
# create a new interpreter
my $nouse = new Language::Nouse;
# load a linenoise formatted program
$nouse->load_linenoise( '#0<a>0:0#0>e>0:0#0>f>0>0:0#0^f>0:0#0+4>0:0#0#h>0:0#0^f>0:0#0<g>0:0#0>f' );
$nouse->load_linenoise( '>0:0#0<e>0:0#0?4>0:0#0^1>0:0#0>1>0:0^0' );
# display the loaded program in assembly mode, with 5 ops per line
print $nouse->get_assembly( 5 );
# clear the ring/stack
# load an assembly formatted program
$nouse->load_assembly( 'read 0, write 6, swap 0, test 2, add 1' );
# run a single step of the program
# display the loaded program in linenoise mode
# NOTE: the previous step() call may have chaged the program in the ring!
# run the program to completion (until the ring is empty)
The Language::Nouse module is an interpreter for the "nouse" language. It allows you to load and save nouse programs in both linenoise and assembly format, single step and run through code.
IO is handled via two callbacks. By default these simply "print" the output and "getc" for input, but can be configured to use custom routines.
The internals of the execution engine contain a whole bunch of microcode methods with are used to run the interpreter. The more adventurous can use these methods to finely control the engine and inspect the ring and stack.
Creates and returns a new interpreter. The ring and stack are both empty and the ring pointer is set to zero.
set_get( $code_ref )
Sets the IO get routine. This routine must return a character when called, or Undef for the end of available IO.
set_put( $code_ref )
Sets the IO put routine. This routine is passed a single argument containing a single char to output.
load_linenoise( $source_code )
Loads a program into the ring, formatted in linenoise mode. If the ring is not empty, the program is appended to the end of the ring (that is, in the position just *before* the ring pointer).
load_assembly( $source_code )
Loads a program into the ring, formatted in assemblye mode. If the ring is not empty, the program is appended to the end of the ring (that is, in the position just *before* the ring pointer).
Clears the ring and the stack and resets the ring pointer to zero. After a call to clear(), the interpreter is in the same state as when it was created.
Returns a scalar containing the current program, formatted in linenoise mode.
get_assembly( $ops_per_line )
Returns a scalar containing the current program, formatted in assembly mode. The optional argument specifies how many ops to show per line. The code is formatted with commas to seperate ops and, by default, 4 ops per line, which are seperated with newlines.
Runs the program for a single step - that is, it executes the op currently under the ring pointer.
Calls step() until the ring is empty.
Copyright (C) 2003 Cal Henderson, <email@example.com>
To install Language::Nouse, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.