mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2184 from ethereum/julia-parentheses
Remove parentheses from around function return parameters
This commit is contained in:
commit
abe77f48b6
@ -29,7 +29,7 @@ arising when writing manual assembly by the following features:
|
|||||||
* labels: ``let x := 10 repeat: x := sub(x, 1) jumpi(repeat, eq(x, 0))``
|
* labels: ``let x := 10 repeat: x := sub(x, 1) jumpi(repeat, eq(x, 0))``
|
||||||
* loops: ``for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }``
|
* loops: ``for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }``
|
||||||
* switch statements: ``switch x case 0: { y := mul(x, 2) } default: { y := 0 }``
|
* switch statements: ``switch x case 0: { y := mul(x, 2) } default: { y := 0 }``
|
||||||
* function calls: ``function f(x) -> (y) { switch x case 0: { y := 1 } default: { y := mul(x, f(sub(x, 1))) } }``
|
* function calls: ``function f(x) -> y { switch x case 0: { y := 1 } default: { y := mul(x, f(sub(x, 1))) } }``
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
Of the above, loops, function calls and switch statements are not yet implemented.
|
Of the above, loops, function calls and switch statements are not yet implemented.
|
||||||
@ -566,7 +566,7 @@ The following example implements the power function by square-and-multiply.
|
|||||||
.. code::
|
.. code::
|
||||||
|
|
||||||
assembly {
|
assembly {
|
||||||
function power(base, exponent) -> (result) {
|
function power(base, exponent) -> result {
|
||||||
switch exponent
|
switch exponent
|
||||||
0: { result := 1 }
|
0: { result := 1 }
|
||||||
1: { result := base }
|
1: { result := base }
|
||||||
@ -701,12 +701,12 @@ The following assembly will be generated::
|
|||||||
}
|
}
|
||||||
default: { jump(invalidJumpLabel) }
|
default: { jump(invalidJumpLabel) }
|
||||||
// memory allocator
|
// memory allocator
|
||||||
function $allocate(size) -> (pos) {
|
function $allocate(size) -> pos {
|
||||||
pos := mload(0x40)
|
pos := mload(0x40)
|
||||||
mstore(0x40, add(pos, size))
|
mstore(0x40, add(pos, size))
|
||||||
}
|
}
|
||||||
// the contract function
|
// the contract function
|
||||||
function f(x) -> (y) {
|
function f(x) -> y {
|
||||||
y := 1
|
y := 1
|
||||||
for { let i := 0 } lt(i, x) { i := add(i, 1) } {
|
for { let i := 0 } lt(i, x) { i := add(i, 1) } {
|
||||||
y := mul(2, y)
|
y := mul(2, y)
|
||||||
|
@ -242,15 +242,13 @@ assembly::FunctionDefinition Parser::parseFunctionDefinition()
|
|||||||
{
|
{
|
||||||
expectToken(Token::Sub);
|
expectToken(Token::Sub);
|
||||||
expectToken(Token::GreaterThan);
|
expectToken(Token::GreaterThan);
|
||||||
expectToken(Token::LParen);
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
funDef.returns.push_back(expectAsmIdentifier());
|
funDef.returns.push_back(expectAsmIdentifier());
|
||||||
if (m_scanner->currentToken() == Token::RParen)
|
if (m_scanner->currentToken() == Token::LBrace)
|
||||||
break;
|
break;
|
||||||
expectToken(Token::Comma);
|
expectToken(Token::Comma);
|
||||||
}
|
}
|
||||||
expectToken(Token::RParen);
|
|
||||||
}
|
}
|
||||||
funDef.body = parseBlock();
|
funDef.body = parseBlock();
|
||||||
funDef.location.end = funDef.body.location.end;
|
funDef.location.end = funDef.body.location.end;
|
||||||
|
@ -116,7 +116,7 @@ string AsmPrinter::operator()(assembly::FunctionDefinition const& _functionDefin
|
|||||||
{
|
{
|
||||||
string out = "function " + _functionDefinition.name + "(" + boost::algorithm::join(_functionDefinition.arguments, ", ") + ")";
|
string out = "function " + _functionDefinition.name + "(" + boost::algorithm::join(_functionDefinition.arguments, ", ") + ")";
|
||||||
if (!_functionDefinition.returns.empty())
|
if (!_functionDefinition.returns.empty())
|
||||||
out += " -> (" + boost::algorithm::join(_functionDefinition.returns, ", ") + ")";
|
out += " -> " + boost::algorithm::join(_functionDefinition.returns, ", ");
|
||||||
return out + "\n" + (*this)(_functionDefinition.body);
|
return out + "\n" + (*this)(_functionDefinition.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,17 +209,17 @@ BOOST_AUTO_TEST_CASE(blocks)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(function_definitions)
|
BOOST_AUTO_TEST_CASE(function_definitions)
|
||||||
{
|
{
|
||||||
BOOST_CHECK(successParse("{ function f() { } function g(a) -> (x) { } }"));
|
BOOST_CHECK(successParse("{ function f() { } function g(a) -> x { } }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(function_definitions_multiple_args)
|
BOOST_AUTO_TEST_CASE(function_definitions_multiple_args)
|
||||||
{
|
{
|
||||||
BOOST_CHECK(successParse("{ function f(a, d) { } function g(a, d) -> (x, y) { } }"));
|
BOOST_CHECK(successParse("{ function f(a, d) { } function g(a, d) -> x, y { } }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(function_calls)
|
BOOST_AUTO_TEST_CASE(function_calls)
|
||||||
{
|
{
|
||||||
BOOST_CHECK(successParse("{ function f(a) -> (b) {} function g(a, b, c) {} function x() { g(1, 2, f(mul(2, 3))) x() } }"));
|
BOOST_CHECK(successParse("{ function f(a) -> b {} function g(a, b, c) {} function x() { g(1, 2, f(mul(2, 3))) x() } }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(opcode_for_functions)
|
BOOST_AUTO_TEST_CASE(opcode_for_functions)
|
||||||
@ -230,7 +230,7 @@ BOOST_AUTO_TEST_CASE(opcode_for_functions)
|
|||||||
BOOST_AUTO_TEST_CASE(opcode_for_function_args)
|
BOOST_AUTO_TEST_CASE(opcode_for_function_args)
|
||||||
{
|
{
|
||||||
CHECK_PARSE_ERROR("{ function f(gas) { } }", ParserError, "Cannot use instruction names for identifier names.");
|
CHECK_PARSE_ERROR("{ function f(gas) { } }", ParserError, "Cannot use instruction names for identifier names.");
|
||||||
CHECK_PARSE_ERROR("{ function f() -> (gas) { } }", ParserError, "Cannot use instruction names for identifier names.");
|
CHECK_PARSE_ERROR("{ function f() -> gas { } }", ParserError, "Cannot use instruction names for identifier names.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_clashes)
|
BOOST_AUTO_TEST_CASE(name_clashes)
|
||||||
@ -295,7 +295,7 @@ BOOST_AUTO_TEST_CASE(print_string_literal_unicode)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(function_definitions_multiple_args)
|
BOOST_AUTO_TEST_CASE(function_definitions_multiple_args)
|
||||||
{
|
{
|
||||||
parsePrintCompare("{\n function f(a, d)\n {\n mstore(a, d)\n }\n function g(a, d) -> (x, y)\n {\n }\n}");
|
parsePrintCompare("{\n function f(a, d)\n {\n mstore(a, d)\n }\n function g(a, d) -> x, y\n {\n }\n}");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(function_calls)
|
BOOST_AUTO_TEST_CASE(function_calls)
|
||||||
@ -304,7 +304,7 @@ BOOST_AUTO_TEST_CASE(function_calls)
|
|||||||
function y()
|
function y()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
function f(a) -> (b)
|
function f(a) -> b
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
function g(a, b, c)
|
function g(a, b, c)
|
||||||
|
Loading…
Reference in New Issue
Block a user