UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

79 lines (77 loc) 2.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.add = void 0; const ts_utils_1 = require("@neo-one/ts-utils"); const BuiltinInterface_1 = require("../BuiltinInterface"); const BuiltinNew_1 = require("../BuiltinNew"); const delete_1 = require("../map/delete"); const has_1 = require("../map/has"); const size_1 = require("../map/size"); const add_1 = require("./add"); const forEach_1 = require("./forEach"); const iterator_1 = require("./iterator"); class SetInterface extends BuiltinInterface_1.BuiltinInterface { } class ReadonlySetInterface extends BuiltinInterface_1.BuiltinInterface { } class SetValue extends BuiltinNew_1.BuiltinNew { constructor() { super(...arguments); this.type = 'SetConstructor'; } emitInstanceOf(sb, node, optionsIn) { const options = sb.pushValueOptions(optionsIn); sb.visit(node, options); if (optionsIn.pushValue) { sb.emitHelper(node, options, sb.helpers.isSet); sb.emitHelper(node, options, sb.helpers.wrapBoolean); } else { sb.emitOp(node, 'DROP'); } } emitNew(sb, node, optionsIn) { const options = sb.pushValueOptions(optionsIn); const args = ts_utils_1.tsUtils.argumented.getArgumentsArray(node); sb.emitOp(node, 'NEWMAP'); if (args.length > 0) { sb.visit(args[0], options); sb.emitHelper(node, options, sb.helpers.unwrapArray); sb.emitOp(node, 'SWAP'); sb.emitHelper(node, options, sb.helpers.arrReduce({ each: () => { sb.emitOp(node, 'TUCK'); sb.emitOp(node, 'SWAP'); sb.emitSysCall(node, 'Neo.Runtime.Serialize'); sb.emitPushBoolean(node, true); sb.emitOp(node, 'SETITEM'); }, })); } sb.emitHelper(node, options, sb.helpers.wrapSet); if (!optionsIn.pushValue) { sb.emitOp(node, 'DROP'); } } } class SetConstructorInterface extends BuiltinInterface_1.BuiltinInterface { } const COMMON = [ ['__@iterator', new iterator_1.SetIterator()], ['forEach', new forEach_1.SetForEach()], ['has', new has_1.MapHas()], ['size', new size_1.MapSize()], ]; exports.add = (builtins) => { builtins.addInterface('Set', new SetInterface()); builtins.addInterface('ReadonlySet', new ReadonlySetInterface()); builtins.addValue('Set', new SetValue()); COMMON.forEach(([name, builtin]) => { builtins.addGlobalMember('Set', name, builtin); builtins.addGlobalMember('ReadonlySet', name, builtin); }); builtins.addGlobalMember('Set', 'delete', new delete_1.MapDelete()); builtins.addGlobalMember('Set', 'add', new add_1.SetAdd()); builtins.addInterface('SetConstructor', new SetConstructorInterface()); }; //# sourceMappingURL=index.js.map