UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

194 lines (192 loc) 7.93 kB
import { Types } from '../../constants'; import { Helper } from '../Helper'; export class EqualsEqualsEqualsHelper extends 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', Types.Array), arrayStorage: createProcessStorage('arrayStorage'), boolean: createProcess('boolean', Types.Boolean), buffer: createProcess('buffer', Types.Buffer), null: createProcessNullOrUndefined('null'), number: createProcess('number', Types.Number, compareNumber), object: createProcess('object', Types.Object), string: createProcess('string', Types.String), symbol: createProcess('symbol', Types.Symbol), undefined: createProcessNullOrUndefined('undefined'), map: createProcess('map', Types.Map), mapStorage: createProcessStorage('mapStorage'), set: createProcess('set', Types.Set), setStorage: createProcessStorage('setStorage'), error: createProcess('error', Types.Error), forwardValue: createProcess('error', Types.ForwardValue), iteratorResult: createProcess('iteratorResult', Types.IteratorResult), iterable: createProcessIterable(), iterableIterator: createProcess('iterableIterator', Types.IterableIterator), transaction: createProcess('transaction', Types.Transaction), output: createProcess('output', Types.Output), attribute: createProcess('attribute', Types.Attribute), input: createProcess('input', Types.Input), account: createProcess('account', Types.Account), asset: createProcess('asset', Types.Asset), contract: createProcess('contract', Types.Contract), header: createProcess('header', Types.Header), block: createProcess('block', Types.Block), })); } } //# sourceMappingURL=EqualsEqualsEqualsHelper.js.map