how to compile perl6 program to generate bytecode?

1k Views Asked by At

I am trying to understand perl6 and its changes than perl5. I come to know that perl 6 is compiled languages but I am not getting how? It is not generating any intermediate code (directly executable or jvm bytecode)? I am not getting any option to do the same. How to do it?

Currently I am able to directly execute my code.

$ perl6-j hello.p6
Hello world

I am following https://github.com/rakudo/rakudo

3

There are 3 best solutions below

0
On

Writing bytecode to a file both for modules and programs is not official supported yet. Hence the lack of documentation for --target.

2
On

You can use --target= on the perl6 command line to see a human readable trace of each stage of the compiler. On JVM if you wish to have a "compiled" bytecode output you can use --target=jar and then take a look inside there. But ultimately Perl 6 compiles on the fly unless asked otherwise. It leaves a bytecode representation cached in library path directories of each "CompUnit", so that the compile step is faster next time. This can be seen in .precomp directories. The precomp cache is very tricky to use by hand due to how Perl 6 hashes and indexes all comp units. This is so libraries with the same name but different version and author can sit side by side. On MoarVM there is no equivalent to --target=jar but in the .precomp directory you can see the raw bytecode files that can be directly executed by moar if you link the runtime setting.

1
On

Updating the answer for this as this is now supported.

To generate the bytecode for a perl6 program, run perl6 --target=<backend> --output=foo foo.pl6. You can use mbc, jvm, or js as your target backend. The bytecode will be written to the file foo.