Created
June 23, 2016 14:46
-
-
Save peschwa/785b29f2ebd9505aabed400267808653 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/vm/jvm/QAST/Compiler.nqp b/src/vm/jvm/QAST/Compiler.nqp | |
index e9632d0..30eef42 100644 | |
--- a/src/vm/jvm/QAST/Compiler.nqp | |
+++ b/src/vm/jvm/QAST/Compiler.nqp | |
@@ -3189,14 +3189,80 @@ class QAST::CompilerJAST { | |
$source; | |
} | |
- method jast($source, :$classname!, *%adverbs) { | |
+ | |
+ sub p6sort(@input_data, | |
+ &comparator = -> $a, $b { $a < $b ?? -1 !! $a > $b ?? 1 !! 0 }) { | |
+ # using the "bottom-up" mergesort implementation as shown in the english | |
+ # wikipedia article | |
+ | |
+ # for some extra (hopefully measurable) benefit, we plop our indices | |
+ # into native integer lists before going on. | |
+ | |
+ my @b_list := nqp::list_i(); | |
+ my @data := nqp::list_i(); | |
+ nqp::setelems(@b_list, +@input_data); | |
+ nqp::setelems(@data, +@input_data); | |
+ | |
+ my int $copy_idx; | |
+ for @input_data { | |
+ nqp::bindpos_i(@data, $copy_idx++, $_); | |
+ } | |
+ | |
+ my int $n := +@data; | |
+ | |
+ my int $run_w := 1; # the width of each of the runs we are looking at | |
+ while $run_w < $n { | |
+ my int $i; | |
+ | |
+ while $i < $n { | |
+ my int $left := $i; | |
+ my int $right := $i + $run_w; | |
+ $right := $n if $n < $right; | |
+ | |
+ my int $end := $i + 2 * $run_w; | |
+ $end := $n if $n < $end; | |
+ | |
+ my int $i0 := $left; | |
+ my int $i1 := $right; | |
+ my int $j := $i0; | |
+ | |
+ while $j < $end { | |
+ if $i0 < $right && ($i1 >= $end || -1 == comparator(nqp::atpos_i(@data, $i0), nqp::atpos_i(@data, $i1))) { | |
+ nqp::bindpos_i(@b_list, $j, nqp::atpos_i(@data, $i0)); | |
+ $i0 := $i0 + 1; | |
+ } else { | |
+ nqp::bindpos_i(@b_list, $j, nqp::atpos_i(@data, $i1)); | |
+ $i1 := $i1 + 1; | |
+ } | |
+ $j := $j + 1; | |
+ } | |
+ | |
+ $i := $i + 2 * $run_w; | |
+ } | |
+ | |
+ { | |
+ my $t := @b_list; | |
+ @b_list := @data; | |
+ @data := $t; | |
+ } | |
+ | |
+ $run_w := $run_w * 2; | |
+ } | |
+ | |
+ $copy_idx := 0; | |
+ for @data { | |
+ nqp::bindpos(@input_data, $copy_idx++, $_); | |
+ } | |
+ } | |
+ | |
+ method jast($source, :$frames!, :$classname!, *%adverbs) { | |
# Wrap $source in a QAST::CompUnit if it's not already a viable root node. | |
unless nqp::istype($source, QAST::CompUnit) { | |
my $unit := $source; | |
$unit := QAST::Block.new($unit) unless nqp::istype($unit, QAST::Block); | |
$source := QAST::CompUnit.new(:hll(''), $unit); | |
} | |
- | |
+ | |
# Set up a JAST::Class that will hold all the blocks (which become Java | |
# methods) that we shall compile. | |
my $file := nqp::ifnull(nqp::getlexdyn('$?FILES'), ""); | |
@@ -3205,6 +3271,10 @@ class QAST::CompilerJAST { | |
:super('org.perl6.nqp.runtime.CompilationUnit'), | |
:filename($file) | |
); | |
+ | |
+ nqp::bindkey($frames, $file, $classname); | |
+ | |
+ nqp::sayfh(nqp::getstderr, "compiling $classname $file, elems frames: " ~ nqp::elems($frames)); | |
# We'll also need to keep track of all the blocks we compile into Java | |
# methods; the CodeRefBuilder takes care of that. | |
@@ -3214,6 +3284,26 @@ class QAST::CompilerJAST { | |
# set up above will be fully populated. | |
self.as_jast($source); | |
+ my @qbids := nqp::list_i; | |
+ for $*JCLASS.methods { | |
+ my $name := $_.name; | |
+ if nqp::substr($name, 0, 3) eq 'qb_' { | |
+ my $number := nqp::substr($name, nqp::index($name, '_') + 1); | |
+ nqp::sayfh(nqp::getstderr, $number); | |
+ nqp::bindpos_i(@qbids, +@qbids, +$number); | |
+ } | |
+ } | |
+ nqp::sayfh(nqp::getstderr(), 'have elems: ' ~ +@qbids); | |
+ p6sort(@qbids) if nqp::elems(@qbids); | |
+ my $missing; | |
+ my $i := 1; | |
+ while $i < +@qbids { | |
+ if @qbids[$i - 1] - @qbids[$i] != -1 { | |
+ $missing := @qbids[$i] - 1; | |
+ } | |
+ } | |
+ nqp::sayfh(nqp::getstderr, "found missing: $missing"); | |
+ | |
# Make various code-ref/dispatch related things. | |
$*CODEREFS.jastify(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment