From f2ce98ccc0184284e45d71b6af42f658963216bc Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Quelin?= Date: Tue, 11 Nov 2008 14:29:21 +0100 Subject: [PATCH] new extension PERL --- MANIFEST | 1 + lib/Language/Befunge/lib/PERL.pm | 112 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 lib/Language/Befunge/lib/PERL.pm diff --git a/MANIFEST b/MANIFEST index 6ad2f5c..7c0d34a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -19,6 +19,7 @@ lib/Language/Befunge/IP.pm lib/Language/Befunge/lib/FOO.pm lib/Language/Befunge/lib/HELO.pm lib/Language/Befunge/lib/NULL.pm +lib/Language/Befunge/lib/PERL.pm lib/Language/Befunge/lib/TEST.pm lib/Language/Befunge/Ops.pm lib/Language/Befunge/Ops/Befunge98.pm diff --git a/lib/Language/Befunge/lib/PERL.pm b/lib/Language/Befunge/lib/PERL.pm new file mode 100644 index 0000000..0f28468 --- /dev/null +++ b/lib/Language/Befunge/lib/PERL.pm @@ -0,0 +1,112 @@ +# +# This file is part of Language::Befunge. +# Copyright (c) 2001-2008 Jerome Quelin, all rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the same terms as Perl itself. +# +# + +package Language::Befunge::lib::PERL; + +use strict; +use warnings; + + +sub new { return bless {}, shift; } + + +sub E { + my ($self, $interp) = @_; + my $ip = $interp->get_curip(); + + # pop the perl string + my $perl = $ip->spop_gnirts(); + my $return = eval $perl; + + $ip->spush( 0 ); # finish the string + $ip->spush( map{ ord($_) } reverse split(//, $return) ); +} + +sub I { + my ($self, $interp) = @_; + my $ip = $interp->get_curip(); + + # pop the perl string + my $perl = $ip->spop_gnirts(); + my $return = eval $perl; + + $ip->spush( int $return ); +} + +sub S { + my ($self, $interp) = @_; + $interp->get_curip->spush(0); +} + +1; + +__END__ + + +=head1 NAME + +Language::Befunge::IP::lib::PERL - extension to embed Perl within Befunge + + + +=head1 DESCRIPTION + +The PERL fingerprint (0x5045524c) is designed to provide a basic, no-frills +interface to the Perl language. + +After successfully loading PERL, the instructions E, I, and S take on new +semantics. + + + +=head1 FUNCTIONS + +=head2 new + +Create a new PERL instance. + + +=head2 E( 0gnirts ) + +C pops a 0gnirts string and performs a Perl C on it. The +result of the call is pushed as a 0gnirts string back onto the stack. + + +=head2 I( 0gnirts ) + +C<'Int Eval'> acts the same as C, except that the result of the call +is converted to an integer and pushed as a single cell onto the stack. + + +=head2 S + +C pushes a 0 on the stack, meaning that the Perl language is already +loaded (e.g. the interpreter is written in Perl). + + + +=head1 SEE ALSO + +L. + + +=head1 AUTHOR + +Jerome Quelin, C<< >> + + +=head1 COPYRIGHT & LICENSE + +Copyright (c) 2001-2008 Jerome Quelin, all rights reserved. + +This program is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + + +=cut -- 2.11.4.GIT