Permalink
Browse files

implemented (copypaste) >,>=,<,<= for NQPInts & NQPNums

  • Loading branch information...
1 parent e081fb5 commit ee58ecd64cae77dc1eef4b4b569cf4c61da95a34 @diakopter diakopter committed Oct 31, 2010
Showing with 191 additions and 2 deletions.
  1. +32 −0 common/NQP/NQPSetting.pm
  2. +114 −2 dotnet/runtime/Runtime/Ops.cs
  3. +45 −0 t/nqp/13-op.t
View
@@ -172,6 +172,38 @@ multi sub &infix:<!=>(NQPNum $x, NQPNum $y) {
nqp::logical_not_int(nqp::equal_nums($x, $y))
}
+proto sub &infix:«<=»($x, $y) { * }
+multi sub &infix:«<=»(NQPInt $x, NQPInt $y) {
+ nqp::less_than_or_equal_ints($x, $y)
+}
+multi sub &infix:«<=»(NQPNum $x, NQPNum $y) {
+ nqp::less_than_or_equal_nums($x, $y)
+}
+
+proto sub &infix:«<»($x, $y) { * }
+multi sub &infix:«<»(NQPInt $x, NQPInt $y) {
+ nqp::less_than_ints($x, $y)
+}
+multi sub &infix:«<»(NQPNum $x, NQPNum $y) {
+ nqp::less_than_nums($x, $y)
+}
+
+proto sub &infix:«>=»($x, $y) { * }
+multi sub &infix:«>=»(NQPInt $x, NQPInt $y) {
+ nqp::greater_than_or_equal_ints($x, $y)
+}
+multi sub &infix:«>=»(NQPNum $x, NQPNum $y) {
+ nqp::greater_than_or_equal_nums($x, $y)
+}
+
+proto sub &infix:«>»($x, $y) { * }
+multi sub &infix:«>»(NQPInt $x, NQPInt $y) {
+ nqp::greater_than_ints($x, $y)
+}
+multi sub &infix:«>»(NQPNum $x, NQPNum $y) {
+ nqp::greater_than_nums($x, $y)
+}
+
sub &infix:<eq>($x, $y) {
nqp::equal_strs($x.Str, $y.Str)
}
@@ -449,8 +449,120 @@ public static RakudoObject equal_strs(ThreadContext TC, RakudoObject x, RakudoOb
/// <returns></returns>
public static RakudoObject equal_refs(ThreadContext TC, RakudoObject x, RakudoObject y)
{
- return Ops.box_int(TC, x == y ? 1 : 0, TC.DefaultBoolBoxType);
- }
+ return Ops.box_int(TC, x == y ? 1 : 0, TC.DefaultBoolBoxType);
+ }
+
+ /// <summary>
+ /// Compares two floating point numbers for less-than inequality.
+ /// </summary>
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ /// <param name="ResultType"></param>
+ /// <returns></returns>
+ public static RakudoObject less_than_nums(ThreadContext TC, RakudoObject x, RakudoObject y)
+ {
+ return Ops.box_int(TC,
+ (Ops.unbox_num(TC, x) < Ops.unbox_num(TC, y) ? 1 : 0),
+ TC.DefaultBoolBoxType);
+ }
+
+ /// <summary>
+ /// Compares two integers for less-than inequality.
+ /// </summary>
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ /// <param name="ResultType"></param>
+ /// <returns></returns>
+ public static RakudoObject less_than_ints(ThreadContext TC, RakudoObject x, RakudoObject y)
+ {
+ return Ops.box_int(TC,
+ (Ops.unbox_int(TC, x) < Ops.unbox_int(TC, y) ? 1 : 0),
+ TC.DefaultBoolBoxType);
+ }
+
+ /// <summary>
+ /// Compares two floating point numbers for less-than-or-equal inequality.
+ /// </summary>
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ /// <param name="ResultType"></param>
+ /// <returns></returns>
+ public static RakudoObject less_than_or_equal_nums(ThreadContext TC, RakudoObject x, RakudoObject y)
+ {
+ return Ops.box_int(TC,
+ (Ops.unbox_num(TC, x) <= Ops.unbox_num(TC, y) ? 1 : 0),
+ TC.DefaultBoolBoxType);
+ }
+
+ /// <summary>
+ /// Compares two integers for less-than-or-equal inequality.
+ /// </summary>
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ /// <param name="ResultType"></param>
+ /// <returns></returns>
+ public static RakudoObject less_than_or_equal_ints(ThreadContext TC, RakudoObject x, RakudoObject y)
+ {
+ return Ops.box_int(TC,
+ (Ops.unbox_int(TC, x) <= Ops.unbox_int(TC, y) ? 1 : 0),
+ TC.DefaultBoolBoxType);
+ }
+
+ /// <summary>
+ /// Compares two floating point numbers for greater-than inequality.
+ /// </summary>
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ /// <param name="ResultType"></param>
+ /// <returns></returns>
+ public static RakudoObject greater_than_nums(ThreadContext TC, RakudoObject x, RakudoObject y)
+ {
+ return Ops.box_int(TC,
+ (Ops.unbox_num(TC, x) > Ops.unbox_num(TC, y) ? 1 : 0),
+ TC.DefaultBoolBoxType);
+ }
+
+ /// <summary>
+ /// Compares two integers for greater-than inequality.
+ /// </summary>
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ /// <param name="ResultType"></param>
+ /// <returns></returns>
+ public static RakudoObject greater_than_ints(ThreadContext TC, RakudoObject x, RakudoObject y)
+ {
+ return Ops.box_int(TC,
+ (Ops.unbox_int(TC, x) > Ops.unbox_int(TC, y) ? 1 : 0),
+ TC.DefaultBoolBoxType);
+ }
+
+ /// <summary>
+ /// Compares two floating point numbers for greater-than-or-equal inequality.
+ /// </summary>
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ /// <param name="ResultType"></param>
+ /// <returns></returns>
+ public static RakudoObject greater_than_or_equal_nums(ThreadContext TC, RakudoObject x, RakudoObject y)
+ {
+ return Ops.box_int(TC,
+ (Ops.unbox_num(TC, x) >= Ops.unbox_num(TC, y) ? 1 : 0),
+ TC.DefaultBoolBoxType);
+ }
+
+ /// <summary>
+ /// Compares two integers for greater-than-or-equal inequality.
+ /// </summary>
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ /// <param name="ResultType"></param>
+ /// <returns></returns>
+ public static RakudoObject greater_than_or_equal_ints(ThreadContext TC, RakudoObject x, RakudoObject y)
+ {
+ return Ops.box_int(TC,
+ (Ops.unbox_int(TC, x) >= Ops.unbox_int(TC, y) ? 1 : 0),
+ TC.DefaultBoolBoxType);
+ }
/// <summary>
/// Logical not.
View
@@ -0,0 +1,45 @@
+#!./parrot nqp.pbc
+
+# checking basic operands and circumfix:( )
+
+plan(8);
+
+###Additive operators
+#ok( 1+2 == 3, 'Checking addition 1+2');
+#ok( 10-9 == 1, 'Checking subtraction 10-9');
+#ok( 10-3+2 == 9, 'Checking compound statements 10-3+2');
+#ok( 10-(3+2) == 5, 'Checking parenthesized statement 10-(3+2)');
+#
+###Multiplicative operators
+#ok( 6*7 == 42, 'Checking multiplication 6*7');
+#ok( 36/6 == 6, 'Checking division 36/6');
+#ok( 4*3+5 == 17, 'Checking compound statements 4*3+5');
+#ok( 4*(3+5) == 32, 'Checking parenthesized statements 4*(3+5)');
+#ok( 12/4*3 == 9, 'Checking compound statements 12/4*3');
+#ok( 12/(4*3) == 1, 'Checking compound statements 12/(4*3)');
+#ok( 5-3*2 == -1, 'Checking compound statements 5-3*2');
+#
+##Modulo operator
+#ok( 8%3 == 2, 'Checking modulo 8%3');
+#ok( 8%3+2 == 4, 'Checking compound statement 8%3+2');
+#ok( 8%(3+2) == 3, 'Checking compound statement 8%(3+2)');
+#
+###Concatenation operator
+#ok( 'a' ~ 'b' eq 'ab', 'Checking concatenation "a" ~ "b"');
+#ok( 1 ~ 'b' eq '1b', 'Checking concatenation 1 ~ "b"');
+#ok( 'a' ~ 2 eq 'a2', 'Checking concatenation "a" ~ 2 ');
+
+##Relational operators
+ok( ?(1 < 2) );
+ok( !(2 < 1) );
+ok( ?(2 <= 2) );
+ok( !(3 <= 2) );
+ok( ?(2 > 1) );
+ok( !(2 > 3) );
+ok( ?(2 >= 1) );
+ok( !(2 >= 3) );
+
+##Bitwise operators
+#ok( (1 +| 3) == 3, 'Checking 1 +| 3' );
+#ok( (3 +& 2) == 2, 'Checking 3 +& 2' );
+#ok( (3 +^ 3) == 0, 'Checking 3 +^ 3' );

0 comments on commit ee58ecd

Please sign in to comment.