UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

69 lines (67 loc) 2.54 kB
import { tsUtils } from '@neo-one/ts-utils'; import { BuiltinInstanceMemberCall } from '../BuiltinInstanceMemberCall'; export class ArrayConcat extends BuiltinInstanceMemberCall { canCall() { return true; } emitCall(sb, func, node, optionsIn, visited) { const options = sb.pushValueOptions(optionsIn); if (!visited) { sb.visit(tsUtils.expression.getExpression(func), options); } const handleArray = (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.unwrapArray); }; const handleOther = () => { sb.emitPushInt(node, 0); sb.emitOp(node, 'NEWARRAY'); sb.emitOp(node, 'TUCK'); sb.emitOp(node, 'SWAP'); sb.emitOp(node, 'APPEND'); }; sb.emitHelper(node, options, sb.helpers.unwrapArray); sb.emitHelper(node, options, sb.helpers.cloneArray); tsUtils.argumented.getArguments(node).forEach((arg) => { sb.visit(arg, options); sb.emitHelper(node, options, sb.helpers.forBuiltinType({ type: sb.context.analysis.getType(arg), array: handleArray, arrayStorage: handleOther, boolean: handleOther, buffer: handleOther, null: handleOther, number: handleOther, object: handleOther, string: handleOther, symbol: handleOther, undefined: handleOther, map: handleOther, mapStorage: handleOther, set: handleOther, setStorage: handleOther, error: handleOther, forwardValue: handleOther, iteratorResult: handleOther, iterable: handleOther, iterableIterator: handleOther, transaction: handleOther, output: handleOther, attribute: handleOther, input: handleOther, account: handleOther, asset: handleOther, contract: handleOther, header: handleOther, block: handleOther, })); sb.emitHelper(node, options, sb.helpers.arrConcat); }); if (optionsIn.pushValue) { sb.emitHelper(node, options, sb.helpers.wrapArray); } else { sb.emitOp(node, 'DROP'); } } } //# sourceMappingURL=concat.js.map