comparison graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/core/ArrayConcatNode.java @ 13529:856c2c294f84

Merge.
author Christian Humer <christian.humer@gmail.com>
date Tue, 07 Jan 2014 18:53:04 +0100
parents 0fbee3eb71f0
children
comparison
equal deleted inserted replaced
13528:5a0c694ef735 13529:856c2c294f84
1 /*
2 * Copyright (c) 2013 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 com.oracle.truffle.ruby.nodes.core;
11
12 import com.oracle.truffle.api.*;
13 import com.oracle.truffle.api.frame.*;
14 import com.oracle.truffle.api.nodes.*;
15 import com.oracle.truffle.ruby.nodes.*;
16 import com.oracle.truffle.ruby.runtime.*;
17 import com.oracle.truffle.ruby.runtime.core.array.*;
18
19 /**
20 * Concatenate arrays.
21 */
22 @NodeInfo(shortName = "array-concat")
23 public final class ArrayConcatNode extends RubyNode {
24
25 @Children protected final RubyNode[] children;
26
27 public ArrayConcatNode(RubyContext context, SourceSection sourceSection, RubyNode[] children) {
28 super(context, sourceSection);
29 assert children.length > 1;
30 this.children = adoptChildren(children);
31 }
32
33 @ExplodeLoop
34 @Override
35 public Object execute(VirtualFrame frame) {
36 final RubyArray array = new RubyArray(getContext().getCoreLibrary().getArrayClass());
37
38 for (int n = 0; n < children.length; n++) {
39 final Object childObject = children[n].execute(frame);
40
41 if (childObject instanceof RubyArray) {
42 // setRangeArray has special cases for setting a zero-length range at the end
43 final int end = array.size();
44 array.setRangeArrayExclusive(end, end, (RubyArray) childObject);
45 } else {
46 array.push(childObject);
47 }
48 }
49
50 return array;
51 }
52
53 @ExplodeLoop
54 @Override
55 public void executeVoid(VirtualFrame frame) {
56 for (int n = 0; n < children.length; n++) {
57 children[n].executeVoid(frame);
58 }
59 }
60
61 }