From 306da23b78dbc7afc9c1c9f8faf42c1a9e23e96b Mon Sep 17 00:00:00 2001 From: Mouq Date: Wed, 12 Nov 2014 01:53:37 -0500 Subject: [PATCH 1/4] Change NQPMatch!make to NQPMatch.make Not sure why it was private in the first place, when it was written in 2012 by jnthn++, but having it public makes it much easier to work with $/ when crossing the Perl6/NQP border --- src/NQP/Actions.nqp | 2 +- src/QRegex/Cursor.nqp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/NQP/Actions.nqp b/src/NQP/Actions.nqp index 2401b4ee1a..f8b2022dd8 100644 --- a/src/NQP/Actions.nqp +++ b/src/NQP/Actions.nqp @@ -1647,7 +1647,7 @@ class NQP::Actions is HLL::Actions { make QAST::Op.new( QAST::Var.new( :name('$/'), :scope('lexical') ), :op('callmethod'), - :name('!make'), + :name('make'), :node($/) ); } diff --git a/src/QRegex/Cursor.nqp b/src/QRegex/Cursor.nqp index d29ad8be45..c24c0037a1 100755 --- a/src/QRegex/Cursor.nqp +++ b/src/QRegex/Cursor.nqp @@ -733,7 +733,8 @@ class NQPMatch is NQPCapture { $!cursor := NQPMu; } - method !make($made) { $!made := $made } + method !make($made) { $!made := $made } # remove after rebootstrap + method make($made) { $!made := $made } method made() { $!made } method ast() { $!made } # for historical reasons From 09cee28b17371c0e97103c10b6b818f75f2c6261 Mon Sep 17 00:00:00 2001 From: TimToady Date: Wed, 12 Nov 2014 11:45:10 -0800 Subject: [PATCH 2/4] reduce fates to 24 bits, remove redundant AND --- src/QRegex/Cursor.nqp | 2 +- src/QRegex/NFA.nqp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/QRegex/Cursor.nqp b/src/QRegex/Cursor.nqp index c24c0037a1..8b19703284 100755 --- a/src/QRegex/Cursor.nqp +++ b/src/QRegex/Cursor.nqp @@ -324,7 +324,7 @@ role NQPCursorRole is export { my $cur; my $rxname; while @fates { - $rxname := nqp::atpos(@rxfate, nqp::bitand_i(nqp::pop_i(@fates), 0xffffffff)); + $rxname := nqp::atpos(@rxfate, nqp::pop_i(@fates)); #nqp::say("invoking $rxname"); $cur := self."$rxname"(); @fates := @EMPTY if nqp::getattr_i($cur, $?CLASS, '$!pos') >= 0; diff --git a/src/QRegex/NFA.nqp b/src/QRegex/NFA.nqp index 3d98e9a126..5def07927e 100755 --- a/src/QRegex/NFA.nqp +++ b/src/QRegex/NFA.nqp @@ -375,7 +375,7 @@ class QRegex::NFA { my int $k := nqp::elems($substate); while $j < $k { $substate[$j+2] := $substate[$j+2] + $substart; - $substate[$j+1] := $fate # XXX add in $lits +< 32 after rebootstrap + $substate[$j+1] := $fate # XXX add in $lits +< 24 after rebootstrap if $substate[$j] == $EDGE_FATE; self.mergesubrule($i, $substate[$j+2], $fate, $cursor, $substate[$j+1], %seen) if $substate[$j] == $EDGE_SUBRULE; @@ -392,7 +392,7 @@ class QRegex::NFA { self.addedge($start, $substart+1, $EDGE_EPSILON, 0); $to > 0 ?? self.addedge($substart, $to, $EDGE_EPSILON, 0) - !! self.addedge($substart, 0, $EDGE_FATE, $fate) # XXX add in $lits +< 32 after rebootstrap + !! self.addedge($substart, 0, $EDGE_FATE, $fate) # XXX add in $lits +< 24 after rebootstrap } else { self.addedge($start, 0, $EDGE_FATE, $fate); From 005b2f3a64c49cd8a261f72926b147361e8eff0d Mon Sep 17 00:00:00 2001 From: ugexe Date: Wed, 12 Nov 2014 20:18:15 -0500 Subject: [PATCH 3/4] Document ops.markdown cleanup; ambigious two/to Fixes statements that could be interpreted multiple ways. i.e.: Return non-zero if $l is greater than or equal two $r. ('two' should be 'to' for equals-to, not 2 for 2*$r) Return non-zero if $l is greater than two $r. ('two' left in from c&p?) --- docs/ops.markdown | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/ops.markdown b/docs/ops.markdown index eeab2c8da8..31f90161e8 100755 --- a/docs/ops.markdown +++ b/docs/ops.markdown @@ -108,7 +108,7 @@ Return the modulus of $l by $r. * `mul_n(num $l, num $r)` * `mul_I(Int $l, Int $r, Mu:T $type)` -Multiple two numbers, returning the result. +Multiply two numbers, returning the result. `_I` variant returns an object of the given type. ## neg @@ -142,7 +142,7 @@ Return the ceiling of a number. ## exp * `exp_n(num $exponent)` -Return the value of `e` raised to $exponent; +Return the value of `e` raised to $exponent. ## floor * `floor_n(num $n)` @@ -274,7 +274,7 @@ Return non-zero if the two parameters are equal. * `isgt_s(str $l, str $r)` * `isgt_I(Int $l, Int $r)` -Return non-zero if $l is greater than two $r. +Return non-zero if $l is greater than $r. ## isge * `isge_i(int $l, int $r)` @@ -282,7 +282,7 @@ Return non-zero if $l is greater than two $r. * `isge_s(str $l, str $r)` * `isge_I(Int $l, Int $r)` -Return non-zero if $l is greater than or equal two $r. +Return non-zero if $l is greater than or equal to $r. ## islt * `islt_i(int $l, int $r)` @@ -290,7 +290,7 @@ Return non-zero if $l is greater than or equal two $r. * `islt_s(str $l, str $r)` * `islt_I(Int $l, Int $r)` -Return non-zero if $l is less than two $r. +Return non-zero if $l is less than $r. ## isle * `isle_i(int $l, int $r)` @@ -298,7 +298,7 @@ Return non-zero if $l is less than two $r. * `isle_s(str $l, str $r)` * `isle_I(Int $l, Int $r)` -Return non-zero if $l is less than or equal two $r. +Return non-zero if $l is less than or equal to $r. ## isne * `isne_i(int $l, int $r)` From 28ff0493c2d67360663f90a3fe26f38d53935a51 Mon Sep 17 00:00:00 2001 From: TimToady Date: Thu, 13 Nov 2014 20:46:40 -0800 Subject: [PATCH 4/4] fix java and parrot backends for lit lengths too --- .../runtime/org/perl6/nqp/runtime/Ops.java | 3 ++- src/vm/parrot/ops/nqp.ops | 23 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java b/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java index c423eca063..d17fe4bd0d 100644 --- a/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java +++ b/src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java @@ -5066,9 +5066,10 @@ else if (act == NFA.EDGE_CHARRANGE_NEG) { } } + /* strip any literal lengths, leaving only fates */ int[] result = new int[fates.size()]; for (int i = 0; i < fates.size(); i++) - result[i] = fates.get(i); + result[i] = fates.get(i) & 0xffffff; return result; } diff --git a/src/vm/parrot/ops/nqp.ops b/src/vm/parrot/ops/nqp.ops index a1ddd81631..aae0127aed 100644 --- a/src/vm/parrot/ops/nqp.ops +++ b/src/vm/parrot/ops/nqp.ops @@ -98,7 +98,7 @@ nqp_ishash(PMC *pmc) { /* This public-domain C quick sort implementation by Darel Rex Finley. */ static INTVAL -quicksort(INTVAL *arr, INTVAL elements) { +revquicksort(INTVAL *arr, INTVAL elements) { #define MAX_LEVELS 100 INTVAL piv, beg[MAX_LEVELS], end[MAX_LEVELS], i = 0, L, R ; beg[0] = 0; @@ -111,11 +111,11 @@ quicksort(INTVAL *arr, INTVAL elements) { if (i == MAX_LEVELS - 1) return 0; while (L < R) { - while (arr[R] >= piv && L < R) + while (arr[R] <= piv && L < R) R--; if (L < R) arr[L++] = arr[R]; - while (arr[L] <= piv && L < R) + while (arr[L] >= piv && L < R) L++; if (L < R) arr[R--] =arr[L]; @@ -283,21 +283,22 @@ static INTVAL * nqp_nfa_run(PARROT_INTERP, NFABody *nfa, STRING *target, INTVAL gen++; /* If we got multiple fates at this offset, sort them by the - * declaration order (represented by the fate number). In the - * future, we'll want to factor in longest literal prefix too. */ + * literal length and declaration order (both encoded in fate number). + * The high 40 bits of the fate encodes literal length, while the low + * 24 bits encode fate. Both want to be descending order. */ if (total_fates - prev_fates > 1) { INTVAL char_fates = total_fates - prev_fates; - for (i = total_fates - char_fates; i < total_fates; i++) - fates[i] = -fates[i]; - quicksort(&fates[total_fates - char_fates], char_fates); - for (i = total_fates - char_fates; i < total_fates; i++) - fates[i] = -fates[i]; + revquicksort(&fates[total_fates - char_fates], char_fates); } } mem_sys_free(done); mem_sys_free(curst); mem_sys_free(nextst); - + + /* strip any literal lengths, leaving only fates */ + for (i = 0; i < total_fates; i++) + fates[i] &= 0xffffff; + *total_fates_out = total_fates; return fates; }