Categories
Posts in this category
- A shiny perl6.org site
- Creating an entry point for newcomers
- Sprixel, a 6 compiler powered by JavaScript
- Another perl6.org iteration
- Blackjack and Perl 6
- Why I commit Crud to the Perl 6 Test Suite
- Report from the Perl 6 Hackathon in Copenhagen
- Custom operators in Rakudo
- Defined Behaviour with Undefined Values
- Dissecting the "Starry obfu"
- Perl 6: Failing Softly with Unthrown Exceptions
- The first Perl 6 module on CPAN
- Google Summer of Code Mentor Recap
- Building a Huffman Tree With Rakudo
- Immutable Sigils and Context
- Is Perl 6 really Perl?
- Perl 6: Lost in Wonderland
- Lots of momentum in the Perl 6 community
- Musing and the future of feather and the Pugs repository
- Musings on Rakudo's spectest chart
- My first executable from Perl 6
- Trying to implement new operators - failed
- Let's build an object
- Perl 6 is optimized for fun
- How to get a parse tree for a Perl 6 Program
- Perl 6 in 2009
- Perl 6 ticket life cycle
- The Perl 6 Advent Calendar
- How to Plot a Segment of a Circle with SVG
- Publicity for Perl 6
- Rakudo architectural overview
- Rakudo Rocks
- Rakudo "star" announced
- Rakudo's rough edges
- Rats and other pets
- Releasing Rakudo made easy
- Set Phasers to Stun!
- Starry Perl 6 obfu
- Recent Perl 6 Developments August 2008
- Strings and Buffers
- Subroutines vs. Methods - Differences and Commonalities
- A SVG plotting adventure
- A Syntax Highlighter for Perl 6
- Test Suite Reorganization: How to move tests
- The Happiness of Design Convergence
- Perl 6 Tidings from September and October 2008
- Perl 6 Tidings for November 2008
- Perl 6 Tidings from December 2008
- Perl 6 Tidings from January 2009
- Perl 6 Tidings from February 2009
- Perl 6 Tidings from March 2009
- Perl 6 Tidings from April 2009
- Perl 6 Tidings from May 2009
- Perl 6 Tidings from May 2009 (second iteration)
- Perl 6 Tidings from June 2009
- Perl 6 Tidings from August 2009
- Perl 6 Tidings from October 2009
- Timeline for a syntax change in Perl 6
- Visualizing match trees
- We write a Perl 6 book for you
- When we reach 100% we did something wrong
- Where Rakudo Lives Now
- Why was the Perl 6 Advent Calendar such a Success?
- What you can write in Perl 6 today
- Why you don't need the Y combinator in Perl 6
Tue, 05 May 2009
My first executable from Perl 6
Permanent link
In various occasions I have been asked if "Perl 6 compiles programs into real executables" or so.
The answer so far has always been the same: Perl 6 is a language specification, and it's up to the implementations if they offer that option, it's not a required feature.
But today I actually compiled a Perl 6 program into an executable, with Rakudo. It's not automated, so it takes a few steps, but it would be easy to wrap into a shell script or Makefile. Here it goes:
$ cat hello.pl say "Hello, Perl people"; $ ./perl6 --target=PIR hello.pl > hello.pir $ ./parrot/parrot -o hello.pbc hello.pir $ ./parrot/pbc_to_exe hello.pbc > hello $ file hello hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.8, not stripped $./hello Hello, Perl people
This is what the Parrot folks call a "fake executable" - it contains the byte code as a string, links to libparrot, and has a small main program that initializes parrot. But hey, it's an executable ;-)
Comments / Trackbacks:
Trackback URL:
/blog-en/perl-6/my-first-executable.trackback
j1n3l0 wrote
Cool!
I managed to do the same on a Mac with an interactive perl6 program:
mib19412i:~/Applications/rakudo io1$ cat > hello.pl
use v6;
sub MAIN() {
my $name = prompt 'What is our name: ';
say "Hello, {$name}!";
}
mib19412i:~/Applications/rakudo io1$ ./perl6 --target=PIR hello.pl > hello.pir
mib19412i:~/Applications/rakudo io1$ ./parrot/parrot -o hello.pbc hello.pir
mib19412i:~/Applications/rakudo io1$ ./parrot/pbc_to_exe hello.pbc > hello
mib19412i:~/Applications/rakudo io1$ file hello
hello: Mach-O executable i386
mib19412i:~/Applications/rakudo io1$ ./hello
What is our name: Nelo
Hello, Nelo!
mib19412i:~/Applications/rakudo io1$
A couple of notes/issues to raise:
1 - This has to be done in the same directory as the perl6 executable (I think the rakudo folk are already aware of this)
2 - There is an --output option for the perl6 executable but it does not output to the specified file
Moritz wrote
output option
The --output option works here (thanks; I forgot about that. Actually it's preferable over a redirect because an aborted compilation won't clobber the output file with --output), you just have to use an = sign:
./perl6 --target=PIR --output=bar Test.pm
Klaus wrote
Or slightly less bloated ;-)
<code>
$ ls -l hello
-rwxr-xr-x 1 klaus klaus 440 7. Mai 13:42 hello
$ ldd hello
not a dynamic executable
$ file hello
hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped
$ ./hello
Hello, Perl people
</code>
Ahmad Zawawi wrote
It also works on win32 (moritz++):
$ perl6 --target=PIR hello.pl > hello.pir
$ parrot\parrot -o hello.pbc hello.pir
$ parrot\pbc_to_exe hello.pbc
$ dir hello.exe
05/14/2009 04:33 PM 505,654 hello.exe
$ hello.exe
mark wrote
can you do static programs as well?
this would be kinda cool
Moritz wrote
Broken
Currently the fake-executable generation is broken, see http://rt.perl.org/rt3/Public/Bug/Display.html?id=65994
Michael wrote
Didn't work for me
I'm using Rakudo Pittsburgh on Lnux 64bit and this is what I got:
[root@mrPeanut rakudo-2009-06]# ./perl6 --target=PIR circle2.pl > circle2.pir
[root@mrPeanut rakudo-2009-06]# ./parrot/parrot -o circle2.pbc circle2.pir
[root@mrPeanut rakudo-2009-06]# ./parrot/pbc_to_exe circle2.pbc > circle2
[root@mrPeanut rakudo-2009-06]# ./circle2
Class '[ 'parrot' ; 'Perl6MultiSub' ]' not found
current instr.: 'perl6;Perl6Role;!add_variant' pc 3875 (src/classes/Role.pir:42)
called from Sub '!create_simple_role' pc 20874 (src/builtins/guts.pir:1304)
called from Sub '' pc 4260 (src/classes/Abstraction.pir:15)
called from Sub '' pc 35 (circle2.pir:25)
called from Sub '_block11' pc -1 ((unknown file):-1)
[root@mrPeanut rakudo-2009-06]#
Write a comment
The comments on this blog post have been disabled; the comment form below will not work.