UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

52 lines (50 loc) 1.9 kB
import { tsUtils } from '@neo-one/ts-utils'; import { ErrorSlots, Types } from '../../constants'; import { BuiltinInterface } from '../BuiltinInterface'; import { BuiltinNew } from '../BuiltinNew'; import { BuiltinSlotInstanceMemberValue } from '../BuiltinSlotInstanceMemberValue'; class ErrorInterface extends BuiltinInterface { } class ErrorValue extends BuiltinNew { constructor() { super(...arguments); this.type = 'ErrorConstructor'; } emitInstanceOf(sb, node, optionsIn) { const options = sb.pushValueOptions(optionsIn); sb.visit(node, options); if (optionsIn.pushValue) { sb.emitHelper(node, options, sb.helpers.isError); sb.emitHelper(node, options, sb.helpers.wrapBoolean); } else { sb.emitOp(node, 'DROP'); } } emitNew(sb, node, optionsIn) { const options = sb.pushValueOptions(optionsIn); const args = tsUtils.argumented.getArgumentsArray(node); if (args.length === 0) { sb.emitPushString(node, ''); sb.emitHelper(node, options, sb.helpers.wrapString); } else { sb.visit(args[0], options); } sb.emitOp(node, 'NEWMAP'); sb.emitOp(node, 'TUCK'); sb.emitPushInt(node, ErrorSlots.message); sb.emitOp(node, 'ROT'); sb.emitOp(node, 'SETITEM'); sb.emitHelper(node, optionsIn, sb.helpers.wrapError); } } class ErrorConstructorInterface extends BuiltinInterface { } export const add = (builtins) => { builtins.addInterface('Error', new ErrorInterface()); builtins.addValue('Error', new ErrorValue()); builtins.addGlobalMember('Error', 'message', new BuiltinSlotInstanceMemberValue(Types.Error, ErrorSlots.message)); builtins.addInterface('ErrorConstructor', new ErrorConstructorInterface()); }; //# sourceMappingURL=index.js.map