Merge pull request #6589 from ethereum/addReturn

[Yul] Add code generation for "return" and for loops.
This commit is contained in:
chriseth
2019-04-30 17:07:45 +02:00
committed by GitHub
8 changed files with 171 additions and 37 deletions
@@ -0,0 +1,40 @@
contract C {
function f() public returns (uint x) {
x = 1;
for (uint a = 0; a < 10; a = a + 1) {
x = x + x;
}
}
function g() public returns (uint x) {
x = 1;
for (uint a = 0; a < 10; a = a + 1) {
x = x + x;
break;
}
}
function h() public returns (uint x) {
x = 1;
uint a = 0;
for (; a < 10; a = a + 1) {
continue;
x = x + x;
}
x = x + a;
}
function i() public returns (uint x) {
x = 1;
uint a;
for (; a < 10; a = a + 1) {
return x;
x = x + x;
}
x = x + a;
}
}
// ===
// compileViaYul: true
// ----
// f() -> 1024
// g() -> 2
// h() -> 11
// i() -> 1
@@ -0,0 +1,10 @@
contract C {
function f() public pure returns (uint x) {
return 7;
x = 3;
}
}
// ====
// compileViaYul: true
// ----
// f() -> 7
@@ -0,0 +1,11 @@
contract C {
function f() public pure returns (uint) {
uint8 b;
assembly { b := 0xffff }
return b;
}
}
// ====
// compileViaYul: true
// ----
// f() -> 255