UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

39 lines (37 loc) 1.28 kB
import { Helper } from '../Helper'; export class IfHelper extends Helper { constructor({ condition, whenTrue, whenFalse }) { super(); this.condition = condition; this.whenTrue = whenTrue; this.whenFalse = whenFalse; } emit(sb, node, _options) { this.condition(); const { whenTrue, whenFalse } = this; if (whenTrue === undefined) { if (whenFalse === undefined) { throw new Error('If statement must have a true or false value'); } sb.withProgramCounter((endPC) => { sb.emitJmp(node, 'JMPIF', endPC.getLast()); whenFalse(); }); } else { sb.withProgramCounter((whenFalsePC) => { sb.withProgramCounter((whenTruePC) => { sb.emitJmp(node, 'JMPIFNOT', whenTruePC.getLast()); whenTrue(); if (this.whenFalse !== undefined) { sb.emitJmp(node, 'JMP', whenFalsePC.getLast()); } }); if (this.whenFalse !== undefined) { this.whenFalse(); } }); } } } //# sourceMappingURL=IfHelper.js.map