# New Ticket Created by  Stepan Roh 
# Please include the string:  [perl #32112]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=32112 >


While playing with Parrot I found a few bugs and problems in Befunge 
interpreter. Although it is not important part of Parrot I tried to fix 
them. All changes are in attached patch created with cvs diff -u against 
CVS HEAD 2004/10/23 and one new file.

Changes:

- Befunge-97 directives (lines starting with =) are ignored
- stdout buffering is disabled
- fixed bug in integer input (instead of read integer, length of it's 
string representation was returned)
- fixed bug in integer input (only integers with one digit were 
allowed which was fixed by using readline instead of read)
- when outputing integer, output one space as well to conform with specs

I tested all Befunge scripts I have and there is one which does not work 
as expected. I attached it as pascserp.bef, it is also mentioned in 
README.

Hope I did everything right.

Have a nice day.

Stepan Roh
Index: languages/befunge/README

===================================================================

RCS file: /cvs/public/parrot/languages/befunge/README,v

retrieving revision 1.9

diff -u -r1.9 README

--- languages/befunge/README    6 Feb 2004 14:23:09 -0000       1.9

+++ languages/befunge/README    23 Oct 2004 15:20:50 -0000

@@ -35,12 +35,14 @@

                         developement

         test.bef        a befunge script that test almost all the

                         instructions (and is even self-modifying!)

+        pascserp.bef    a befunge script generating variant of Sierpinsky

+                        triangle (by Chris Pressey)

 

 

 BUGS

 ----

-* The "input char" and "input int" instructions are a bit broken since

-  Parrot does not handle I/O very well...

+* pascserp.bef output is not correct (right bottom part of image is just

+noise)

 

 

 TODO

Index: languages/befunge/befunge.pasm

===================================================================

RCS file: /cvs/public/parrot/languages/befunge/befunge.pasm,v

retrieving revision 1.5

diff -u -r1.5 befunge.pasm

--- languages/befunge/befunge.pasm      30 Aug 2003 10:01:11 -0000      1.5

+++ languages/befunge/befunge.pasm      23 Oct 2004 15:20:51 -0000

@@ -8,6 +8,8 @@

 .include "stack.pasm"

 

 MAIN:

+        getstdout P10

+        pioctl I10, P10, 3, 0   # disable buffering on stdout

         set I0, 0

         set I5, 0               # debug mode

 ARGV_NEXT:

Index: languages/befunge/io.pasm

===================================================================

RCS file: /cvs/public/parrot/languages/befunge/io.pasm,v

retrieving revision 1.4

diff -u -r1.4 io.pasm

--- languages/befunge/io.pasm   21 Dec 2002 16:56:09 -0000      1.4

+++ languages/befunge/io.pasm   23 Oct 2004 15:20:51 -0000

@@ -22,7 +22,8 @@

         restore S2

         length I10, S2

         gt I10, 0, IO_INPUT_INT_PARSE_INPUT

-        read S2, 1

+        getstdin P15

+        readline S2, P15

         length I10, S2

 IO_INPUT_INT_PARSE_INPUT:

         set I11, 0

@@ -38,7 +39,7 @@

         set I11, 0

 IO_INPUT_INT_NAN:

         substr S2, S2, I11, I10

-        push P2, I10

+        push P2, S10

         pops

         popi

         branch MOVE_PC

@@ -55,7 +56,8 @@

         restore S2

         length I10, S2

         gt I10, 0, IO_INPUT_CHAR_SUBSTR

-        read S2, 1

+        getstdin P15

+        readline S2, P15

 IO_INPUT_CHAR_SUBSTR:

         substr S10, S2, 0, 1

         length I10, S2

@@ -80,6 +82,7 @@

         pop I10, P2

 IO_OUTPUT_INT_POP_1:    

         print I10

+        print " "

         popi

         branch MOVE_PC

 

Index: languages/befunge/load.pasm

===================================================================

RCS file: /cvs/public/parrot/languages/befunge/load.pasm,v

retrieving revision 1.3

diff -u -r1.3 load.pasm

--- languages/befunge/load.pasm 21 Dec 2002 16:56:09 -0000      1.3

+++ languages/befunge/load.pasm 23 Oct 2004 15:20:51 -0000

@@ -44,7 +44,10 @@

         branch LOAD_FILL_LINE

 LOAD_TRUNCATE_LINE:

         set P2, 80              # Truncate the line.

+        set I11, P2[0]          # Skip lines with leading "=" (Befunge-97 directive)

+        eq I11, 0x3d, LOAD_SKIP_DIRECTIVE

         push P1, P2             # Store the line.

+LOAD_SKIP_DIRECTIVE:

         new P2, .PerlArray      # Create a new line.

         branch LOAD_PARSE_BUFFER

 

58*00p010p>58*00g-|>0g#<1-10gg00g10v

v98p00:+1g00< v67<>    >1    v+g-1g<

>*7+-! #v_v>^^<  |%2pg0 1g00:<

v p00*58<  ^,<^48<>10g!|@

>52*,10g1+ :1 0p83 *- ! |

          v             <

Reply via email to