@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
69 lines (67 loc) • 2.41 kB
JavaScript
import { tsUtils } from '@neo-one/ts-utils';
import { Helper } from '../Helper';
export class LessThanHelper extends Helper {
constructor(options) {
super();
this.leftFirst = options.leftFirst;
this.left = options.left;
this.right = options.right;
}
emit(sb, node, options) {
if (!options.pushValue) {
if (this.leftFirst) {
sb.visit(this.left, options);
sb.visit(this.right, options);
}
else {
sb.visit(this.right, options);
sb.visit(this.left, options);
}
return;
}
const leftType = sb.context.analysis.getType(this.left);
const rightType = sb.context.analysis.getType(this.right);
if (this.leftFirst) {
sb.visit(this.left, options);
sb.emitHelper(this.left, options, sb.helpers.toPrimitive({
type: leftType,
preferredType: 'number',
}));
sb.visit(this.right, options);
sb.emitHelper(this.right, options, sb.helpers.toPrimitive({
type: rightType,
preferredType: 'number',
}));
}
else {
sb.visit(this.right, options);
sb.emitHelper(this.right, options, sb.helpers.toPrimitive({
type: rightType,
preferredType: 'number',
}));
sb.visit(this.left, options);
sb.emitHelper(this.left, options, sb.helpers.toPrimitive({
type: leftType,
preferredType: 'number',
}));
sb.emitOp(node, 'SWAP');
}
if (leftType !== undefined &&
rightType !== undefined &&
tsUtils.type_.isOnlyStringish(leftType) &&
tsUtils.type_.isOnlyStringish(rightType)) {
sb.context.reportUnsupported(node);
}
else {
sb.emitHelper(this.right, options, sb.helpers.toNumber({ type: rightType }));
sb.emitOp(node, 'SWAP');
sb.emitHelper(this.left, options, sb.helpers.toNumber({ type: leftType }));
sb.emitOp(node, 'SWAP');
sb.emitOp(node, 'LT');
if (!options.pushValue) {
sb.emitOp(node, 'DROP');
}
}
}
}
//# sourceMappingURL=LessThanHelper.js.map