ConcatHashLiteralNode.java

  1. /*
  2.  * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. This
  3.  * code is released under a tri EPL/GPL/LGPL license. You can use it,
  4.  * redistribute it and/or modify it under the terms of the:
  5.  *
  6.  * Eclipse Public License version 1.0
  7.  * GNU General Public License version 2
  8.  * GNU Lesser General Public License version 2.1
  9.  */
  10. package org.jruby.truffle.nodes.literal;

  11. import com.oracle.truffle.api.frame.VirtualFrame;
  12. import com.oracle.truffle.api.nodes.UnexpectedResultException;
  13. import com.oracle.truffle.api.source.SourceSection;
  14. import org.jruby.truffle.nodes.RubyNode;
  15. import org.jruby.truffle.runtime.RubyContext;
  16. import org.jruby.truffle.runtime.core.RubyHash;
  17. import org.jruby.truffle.runtime.hash.HashOperations;
  18. import org.jruby.truffle.runtime.hash.KeyValue;

  19. import java.util.ArrayList;
  20. import java.util.List;

  21. public class ConcatHashLiteralNode extends RubyNode {

  22.     @Children protected final RubyNode[] children;

  23.     public ConcatHashLiteralNode(RubyContext context, SourceSection sourceSection, RubyNode[] children) {
  24.         super(context, sourceSection);
  25.         this.children = children;
  26.     }

  27.     @Override
  28.     public RubyHash executeRubyHash(VirtualFrame frame) {
  29.         notDesignedForCompilation();

  30.         final List<KeyValue> keyValues = new ArrayList<>();

  31.         for (RubyNode child : children) {
  32.             try {
  33.                 keyValues.addAll(HashOperations.verySlowToKeyValues(child.executeRubyHash(frame)));
  34.             } catch (UnexpectedResultException e) {
  35.                 throw new UnsupportedOperationException();
  36.             }
  37.         }

  38.         return HashOperations.verySlowFromEntries(getContext(), keyValues);
  39.     }

  40.     @Override
  41.     public Object execute(VirtualFrame frame) {
  42.         return executeRubyHash(frame);
  43.     }

  44. }