Skip to content

Commit 5b23ca8

Browse files
Franco Victoriomattiaerre
authored andcommitted
Improve function calls in assembly code (#98)
1 parent cedf795 commit 5b23ca8

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

src/printer.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,20 @@ function genericPrint(path, options, print) {
499499
if (node.arguments.length === 0) {
500500
return node.functionName;
501501
}
502-
// @TODO: add call args
503502
return concat([
504503
node.functionName,
505504
'(',
506-
join(', ', path.map(print, 'arguments')),
505+
group(
506+
concat([
507+
indent(
508+
concat([
509+
softline,
510+
join(concat([',', line]), path.map(print, 'arguments'))
511+
])
512+
),
513+
softline
514+
])
515+
),
507516
')'
508517
]);
509518
case 'HexNumber':

tests/Assembly/Assembly.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,14 @@ contract Assembly {
2525
for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
2626
}
2727
}
28+
29+
function callWithComments() {
30+
assembly {
31+
f(
32+
1, // one
33+
2, // two
34+
3 // three
35+
)
36+
}
37+
}
2838
}

tests/Assembly/__snapshots__/jsfmt.spec.js.snap

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ contract Assembly {
2828
for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
2929
}
3030
}
31+
32+
function callWithComments() {
33+
assembly {
34+
f(
35+
1, // one
36+
2, // two
37+
3 // three
38+
)
39+
}
40+
}
3141
}
3242
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3343
contract Assembly {
@@ -43,10 +53,16 @@ contract Assembly {
4353
assembly {
4454
switch value
4555
case 0 {
46-
mstore(0, 0x0000000000000000000000000000000000000000000000000000000000000000)
56+
mstore(
57+
0,
58+
0x0000000000000000000000000000000000000000000000000000000000000000
59+
)
4760
}
4861
case 1 {
49-
mstore(0, 0x1111111111111111111111111111111111111111111111111111111111111111)
62+
mstore(
63+
0,
64+
0x1111111111111111111111111111111111111111111111111111111111111111
65+
)
5066
}
5167
}
5268
}
@@ -62,6 +78,16 @@ contract Assembly {
6278
}
6379
}
6480
}
81+
82+
function callWithComments() {
83+
assembly {
84+
f(
85+
1, // one
86+
2, // two
87+
3 // three
88+
)
89+
}
90+
}
6591
}
6692
6793
`;

tests/Proxy/__snapshots__/jsfmt.spec.js.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,14 @@ contract Proxy {
8686
// block because it will not return to Solidity code. We overwrite the
8787
// Solidity scratch pad at memory position 0.
8888
calldatacopy(0, 0, calldatasize)
89+
8990
// Call the implementation.
9091
// out and outsize are 0 because we don't know the size yet.
9192
let result := delegatecall(gas, implementation, 0, calldatasize, 0, 0)
93+
9294
// Copy the returned data.
9395
returndatacopy(0, 0, returndatasize)
96+
9497
switch result
9598
// delegatecall returns 0 on error.
9699
case 0 {

0 commit comments

Comments
 (0)