Hi,

I'm proud to provide you with a Befunge-93 interpreter written in Parrot! I'd 
like to thanks you all of the parrot team, for giving us such a marvelous toy 
to play with.

Note to Leon Brocard: 
There's a lot more to do in order to provide a Befunge-98 compliant 
interpreter, so don't worry! There's still a lot of fun waiting... :o)

Jerome
-- 
[EMAIL PROTECTED]
diff -urbN parrot.orig/languages/Befunge-93/Makefile parrot/languages/Befunge-93/Makefile
--- parrot.orig/languages/Befunge-93/Makefile	Thu Jan  1 01:00:00 1970
+++ parrot/languages/Befunge-93/Makefile	Fri Aug 16 20:47:51 2002
@@ -0,0 +1,17 @@
+ASSEMBLE=perl ../../assemble.pl
+PARROT=../../parrot
+
+test: build
+	$(PARROT) befunge.pbc test.bef
+
+build: befunge.pasm flow.pasm io.pasm load.pasm maths.pasm stack.pasm
+	$(ASSEMBLE) befunge.pasm > befunge.pbc
+
+clean:
+	rm -f core *.pbc *~
+
+dist: clean
+	rm -f befunge.tgz
+	( cd .. ; tar cvf befunge.tar Befunge-93 )
+	gzip ../befunge.tar
+	mv ../befunge.tar.gz befunge.tgz
diff -urbN parrot.orig/languages/Befunge-93/README parrot/languages/Befunge-93/README
--- parrot.orig/languages/Befunge-93/README	Thu Jan  1 01:00:00 1970
+++ parrot/languages/Befunge-93/README	Fri Aug 16 20:52:11 2002
@@ -0,0 +1,82 @@
+DESCRIPTION
+-----------
+This is a Befunge interpreter written in Parrot assembler, version 0.01
+
+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.
+
+You should compile the files with:
+
+     $ make build
+     $ make test
+
+Then you can run your Befunge program with: 
+
+     $ ../../parrot  befunge.pbc [-v] foo.bef
+
+The -v flag makes the befunge interpreter more verbose.
+
+
+NOTES
+-----
+The files are the following:
+        befunge.pasm    the main loop
+        load.pasm       function to load the code from source file
+        flow.pasm       handles the flow-control instructions
+        io.pasm         handles the io related instructions
+        maths.pasm      handles all the maths instructions
+        stack.pasm      handles the stack operations as well as stack
+                        instructions
+        Makefile        a tiny, little Makefile to help (me) during
+                        developement
+        test.bef        a befunge script that test almost all the instructions
+
+
+BUGS
+----
+* The befunge program *should* be properly newline terminated because
+  of Parrot's I/O...
+* The "input char" and "input int" instructions are a bit broken since
+  Parrot does not handle I/O very well...
+
+
+TODO
+----
+* more error checking
+* better rand()/chr() methods
+* more tests (with Perl and Test::Harness)
+* debugging options
+* use an array of arrays instead of an array of strings
+* implement Befunge 98
+
+
+AUTHOR
+------
+Jerome Quelin, <[EMAIL PROTECTED]>
+
+
+ACKNOWLEDGEMENTS
+----------------
+I would like to thank:
+* Chris Pressey, creator of Befunge, who gave a whole new dimension to
+  both coding and obfuscating.
+* Leon Brocard and Rafael Garcia-Suarez, for giving me this crazy
+  idea.
+* Leon Brocard (again), because he told me he will help me with the
+  Befunge-98 version :o)
+* Dan Sugalski and all the parrot folks for providing such a nice toy
+  to play with.
+
+
+COPYRIGHT
+---------
+This program is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+SEE ALSO
+--------
+* http://www.parrotcode.org
+* http://www.catseye.mb.ca/esoteric/befunge/
+
diff -urbN parrot.orig/languages/Befunge-93/README~ parrot/languages/Befunge-93/README~
--- parrot.orig/languages/Befunge-93/README~	Thu Jan  1 01:00:00 1970
+++ parrot/languages/Befunge-93/README~	Fri Aug 16 20:47:01 2002
@@ -0,0 +1,80 @@
+DESCRIPTION
+-----------
+This is a Befunge interpreter written in Parrot assembler, version 0.01
+
+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.
+
+You should compile the files with:
+
+     $ make build
+     $ make test
+
+Then you can run your Befunge program with: 
+
+     $ ../../parrot  befunge.pbc [-v] foo.bef
+
+The -v flag makes the befunge interpreter more verbose.
+
+
+NOTES
+-----
+The files are the following:
+        befunge.pasm    the main loop
+        load.pasm       function to load the code from source file
+        flow.pasm       handles the flow-control instructions
+        io.pasm         handles the io related instructions
+        maths.pasm      handles all the maths instructions
+        stack.pasm      handles the stack operations as well as stack
+                        instructions
+        Makefile        a tiny, little Makefile to help (me) during
+                        developement
+        test.bef        a befunge script that test almost all the instructions
+
+
+BUGS
+----
+The "input char" and "input int" instructions are a bit broken since
+Parrot does not handle I/O very well...
+
+
+TODO
+----
+* more error checking
+* better rand()/chr() methods
+* more tests (with Perl and Test::Harness)
+* debugging options
+* use an array of arrays instead of an array of strings
+* implement Befunge 98
+
+
+AUTHOR
+------
+Jerome Quelin, <[EMAIL PROTECTED]>
+
+
+ACKNOWLEDGEMENTS
+----------------
+I would like to thank:
+* Chris Pressey, creator of Befunge, who gave a whole new dimension to
+  both coding and obfuscating.
+* Leon Brocard and Rafael Garcia-Suarez, for giving me this crazy
+  idea.
+* Leon Brocard (again), because he told me he will help me with the
+  Befunge-98 version :o)
+* Dan Sugalski and all the parrot folks for providing such a nice toy
+  to play with.
+
+
+COPYRIGHT
+---------
+This program is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+SEE ALSO
+--------
+* http://www.parrotcode.org
+* http://www.catseye.mb.ca/esoteric/befunge/
+
diff -urbN parrot.orig/languages/Befunge-93/befunge.pasm parrot/languages/Befunge-93/befunge.pasm
--- parrot.orig/languages/Befunge-93/befunge.pasm	Thu Jan  1 01:00:00 1970
+++ parrot/languages/Befunge-93/befunge.pasm	Fri Aug 16 20:19:42 2002
@@ -0,0 +1,181 @@
+        branch MAIN
+
+.include "flow.pasm"
+.include "io.pasm"
+.include "load.pasm"
+.include "maths.pasm"
+.include "stack.pasm"
+        
+MAIN:
+        set I0, 0
+        set I4, 0               # verbose mode
+ARGV_NEXT:        
+        inc I0       
+        set S10, P0[I0]
+        substr S11, S10, 0, 1
+        ne S11, "-", ARGV_DONE
+        eq S10, "-v", ARGV_VERBOSE
+        branch ARGV_NEXT
+ARGV_VERBOSE:
+        inc I4
+        branch ARGV_NEXT
+ARGV_DONE:
+        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 I5, 0               # flag (1=string-mode,2=bridge,3=end)
+        time N0                 # random seed
+        mod N0, N0, .RANDMAX
+        set S0, " "             # current instruction
+        set S1, P1[0]           # current line
+        set S2, ""              # user input
+	set S3, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
+        
+TICK:
+        substr S0, S1, I0, 1
+        eq I4, 0, TICK_NOVERBOSE
+        bsr VERBOSE
+TICK_NOVERBOSE:
+        eq S0, "\"", FLOW_TOGGLE_STRING_MODE
+        eq I5, 1, IO_PUSH_CHAR
+        eq I5, 2, MAIN_TRAMPOLINE
+        eq I5, 3, MAIN_END
+
+        # Sole number.
+        lt S0, "0", NOT_NUM
+        le S0, "9", MATHS_PUSH_NUMBER
+NOT_NUM:
+        
+        # Direction changing.
+        eq S0, "^", FLOW_GO_NORTH
+        eq S0, ">", FLOW_GO_EAST
+        eq S0, "v", FLOW_GO_SOUTH
+        eq S0, "<", FLOW_GO_WEST
+        eq S0, "?", FLOW_GO_AWAY
+
+        # Flow control.
+        eq S0, "`", FLOW_COMPARE
+        eq S0, "_", FLOW_EW_IF
+        eq S0, "|", FLOW_NS_IF
+        eq S0, "#", FLOW_BRIDGE
+        eq S0, "@", FLOW_END
+        
+        # Math functions.
+        eq S0, "+", MATHS_ADD
+        eq S0, "-", MATHS_SUB
+        eq S0, "*", MATHS_MUL
+        eq S0, "/", MATHS_DIV
+        eq S0, "%", MATHS_MOD
+        eq S0, "!", MATHS_NOT
+
+        # Stack operations.
+        eq S0, ":", STACK_DUP
+        eq S0, "$", STACK_POP
+        eq S0, "\\", STACK_SWAP
+        
+        # I/O operations.
+        eq S0, "&", IO_INPUT_INT
+        eq S0, "~", IO_INPUT_CHAR
+        eq S0, ".", IO_OUTPUT_INT
+        eq S0, ",", IO_OUTPUT_CHAR
+        eq S0, "g", IO_GET_VALUE
+        eq S0, "p", IO_PUT_VALUE
+
+        # Unknow instruction.
+        branch MOVE_PC
+        
+MAIN_TRAMPOLINE:        
+        set I5, 0               # no more trampoline
+MOVE_PC:
+        eq I2, 1, MOVE_EAST
+        eq I2, 2, MOVE_SOUTH
+        eq I2, 3, MOVE_WEST
+        # fallback MOVE_NORTH
+MOVE_NORTH:
+        dec I1
+        mod I1, I1, 25
+        set S1, P1[I1]
+        branch TICK
+MOVE_EAST:
+        inc I0
+        mod I0, I0, 80
+        branch TICK
+MOVE_SOUTH:
+        inc I1
+        mod I1, I1, 25
+        set S1, P1[I1]
+        branch TICK
+MOVE_WEST:
+        dec I0
+        mod I0, I0, 80
+        branch TICK
+        
+MAIN_END:
+        end
+
+VERBOSE:
+        # Coordinates.
+        print "("
+        print I0
+        print ","
+        print I1
+        print ")"
+        # Current char.
+        print " - '"
+        print S0
+        print "' (ord="
+        ord I10, S0
+        print I10
+        print ")"
+        # Direction.
+        print " dir="
+        print I2
+        # Flags:        
+        set S10, " \""
+        eq I5, 1, VERBOSE_PRINT_FLAG
+        set S10, " #"
+        eq I5, 2, VERBOSE_PRINT_FLAG
+        set S10, " @"
+        eq I5, 3, VERBOSE_PRINT_FLAG
+        set S10, "  "
+VERBOSE_PRINT_FLAG:
+        print S10
+        # Stack.
+        print " stack="
+        set I11, P2
+        set I10, 0
+        ge  I10, I11, VERBOSE_STACK_END
+VERBOSE_STACK_LOOP:       
+        set I12, P2[I10]
+        print I12
+        inc I10
+        ge I10, I11, VERBOSE_STACK_END
+        print ","
+        branch VERBOSE_STACK_LOOP
+VERBOSE_STACK_END:
+        print "\n"
+        ret
+
+DUMP_PLAYFIELD:
+        pushi
+        pushs
+        repeat S10, "-", 82
+        concat S10, "\n"        
+        print S10
+        set I10, 0
+DUMP_NEXT_LINE: 
+        set S11, P1[I10]
+        print "|"
+        print S11
+        print "|\n"
+        inc I10
+        lt I10, 25, DUMP_NEXT_LINE
+        print S10
+        pops
+        popi
+        ret
\ No newline at end of file
diff -urbN parrot.orig/languages/Befunge-93/flow.pasm parrot/languages/Befunge-93/flow.pasm
--- parrot.orig/languages/Befunge-93/flow.pasm	Thu Jan  1 01:00:00 1970
+++ parrot/languages/Befunge-93/flow.pasm	Fri Aug 16 20:25:30 2002
@@ -0,0 +1,106 @@
+# Go north.
+# Befunge stack unchanged.
+# delta <- (0,-1)
+FLOW_GO_NORTH:
+        set I2, 0
+        branch MOVE_PC
+
+# Go east.
+# Befunge stack unchanged.
+# delta <- (1,0)
+FLOW_GO_EAST:
+        set I2, 1
+        branch MOVE_PC
+
+# Go south.
+# Befunge stack unchanged.
+# delta <- (0,1)
+FLOW_GO_SOUTH:
+        set I2, 2
+        branch MOVE_PC
+        
+# Go west.
+# Befunge stack unchanged.
+# delta <- (-1,0)
+FLOW_GO_WEST:
+        set I2, 3
+        branch MOVE_PC
+
+FLOW_GO_AWAY:
+        save 4
+        bsr MATHS_RAND
+        pushi
+        restore I10
+        set I2, I10
+        save I2
+        popi
+        restore I2
+        branch MOVE_PC
+        
+# East/West if.
+# Befunge stack:
+#   before:     ... b
+#   after:      ...
+# delta <- if (b) (-1,0) else (1,0)
+FLOW_EW_IF:
+        bsr POP
+        restore I10
+        eq I10, 0, FLOW_GO_EAST
+        branch FLOW_GO_WEST
+
+# North/South if.
+# Befunge stack:
+#   before:     ... b
+#   after:      ...
+# delta <- if (b) (0,-1) else (0,1)
+FLOW_NS_IF:
+        bsr POP
+        restore I10
+        eq I10, 0, FLOW_GO_SOUTH
+        branch FLOW_GO_NORTH
+
+
+# Greater than. 
+# Befunge stack:        
+#   before:     ... a b
+#   after:      ... a>b
+# Result is either 1 or 0.
+FLOW_COMPARE:
+        pushi
+        bsr POP
+        restore I10
+        bsr POP
+        restore I11
+        set I12, 1
+        gt I11, I10, FLOW_COMPARE_TRUE
+        set I12, 0
+FLOW_COMPARE_TRUE:
+        save I12
+        bsr PUSH
+        popi
+        branch MOVE_PC
+        
+# Toggle string mode.
+# Befunge stack unchanged.
+FLOW_TOGGLE_STRING_MODE:
+        eq I5, 1, FLOW_TOGGLE_STRING_MODE_OFF
+        set I5, 1
+        branch MOVE_PC
+FLOW_TOGGLE_STRING_MODE_OFF:      
+        set I5, 0
+        branch MOVE_PC
+        
+# Trampoline.
+# Befunge stack unchanged.
+# Skip next instruction (pos < pos + delta)
+FLOW_BRIDGE:
+        set I5, 2
+        branch MOVE_PC
+
+# Stop.
+# Befunge stack unchanged.
+# End program.
+FLOW_END:
+        set I5, 3
+        branch MOVE_PC
+        
\ No newline at end of file
diff -urbN parrot.orig/languages/Befunge-93/io.pasm parrot/languages/Befunge-93/io.pasm
--- parrot.orig/languages/Befunge-93/io.pasm	Thu Jan  1 01:00:00 1970
+++ parrot/languages/Befunge-93/io.pasm	Fri Aug 16 19:33:38 2002
@@ -0,0 +1,167 @@
+# Implement the chr() function.
+# Generic method. 
+# Parrot stack: 
+#   before:     ... i
+#   after:      ... c
+# c = chr(i)        
+IO_CHR:
+        pushi
+        pushs
+        restore I10
+        substr S10, S3, I10, 1
+        save S10
+        pops
+        popi
+        ret
+       
+# String mode.
+# Befunge stack:        
+#   before:     ...
+#   after:      ... c
+# i = ord(current char)
+IO_PUSH_CHAR:
+        pushi
+        ord I10, S0
+        save I10
+        bsr PUSH
+        popi
+        branch MOVE_PC
+
+# Input integer.
+# Befunge stack:        
+#   before:     ...
+#   after:      ... i                                   
+# i = readint()
+IO_INPUT_INT:
+        save S2
+        pushi
+        pushs
+        restore S2
+        length I10, S2
+        gt I10, 0, IO_INPUT_INT_PARSE_INPUT
+        read S2, 1
+        length I10, S2
+IO_INPUT_INT_PARSE_INPUT:
+        set I11, 0
+        set S10, ""
+IO_INPUT_INT_NEXT_CHAR:
+        substr S11, S2, I11, 1
+        lt S11, "0", IO_INPUT_INT_NAN
+        gt S11, "9", IO_INPUT_INT_NAN
+        concat S10, S10, S11
+        inc I11
+        lt I11, I10, IO_INPUT_INT_NEXT_CHAR
+        set I10, 0
+        set I11, 0
+IO_INPUT_INT_NAN:
+        substr S2, S2, I11, I10
+        save I10
+        bsr PUSH
+        pops
+        popi
+        branch MOVE_PC
+
+# Input character.
+# Befunge stack:        
+#   before:     ...
+#   after:      ... c
+# c = getchar()
+IO_INPUT_CHAR:
+        save S2
+        pushi
+        pushs
+        restore S2
+        length I10, S2
+        gt I10, 0, IO_INPUT_CHAR_SUBSTR
+        read S2, 1
+IO_INPUT_CHAR_SUBSTR:
+        substr S10, S2, 0, 1
+        length I10, S2
+        substr S2, S2, 1, I10
+        ord I10, S10
+        save I10
+        bsr PUSH
+        save S2
+        pops
+        restore S2
+        popi
+        branch MOVE_PC
+                             
+# Output integer.
+# Befunge stack:        
+#   before:     ... i
+#   after:      ...                                   
+# writeint(i)
+IO_OUTPUT_INT:
+        pushi
+        bsr POP
+        restore I10
+        print I10
+        popi
+        branch MOVE_PC
+
+# Output character.
+# Befunge stack:        
+#   before:     ... i
+#   after:      ...
+# writechar( chr(i) )
+IO_OUTPUT_CHAR:
+        pushs
+        bsr POP
+        bsr IO_CHR
+        restore S10
+        print S10
+        pops
+        branch MOVE_PC
+                             
+# Get a value from playfield.
+# Befunge stack:        
+#   before:     ... x y
+#   after:      ... i
+# i = value_at(x,y)                                
+IO_GET_VALUE:
+        pushi
+        pushs
+        bsr POP
+        restore I11
+        bsr POP
+        restore I10
+        set S10, P1[I11]
+        ord I12, S10, I10
+        save I12
+        bsr PUSH
+        pops
+        popi
+        branch MOVE_PC
+        
+# Put a value in the playfield.
+# Befunge stack:        
+#   before:     ... i x y
+#   after:      ...
+# value_at(x,y) = i                                
+IO_PUT_VALUE:
+        pushi
+        pushs
+        bsr POP
+        restore I11
+        set S10, P1[I11]        # original line
+        bsr POP
+        restore I10             # offset
+        bsr POP
+        bsr IO_CHR
+        restore S11             # 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
+        popi
+        set S1, P1[I1]          # Restore line, in case we changed the current line...
+        branch MOVE_PC
diff -urbN parrot.orig/languages/Befunge-93/load.pasm parrot/languages/Befunge-93/load.pasm
--- parrot.orig/languages/Befunge-93/load.pasm	Thu Jan  1 01:00:00 1970
+++ parrot/languages/Befunge-93/load.pasm	Fri Aug 16 17:32:15 2002
@@ -0,0 +1,65 @@
+# Load a file given as parameter.
+# Parrot stack:
+#   before:     ... filename
+#   after:      ... PerlArray        
+# The perlarray is filled with 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
+
+# Read the file.  
+LOAD_READ:
+	read S2, P0, 256
+	length I0, S2
+	le I0, 0, LOAD_EOF
+	concat S1, S2
+	branch LOAD_READ
+
+# Split the buffer around its newlines.
+LOAD_EOF:
+        close P0
+        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
+
+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
+        branch LOAD_PARSE_BUFFER
+
+# Fill/truncate playfield to 25 rows and 80 columns.
+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
+
+# Return the playfield
+        save P1
+        popp
+        pops
+        popi
+        ret
diff -urbN parrot.orig/languages/Befunge-93/maths.pasm parrot/languages/Befunge-93/maths.pasm
--- parrot.orig/languages/Befunge-93/maths.pasm	Thu Jan  1 01:00:00 1970
+++ parrot/languages/Befunge-93/maths.pasm	Fri Aug 16 20:24:40 2002
@@ -0,0 +1,129 @@
+# Create a pseudo-random number.
+# Parrot's stack:
+#   before:     ... max
+#   after:      ... rand
+# 0 <= rand < max
+.constant RANDMAX 65536.0
+MATHS_RAND:
+        pushi
+        restore I10
+        mul N0, N0, 5.0
+        add N0, N0, 1.0
+        mod N0, N0, .RANDMAX
+        save N0
+        pushn
+        restore N0
+        set N10, I10
+        mul N10, N0, N10
+        div N10, N10, .RANDMAX
+        set I10, N10
+        popn
+        save I10
+        popi
+        ret
+        
+# Push number on Befunge's stack.
+# Befunge Stack:
+#   before:     ...
+#   after:      ... <number>
+MATHS_PUSH_NUMBER:
+        pushi
+        set I10, S0
+        save I10
+        bsr PUSH
+        popi
+        branch MOVE_PC
+
+# Addition.
+# Befunge Stack:
+#   before:     ... a b
+#   after:      ... a+b
+MATHS_ADD:
+        pushi
+        bsr POP
+        restore I11
+        bsr POP
+        restore I10
+        add I12, I10, I11
+        save I12
+        bsr PUSH
+        popi
+        branch MOVE_PC
+        
+# Substraction.
+# Befunge Stack:
+#   before:     ... a b
+#   after:      ... a-b
+MATHS_SUB:
+        pushi
+        bsr POP
+        restore I11
+        bsr POP
+        restore I10
+        sub I12, I10, I11
+        save I12
+        bsr PUSH
+        popi
+        branch MOVE_PC
+
+# Multiplication.
+# Befunge Stack:
+#   before:     ... a b
+#   after:      ... a*b
+MATHS_MUL:
+        pushi
+        bsr POP
+        restore I11
+        bsr POP
+        restore I10
+        mul I12, I10, I11
+        save I12
+        bsr PUSH
+        popi
+        branch MOVE_PC
+
+# Division.
+# Befunge Stack:
+#   before:     ... a b
+#   after:      ... a/b
+MATHS_DIV:
+        pushi
+        bsr POP
+        restore I11
+        bsr POP
+        restore I10
+        div I12, I10, I11
+        save I12
+        bsr PUSH
+        popi
+        branch MOVE_PC
+
+# Remainder.
+# Befunge Stack:
+#   before:     ... a b
+#   after:      ... a mod b
+MATHS_MOD:
+        pushi
+        bsr POP
+        restore I11
+        bsr POP
+        restore I10
+        mod I12, I10, I11
+        save I12
+        bsr PUSH
+        popi
+        branch MOVE_PC
+
+# Logical not.        
+# Befunge Stack:
+#   before:     ... a
+#   after:      ... not(a)
+MATHS_NOT:
+        pushi
+        bsr POP
+        restore I10
+        not I10, I10
+        save I10
+        bsr PUSH
+        popi
+        branch MOVE_PC
\ No newline at end of file
diff -urbN parrot.orig/languages/Befunge-93/stack.pasm parrot/languages/Befunge-93/stack.pasm
--- parrot.orig/languages/Befunge-93/stack.pasm	Thu Jan  1 01:00:00 1970
+++ parrot/languages/Befunge-93/stack.pasm	Fri Aug 16 17:42:35 2002
@@ -0,0 +1,74 @@
+# Push an integer in Befunge's stack.
+# The integer is popped from Parrot's stack.
+# Generic method.
+PUSH:
+        pushi
+        restore I6
+        set I7, P2
+        set P2[I7], I6
+        popi
+        ret
+
+# Pop an integer from Befunge's stack.
+# the integer is pushed on Parrot's stack.
+# Generic method.
+POP:
+        pushi
+        set I7, P2
+        eq I7, 0, POP_EMPTY
+        dec I7
+        set I6, P2[I7]
+        save I6
+        set P2, I7
+        popi
+        ret
+
+POP_EMPTY:      
+        set I10, 0
+        save I10
+        popi
+        ret
+
+# Duplicate.
+# Befunge stack:        
+#   before:     ... v
+#   after:      ... v 
+STACK_DUP:
+        pushi
+        bsr POP
+        restore I10
+        save I10
+        bsr PUSH
+        save I10
+        bsr PUSH
+        popi
+        branch MOVE_PC
+
+# Pop.
+# Befunge stack:        
+#    before:    ... v
+#    after:     ...
+# Element is just discarded.
+STACK_POP:
+        pushi
+        bsr POP
+        restore I10
+        popi
+        branch MOVE_PC
+        
+# Swap.
+# Befunge stack:        
+#   before:     ... a b
+#   after:      ... b a
+STACK_SWAP:
+        pushi
+        bsr POP
+        restore I10
+        bsr POP
+        restore I11
+        save I10
+        bsr PUSH
+        save I11
+        bsr PUSH
+        popi
+        branch MOVE_PC
\ No newline at end of file
diff -urbN parrot.orig/languages/Befunge-93/test.bef parrot/languages/Befunge-93/test.bef
--- parrot.orig/languages/Befunge-93/test.bef	Thu Jan  1 01:00:00 1970
+++ parrot/languages/Befunge-93/test.bef	Fri Aug 16 20:25:52 2002
@@ -0,0 +1,10 @@
+<                   p 04   "v"
+  ^ > 
+I                       @   _v
+                            !,
+  _   2! |                  :
+    . \-  %2/36 `21  $   <  ^<   "<- then everything is ok!" +37
+  !      #
+  3      >               
+         <       v  ,  _ ^# -8 : g20 "f you can see a 4 here ->" 8 4
+                 > :8- ^

Reply via email to