UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

198 lines (196 loc) 8.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EqualsEqualsEqualsHelper = void 0; const constants_1 = require("../../constants"); const Helper_1 = require("../Helper"); class EqualsEqualsEqualsHelper extends Helper_1.Helper { constructor(options) { super(); this.leftType = options.leftType; this.leftKnownType = options.leftKnownType; this.rightType = options.rightType; this.rightKnownType = options.rightKnownType; } emit(sb, node, options) { if (!options.pushValue) { sb.emitOp(node, 'DROP'); sb.emitOp(node, 'DROP'); return; } const pushFalse = () => { sb.emitOp(node, 'DROP'); sb.emitOp(node, 'DROP'); sb.emitPushBoolean(node, false); }; const pushTrue = () => { sb.emitOp(node, 'DROP'); sb.emitOp(node, 'DROP'); sb.emitPushBoolean(node, true); }; const compare = (type) => (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.unwrapVal({ type })); sb.emitOp(node, 'SWAP'); sb.emitHelper(node, innerOptions, sb.helpers.unwrapVal({ type })); sb.emitOp(node, 'EQUAL'); }; const compareStorageValue = () => { sb.emitPushInt(node, 1); sb.emitOp(node, 'PICKITEM'); sb.emitOp(node, 'SWAP'); sb.emitPushInt(node, 1); sb.emitOp(node, 'PICKITEM'); sb.emitOp(node, 'EQUAL'); }; const compareNumber = (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.unwrapNumber); sb.emitOp(node, 'SWAP'); sb.emitHelper(node, innerOptions, sb.helpers.unwrapNumber); sb.emitOp(node, 'NUMEQUAL'); }; const createProcess = (value, type, compareValue = compare(type)) => (innerOptions) => { sb.emitOp(node, 'SWAP'); sb.emitHelper(node, innerOptions, sb.helpers.forBuiltinType({ type: this.leftType, knownType: this.leftKnownType, array: pushFalse, arrayStorage: pushFalse, boolean: pushFalse, buffer: pushFalse, null: pushFalse, number: pushFalse, object: pushFalse, string: pushFalse, symbol: pushFalse, undefined: pushFalse, map: pushFalse, mapStorage: pushFalse, set: pushFalse, setStorage: pushFalse, error: pushFalse, forwardValue: pushFalse, iteratorResult: pushFalse, iterable: pushFalse, iterableIterator: pushFalse, transaction: pushFalse, output: pushFalse, attribute: pushFalse, input: pushFalse, account: pushFalse, asset: pushFalse, contract: pushFalse, header: pushFalse, block: pushFalse, [value]: compareValue, })); }; const createProcessStorage = (value) => (innerOptions) => { sb.emitOp(node, 'SWAP'); sb.emitHelper(node, innerOptions, sb.helpers.forBuiltinType({ type: this.leftType, knownType: this.leftKnownType, array: pushFalse, arrayStorage: pushFalse, boolean: pushFalse, buffer: pushFalse, null: pushFalse, number: pushFalse, object: pushFalse, string: pushFalse, symbol: pushFalse, undefined: pushFalse, map: pushFalse, mapStorage: pushFalse, set: pushFalse, setStorage: pushFalse, error: pushFalse, forwardValue: pushFalse, iteratorResult: pushFalse, iterable: pushFalse, iterableIterator: pushFalse, transaction: pushFalse, output: pushFalse, attribute: pushFalse, input: pushFalse, account: pushFalse, asset: pushFalse, contract: pushFalse, header: pushFalse, block: pushFalse, [value]: compareStorageValue, })); }; const createProcessNullOrUndefined = (value) => (innerOptions) => { sb.emitOp(node, 'SWAP'); sb.emitHelper(node, innerOptions, sb.helpers.forBuiltinType({ type: this.leftType, knownType: this.leftKnownType, array: pushFalse, arrayStorage: pushFalse, boolean: pushFalse, buffer: pushFalse, null: pushFalse, number: pushFalse, object: pushFalse, string: pushFalse, symbol: pushFalse, undefined: pushFalse, map: pushFalse, mapStorage: pushFalse, set: pushFalse, setStorage: pushFalse, error: pushFalse, forwardValue: pushFalse, iteratorResult: pushFalse, iterable: pushFalse, iterableIterator: pushFalse, transaction: pushFalse, output: pushFalse, attribute: pushFalse, input: pushFalse, account: pushFalse, asset: pushFalse, contract: pushFalse, header: pushFalse, block: pushFalse, [value]: pushTrue, })); }; const createProcessIterable = () => (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.throwTypeError); }; sb.emitHelper(node, options, sb.helpers.forBuiltinType({ type: this.rightType, knownType: this.rightKnownType, array: createProcess('array', constants_1.Types.Array), arrayStorage: createProcessStorage('arrayStorage'), boolean: createProcess('boolean', constants_1.Types.Boolean), buffer: createProcess('buffer', constants_1.Types.Buffer), null: createProcessNullOrUndefined('null'), number: createProcess('number', constants_1.Types.Number, compareNumber), object: createProcess('object', constants_1.Types.Object), string: createProcess('string', constants_1.Types.String), symbol: createProcess('symbol', constants_1.Types.Symbol), undefined: createProcessNullOrUndefined('undefined'), map: createProcess('map', constants_1.Types.Map), mapStorage: createProcessStorage('mapStorage'), set: createProcess('set', constants_1.Types.Set), setStorage: createProcessStorage('setStorage'), error: createProcess('error', constants_1.Types.Error), forwardValue: createProcess('error', constants_1.Types.ForwardValue), iteratorResult: createProcess('iteratorResult', constants_1.Types.IteratorResult), iterable: createProcessIterable(), iterableIterator: createProcess('iterableIterator', constants_1.Types.IterableIterator), transaction: createProcess('transaction', constants_1.Types.Transaction), output: createProcess('output', constants_1.Types.Output), attribute: createProcess('attribute', constants_1.Types.Attribute), input: createProcess('input', constants_1.Types.Input), account: createProcess('account', constants_1.Types.Account), asset: createProcess('asset', constants_1.Types.Asset), contract: createProcess('contract', constants_1.Types.Contract), header: createProcess('header', constants_1.Types.Header), block: createProcess('block', constants_1.Types.Block), })); } } exports.EqualsEqualsEqualsHelper = EqualsEqualsEqualsHelper; //# sourceMappingURL=EqualsEqualsEqualsHelper.js.map