Skip to content

Commit ae15fb9

Browse files
Franco Victoriomattiaerre
authored andcommitted
Add support for AssemblyFor (#94)
* Add support for AssemblyIf * Print assembly cases blocks * Add support for AssemblyFor
1 parent 952ea35 commit ae15fb9

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/printer.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ function genericPrint(path, options, print) {
489489
return concat([
490490
'{',
491491
indent(hardline),
492-
indent(join(line, path.map(print, 'operations'))),
492+
indent(printPreservingEmptyLines(path, 'operations', options, print)),
493493
hardline,
494494
'}'
495495
]);
@@ -545,6 +545,15 @@ function genericPrint(path, options, print) {
545545
' ',
546546
path.call(print, 'body')
547547
]);
548+
case 'AssemblyFor': {
549+
return join(' ', [
550+
'for',
551+
path.call(print, 'pre'),
552+
path.call(print, 'condition'),
553+
path.call(print, 'post'),
554+
path.call(print, 'body')
555+
]);
556+
}
548557
case 'FunctionTypeName': {
549558
const returns = returnTypes => {
550559
if (returnTypes.length > 0) {

tests/Assembly/Assembly.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ contract Assembly {
1919
}
2020
}
2121
}
22+
23+
function forAssembly() {
24+
assembly {
25+
for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
26+
}
27+
}
2228
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ contract Assembly {
2222
}
2323
}
2424
}
25+
26+
function forAssembly() {
27+
assembly {
28+
for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) }
29+
}
30+
}
2531
}
2632
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2733
contract Assembly {
@@ -44,6 +50,18 @@ contract Assembly {
4450
}
4551
}
4652
}
53+
54+
function forAssembly() {
55+
assembly {
56+
for {
57+
let i := 0
58+
} lt(i, x) {
59+
i := add(i, 1)
60+
} {
61+
y := mul(2, y)
62+
}
63+
}
64+
}
4765
}
4866
4967
`;

0 commit comments

Comments
 (0)