Skip to content

Working in Rakudo NQP Land

Tom Browder edited this page Sep 18, 2018 · 3 revisions

Working in Rakudo NQP Land

The code in Rakudo "src/Perl6/*.nqp" is in a strange state. It is written in NQP, but some of its objects are still malleable (that is, subject to change) and some are immutable when one would like to modify them.

Some of the questions below mention unpacking which means being able to access all the object's attributes, change, add, or delete them, and create a new object to take its place.

Some questions to be answered:##

  • When using nqp::istype($object, Type), what Types are available for querying?

  • Is there any way to unpack an NQPMu object?

  • What type $object results from $object.compile_time_value? Can it be unpacked?

  • What does the .ast method do? Can the resulting object be unpacked? If so, how?

Use basic NQP to develop subs and classes

Before adding larger chunks of NQP code to Rakudo, you may try the code as basic NQP which does not use Perl 6. Here is a short NQP program that illustrates the idea:

#!/usr/bin/env nqp

my $x:= 1;
say("\$x = '$x'");

which, when executed, results in:

$x = '1'

Debugging

Debugging is tough. In contrast to "raw" NQP, debugging Rakudo NQP is hostage to Rakudo's long build time (3+ minutes). Use of strategically placed nqp::die and say statements are helpful, as is the .dump method on objects, e.g.,

sub defn($/) {
    say($/.dump);
}

There are some introspection methods available on an $object:

[TO BE CONTINUED]