Skip Menu |

This queue is for tickets about the Acme-Brainfuck CPAN distribution.

Report information
The Basics
Id: 81821
Status: new
Priority: 0/
Queue: Acme-Brainfuck

People
Owner: jaldhar [...] braincells.com
Requestors: hugh [...] davenport.net.nz
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.1.1
Fixed in: (no value)



Subject: Add support for EsoAPI
There is an extension to Brainfuck (as well as other esoterical languages) called EsoAPI (mentioned http://esolangs.org/wiki/EsoAPI, defined http://kidsquid.99k.org/programs/esoapi/esoapi.html, example implemention http://esolangs.org/wiki/User:JayCampbell/weave.rb). I've attached a patch to add support for this API to the Acme::Brainfuck module. You can test via the attache esoapi-hello.pl. Before the patch it will print "EsoAPI required\n", and after the patch will print "Hello World!\n" Cheers, Hugh
Subject: esoapi-hello.pl
use Acme::Brainfuck qw/esoapi/; +>.++++++++.[++++++[>++>+++++>++++++++>+++++++>+<<<<<-]>>-.>+++.----.<----.+++++++++++++++.-------.<++++.>>+++.>+++.<-.++++.>++++.<---.>----.-.>-.---.>>]<[>++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.<<<<<-]
Subject: esoapi.patch
--- /usr/share/perl5/Acme/Brainfuck.pm 2004-04-07 04:12:29.000000000 +1200 +++ /usr/local/share/perl/5.10.1/Acme/Brainfuck.pm 2012-12-09 13:52:11.875311240 +1300 @@ -5,6 +5,8 @@ # package Acme::Brainfuck; use Filter::Simple; +use Fcntl qw/SEEK_CUR SEEK_SET O_RDWR O_CREAT/; +use List::Util qw/min/; use strict; use warnings; @@ -15,6 +17,12 @@ our $p = 0; our @m = (); +# ESOAPI +our $esoapi = 0; +my $prevout = undef; +my $esofile = undef; +my $sectorsize = 512; + # The basic Brainfuck instructions. Extras will be added in import(). our $ops = '+-<>,.[]'; @@ -38,9 +46,57 @@ { $debug = 1; } + if (/^esoapi$/) + { + $esoapi = 1; + sysopen $esofile, "esoapi.dsk", O_RDWR|O_CREAT and do + { + binmode $esofile; + } or do + { + warn "Could not open esofile.dsk, turning off EsoAPI support\n"; + $esoapi = 0; + $esofile = undef; + }; + } } } +sub esosub +{ + my $val = shift; + my $tmp; + + if (!defined $val) + { + $val = 0; + } + + if (!defined $prevout || $prevout != 0) + { + print chr $val; + } elsif ($val == 1) + { + sysseek $esofile, $sectorsize, SEEK_CUR; + } elsif ($val == 2) { + sysseek $esofile, -$sectorsize, SEEK_CUR; + } elsif ($val == 3) { + my $length = sysread $esofile, $tmp, $sectorsize; + @m[$p + 1 .. $p + min($length, $sectorsize)] = map ord, split //, $tmp; + } elsif ($val == 4) { + my @tmpa = @m[$p + 1 .. min($#m, $p + $sectorsize)]; + syswrite $esofile, join '', map(chr, @tmpa); + } elsif ($val == 5) { + sysseek $esofile, 0, SEEK_SET; + } elsif ($val == 8) { + $m[$p] = 0; + } else { + print chr $val; + } + + $prevout = $val; +}; + FILTER_ONLY code => sub { my $ret = $_; @@ -56,7 +112,15 @@ $code =~ s/(\-+)/"P -= ".length($1).";" /eg; $code =~ s/(<+)/"\$Acme::Brainfuck::p -= ".length($1).";" /eg; $code =~ s/(>+)/"\$Acme::Brainfuck::p += ".length($1).";" /eg; - $code =~ s/\./print chr P; /g; + if ($esoapi) + { + $code =~ + s/\./Acme::Brainfuck::esosub P; /g; + } + else + { + $code =~ s/\./print chr P; /g; + } $code =~ s/,/P = ord getc;/g; $code =~ s/\[/while(P){/g; $code =~ s/\]/}; /g;