@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
55 lines (53 loc) • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.add = void 0;
const ts_utils_1 = require("@neo-one/ts-utils");
const constants_1 = require("../../constants");
const BuiltinInterface_1 = require("../BuiltinInterface");
const BuiltinNew_1 = require("../BuiltinNew");
const BuiltinSlotInstanceMemberValue_1 = require("../BuiltinSlotInstanceMemberValue");
class ErrorInterface extends BuiltinInterface_1.BuiltinInterface {
}
class ErrorValue extends BuiltinNew_1.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 = ts_utils_1.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, constants_1.ErrorSlots.message);
sb.emitOp(node, 'ROT');
sb.emitOp(node, 'SETITEM');
sb.emitHelper(node, optionsIn, sb.helpers.wrapError);
}
}
class ErrorConstructorInterface extends BuiltinInterface_1.BuiltinInterface {
}
exports.add = (builtins) => {
builtins.addInterface('Error', new ErrorInterface());
builtins.addValue('Error', new ErrorValue());
builtins.addGlobalMember('Error', 'message', new BuiltinSlotInstanceMemberValue_1.BuiltinSlotInstanceMemberValue(constants_1.Types.Error, constants_1.ErrorSlots.message));
builtins.addInterface('ErrorConstructor', new ErrorConstructorInterface());
};
//# sourceMappingURL=index.js.map