Skip to content

Commit

Permalink
Merge pull request #780 from MasterDuke17/add_unsigned_comparison_ops
Browse files Browse the repository at this point in the history
Add unsigned comparison ops
  • Loading branch information
MasterDuke17 authored Oct 8, 2022
2 parents bddcbca + 9dcf422 commit d397598
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/ops.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,7 @@ Output the given object to the filehandle. Returns the number of bytes written.
* `cmp_n(num $l, num $r --> int)`
* `cmp_s(str $l, str $r --> int)`
* `cmp_I(Int $l, Int $r --> int)`
* `cmp_u(uint $l, uint $r --> int)`

Compare two values, returns -1 if $l is greater than $r, 0 if they are equal,
and 1 if $r is greater than $l.
Expand Down Expand Up @@ -2014,6 +2015,7 @@ Return 0 if the parameter has a truthy value, 1 otherwise.
* `iseq_n(num $l, num $r --> int)`
* `iseq_s(str $l, str $r --> int)`
* `iseq_I(Int $l, Int $r --> int)`
* `iseq_u(uint $l, uint $r --> int)`
* `iseq_snfg(str $l, str $r --> int)` `js`

Return 1 if the two parameters are equal, 0 otherwise.
Expand All @@ -2025,6 +2027,7 @@ Return 1 if the two parameters are equal, 0 otherwise.
* `isge_n(num $l, num $r --> int)`
* `isge_s(str $l, str $r --> int)`
* `isge_I(Int $l, Int $r --> int)`
* `isge_u(uint $l, uint $r --> int)`

Return 1 if $l is greater than or equal to $r, otherwise 0.

Expand All @@ -2033,6 +2036,7 @@ Return 1 if $l is greater than or equal to $r, otherwise 0.
* `isgt_n(num $l, num $r --> int)`
* `isgt_s(str $l, str $r --> int)`
* `isgt_I(Int $l, Int $r --> int)`
* `isgt_u(uint $l, uint $r --> int)`

Return 1 if the two parameters are equal if $l is greater than $r, otherwise 0.

Expand All @@ -2041,6 +2045,7 @@ Return 1 if the two parameters are equal if $l is greater than $r, otherwise 0.
* `isle_n(num $l, num $r --> int)`
* `isle_s(str $l, str $r --> int)`
* `isle_I(Int $l, Int $r --> int)`
* `isle_u(uint $l, uint $r --> int)`

Return 1 if $l is less than or equal to $r, otherwise 0.

Expand All @@ -2049,6 +2054,7 @@ Return 1 if $l is less than or equal to $r, otherwise 0.
* `islt_n(num $l, num $r --> int)`
* `islt_s(str $l, str $r --> int)`
* `islt_I(Int $l, Int $r --> int)`
* `islt_u(uint $l, uint $r --> int)`

Return 1 if $l is less than $r, otherwise 0.

Expand All @@ -2057,6 +2063,7 @@ Return 1 if $l is less than $r, otherwise 0.
* `isne_n(num $l, num $r --> int)`
* `isne_s(str $l, str $r --> int)`
* `isne_I(Int $l, Int $r --> int)`
* `isne_u(uint $l, uint $r --> int)`
* `isne_snfg(str $l, str $r --> int)` `js`

