Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move compilation unit handling to backend class.
This should also help make the addition of --target=pbc a bit cleaner.
  • Loading branch information
jnthn committed Feb 27, 2013
1 parent 1c6c851 commit 6613df0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
17 changes: 14 additions & 3 deletions src/HLL/Compiler.pm
Expand Up @@ -115,6 +115,18 @@ class HLL::Backend::Parrot {
my $compiler := nqp::getcomp('PIR');
$compiler($source)
}

method is_compunit($cuish) {
!pir::isa__IPs($cuish, 'String')
}

method compunit_mainline($cu) {
$cu[0]
}

method compunit_coderefs($cu) {
$cu
}
}

# Role specifying the default backend for this build.
Expand Down Expand Up @@ -252,11 +264,10 @@ class HLL::Compiler does HLL::Backend::Default {
$output := self.compile($code, |%adverbs);
}

if !pir::isa__IPs($output, 'String')
&& %adverbs<target> eq '' {
if $!backend.is_compunit($output) && %adverbs<target> eq '' {
my $outer_ctx := %adverbs<outer_ctx>;
if nqp::defined($outer_ctx) {
$output[0].set_outer_ctx($outer_ctx);
$!backend.compunit_mainline($output).set_outer_ctx($outer_ctx);
}

if (%adverbs<profile>) {
Expand Down
19 changes: 11 additions & 8 deletions src/NQP/World.pm
Expand Up @@ -230,28 +230,30 @@ class NQP::World is HLL::World {
my $stub_code := sub (*@args, *%named) {
# Do the compilation.
$past.unshift(self.libs());
my $compiled := nqp::getcomp('nqp').compile(
my $compiler := nqp::getcomp('nqp');
my $compiled := $compiler.compile(
QAST::CompUnit.new( :hll('nqp'), $past ),
:from<ast>);

# Fix up any code objects holding stubs with the real compiled thing.
my $c := nqp::elems($compiled);
my @allcodes := $compiler.backend.compunit_coderefs($compiled);
my $c := nqp::elems(@allcodes);
my $i := 0;
while $i < $c {
my $subid := $compiled[$i].get_subid();
my $subid := @allcodes[$i].get_subid();
if nqp::existskey(%!code_objects_to_fix_up, $subid) {
# First, go over the code objects. Update the $!do, and the
# entry in the SC. Make sure the newly compiled code is marked
# as a static code ref.
my $static := %!code_objects_to_fix_up{$subid}.shift();
nqp::bindattr($static, %!code_object_types{$subid}, '$!do', $compiled[$i]);
nqp::bindattr($static, %!code_object_types{$subid}, '$!do', @allcodes[$i]);
nqp::bindattr($static, %!code_object_types{$subid}, '$!clone_callback', nqp::null());
for %!code_objects_to_fix_up{$subid} {
nqp::bindattr($_, %!code_object_types{$subid}, '$!do', nqp::clone($compiled[$i]));
nqp::bindattr($_, %!code_object_types{$subid}, '$!do', nqp::clone(@allcodes[$i]));
nqp::bindattr($_, %!code_object_types{$subid}, '$!clone_callback', nqp::null());
}
nqp::markcodestatic($compiled[$i]);
self.update_root_code_ref(%!code_stub_sc_idx{$subid}, $compiled[$i]);
nqp::markcodestatic(@allcodes[$i]);
self.update_root_code_ref(%!code_stub_sc_idx{$subid}, @allcodes[$i]);

# Clear up the fixup statements.
my $fixup_stmts := %!code_object_fixup_list{$subid};
Expand All @@ -260,7 +262,8 @@ class NQP::World is HLL::World {
$i := $i + 1;
}

$compiled(|@args, |%named);
my $mainline := $compiler.backend.compunit_mainline($compiled);
$mainline(|@args, |%named);
};

# Create code object, if we'll need one.
Expand Down

0 comments on commit 6613df0

Please sign in to comment.