Skip to content

Commit b721d28

Browse files
authored
issue-with-assembly (#61)
* add contract * assembly all the things * fix issue w/ for statement * fix Parameter
1 parent d16f203 commit b721d28

File tree

4 files changed

+2275
-10
lines changed

4 files changed

+2275
-10
lines changed

src/printer.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ function genericPrint(path, options, print) {
133133
);
134134
case 'Parameter':
135135
doc = path.call(print, 'typeName');
136-
if (node.name) {
137-
doc = join(' ', [doc, node.name]);
138-
}
136+
doc = join(
137+
' ',
138+
[doc, node.storageLocation, node.name].filter(element => element)
139+
);
139140
return doc;
140141
case 'ModifierInvocation':
141142
doc = node.name;
@@ -217,7 +218,7 @@ function genericPrint(path, options, print) {
217218
return concat([
218219
'for (',
219220
node.initExpression ? path.call(print, 'initExpression') : '',
220-
' ',
221+
'; ',
221222
node.conditionExpression ? path.call(print, 'conditionExpression') : '',
222223
'; ',
223224
path.call(print, 'loopExpression'),
@@ -226,7 +227,7 @@ function genericPrint(path, options, print) {
226227
]);
227228
case 'EmitStatement':
228229
return concat(['emit ', path.call(print, 'eventCall'), ';']);
229-
case 'VariableDeclarationStatement':
230+
case 'VariableDeclarationStatement': {
230231
doc = join(
231232
', ',
232233
path.map(statementPath => {
@@ -244,7 +245,9 @@ function genericPrint(path, options, print) {
244245
if (node.initialValue) {
245246
doc = concat([doc, ' = ', path.call(print, 'initialValue')]);
246247
}
247-
return concat([doc, ';']);
248+
const addSemicolon = path.getParentNode().type !== 'ForStatement';
249+
return concat([doc, addSemicolon ? ';' : '']);
250+
}
248251
case 'StateVariableDeclaration':
249252
doc = concat(
250253
path.map(statementPath => {
@@ -431,13 +434,17 @@ function genericPrint(path, options, print) {
431434
case 'AssemblyBlock':
432435
return concat([
433436
'{',
437+
indent(hardline),
438+
indent(join(line, path.map(print, 'operations'))),
434439
hardline,
435-
join(line, path.map(print, 'operations')),
436440
'}'
437441
]);
438442
case 'LabelDefinition':
439443
return concat([node.name, ':', line]);
440444
case 'AssemblyCall':
445+
if (node.arguments.length === 0) {
446+
return node.functionName;
447+
}
441448
// @TODO: add call args
442449
return concat([
443450
node.functionName,
@@ -459,9 +466,19 @@ function genericPrint(path, options, print) {
459466
doc = concat(['case ', path.call(print, 'value')]);
460467
}
461468
return join(' ', [doc, '{}']);
462-
case 'AssemblyFunctionDefinition':
463-
// @TODO
464-
return '';
469+
case 'AssemblyLocalDefinition':
470+
return join(' ', [
471+
'let',
472+
join(', ', path.map(print, 'names')),
473+
':=',
474+
path.call(print, 'expression')
475+
]);
476+
case 'AssemblyAssignment':
477+
return join(' ', [
478+
join(', ', path.map(print, 'names')),
479+
':=',
480+
path.call(print, 'expression')
481+
]);
465482
default:
466483
throw new Error(`Unknown type: ${JSON.stringify(node.type)}`);
467484
}

0 commit comments

Comments
 (0)