Permalink
Browse files

[dotnet] implement bitwise operators for infix NQPInt... can make coe…

…rcive and multi ones later...
  • Loading branch information...
1 parent 9eb0c55 commit f5cd961ba5d4139a1cc46f8f18ffb61034393cda @diakopter diakopter committed Nov 14, 2010
Showing with 46 additions and 0 deletions.
  1. +10 −0 common/NQP/NQPSetting.pm
  2. +36 −0 dotnet/runtime/Runtime/Ops/Primitive.cs
@@ -362,6 +362,16 @@ sub &infix:<~>($x, $y) {
nqp::concat($x.Str, $y.Str);
}
+sub &infix:<+|>(NQPInt $x, NQPInt $y) {
+ nqp::bitwise_or_int($x, $y);
+}
+sub &infix:<+&>(NQPInt $x, NQPInt $y) {
+ nqp::bitwise_and_int($x, $y);
+}
+sub &infix:<+^>(NQPInt $x, NQPInt $y) {
+ nqp::bitwise_xor_int($x, $y);
+}
+
# A basic, fairly bare-bones exception object.
my knowhow NQPException {
has $!message;
@@ -130,6 +130,42 @@ public static RakudoObject mul_num(ThreadContext TC, RakudoObject x, RakudoObjec
public static RakudoObject div_num(ThreadContext TC, RakudoObject x, RakudoObject y)
{
return Ops.box_num(TC, Ops.unbox_num(TC, x) / Ops.unbox_num(TC, y), TC.DefaultNumBoxType);
+ }
+
+ /// <summary>
+ /// Performs a bitwise or.
+ /// </summary>
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ /// <param name="ResultType"></param>
+ /// <returns></returns>
+ public static RakudoObject bitwise_or_int(ThreadContext TC, RakudoObject x, RakudoObject y)
+ {
+ return Ops.box_int(TC, Ops.unbox_int(TC, x) | Ops.unbox_int(TC, y), TC.DefaultIntBoxType);
+ }
+
+ /// <summary>
+ /// Performs a bitwise and.
+ /// </summary>
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ /// <param name="ResultType"></param>
+ /// <returns></returns>
+ public static RakudoObject bitwise_and_int(ThreadContext TC, RakudoObject x, RakudoObject y)
+ {
+ return Ops.box_int(TC, Ops.unbox_int(TC, x) & Ops.unbox_int(TC, y), TC.DefaultIntBoxType);
+ }
+
+ /// <summary>
+ /// Performs a bitwise xor.
+ /// </summary>
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ /// <param name="ResultType"></param>
+ /// <returns></returns>
+ public static RakudoObject bitwise_xor_int(ThreadContext TC, RakudoObject x, RakudoObject y)
+ {
+ return Ops.box_int(TC, Ops.unbox_int(TC, x) ^ Ops.unbox_int(TC, y), TC.DefaultIntBoxType);
}
/// <summary>

0 comments on commit f5cd961

Please sign in to comment.