Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial import

  • Loading branch information...
commit a21b75b42bd5ddd06f23afec901377555e47df6f 0 parents
@szabgab authored
4 Changes
@@ -0,0 +1,4 @@
+
+0.01 2009.03.23
+
+ Blogged about it...
43 MANIFEST.SKIP
@@ -0,0 +1,43 @@
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+,v$
+\B\.svn\b
+\B\.cvsignore$
+
+# Avoid Makemaker generated and utility files.
+\bMakefile$
+\bblib
+\bMakeMaker-\d
+\bpm_to_blib$
+\bblibdirs$
+^MANIFEST\.SKIP$
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\bBuild.bat$
+\b_build
+
+# Avoid Devel::Cover generated files
+\bcover_db
+
+# Avoid temp and backup files.
+~$
+\.tmp$
+\.old$
+\.bak$
+\#$
+\.#
+\.rej$
+
+# Avoid OS-specific files/dirs
+# Mac OSX metadata
+\B\.DS_Store
+# Mac OSX SMB mount metadata files
+\B\._
+# Avoid archives of this distribution
+\bInline-Rakudo-[\d\.\_]+
+
+
+
+
22 Makefile.PL
@@ -0,0 +1,22 @@
+use 5.008005;
+use strict;
+use inc::Module::Install 0.77;
+
+
+
+
+
+#####################################################################
+# Normal Boring Commands
+
+# NOTE: Core modules that aren't dual-life should always have a version of 0
+
+name 'Inline-Rakudo';
+license 'perl';
+author 'Gabor Szabo';
+all_from 'lib/Inline/Rakudo.pm';
+requires 'perl' => '5.008005';
+requires 'FindBin' => 0;
+test_requires 'Test::More' => '0.47';
+
+WriteAll;
25 README
@@ -0,0 +1,25 @@
+Perl 6 in Perl 5
+
+After building Parrot and Rakudo I set the RAKUDO_DIR
+environment variable to point to the directory
+where Rakudo was checked out. I also set the PARROT_DIR
+environment variable to point to the directory
+where Parrot was checked out (in the currently standard setup
+that would be $RAKUDO_DIR/parrot).
+
+Then I set LD_LIBRARY_PATH to point to $PARROT_DIR/blib/lib/
+
+This is what I have now in .bashrc
+
+ export RAKUDO_DIR=$HOME/work/rakudo
+ export PARROT_DIR=$RAKUDO_DIR/parrot
+ export LD_LIBRARY_PATH=$PARROT_DIR/blib/lib/
+
+
+Other than that
+
+perl Makefile.PL
+make
+make test
+make install
+
72 lib/Inline/Rakudo.pm
@@ -0,0 +1,72 @@
+package Inline::Rakudo;
+use strict;
+use warnings;
+
+# Needs the following environment variables:
+# RAKUDO_DIR needs to point to the Rakudo directory
+# PARROT_DIR needs to point to the directory where parrot was checked out
+# export LD_LIBRARY_PATH=$PARROT_DIR/blib/lib/
+
+# cwd still needs to be PARROT_DIR or I get the following error:
+#"load_bytecode" couldn't find file 'PCT.pbc'
+#current instr.: '' pc 743 (src/classes/Object.pir:20)
+#called from Sub 'myperl6' pc 3 (EVAL_1:3)
+
+# Before running I had to build Parrot::Embed:
+# cd $ENV{PARROT_DIR}/ext/Parrot-Embed/
+# perl Build.PL
+# perl Build
+# perl Build test
+
+sub new {
+ my ($class) = @_;
+ my $self = bless {}, $class;
+ $self->{parrot} = load_rakudo();
+ return $self;
+}
+
+sub load_rakudo {
+ die "need PARROT_DIR" if not $ENV{PARROT_DIR};
+ unshift @INC, (
+ "$ENV{PARROT_DIR}/ext/Parrot-Embed/blib/lib",
+ "$ENV{PARROT_DIR}/ext/Parrot-Embed/blib/arch",
+ );
+
+ require Parrot::Embed;
+ my $interp = Parrot::Interpreter->new;
+
+ my $load_rakudo =<<"END_PIR";
+.sub load_rakudo
+ load_bytecode '$ENV{RAKUDO_DIR}/perl6.pbc'
+.end
+END_PIR
+ my $eval = $interp->compile( $load_rakudo );
+ my $rakudo = $interp->find_global('load_rakudo');
+ my $pmc = $rakudo->invoke( 'PS', '' );
+ return $interp;
+}
+
+sub run_code {
+ my ($self, $code) = @_;
+
+ my $perl6 =<<"END_PIR";
+.sub myperl6
+ .param string in_string
+ .local pmc compiler, invokable
+ .local string result
+ compiler = compreg 'Perl6'
+ invokable = compiler.'compile'(in_string)
+ result = invokable()
+ .return(result)
+.end
+END_PIR
+
+
+ my $eval = $self->{parrot}->compile( $perl6 );
+ my $foo = $self->{parrot}->find_global('myperl6');
+ my $pmc = $foo->invoke( 'PS', $code );
+ return $pmc->get_string();
+}
+
+
+1;
20 t/01-simple.t
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Inline::Rakudo;
+
+my $rakudo = Inline::Rakudo->new;
+#print $rakudo->run_code('"world".say'). "\n";
+
+my $code = <<'END_CODE';
+sub f($n) {
+ return $n+1;
+}
+END_CODE
+$rakudo->run_code($code);
+
+print $rakudo->run_code('f(41)'). "\n";
+
Please sign in to comment.
Something went wrong with that request. Please try again.