@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
43 lines (41 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IfHelper = void 0;
const Helper_1 = require("../Helper");
class IfHelper extends Helper_1.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();
}
});
}
}
}
exports.IfHelper = IfHelper;
//# sourceMappingURL=IfHelper.js.map