@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
52 lines (50 loc) • 1.91 kB
JavaScript
import { Helper } from '../Helper';
export class RawIteratorForEachFuncBaseHelper extends 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');
},
}));
}
}
//# sourceMappingURL=RawIteratorForEachFuncBaseHelper.js.map