Permalink
Browse files

import following languages : bf, chitchat, forth, jako, lisp, ook, sc…

…heme & urm
  • Loading branch information...
fperrad committed Mar 15, 2009
0 parents commit 63f89e55e632e356b082745341fb4e572331c313
Showing with 898 additions and 0 deletions.
  1. +4 −0 MAINTAINER
  2. +38 −0 README
  3. +6 −0 bench.bf
  4. +135 −0 bf.pasm
  5. +262 −0 bfc.pir
  6. +284 −0 bfco.pir
  7. +51 −0 config/makefiles/root.in
  8. +3 −0 countdown.bf
  9. +46 −0 cw.bf
  10. +6 −0 cw.txt
  11. +3 −0 helloworld.bf
  12. +31 −0 t/harness
  13. +6 −0 t/test_bf.t
  14. +6 −0 t/test_bfc.t
  15. +6 −0 t/test_bfco.t
  16. +11 −0 test.bf
@@ -0,0 +1,4 @@
+# $Id$
+
+N: Leon Brocard
+E: acme@astray.com
38 README
@@ -0,0 +1,38 @@
+DESCRIPTION
+
+This is a Brainfuck interpreter for Parrot. Brainfuck is a full
+computer programming language with only eight commands. For more
+information, see http://www.catseye.mb.ca/esoteric/bf/ or
+http://en.wikipedia.org/wiki/Brainfuck.
+
+To compile the files:
+
+ $ make
+
+To check that the compiler is working:
+
+ $ make test
+
+To run an example Brainfuck program:
+
+ $ ../../parrot bf.pasm helloworld.bf
+
+There is also a compiler:
+
+ $ ../../parrot bfc.pir helloworld.bf
+
+Clifford Wolf <clifford (at) clifford.at> contributed a nice bf
+program:
+
+ $ cat cw.txt
+ $ ../../parrot bf.pasm cw.bf < cw.txt > cw.c
+ $ cc -o cw cw.c
+ $ ./cw
+
+If you want to run it faster, use the bf compiler:
+
+ $ ../../parrot -j bfc.pir cw.bf < cw.txt > cw.c
+
+AUTHOR
+
+Leon Brocard <acme@astray.com>
@@ -0,0 +1,6 @@
+*LL*LH*FF*01
+>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
+[>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
+++++++++[>++++++++++[>++++++++++[>++++++++++[>+
++++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++.
+*00
135 bf.pasm
@@ -0,0 +1,135 @@
+# $Id$
+# A Brainfuck interpreter
+# By Leon Brocard <acme@astray.com>
+#
+# See http://www.catseye.mb.ca/esoteric/bf/
+# for more information on this silly language
+
+ get_params '0', P5 # P5 = @ARGV
+ # Get the brainfuck source file into S0
+ set S0, P5[1]
+ if S0, SOURCE
+usage:
+ set S0, P5[0]
+ print "usage: ./parrot "
+ print S0
+ print " file.bf\n"
+ end
+
+ # Read the file into S1
+SOURCE:
+ null I3
+ ne S0, "-O", no_o
+ set I3, 1 # optimize switch
+ set S0, P5[2]
+no_o:
+ open P1, S0, 'r'
+ defined I0, P1
+ unless I0, usage
+SOURCE_LOOP:
+ readline S2, P1
+ concat S1, S2
+ if S2, SOURCE_LOOP
+ close P1
+
+ length I30, S1
+
+ # Initialise
+
+ set I0, 0 # Our program counter
+ new P0, 'ResizableIntegerArray' # Our memory
+ set I1, 0 # Our pointer
+ getstdin P30
+
+ # The main interpreter loop
+INTERP:
+ substr S0, S1, I0, 1
+ ne S0, "+", NOTPLUS
+ set I2, P0[I1]
+ inc I2
+ band I2, 0xff
+ set P0[I1], I2
+ branch NEXT
+
+NOTPLUS:
+ ne S0, "-", NOTMINUS
+ set I2, P0[I1]
+ dec I2
+ band I2, 0xff
+ set P0[I1], I2
+ branch NEXT
+
+NOTMINUS:
+ ne S0, ">", NOTGT
+ inc I1
+ branch NEXT
+
+NOTGT:
+ ne S0, "<", NOTLT
+ dec I1
+ branch NEXT
+
+NOTLT:
+ ne S0, "[", NOTOPEN
+
+ set I2, P0[I1]
+ if I2, NEXT
+ set I2, 0 # "depth"
+
+OPEN_LOOP:
+ inc I0
+ substr S2, S1, I0, 1
+ ne S2, "[", OPEN_NOTOPEN
+ inc I2
+ branch OPEN_LOOP
+OPEN_NOTOPEN:
+ ne S2, "]", OPEN_LOOP
+ eq I2, 0, NEXT
+ dec I2
+ branch OPEN_LOOP
+
+NOTOPEN:
+ ne S0, "]", NOTCLOSE
+ unless I3, no_opt
+ set I2, P0[I1]
+ unless I2, NEXT
+no_opt:
+ set I2, 0 # "height"
+
+CLOSE_LOOP:
+ dec I0
+ substr S2, S1, I0, 1
+ ne S2, "]", CLOSE_NOTCLOSE
+ inc I2
+ branch CLOSE_LOOP
+CLOSE_NOTCLOSE:
+ ne S2, "[", CLOSE_LOOP
+ eq I2, 0, INTERP
+ dec I2
+ branch CLOSE_LOOP
+
+NOTCLOSE:
+ ne S0, ".", NOTDOT
+ set I2, P0[I1]
+ chr S31, I2
+ print S31
+ branch NEXT
+
+NOTDOT:
+ ne S0, ",", NEXT
+ read S31, P30, 1
+ if S31, no_eof
+ null I2 # some return -1, some don't change data
+ branch eof
+no_eof:
+ ord I2, S31
+eof:
+ set P0[I1], I2
+ branch NEXT
+
+NEXT:
+ inc I0
+ lt I0, I30, INTERP
+ end
+
+
Oops, something went wrong.

0 comments on commit 63f89e5

Please sign in to comment.