On 30/08/01 15:39 +0000, Jo�o Pedro Gon�alves wrote:
> Hi,
> First of all congratulations to all involved in the amazing Inline
> package.
> You do deserve all the awards and beer that you're getting.
>
> As a way to explore deeper the Inline details, and as Perl is a language
> that was made to make your job easier, Inline allows us to include
> in Perl languages developed to make our job *HARD*.
> As ASM was already available, i went for more obscure ones,
> and brainfuck was the chosen one.
You are an evil person. I like you.
This module should of course be realeased in the Acme namespace. Go for it.
It's fun. (see code comments below)
In closing, I have this simple advice for you:
use YourBrainForOnceDude;
Seriously. Use it.
Cheers, Brian
> If you don't know Urban Mueller's Brainfuck already, it's an
> 8 command set language, check http://www.catseye.mb.ca/esoteric/bf/
>
> Basically it's just a regexp set that converts the brainfuck
> instructions
> to Perl code, this had already been done by Markko Nippula,
> http://www.hut.fi/~mnippula/useless/
> .
>
>
> Here's the JaXH subroutine:
>
> use Inline Brainfuck => <<EOF;
>
> JaXH (
>
> >+++++++++[<++++++++>-]<++.>+++++++[<++++++>-]<+.--.+.[-]>++++++++[<++++>-]<.>+
>
> +++++++[<++++>-]<+.>+++++++[<++++++>-]<+++.+.+++++.>++++[<--->-]<.---.>++++[<++
>
> +>-]<+.[-]>++++++++[<++++>-]<.,[.,][-]>++++++++[<++++>-]<.>+++++[<++++++++>-]<.
>
> >+++++[<+++++>-]<.++.++++++++.------.>++++[<+++>-]<+.[-]++++++++++.
> )
> EOF
>
> print JaXH("Inline");
>
>
> The Brainfuck input command (",") reads from $_[0],
> The Brainfuck print command (".") is buffered and returned.
>
>
> Anyway, just another way to congratulate you guys for the wonderful work
> and documentation that allowed me to get into Inline world in a morning.
>
> Have fun!
>
> Jo�o Pedro Gon�alves
> package Inline::Brainfuck;
> $VERSION = '0.01';
> require Inline;
> @ISA = qw(Inline);
> use strict;
> use Carp;
Hmm. I see Inline::Foo is getting put to, er, good use again.
> sub register {
> return {
> language => 'Brainfuck',
> aliases => ['brainfuck'],
> type => 'interpreted',
> suffix => 'bf',
> };
> }
>
> sub usage_config {
> my $key = shift;
> "'$key' is not a valid config option for Inline::Brainfuck\n";
> }
>
> sub validate {
> my $o = shift;
> $o->{ILSM}{PATTERN} ||= 'bf-';
> $o->{ILSM}{BAR} ||= 0;
> while (@_) {
> my ($key, $value) = splice @_, 0, 2;
> if ($key eq 'PATTERN') {
> $o->{ILSM}{PATTERN} = $value;
> next;
> }
> croak usage_config($key);
> }
> }
The validate() routine is used to validate language specific options. Since
you have none, an empty routine would be fine here.
NOTE: I use Inline::Foo to test Inline, which is why I do things that emulate
a real language. Since Brainf*ck already is a real language, there's no
reason for the added things.
>
>
> sub bf_interp {
> $_ = shift;
> s/\(/__/g;
> s/\)/==/g;
> s/([\[\]+-<>\.,])/$1;/g;
> s/(\+|-)/P$1$1/g;
> s/</\$p--/g;
> s/>/\$p++/g;
> s/\./ \$buf .= chr P/g;
> y/[]/{}/;
> s/{/while(P){/g;
> s/,/P=ord substr(\$_[0],\$i++,1)/g;
> s/P/\$m[\$p]/g;
> s/==/return \$buf }/g;
> s/(\w+) __/sub $1 {my (\$p,\$buf,\$i,\@m);/g;
> return $_;
> }
>
>
> sub build {
> my $o = shift;
> my $code = $o->{API}{code};
> my $pattern = $o->{ILSM}{PATTERN};
> $code = bf_interp($code);
> {
> package Brainfuck::Tester;
> eval $code;
> }
> croak "Brainfuck build failed:\n$@" if $@;
> my $path = "$o->{API}{install_lib}/auto/$o->{API}{modpname}";
> my $obj = $o->{API}{location};
> $o->mkpath($path) unless -d $path;
> open FOO_OBJ, "> $obj"
> or croak "Can't open $obj for output\n$!";
> print FOO_OBJ $code;
> close \*FOO_OBJ;
> }
>
> sub load {
> my $o = shift;
> my $obj = $o->{API}{location};
> open FOO_OBJ, "< $obj"
> or croak "Can't open $obj for output\n$!";
> my $code = join '', <FOO_OBJ>;
> close \*FOO_OBJ;
> eval "package $o->{API}{pkg};\n$code";
> croak "Unable to load Foo module $obj:\n$@" if $@;
> }
>
> sub info {
> my $o = shift;
> }
>
> 1;
>
> __END__