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


Thanks to our dear summarizer, I'm now known (from a googlism point of 
view) as 'one of the "let's implement a bunch of languages on parrot" 
crew'. So, in order to prove him right definitely (and also because 
orang-utans should also benefit from Parrot's speed), here's a new 
language supported by Parrot: the Ook! language.

For the unlucky who don't know it, Ook! is essentially isomorphic to the 
well-known brainfsck language. 
Refer to http://www.dangermouse.net/esoteric/ook.html for more details.

Ok, about this implementation:
 - this is a compiler (and not an interpreter) that spits Parrot 
assembly code (yes, I'm targeting Parrot).
 - it implements every Ook! instruction but the "Ook. Ook!" one. I'll 
work on it later.
 - currently I'm just printing on stdout the resulting parrot code, I 
lack an eval instruction in Parrot. Dan, Leo? :-)

Disclaimer: it's all of Nicholas Clark's fault. Really. He's the one to 
take the blame for it.

Jerome
-- 
[EMAIL PROTECTED]


-- attachment  1 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/46602/36599/6c9317/ook_first_draft.patch

diff -urbN parrot.old/config/gen/makefiles/ook.in parrot/config/gen/makefiles/ook.in
--- parrot.old/config/gen/makefiles/ook.in	1970-01-01 01:00:00.000000000 +0100
+++ parrot/config/gen/makefiles/ook.in	2002-12-30 23:25:20.000000000 +0100
@@ -0,0 +1,18 @@
+RM_F = ${rm_f}
+PERL = ${perl}
+
+ASSEMBLE=$(PERL) ../../assemble.pl
+PARROT=../../parrot
+
+all: build
+
+test: build
+	$(PARROT) ook.pbc hello.ook > foo.pasm
+	$(ASSEMBLE) foo.pasm > foo.pbc
+	$(PARROT) foo.pbc
+
+build: ook.pasm
+	$(ASSEMBLE) ook.pasm > ook.pbc
+
+clean:
+	$(RM_F) core *.pbc *~ foo.p*
diff -urbN parrot.old/config/gen/makefiles.pl parrot/config/gen/makefiles.pl
--- parrot.old/config/gen/makefiles.pl	2002-12-30 23:43:54.000000000 +0100
+++ parrot/config/gen/makefiles.pl	2002-12-30 23:25:02.000000000 +0100
@@ -31,6 +31,8 @@
           commentType => '#');
   genfile('config/gen/makefiles/befunge.in',   'languages/befunge/Makefile',
           commentType => '#');
+  genfile('config/gen/makefiles/ook.in',       'languages/ook/Makefile',
+          commentType => '#');
 }
 
 1;
