how to compile perl6 program to generate bytecode?
Asked Answered
B

3

5

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

Blackford answered 14/8, 2016 at 5:47 Comment(2)
2024 update I'm briefly reviewing SOs related to producing a stand-alone exe. I've decided to write some FYI comments. I've found this SO plus 3 others: How can I compile perl6 file to exe, how do I create a stand-alone executable with perl 6?, Deploying self contained Perl 6 script.Inculpate
See also reddit post "Distributing Raku Programs".Inculpate
F
7

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.

Frothy answered 14/8, 2016 at 7:9 Comment(2)
--target=moar is a thingJaclyn
Does target moar package everything up so you have a single file that is executable by MoarVM? Or is it the equivalent of the class file which is found int he .precompFrothy
C
5

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.

Claudication answered 3/8, 2019 at 12:45 Comment(1)
raku --target=mbc -e "say ""Hello, World!""" ===SORRY!=== Cannot dump this object; no dump methodInfertile
B
3

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

Blocker answered 14/8, 2016 at 6:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.