Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tweak istrue_s on jvm, every non-empty string is true now
We also bump MoarVM to get the very same fix in. For Parrot we have
to tweak Parrot_str_boolean, that means pull requesting the change
and bumping its version.
  • Loading branch information
FROGGS committed Apr 10, 2015
1 parent 7238985 commit d2d27cc
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 12 deletions.
9 changes: 2 additions & 7 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -3237,11 +3237,6 @@ public static long istrue(SixModelObject obj, ThreadContext tc) {
return obj instanceof TypeObject || obj.get_num(tc) == 0.0 ? 0 : 1;
case BoolificationSpec.MODE_UNBOX_STR_NOT_EMPTY:
return obj instanceof TypeObject || obj.get_str(tc).equals("") ? 0 : 1;
case BoolificationSpec.MODE_UNBOX_STR_NOT_EMPTY_OR_ZERO:
if (obj instanceof TypeObject)
return 0;
String str = obj.get_str(tc);
return str == null || str.equals("") || str.equals("0") ? 0 : 1;
case BoolificationSpec.MODE_NOT_TYPE_OBJECT:
return obj instanceof TypeObject ? 0 : 1;
case BoolificationSpec.MODE_BIGINT:
Expand All @@ -3258,10 +3253,10 @@ public static long isfalse(SixModelObject obj, ThreadContext tc) {
return istrue(obj, tc) == 0 ? 1 : 0;
}
public static long istrue_s(String str) {
return str == null || str.equals("") || str.equals("0") ? 0 : 1;
return str == null || str.equals("") ? 0 : 1;
}
public static long isfalse_s(String str) {
return str == null || str.equals("") || str.equals("0") ? 1 : 0;
return str == null || str.equals("") ? 1 : 0;
}
public static long not_i(long v) {
return v == 0 ? 1 : 0;
Expand Down
Expand Up @@ -11,7 +11,6 @@ public class BoolificationSpec {
public static final int MODE_UNBOX_INT = 1;
public static final int MODE_UNBOX_NUM = 2;
public static final int MODE_UNBOX_STR_NOT_EMPTY = 3;
public static final int MODE_UNBOX_STR_NOT_EMPTY_OR_ZERO = 4;
public static final int MODE_NOT_TYPE_OBJECT = 5;
public static final int MODE_BIGINT = 6;
public static final int MODE_ITER = 7;
Expand Down
Expand Up @@ -47,7 +47,7 @@ public static void bootstrap(ThreadContext tc)
Ops.setboolspec(tc.gc.BOOTIter, BoolificationSpec.MODE_ITER, null, tc);
Ops.setboolspec(tc.gc.BOOTInt, BoolificationSpec.MODE_UNBOX_INT, null, tc);
Ops.setboolspec(tc.gc.BOOTNum, BoolificationSpec.MODE_UNBOX_NUM, null, tc);
Ops.setboolspec(tc.gc.BOOTStr, BoolificationSpec.MODE_UNBOX_STR_NOT_EMPTY_OR_ZERO, null, tc);
Ops.setboolspec(tc.gc.BOOTStr, BoolificationSpec.MODE_UNBOX_STR_NOT_EMPTY, null, tc);
Ops.setboolspec(tc.gc.BOOTArray, BoolificationSpec.MODE_HAS_ELEMS, null, tc);
Ops.setboolspec(tc.gc.BOOTIntArray, BoolificationSpec.MODE_HAS_ELEMS, null, tc);
Ops.setboolspec(tc.gc.BOOTNumArray, BoolificationSpec.MODE_HAS_ELEMS, null, tc);
Expand Down
2 changes: 1 addition & 1 deletion t/nqp/07-boolean.t
Expand Up @@ -6,7 +6,6 @@ plan(8);

##Negation
ok(!0, 'prefix negation on integer 0');
ok(!"0", 'prefix negation on string 0');

if !1 {
print("not");
Expand All @@ -18,6 +17,7 @@ ok(!!1, 'double negation on 1');
##Boolean context
ok(?1, 'prefix negation on integer 1');
ok(?"10", 'prefix negation on string 10');
ok(?"0", 'prefix negation on string 0');

if ?0 {
print("not");
Expand Down
2 changes: 1 addition & 1 deletion t/nqp/59-nqpop.t
Expand Up @@ -133,7 +133,7 @@ ok( nqp::isnull(13232) == 0, 'nqp::isnull(number)' );
ok( nqp::istrue(0) == 0, 'nqp::istrue');
ok( nqp::istrue(1) == 1, 'nqp::istrue');
ok( nqp::istrue('') == 0, 'nqp::istrue');
ok( nqp::istrue('0') == 0, 'nqp::istrue');
ok( nqp::istrue('0') == 1, 'nqp::istrue');
ok( nqp::istrue('no') == 1, 'nqp::istrue');
ok( nqp::istrue(0.0) == 0, 'nqp::istrue');
ok( nqp::istrue(0.1) == 1, 'nqp::istrue');
Expand Down
2 changes: 1 addition & 1 deletion tools/build/MOAR_REVISION
@@ -1 +1 @@
2015.03-80-g1d592be
2015.03-83-g575c486

0 comments on commit d2d27cc

Please sign in to comment.