Return 1 if the two parameters are not equal, otherwise 0.
Expand Down
3 changes: 2 additions & 1 deletion src/vm/js/Operations.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class QAST::OperationsJS {

add_infix_op('concat', $T_STR, '+', $T_STR, $T_STR);

for ['_i', $T_INT, '_n', $T_NUM, '_s', $T_STR] -> $suffix, $type {
for ['_i', $T_INT, '_n', $T_NUM, '_s', $T_STR, '_u', $T_UINT64] -> $suffix, $type {
add_infix_op('isle' ~ $suffix, $type, '<=', $type, $T_BOOL);
add_infix_op('islt' ~ $suffix, $type, '<', $type, $T_BOOL);
add_infix_op('isgt' ~ $suffix, $type, '>', $type, $T_BOOL);
Expand Down Expand Up @@ -433,6 +433,7 @@ class QAST::OperationsJS {
add_cmp_op('cmp_i', $T_INT);
add_cmp_op('cmp_n', $T_NUM);
add_cmp_op('cmp_s', $T_STR);
add_cmp_op('cmp_u', $T_UINT64);

for <preinc predec> -> $op {
add_op($op, sub ($comp, $node, :$want) {
Expand Down
8 changes: 8 additions & 0 deletions src/vm/jvm/QAST/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -2543,6 +2543,14 @@ QAST::OperationsJAST.map_classlib_core_op('isle_i', $TYPE_OPS, 'isle_i', [$RT_IN
QAST::OperationsJAST.map_classlib_core_op('isgt_i', $TYPE_OPS, 'isgt_i', [$RT_INT, $RT_INT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('isge_i', $TYPE_OPS, 'isge_i', [$RT_INT, $RT_INT], $RT_INT);

QAST::OperationsJAST.map_classlib_core_op('cmp_u', $TYPE_OPS, 'cmp_u', [$RT_UINT, $RT_UINT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('iseq_u', $TYPE_OPS, 'iseq_u', [$RT_UINT, $RT_UINT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('isne_u', $TYPE_OPS, 'isne_u', [$RT_UINT, $RT_UINT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('islt_u', $TYPE_OPS, 'islt_u', [$RT_UINT, $RT_UINT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('isle_u', $TYPE_OPS, 'isle_u', [$RT_UINT, $RT_UINT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('isgt_u', $TYPE_OPS, 'isgt_u', [$RT_UINT, $RT_UINT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('isge_u', $TYPE_OPS, 'isge_u', [$RT_UINT, $RT_UINT], $RT_INT);

QAST::OperationsJAST.map_classlib_core_op('bool_I', $TYPE_OPS, 'bool_I', [$RT_OBJ], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('cmp_I', $TYPE_OPS, 'cmp_I', [$RT_OBJ, $RT_OBJ], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('iseq_I', $TYPE_OPS, 'iseq_I', [$RT_OBJ, $RT_OBJ], $RT_INT, :tc);
Expand Down
22 changes: 22 additions & 0 deletions src/vm/jvm/runtime/org/raku/nqp/runtime/Ops.java
Original file line number Diff line number Diff line change
Expand Up @@ -5518,6 +5518,28 @@ public static long isge_i(long a, long b) {
return a >= b ? 1 : 0;
}

public static long cmp_u(long a, long b) {
return Long.compareUnsigned(a, b);
}
public static long iseq_u(long a, long b) {
return Long.compareUnsigned(a, b) == 0 ? 1 : 0;
}
public static long isne_u(long a, long b) {
return Long.compareUnsigned(a, b) != 0 ? 1 : 0;
}
public static long islt_u(long a, long b) {
return Long.compareUnsigned(a, b) < 0 ? 1 : 0;
}
public static long isle_u(long a, long b) {
return Long.compareUnsigned(a, b) <= 0 ? 1 : 0;
}
public static long isgt_u(long a, long b) {
return Long.compareUnsigned(a, b) > 0 ? 1 : 0;
}
public static long isge_u(long a, long b) {
return Long.compareUnsigned(a, b) >= 0 ? 1 : 0;
}

public static long cmp_n(double a, double b) {
if (a < b) {
return -1;
Expand Down
7 changes: 7 additions & 0 deletions src/vm/moar/QAST/QASTOperationsMAST.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -2947,6 +2947,13 @@ my constant SIMPLE_OP_MAPPINGS := nqp::list_s(
'isle_i', 'le_i',
'isgt_i', 'gt_i',
'isge_i', 'ge_i',
'cmp_u', 'cmp_u',
'iseq_u', 'eq_u',
'isne_u', 'ne_u',
'islt_u', 'lt_u',
'isle_u', 'le_u',
'isgt_u', 'gt_u',
'isge_u', 'ge_u',
'cmp_n', 'cmp_n',
'not_i', 'not_i',
'iseq_n', 'eq_n',
Expand Down
2 changes: 1 addition & 1 deletion tools/templates/MOAR_REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022.07-9-g740f3bcbe
2022.07-16-g3ae8a31c1

0 comments on commit d397598

Please sign in to comment.