Compiling QAST fragments to js from nqp-js

The nqp-js backend works when compiled to javascript.

# save this as hello-world.nqp

use QAST::Compiler;

my $sc := nqp::createsc('TEST_SC');
nqp::scsetdesc($sc, "description");
my $qast := QAST::Block.new(
        :blocktype('immediate'),
        QAST::Op.new(
            :op('say'),
            QAST::Op.new(
                :op('concat'),
                QAST::SVal.new(:value("Hello ")),
                QAST::SVal.new(:value("World"))
            )
        )
    );

my $compunit := QAST::CompUnit.new(
    :sc($sc),
    :code_ref_blocks(nqp::list()),
    $qast
);
my $compiler := QAST::CompilerJS.new();
say($compiler.emit($compunit));

Run it like

make js-all
make js-bootstrap
./nqp-js hello-world.nqp | node

Leave a comment

About Paweł Murias

user-pic This is my JavaScript backend for Rakudo/NQP blog.