# New Ticket Created by Jerome Quelin # Please include the string: [perl #19331] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=19331 >
Thanks to Leo who fixed the bug when setting a list of lists element, the befunge interpreter now uses a list of lists (perlarray of perlarrays to be more precise) instead of a list of strings. I thought this big evolution needed a gap in my versioning scheme, so this is now befunge 0.1.0 (instead of 0.07 - yes, I also went for a traditional open-source versioning system) Jerome -- [EMAIL PROTECTED] -- attachment 1 ------------------------------------------------------ url: http://rt.perl.org/rt2/attach/46012/35999/0f0469/befunge_use_array_of_arrays.patch
? befunge.pbc Index: Changes =================================================================== RCS file: /cvs/public/parrot/languages/befunge/Changes,v retrieving revision 1.4 diff -u -d -r1.4 Changes --- Changes 1 Dec 2002 16:22:28 -0000 1.4 +++ Changes 21 Dec 2002 14:25:37 -0000 @@ -1,4 +1,11 @@ -Revision history for Befunge-93 interpreter written for Parrot. +Revision history for a Befunge interpreter written for Parrot. + +0.1.0 Sat Dec 21 14:58:24 CET 2002 + - playfield now is an array of array (of integers) instead of + an array of strings. + - load, io and debug updated to reflect this. + - new versioning scheme, and minor version incrementing since + this is a big step for the project. 0.06 Sun Dec 1 10:00:35 CET 2002 - debugger can now interact with user. Index: README =================================================================== RCS file: /cvs/public/parrot/languages/befunge/README,v retrieving revision 1.6 diff -u -d -r1.6 README --- README 1 Dec 2002 16:22:28 -0000 1.6 +++ README 21 Dec 2002 14:25:37 -0000 @@ -1,11 +1,12 @@ DESCRIPTION ----------- -This is a Befunge interpreter written in Parrot assembler, version 0.06 +This is a Befunge interpreter written in Parrot assembler, version 0.1.0 This interpreter should be Befunge-93 compliant. This means the -playfield is limited to 80x25 and can hold *only bytes*. This means -that you can't fetch/store numbers greater than 255 or less than 0 in -the torus (even if I do not check for over/underflow - for now). +playfield is limited to 80x25. This should also mean that the torus +can hold *only bytes* (that is, you can't store/fetch numbers greater +than 255 or less than 0), but actually I do not check for over / +underflow - for now. You should compile and test the files with: @@ -25,7 +26,7 @@ befunge.pasm the main loop debug.pasm routines for the debugger flow.pasm handles the flow-control instructions - io.pasm handles the io related instructions + io.pasm handles the i/o related instructions load.pasm function to load the code from source file maths.pasm handles all the maths instructions stack.pasm handles the stack instructions @@ -47,7 +48,6 @@ * better rand() methods * more tests (with Perl and Test::Harness) * debugging options (work in progress) -* use an array of arrays instead of an array of strings * implement Befunge 98 Index: befunge.pasm =================================================================== RCS file: /cvs/public/parrot/languages/befunge/befunge.pasm,v retrieving revision 1.3 diff -u -d -r1.3 befunge.pasm --- befunge.pasm 30 Nov 2002 15:51:09 -0000 1.3 +++ befunge.pasm 21 Dec 2002 14:25:38 -0000 @@ -25,20 +25,19 @@ set S10, P0[I0] save S10 bsr LOAD - restore P1 # the playfield - new P2, .PerlArray # the stack - set I0, 0 # x coord of the PC - set I1, 0 # y coord of the PC - set I2, 1 # direction of the PC - set I4, 0 # flag (1=string-mode,2=bridge,3=end) - time N0 # random seed + restore P1 # P1 = the playfield + new P2, .PerlArray # P2 = the stack + set I0, 0 # I0 = x coord of the PC + set I1, 0 # I1 = y coord of the PC + set I2, 1 # I2 = direction of the PC + set I4, 0 # I4 = flag (1=string-mode,2=bridge,3=end) + time N0 # N0 = random seed mod N0, N0, .RANDMAX - set S0, " " # current instruction - set S1, P1[0] # current line - set S2, "" # user input + set S2, "" # S2 = user input TICK: - substr S0, S1, I0, 1 + set I20, P1[I1;I0] + chr S0, I20 # S0 = current instruction eq I5, 0, TICK_NODEBUG bsr DEBUG_CHECK_BREAKPOINT TICK_NODEBUG: @@ -100,7 +99,6 @@ MOVE_NORTH: dec I1 mod I1, I1, 25 - set S1, P1[I1] branch TICK MOVE_EAST: inc I0 @@ -109,7 +107,6 @@ MOVE_SOUTH: inc I1 mod I1, I1, 25 - set S1, P1[I1] branch TICK MOVE_WEST: dec I0 Index: debug.pasm =================================================================== RCS file: /cvs/public/parrot/languages/befunge/debug.pasm,v retrieving revision 1.2 diff -u -d -r1.2 debug.pasm --- debug.pasm 1 Dec 2002 16:22:28 -0000 1.2 +++ debug.pasm 21 Dec 2002 14:25:38 -0000 @@ -162,13 +162,23 @@ concat S10, "\n" print S10 set I10, 0 -DEBUG_DUMP_PLAYFIELD_NEXT_LINE: - set S11, P1[I10] - print "|" +DEBUG_DUMP_PLAYFIELD_NEXT_LINE: + ge I10, 25, DEBUG_DUMP_PLAYFIELD_END + set I11, 0 + set S11, "|" +DEBUG_DUMP_PLAYFIELD_NEXT_CHAR: + ge I11, 80, DEBUG_DUMP_PLAYFIELD_EOL + set I12, P1[I10;I11] + chr S12, I12 + concat S11, S12 + inc I11 + branch DEBUG_DUMP_PLAYFIELD_NEXT_CHAR +DEBUG_DUMP_PLAYFIELD_EOL: + concat S11, "|\n" print S11 - print "|\n" inc I10 - lt I10, 25, DEBUG_DUMP_PLAYFIELD_NEXT_LINE + branch DEBUG_DUMP_PLAYFIELD_NEXT_LINE +DEBUG_DUMP_PLAYFIELD_END: print S10 pops popi Index: io.pasm =================================================================== RCS file: /cvs/public/parrot/languages/befunge/io.pasm,v retrieving revision 1.3 diff -u -d -r1.3 io.pasm --- io.pasm 24 Nov 2002 21:17:34 -0000 1.3 +++ io.pasm 21 Dec 2002 14:25:38 -0000 @@ -108,7 +108,6 @@ # i = value_at(x,y) IO_GET_VALUE: pushi - pushs set I11, P2 unless I11, IO_GET_VALUE_POP_1 pop I11, P2 @@ -116,11 +115,9 @@ set I10, P2 unless I10, IO_GET_VALUE_POP_2 pop I10, P2 -IO_GET_VALUE_POP_2: - set S10, P1[I11] - ord I12, S10, I10 +IO_GET_VALUE_POP_2: + set I12, P1[I11;I10] push P2, I12 - pops popi branch MOVE_PC @@ -131,12 +128,10 @@ # value_at(x,y) = i IO_PUT_VALUE: pushi - pushs set I11, P2 unless I11, IO_PUT_VALUE_POP_1 pop I11, P2 IO_PUT_VALUE_POP_1: - set S10, P1[I11] # original line set I10, P2 # offset unless I10, IO_PUT_VALUE_POP_2 pop I10, P2 @@ -144,20 +139,7 @@ set I20, P2 unless I20, IO_PUT_VALUE_POP_3 pop I20, P2 -IO_PUT_VALUE_POP_3: - chr S11, I20 # char to store - length I12, S10 - set S13, "" # First part - set S12, "" # Second part - substr S13, S10, 0, I10 - inc I10 - substr S12, S10, I10, I12 - set S14, "" - concat S14, S13 - concat S14, S11 - concat S14, S12 - set P1[I11], S14 - pops +IO_PUT_VALUE_POP_3: + set P1[I11;I10], I20 popi - set S1, P1[I1] # Restore line, in case we changed the current line... branch MOVE_PC Index: load.pasm =================================================================== RCS file: /cvs/public/parrot/languages/befunge/load.pasm,v retrieving revision 1.2 diff -u -d -r1.2 load.pasm --- load.pasm 19 Aug 2002 23:05:11 -0000 1.2 +++ load.pasm 21 Dec 2002 14:25:38 -0000 @@ -1,16 +1,16 @@ # Load a file given as parameter. # Parrot stack: # before: ... filename -# after: ... PerlArray -# The perlarray is filled with the content of the file, 80x25. +# after: ... PerlArray +# The perlarray is a perlarray of perlarrays filled with the +# ordinal values of the content of the file, 80x25. LOAD: pushi pushs pushp restore S0 # Fetch the filename open P0, S0, "<" - set S1, "" # Accumulator - new P1, .PerlArray # The playing field + set S1, "" # S1 = accumulator # Read the file. LOAD_READ: @@ -24,42 +24,49 @@ LOAD_EOF: close P0 concat S1, "\n" # Add a trailing newline if needed. - length I0, S1 # I0 =length of the buffer - set I1, 0 # I1 =ranges from 0 to I0 - set I2, 0 # I2 =beginning of current line - set I3, 0 # I3 =current line in the array + length I0, S1 # I0 = length of the buffer + set I1, -1 # I1 = character offset in the file + new P1, .PerlArray # P1 = the playing field + new P2, .PerlArray # P2 = the current line (array of ints) LOAD_PARSE_BUFFER: - lt I0, I1, LOAD_END_BUFFER - substr S2, S1, I1, 1 - ne S2, "\n", LOAD_NONL - sub I4, I1, I2 - substr S3, S1, I2, I4 - add I2, I4 - inc I2 # Trailing newline - set P1[I3], S3 - inc I3 - -LOAD_NONL: inc I1 + ge I1, I0, LOAD_END_BUFFER + substr S2, S1, I1, 1 # S2 = S1[I1] + eq S2, "\n", LOAD_FILL_LINE + ord I4, S2 + push P2, I4 + branch LOAD_PARSE_BUFFER +LOAD_FILL_LINE: + set I10, P2 # I10 = length of current line + ge I10, 80, LOAD_TRUNCATE_LINE + push P2, 32 + branch LOAD_FILL_LINE +LOAD_TRUNCATE_LINE: + set P2, 80 # Truncate the line. + push P1, P2 # Store the line. + new P2, .PerlArray # Create a new line. branch LOAD_PARSE_BUFFER -# Fill/truncate playfield to 25 rows and 80 columns. +# Fill playfield to 25 rows. LOAD_END_BUFFER: - set P1, 25 - set I0, 0 - repeat S4, " ", 80 - -LOAD_TRUNCATE: - set S3, P1[I0] - concat S3, S4 - substr S3, S3, 0, 80 - set P1[I0], S3 - inc I0 - lt I0, 25, LOAD_TRUNCATE + set I15, P1 + ge I15, 25, LOAD_COMPLETE + new P2, .PerlArray +LOAD_FILL_EMPTY_LINE: + set I10, P2 + ge I10, 80, LOAD_STORE_EMPTY_LINE + push P2, 32 + branch LOAD_FILL_EMPTY_LINE +LOAD_STORE_EMPTY_LINE: + push P1, P2 + new P2, .PerlArray + branch LOAD_END_BUFFER -# Return the playfield - save P1 +# Truncate playfield to 25 rows. +LOAD_COMPLETE: + set P1, 25 # Truncate at 25 lines. + save P1 # Return the playfield popp pops popi