From d93f6ed7003840a180011c86f3fe436a4fb03fa4 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Tue, 16 Jan 2018 08:11:19 +0000 Subject: [PATCH 1/6] [MoarVM Bump] Brings 4 commits MoarVM bump brought: https://github.com/MoarVM/MoarVM/compare/2017.12.1-30-ged7c1234...2017.12.1-34-g4a0a912 4a0a912 New spesh-bisect.pl tool 7ea0802 Fix off-by-one error in uninline 56c03d9 Merge pull request #780 from Kaiepi/compilers 28eaf97 Try to use egcc when compiling on OpenBSD --- tools/build/MOAR_REVISION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build/MOAR_REVISION b/tools/build/MOAR_REVISION index 7f876f49c9..0a3afea43e 100644 --- a/tools/build/MOAR_REVISION +++ b/tools/build/MOAR_REVISION @@ -1 +1 @@ -2017.12.1-30-ged7c1234 +2017.12.1-34-g4a0a912 From 0ed57f6f8a3f3e43e0c5a60c71f40a044c5ed18b Mon Sep 17 00:00:00 2001 From: pmurias Date: Wed, 17 Jan 2018 10:53:03 +0100 Subject: [PATCH 2/6] [js] Handle the DYN_COMP_WRAPPER hack on the js backend too --- src/vm/js/Compiler.nqp | 2 ++ src/vm/js/Operations.nqp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/vm/js/Compiler.nqp b/src/vm/js/Compiler.nqp index 439e349b59..1d3b0e034b 100644 --- a/src/vm/js/Compiler.nqp +++ b/src/vm/js/Compiler.nqp @@ -243,6 +243,8 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce { while $info { + return NQPMu if $info.qast && $info.qast.ann('DYN_COMP_WRAPPER'); + $reached_closure_template := $reached_closure_template || $info.qast.blocktype ne 'immediate'; if $info.has_own_variable($var.name) { diff --git a/src/vm/js/Operations.nqp b/src/vm/js/Operations.nqp index 07467cd0f7..1f9d7c66c9 100644 --- a/src/vm/js/Operations.nqp +++ b/src/vm/js/Operations.nqp @@ -907,6 +907,10 @@ class QAST::OperationsJS { my str $var_name := $node[0].value; my $block := $*BLOCK.outer; while $block { + if ($block.qast && $block.qast.ann('DYN_COMP_WRAPPER')) { + $block := NQPMu; + last; + } last if $block.has_own_variable($var_name); $block := $block.outer; } From c266fcdaa5721cb2c19605b4a15022f57408d5a9 Mon Sep 17 00:00:00 2001 From: pmurias Date: Wed, 17 Jan 2018 12:22:37 +0100 Subject: [PATCH 3/6] [js] Fix nqp::div_In --- src/vm/js/nqp-runtime/bignum.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/vm/js/nqp-runtime/bignum.js b/src/vm/js/nqp-runtime/bignum.js index 19a04224a0..30158b76b3 100644 --- a/src/vm/js/nqp-runtime/bignum.js +++ b/src/vm/js/nqp-runtime/bignum.js @@ -139,18 +139,28 @@ op.expmod_I = function(a, b, c, type) { return makeBI(type, getBI(a).powm(getBI(b), getBI(c))); }; + +/* TODO - optimize by using a smaller bignum when so much isn't needed */ +const digits = 325; +const digitsBignum = bignum(10).pow(digits); + op.div_In = function(a, b) { - const digits = 1e+20; const divisor = getBI(b); if (divisor.eq(0)) { return getBI(a).toNumber() / 0; } - const big = getBI(a).mul(bignum(digits)).div(divisor).toString(); - if (big.length <= 20) { - return parseFloat('0.' + '0'.repeat(20 - big.length) + big); + let sign = 1; + let big = getBI(a).mul(digitsBignum).div(divisor).toString(); + if (big.substr(0, 1) == '-') { + big = big.substr(1); + sign = -1; + } + + if (big.length <= digits) { + return sign * parseFloat('0.' + '0'.repeat(digits - big.length) + big); } else { - return parseFloat(big.substr(0, big.length - 20) + '.' + big.substr(big.length - 20)); + return sign * parseFloat(big.substr(0, big.length - digits) + '.' + big.substr(big.length - digits)); } }; From 46cf36712a17656ea524c663cb311d7cd3931da3 Mon Sep 17 00:00:00 2001 From: pmurias Date: Wed, 17 Jan 2018 12:23:20 +0100 Subject: [PATCH 4/6] Fix typo in test description --- t/nqp/060-bigint.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/nqp/060-bigint.t b/t/nqp/060-bigint.t index 3d6cbc97b7..f42e35c753 100644 --- a/t/nqp/060-bigint.t +++ b/t/nqp/060-bigint.t @@ -211,7 +211,7 @@ ok(str(nqp::expmod_I( $bi_type, )) eq '1527229998585248450016808958343740453059', 'nqp::expmod_I'); -ok(nqp::div_In(box(1234500), box(100)) == 12345, 'div_In santiy'); +ok(nqp::div_In(box(1234500), box(100)) == 12345, 'div_In sanity'); my $n := nqp::div_In( nqp::pow_I(box(203), box(200), $n_type, $bi_type), nqp::pow_I(box(200), box(200), $n_type, $bi_type), From 92730bfef33099ee3bce1eb066dc2b444f0c127a Mon Sep 17 00:00:00 2001 From: pmurias Date: Wed, 17 Jan 2018 12:27:34 +0100 Subject: [PATCH 5/6] Add a few div_In tests --- t/nqp/060-bigint.t | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/t/nqp/060-bigint.t b/t/nqp/060-bigint.t index f42e35c753..5cd9920a33 100644 --- a/t/nqp/060-bigint.t +++ b/t/nqp/060-bigint.t @@ -1,7 +1,7 @@ #! nqp use nqpmo; -plan(130); +plan(134); my $knowhow := nqp::knowhow(); my $bi_type := $knowhow.new_type(:name('TestBigInt'), :repr('P6bigint')); @@ -216,6 +216,14 @@ my $n := nqp::div_In( nqp::pow_I(box(203), box(200), $n_type, $bi_type), nqp::pow_I(box(200), box(200), $n_type, $bi_type), ); + +my $huge := nqp::pow_I(box(10), box(300), $n_type, $bi_type); + +ok(nqp::div_In(box(1), $huge) == 1e-300, 'super small result from div_In work'); +ok(nqp::div_In(box(-1), box(5)) == -0.2, 'div_In -1 by 5'); +ok(nqp::div_In(box(-1), box(20)) == -0.05, 'div_In -1 by 20'); +ok(nqp::div_In(box(1), box(-200)) == -0.005, 'div_In 1 by -20'); + ok(nqp::abs_n($n - 19.6430286394751) < 1e-10, 'div_In with big numbers'); my $maxRand := nqp::fromstr_I('10000000000000000000000000000000000000000', $bi_type); From 3a9a497db9583be2618fba44b354f4f6d9998e59 Mon Sep 17 00:00:00 2001 From: David Warring Date: Thu, 18 Jan 2018 06:24:00 +1300 Subject: [PATCH 6/6] remove unreachable code in cursor_init we're already in an else block from a previous nqp::isconcrete(self) && $!braid test --- src/QRegex/Cursor.nqp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/QRegex/Cursor.nqp b/src/QRegex/Cursor.nqp index d9baf32b50..d78350a06e 100644 --- a/src/QRegex/Cursor.nqp +++ b/src/QRegex/Cursor.nqp @@ -425,12 +425,7 @@ role NQPMatchRole is export { $braid := $!braid."!clone"(); # usually called when switching into a slang } else { - if nqp::isconcrete(self) && $!braid { - $braid := Braid."!braid_init"(:grammar(self), :actions(self.actions), :package(nqp::getattr($!braid, Braid, '$!package'))); - } - else { - $braid := Braid."!braid_init"(:grammar(self)); - } + $braid := Braid."!braid_init"(:grammar(self)); } } nqp::die("No braid in cursor_init!") unless $braid;