Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement the % operator
  • Loading branch information
sorear committed Feb 18, 2011
1 parent b4c48f4 commit dfdfc66
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion TODO
Expand Up @@ -31,7 +31,7 @@ EASY

Stuff spectests are blocking on: "is readonly", "[+]",
"Block", "&prefix:<\>", "&hash",
"writable $_", "closure for", "ranges of chars", "gather for", "%",
"writable $_", "closure for", "ranges of chars", "gather for",
"unless", "my regex / <&foo>", "m//",

At least parsing Int et al on my-decls would help a lot
Expand Down
8 changes: 8 additions & 0 deletions lib/Builtins.cs
Expand Up @@ -204,6 +204,14 @@ public class Builtins {
return Kernel.BoxAnyMO<double>(r1 / r2, Kernel.NumMO);
}

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

public static Variable NumAnd(Variable v1, Variable v2) {
IP6 o1 = NominalCheck("$x", Kernel.AnyMO, v1);
IP6 o2 = NominalCheck("$y", Kernel.AnyMO, v2);
Expand Down
1 change: 1 addition & 0 deletions lib/CLRBackend.cs
Expand Up @@ -3130,6 +3130,7 @@ class NamProcessor {
thandlers["bif_strgt"] = SimpleB("StringGt");
thandlers["bif_plus"] = SimpleB("Plus");
thandlers["bif_minus"] = SimpleB("Minus");
thandlers["bif_mod"] = SimpleB("Mod");
thandlers["bif_mul"] = SimpleB("Mul");
thandlers["bif_divide"] = SimpleB("Divide");
thandlers["bif_not"] = SimpleB("Not");
Expand Down
2 changes: 1 addition & 1 deletion lib/SAFE.setting
Expand Up @@ -269,6 +269,7 @@ sub infix:<+>($l,$r) { $l + $r }
sub infix:<->($l,$r) { $l - $r }
sub infix:<*>($l,$r) { $l * $r }
sub infix:</>($l,$r) { $l / $r }
sub infix:<%>($l,$r) { $l % $r }
sub infix:<< < >>($l,$r) { $l < $r }
sub infix:<< > >>($l,$r) { $l > $r }
Expand Down Expand Up @@ -1066,7 +1067,6 @@ sub infix:<after> ($a, $b) { $a gt $b }
sub seqop($op) { $op } # TODO: Special case with hyper
sub reverseop($op) { sub (\$x, \$y) { $op($y, $x) } }
sub infix:<%> ($x,$y) { die "Modulus calculation NYI"; } #OK
sub infix:<div> ($x,$y) { die "Modulus calculation NYI"; } #OK
sub infix:<mod> ($x,$y) { die "Modulus calculation NYI"; } #OK
sub infix:<~&> ($x, $y) { die "Buffer bitops NYI"; } #OK
Expand Down
1 change: 1 addition & 0 deletions src/NieczaPassSimplifier.pm6
Expand Up @@ -69,6 +69,7 @@ our %funcs = (
'&infix:</>' => do_builtin('divide', 2),
'&infix:<->' => do_builtin('minus', 2),
'&infix:<*>' => do_builtin('mul', 2),
'&infix:<%>' => do_builtin('mod', 2),
'&infix:<==>' => do_builtin('numeq', 2),
'&infix:<>=>' => do_builtin('numge', 2),
'&infix:<>>' => do_builtin('numgt', 2),
Expand Down
1 change: 1 addition & 0 deletions src/niecza
Expand Up @@ -123,6 +123,7 @@ method quote_mod:b ($) { }

augment class CgOp {
method xspan(*@items) { self._cgop('xspan', @items) }
method bif_mod($x,$y) { self._cgop('bif_mod', $x, $y) }
}

augment class Op {
Expand Down

0 comments on commit dfdfc66

Please sign in to comment.