Skip to content

Instantly share code, notes, and snippets.

Created November 19, 2014 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c77f22162dda98efc968 to your computer and use it in GitHub Desktop.
Save anonymous/c77f22162dda98efc968 to your computer and use it in GitHub Desktop.
use QAST:from<NQP>;
my $qast := QAST::Block.new(QAST::Op.new( :op<call>, QAST::Var.new(:name<&say>, :scope<lexical>), QAST::SVal.new(:value('Hello World'))));
my $comp_unit := QAST::CompUnit.new(
# Set the HLL.
:hll('perl6'),
# This variable contains the outermost QAST::Block of the
# program.
$qast,
# If we run the program as the mainline, then call the top
# block automatically.
:main(QAST::Op.new(
:op('call'),
QAST::BVal.new( :value($qast) )
))
);
my $compiler = nqp::getcomp('perl6');
say $_ for $compiler.stages();
my $backend := $compiler.backend();
my $mast := $backend.mast($comp_unit);
my $mbc := $backend.mbc($mast);
my $compiled := $backend.moar($mbc);
$backend.compunit_mainline($compiled)();
say "Compiled and ran with no errors.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment