@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
56 lines (54 loc) • 2.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RawIteratorForEachFuncBaseHelper = void 0;
const Helper_1 = require("../Helper");
class RawIteratorForEachFuncBaseHelper extends Helper_1.Helper {
constructor({ handleNext, hasFilter = false }) {
super();
this.handleNext = handleNext;
this.hasFilter = hasFilter;
}
emit(sb, node, optionsIn) {
const options = sb.pushValueOptions(optionsIn);
sb.emitHelper(node, options, sb.helpers.getCallable({}));
sb.emitOp(node, 'SWAP');
sb.emitHelper(node, options, sb.helpers.forLoop({
condition: () => {
sb.emitOp(node, 'DUP');
sb.emitSysCall(node, 'Neo.Enumerator.Next');
},
each: (innerOptionsIn) => {
const innerOptions = sb.pushValueOptions(innerOptionsIn);
sb.emitOp(node, 'DUP');
const handleCall = () => {
sb.emitPushInt(node, 2);
sb.emitOp(node, 'PICK');
sb.emitHelper(node, sb.noPushValueOptions(innerOptions), sb.helpers.call);
};
if (this.hasFilter) {
sb.emitHelper(node, innerOptions, sb.helpers.if({
condition: () => {
this.handleNext(innerOptions);
},
whenTrue: () => {
handleCall();
},
whenFalse: () => {
sb.emitOp(node, 'DROP');
},
}));
}
else {
this.handleNext(innerOptions);
handleCall();
}
},
cleanup: () => {
sb.emitOp(node, 'DROP');
sb.emitOp(node, 'DROP');
},
}));
}
}
exports.RawIteratorForEachFuncBaseHelper = RawIteratorForEachFuncBaseHelper;
//# sourceMappingURL=RawIteratorForEachFuncBaseHelper.js.map