Unary operators with using for directive fix

This commit is contained in:
wechman
2022-09-28 12:05:41 +02:00
parent 6482f5bb17
commit 56bcb525bc
6 changed files with 136 additions and 34 deletions
@@ -12,34 +12,34 @@ function w(int128 x) pure returns (Int) {
return Int.wrap(x);
}
function bitor(Int, Int) pure returns (Int) {
return w(1);
return w(10);
}
function bitand(Int, Int) pure returns (Int) {
return w(2);
return w(11);
}
function bitxor(Int, Int) pure returns (Int) {
return w(3);
return w(12);
}
function bitnot(Int) pure returns (Int) {
return w(4);
return w(13);
}
function add(Int, Int) pure returns (Int) {
return w(5);
function add(Int x, Int) pure returns (int128) {
return uw(x) + 10;
}
function sub(Int, Int) pure returns (Int) {
return w(6);
return w(15);
}
function unsub(Int) pure returns (Int) {
return w(7);
return w(16);
}
function mul(Int, Int) pure returns (Int) {
return w(8);
return w(17);
}
function div(Int, Int) pure returns (Int) {
return w(9);
return w(18);
}
function mod(Int, Int) pure returns (Int) {
return w(10);
return w(19);
}
function eq(Int x, Int) pure returns (bool) {
return uw(x) == 1;
@@ -48,28 +48,61 @@ function noteq(Int x, Int) pure returns (bool) {
return uw(x) == 2;
}
function lt(Int x, Int) pure returns (bool) {
return uw(x) == 3;
return uw(x) < 10;
}
function gt(Int x, Int) pure returns (bool) {
return uw(x) == 4;
return uw(x) > 10;
}
function leq(Int x, Int) pure returns (bool) {
return uw(x) == 5;
return uw(x) <= 10;
}
function geq(Int x, Int) pure returns (bool) {
return uw(x) == 6;
return uw(x) >= 10;
}
// TODO test that side-effects are executed properly.
contract C {
function f1() public pure returns (Int) {
require(w(1) | w(2) == w(1));
require(!(w(1) | w(2) == w(2)));
return w(1) | w(2);
}
// TODO all the other operators
function test_bitor() public pure returns (Int) { return w(1) | w(2); }
function test_bitand() public pure returns (Int) { return w(1) | w(2); }
function test_bitxor() public pure returns (Int) { return w(1) ^ w(2); }
function test_bitnot() public pure returns (Int) { return ~w(1); }
function test_add(int128 x) public pure returns (int128) { return w(x) + w(2); }
function test_sub() public pure returns (Int) { return w(1) - w(2); }
function test_unsub() public pure returns (Int) { return -w(1); }
function test_mul() public pure returns (Int) { return w(1) * w(2); }
function test_div() public pure returns (Int) { return w(1) / w(2); }
function test_mod() public pure returns (Int) { return w(1) % w(2); }
function test_eq(int128 x) public pure returns (bool) { return w(x) == w(2); }
function test_neq(int128 x) public pure returns (bool) { return w(x) != w(2); }
function test_lt(int128 x) public pure returns (bool) { return w(x) < w(2); }
function test_gt(int128 x) public pure returns (bool) { return w(x) > w(2); }
function test_leq(int128 x) public pure returns (bool) { return w(x) <= w(2); }
function test_geq(int128 x) public pure returns (bool) { return w(x) >= w(2); }
}
// ====
// compileViaYul: also
// ----
// f1()
// test_bitor() -> 10
// test_bitand() -> 10
// test_bitxor() -> 12
// test_bitnot() -> 13
// test_add(int128): 4 -> 14
// test_add(int128): 104 -> 114
// test_sub() -> 15
// test_unsub() -> 16
// test_mul() -> 17
// test_div() -> 18
// test_mod() -> 19
// test_eq(int128): 1 -> true
// test_eq(int128): 2 -> false
// test_neq(int128): 2 -> true
// test_neq(int128): 1 -> false
// test_lt(int128): 9 -> true
// test_lt(int128): 10 -> false
// test_gt(int128): 11 -> true
// test_gt(int128): 10 -> false
// test_leq(int128): 10 -> true
// test_leq(int128): 11 -> false
// test_geq(int128): 10 -> true
// test_geq(int128): 9 -> false