@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
61 lines (59 loc) • 2 kB
JavaScript
import { BuiltinInterface } from '../BuiltinInterface';
import { BuiltinNew } from '../BuiltinNew';
import { MapDelete } from './delete';
import { MapForEach } from './forEach';
import { MapGet } from './get';
import { MapHas } from './has';
import { MapIterator } from './iterator';
import { MapSet } from './set';
import { MapSize } from './size';
class MapInterface extends BuiltinInterface {
}
class ReadonlyMapInterface extends BuiltinInterface {
}
class MapValue extends BuiltinNew {
constructor() {
super(...arguments);
this.type = 'MapConstructor';
}
emitInstanceOf(sb, node, optionsIn) {
const options = sb.pushValueOptions(optionsIn);
sb.visit(node, options);
if (optionsIn.pushValue) {
sb.emitHelper(node, options, sb.helpers.isMap);
sb.emitHelper(node, options, sb.helpers.wrapBoolean);
}
else {
sb.emitOp(node, 'DROP');
}
}
emitNew(sb, node, options) {
if (!options.pushValue) {
return;
}
sb.emitOp(node, 'NEWMAP');
sb.emitHelper(node, options, sb.helpers.wrapMap);
}
}
class MapConstructorInterface extends BuiltinInterface {
}
const COMMON = [
['__@iterator', new MapIterator()],
['forEach', new MapForEach()],
['get', new MapGet()],
['has', new MapHas()],
['size', new MapSize()],
];
export const add = (builtins) => {
builtins.addInterface('Map', new MapInterface());
builtins.addInterface('ReadonlyMap', new ReadonlyMapInterface());
builtins.addValue('Map', new MapValue());
COMMON.forEach(([name, builtin]) => {
builtins.addGlobalMember('Map', name, builtin);
builtins.addGlobalMember('ReadonlyMap', name, builtin);
});
builtins.addGlobalMember('Map', 'delete', new MapDelete());
builtins.addGlobalMember('Map', 'set', new MapSet());
builtins.addInterface('MapConstructor', new MapConstructorInterface());
};
//# sourceMappingURL=index.js.map