@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
34 lines (32 loc) • 1.46 kB
JavaScript
import { tsUtils } from '@neo-one/ts-utils';
import ts from 'typescript';
import * as constants from '../../constants';
import { NodeCompiler } from '../NodeCompiler';
export class DoStatementCompiler extends NodeCompiler {
constructor() {
super(...arguments);
this.kind = ts.SyntaxKind.DoStatement;
}
visitNode(sb, node, options) {
sb.withProgramCounter((breakPC) => {
sb.withProgramCounter((continuePC) => {
sb.visit(tsUtils.statement.getStatement(node), sb.breakPCOptions(sb.continuePCOptions(options, continuePC.getLast()), breakPC.getLast()));
sb.emitPushInt(node, constants.CONTINUE_COMPLETION);
});
sb.emitOp(node, 'DROP');
sb.emitHelper(tsUtils.expression.getExpression(node), options, sb.helpers.if({
condition: () => {
const expr = tsUtils.expression.getExpression(node);
sb.visit(expr, sb.pushValueOptions(options));
sb.emitHelper(expr, sb.pushValueOptions(options), sb.helpers.toBoolean({ type: sb.context.analysis.getType(expr) }));
},
whenTrue: () => {
sb.emitJmp(node, 'JMP', breakPC.getFirst());
},
}));
sb.emitPushInt(node, constants.BREAK_COMPLETION);
});
sb.emitOp(node, 'DROP');
}
}
//# sourceMappingURL=DoStatementCompiler.js.map