[Sol -> Yul] Fix ForLoops and implement WhileLoops

This commit is contained in:
Mathias Baumann
2019-05-09 09:46:19 +02:00
parent f61348728c
commit 0abe00d393
6 changed files with 196 additions and 38 deletions
@@ -0,0 +1,31 @@
contract C {
function f() public returns (uint x) {
x = 1;
for (uint a = 0; a < 10; a = a + 1) {
x = x + x;
break;
}
}
function g() public returns (uint x) {
x = 1;
uint a = 0;
while (a < 10) {
x = x + x;
break;
a = a + 1;
}
}
function h() public returns (uint x) {
x = 1;
do {
x = x + 1;
break;
} while (x < 3);
}
}
// ====
// compileViaYul: true
// ----
// f() -> 2
// g() -> 2
// h() -> 2
@@ -0,0 +1,37 @@
contract C {
function f() public returns (uint x) {
x = 1;
uint a = 0;
for (; a < 10; a = a + 1) {
continue;
x = x + x;
}
x = x + a;
}
function g() public returns (uint x) {
x = 1;
uint a = 0;
while (a < 10) {
a = a + 1;
continue;
x = x + x;
}
x = x + a;
}
function h() public returns (uint x) {
x = 1;
uint a = 0;
do {
a = a + 1;
continue;
x = x + x;
} while (a < 4);
x = x + a;
}
}
// ====
// compileViaYul: true
// ----
// f() -> 11
// g() -> 11
// h() -> 5
@@ -0,0 +1,34 @@
contract C {
function f() public returns (uint x) {
x = 1;
uint a;
for (; a < 10; a = a + 1) {
return x;
x = x + x;
}
x = x + a;
}
function g() public returns (uint x) {
x = 1;
uint a;
while (a < 10) {
return x;
x = x + x;
a = a + 1;
}
x = x + a;
}
function h() public returns (uint x) {
x = 1;
do {
x = x + 1;
return x;
} while (x < 3);
}
}
// ====
// compileViaYul: true
// ----
// f() -> 1
// g() -> 1
// h() -> 2
@@ -7,34 +7,33 @@ contract C {
}
function g() public returns (uint x) {
x = 1;
for (uint a = 0; a < 10; a = a + 1) {
uint a = 0;
while (a < 10) {
x = x + x;
break;
a = a + 1;
}
}
function h() public returns (uint x) {
x = 1;
uint a = 0;
for (; a < 10; a = a + 1) {
continue;
x = x + x;
}
x = x + a;
do {
x = x + 1;
} while (false);
}
function i() public returns (uint x) {
x = 1;
uint a;
for (; a < 10; a = a + 1) {
return x;
x = x + x;
}
x = x + a;
do {
x = x + 1;
} while (x < 3);
}
function j() public {
for (;;) {break;}
}
}
// ===
// ====
// compileViaYul: true
// ----
// f() -> 1024
// g() -> 2
// h() -> 11
// i() -> 1
// g() -> 1024
// h() -> 2
// i() -> 3
// j() ->