Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add bitshift operators
  • Loading branch information
sorear committed Dec 31, 2010
1 parent 520f58d commit 4ff9853
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
18 changes: 17 additions & 1 deletion lib/Builtins.cs
Expand Up @@ -228,6 +228,22 @@ public class Builtins {
return Kernel.BoxAnyMO<double>((double)(r1 ^ r2), Kernel.NumMO);
}

public static Variable NumLShift(Variable v1, Variable v2) {
IP6 o1 = NominalCheck("$x", Kernel.AnyMO, v1);
IP6 o2 = NominalCheck("$y", Kernel.AnyMO, v2);
int r1 = (int)o1.mo.mro_raw_Numeric.Get(v1);
int r2 = (int)o2.mo.mro_raw_Numeric.Get(v2);
return Kernel.BoxAnyMO<double>((double)(r1 << r2), Kernel.NumMO);
}

public static Variable NumRShift(Variable v1, Variable v2) {
IP6 o1 = NominalCheck("$x", Kernel.AnyMO, v1);
IP6 o2 = NominalCheck("$y", Kernel.AnyMO, v2);
int r1 = (int)o1.mo.mro_raw_Numeric.Get(v1);
int r2 = (int)o2.mo.mro_raw_Numeric.Get(v2);
return Kernel.BoxAnyMO<double>((double)(r1 >> r2), Kernel.NumMO);
}

public static Variable NumCompl(Variable v1) {
IP6 o1 = NominalCheck("$x", Kernel.AnyMO, v1);
int r1 = (int)o1.mo.mro_raw_Numeric.Get(v1);
Expand Down Expand Up @@ -271,7 +287,7 @@ public class Builtins {
public static Variable Chr(Variable v) {
IP6 o1 = NominalCheck("$x", Kernel.AnyMO, v);
double r = o1.mo.mro_raw_Numeric.Get(v);
return Kernel.BoxAnyMO(new string((char)r, 1), Kernel.NumMO);
return Kernel.BoxAnyMO(new string((char)r, 1), Kernel.StrMO);
}

public static Variable Make(Frame fr, Variable v) {
Expand Down
10 changes: 9 additions & 1 deletion v6n/CClass.pm6
@@ -1,6 +1,14 @@
# 28f112a757ef2d6f553d144dd8f8b9a1de17c71b
class CClass;

sub ord($x) { Q:CgOp { (rawscall Builtins.Ord {$x}) } }
sub chr($x) { Q:CgOp { (rawscall Builtins.Chr {$x}) } }
sub infix:<+&>($x, $y) { Q:CgOp { (rawscall Builtins.NumAnd {$x} {$y}) } }
sub infix:<+|>($x, $y) { Q:CgOp { (rawscall Builtins.NumOr {$x} {$y}) } }
sub infix:<+^>($x, $y) { Q:CgOp { (rawscall Builtins.NumXor {$x} {$y}) } }
sub infix:<< +< >>($x, $y) { Q:CgOp { (rawscall Builtins.NumLShift {$x} {$y}) } }
sub infix:<< +> >>($x, $y) { Q:CgOp { (rawscall Builtins.NumRShift {$x} {$y}) } }
has $.terms;
our %Gc = < Lu Ll Lt Lm Lo Mn Ms Me Nd Nl No Zs Zl Zp Cc Cf Cs Co Pc
Expand All @@ -11,7 +19,7 @@ our $Full = CClass.new(terms => [ 0, 0x3FFF_FFFF ]);
method range($c1, $c2) {
($c1 gt $c2) ?? $Empty !!
self.new(terms => [ $*Cheats.ord($c1), 0x3FFF_FFFF, $*Cheats.ord($c2) + 1, 0 ]);
self.new(terms => [ ord($c1), 0x3FFF_FFFF, ord($c2) + 1, 0 ]);
}
method enum(*@cs) {
Expand Down
4 changes: 3 additions & 1 deletion v6n/CgOp.pm6
Expand Up @@ -2,6 +2,8 @@

class CgOp;

sub chr($x) { Q:CgOp { (rawscall Builtins,Kernel.Chr {$x}) } }
method _cgop($name, *@bits) {
for @bits { $_ // die "Illegal undef in cgop $name" }
$( @bits );
Expand Down Expand Up @@ -281,7 +283,7 @@ method _process_arglist(*@araw) {
push @aout, $o;
$sig = $sig ~ "\0";
} else {
$sig = $sig ~ $*Cheats.chr(chars $o) ~ $o;
$sig = $sig ~ chr(chars $o) ~ $o;
push @aout, @araw.shift;
}
}
Expand Down

0 comments on commit 4ff9853

Please sign in to comment.