diff -urbN parrot.old/languages/ook/Changes parrot/languages/ook/Changes
--- parrot.old/languages/ook/Changes	1970-01-01 01:00:00.000000000 +0100
+++ parrot/languages/ook/Changes	2002-12-30 23:55:01.000000000 +0100
@@ -0,0 +1,9 @@
+Revision history for a Ook! compiler written in Parrot and targeting Parrot.
+
+0.0.1 Mon Dec 30 23:46:32 CET 2002
+        - thanks to a silly idea of Nicholas Clark, first draft of this
+          Ook! compiler written in Parrot.
+	- every Ook! instruction is implemented but the "Ook. Ook!"
+          one.
+        - currently spitting Parrot assembly on stdout.
+
diff -urbN parrot.old/languages/ook/hello.ook parrot/languages/ook/hello.ook
--- parrot.old/languages/ook/hello.ook	1970-01-01 01:00:00.000000000 +0100
+++ parrot/languages/ook/hello.ook	2002-12-30 23:46:46.000000000 +0100
@@ -0,0 +1,20 @@
+Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
+Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
+Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook.
+Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
+Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook?
+Ook! Ook! Ook? Ook! Ook? Ook. Ook. Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook.
+Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook. Ook. Ook. Ook. Ook.
+Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook.
+Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook.
+Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook.
+Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
+Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook.
+Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
+Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook.
+Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook.
+Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook.
+Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook!
+Ook! Ook. Ook. Ook? Ook. Ook? Ook. Ook. Ook! Ook. Ook! Ook? Ook! Ook! Ook? Ook!
+Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
+Ook. Ook. Ook. Ook. Ook! Ook.
diff -urbN parrot.old/languages/ook/ook.pasm parrot/languages/ook/ook.pasm
--- parrot.old/languages/ook/ook.pasm	1970-01-01 01:00:00.000000000 +0100
+++ parrot/languages/ook/ook.pasm	2002-12-30 23:00:12.000000000 +0100
@@ -0,0 +1,120 @@
+# First, read the file.  
+        set S0, P0[1]      # Name of the Ook source.
+	open P0, S0, "<"   # P0 = file descriptor
+	set S1, ""         # S1 = accumulator
+READ:
+	read S2, P0, 256
+	length I0, S2
+	le I0, 0, EOF
+	concat S1, S2
+	branch READ
+EOF:
+        close P0
+
+        
+# Then, parse it to translate it.
+        length I0, S1       # Total length of file.
+        set I1, 0           # Char number in the file.
+        set I2, 1           # Line number (for error reporting).
+        set I6, 0           # While-level (iterate).
+        set I7, 0           # While-level (nested).
+        set S2, ""          # Current char.
+        set S3, ""          # Current instruction.
+        set S4, "\tnew P0,.PerlArray\n\tset I0,0\n"       # Code generated.
+        branch LOOP_END
+LOOP:
+        length I4, S3
+        eq I4, 8, LOOP_CHECK_INSTRUCTION
+        substr S2, S1, I1, 1
+        inc I1
+        eq S2, "\n", LOOP_LINEFEED
+        eq S2, "\t", LOOP_END
+        eq S2, " ",  LOOP_END
+        concat S3, S2
+        branch LOOP_END
+
+LOOP_CHECK_INSTRUCTION:
+        ne S3, "Ook.Ook?", LOOP_NOT_MOVER
+        concat S4, "\tinc I0\n"
+        set S3, ""
+        branch LOOP_END
+LOOP_NOT_MOVER:
+        ne S3, "Ook?Ook.", LOOP_NOT_MOVEL
+        concat S4, "\tdec I0\n"
+        set S3, ""
+        branch LOOP_END
+LOOP_NOT_MOVEL:
+        ne S3, "Ook.Ook.", LOOP_NOT_INC
+        concat S4, "\tset I1,P0[I0]\n\tinc I1\n\tset P0[I0],I1\n"
+        set S3, ""
+        branch LOOP_END
+LOOP_NOT_INC:
+        ne S3, "Ook!Ook!", LOOP_NOT_DEC
+        concat S4, "\tset I1,P0[I0]\n\tdec I1\n\tset P0[I0],I1\n"
+        set S3, ""
+        branch LOOP_END
+LOOP_NOT_DEC:
+        ne S3, "Ook!Ook?", LOOP_NOT_WHILE
+        inc I7
+        concat S4, "\tbranch OOK"
+        set S5, I6
+        concat S4, S5
+        concat S4, "_"
+        set S5, I7
+        concat S4, S5
+        concat S4, "\nKOO"
+        set S5, I6
+        concat S4, S5
+        concat S4, "_"
+        set S5, I7
+        concat S4, S5
+        concat S4, ":\n"
+        set S3, ""
+        branch LOOP_END
+LOOP_NOT_WHILE:
+        ne S3, "Ook?Ook!", LOOP_NOT_ELIHW
+        concat S4, "OOK"
+        set S5, I6
+        concat S4, S5
+        concat S4, "_"
+        set S5, I7
+        concat S4, S5
+        concat S4, ":\n\tset I1,P0[I0]\n\tne I1,0,KOO"
+        set S5, I6
+        concat S4, S5
+        concat S4, "_"
+        set S5, I7
+        concat S4, S5
+        concat S4, "\n"
+        dec I7
+        ne I7, 0, LOOP_NESTING_DONE
+        inc I6
+LOOP_NESTING_DONE:      
+        set S3, ""
+        branch LOOP_END
+LOOP_NOT_ELIHW:
+        ne S3, "Ook!Ook.", LOOP_NOT_PRINT
+        concat S4, "\tset I1,P0[I0]\n\tchr S1,I1\n\tprint S1\n"
+        set S3, ""
+        branch LOOP_END
+LOOP_NOT_PRINT:
+        ne S3, "Ook.Ook!", LOOP_NOT_READ
+        set S3, ""
+        branch LOOP_END
+LOOP_NOT_READ:
+        print "OOK? "
+        print S0
+        print ":"
+        print I2
+        print " "
+        print S3
+        print "\n"
+        end        
+LOOP_LINEFEED:
+        inc I2
+        # Fallthru.
+LOOP_END:
+        le I1, I0, LOOP
+        concat S4, "\tend\n"
+        print S4
+        end
diff -urbN parrot.old/languages/ook/README parrot/languages/ook/README
--- parrot.old/languages/ook/README	1970-01-01 01:00:00.000000000 +0100
+++ parrot/languages/ook/README	2002-12-31 00:03:36.000000000 +0100
@@ -0,0 +1,60 @@
+DESCRIPTION
+-----------
+This is an Ook! compiler written in Parrot assembly, version 0.0.1
+
+This is a compiler, and not an interpreter. This means that the code
+is read, then compiled into Parrot assembly (yes, the target language
+is also Parrot). Then, you can fetch the Parrot assembly generated,
+assemble it and interpret it with Parrot just as you would with any
+other Parrot assembly file.
+
+You should compile and test the files with (this will run a hello
+world program):
+
+     $ make test
+
+Then you can compile your Ook! program with: 
+
+     $ ../../parrot ook.pbc > foo.pasm
+     $ perl ../../assemble.pl foo.pasm > foo.pbc
+     $ ../../parrot foo.pbc
+
+
+FILES
+-----
+The files are the following:
+        ook.pasm        well, that's pretty much the whole stuff
+        hello.ook       a ook script that greets the world!
+
+
+TODO
+----
+* implement the "Ook. Ook!" instruction
+* get rid of temp file (Parrot needs an eval thingy)
+
+
+AUTHOR
+------
+Jerome Quelin, <[EMAIL PROTECTED]>
+
+
+ACKNOWLEDGEMENTS
+----------------
+I would like to thank:
+* Nicholas Clark for gaving me this crazy idea. He's the one to take
+  the blame for it. Really. :-)
+* Piers Cawley who unwittingly lead me to write it.
+* Dan Sugalski and all the parrot folks (you know who you are) 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.dangermouse.net/esoteric/ook.html
diff -urbN parrot.old/MANIFEST parrot/MANIFEST
--- parrot.old/MANIFEST	2002-12-30 23:38:13.000000000 +0100
+++ parrot/MANIFEST	2002-12-30 23:53:09.000000000 +0100
@@ -82,6 +82,7 @@
 config/gen/makefiles/jako.in
 config/gen/makefiles/languages.in
 config/gen/makefiles/miniperl.in
+config/gen/makefiles/ook.in
 config/gen/makefiles/perl6.in
 config/gen/makefiles/root.in
 config/gen/makefiles/scheme.in
@@ -1470,6 +1471,10 @@
 languages/miniperl/Miniperl/t/003_generator.t
 languages/miniperl/Miniperl/t/004_combined.t
 languages/miniperl/mpc
+languages/ook/Changes
+languages/ook/README
+languages/ook/hello.ook
+languages/ook/ook.pasm
 languages/parrot_compiler/Makefile
 languages/parrot_compiler/gentable.pl
 languages/parrot_compiler/parrot.pasm

Reply via email to