OperatorNode.js 694 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import Node from '../core/Node.js';
  2. class OperatorNode extends Node {
  3. constructor( op, a, b ) {
  4. super();
  5. this.op = op;
  6. this.a = a;
  7. this.b = b;
  8. }
  9. getType( builder ) {
  10. const typeA = this.a.getType( builder );
  11. const typeB = this.b.getType( builder );
  12. // use the greater length vector
  13. if ( builder.getTypeLength( typeB ) > builder.getTypeLength( typeA ) ) {
  14. return typeB;
  15. }
  16. return typeA;
  17. }
  18. generate( builder, output ) {
  19. const type = this.getType( builder );
  20. const a = this.a.build( builder, type );
  21. const b = this.b.build( builder, type );
  22. return builder.format( `( ${a} ${this.op} ${b} )`, type, output );
  23. }
  24. }
  25. export default OperatorNode;