Skip to content

Instantly share code, notes, and snippets.

@niner
Created September 23, 2018 12:05
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 niner/938c307ba8313788cdf9d383dedb4ce3 to your computer and use it in GitHub Desktop.
Save niner/938c307ba8313788cdf9d383dedb4ce3 to your computer and use it in GitHub Desktop.
method to_mast($qast, %mast_frames = nqp::hash()) {
# Set up compilation state.
my $profile := nqp::existskey(nqp::getenvhash(), 'PROFILEMBC') && nqp::istype($qast, QAST::CompUnit) && $qast.compilation_mode && !$qast.is_nested;
nqp::mvmstartprofile(nqp::hash('kind', 'instrumented')) if $profile;
$!hll := '';
my $string-heap := MoarVM::StringHeap.new();
my $callsites := MoarVM::Callsites.new(:$string-heap);
my $annotations := $buf.new;
$!writer := MoarVM::BytecodeWriter.new(:$string-heap, :$callsites, :$annotations);
$!mast_compunit := MAST::CompUnit.new(:$!writer);
$!writer.set-compunit($!mast_compunit);
%!mast_frames := %mast_frames;
$!file := nqp::ifnull(nqp::getlexdyn('$?FILES'), "<unknown file>");
$!sc := NQPMu;
# Compile, and evaluate to compilation unit.
self.as_mast($qast);
HLL::Backend::MoarVM.dump_instrumented_profile_data(nqp::mvmendprofile, nqp::null) if $profile;
#CATCH {
# my $err := $!;
# my $source := self.source_for_node($!last_op);
# nqp::die("QAST -> MAST failed while compiling op " ~ $!last_op.op ~ "$source: $err");
#}
$!mast_compunit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment