StackNode.js 897 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Node from './Node.js';
  2. import OperatorNode from '../math/OperatorNode.js';
  3. import BypassNode from '../core/BypassNode.js';
  4. import ExpressionNode from '../core/ExpressionNode.js';
  5. class StackNode extends Node {
  6. constructor() {
  7. super();
  8. this.nodes = [];
  9. this.outputNode = null;
  10. this.isStackNode = true;
  11. }
  12. getNodeType( builder ) {
  13. return this.outputNode ? this.outputNode.getNodeType( builder ) : 'void';
  14. }
  15. add( node ) {
  16. this.nodes.push( new BypassNode( new ExpressionNode(), node ) );
  17. return this;
  18. }
  19. assign( targetNode, sourceValue ) {
  20. return this.add( new OperatorNode( '=', targetNode, sourceValue ) );
  21. }
  22. build( builder, ...params ) {
  23. for ( const node of this.nodes ) {
  24. node.build( builder );
  25. }
  26. return this.outputNode ? this.outputNode.build( builder, ...params ) : super.build( builder, ...params );
  27. }
  28. }
  29. export default StackNode;