|
27 | 27 |
|
28 | 28 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
|
29 | 29 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ListGeneralizationNode;
|
30 |
| -import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.NoGeneralizationNode; |
31 | 30 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
32 | 31 | import com.oracle.graal.python.nodes.PNode;
|
33 | 32 | import com.oracle.graal.python.nodes.expression.ExpressionNode;
|
34 | 33 | import com.oracle.graal.python.runtime.object.PythonObjectFactory;
|
| 34 | +import com.oracle.graal.python.runtime.sequence.storage.BoolSequenceStorage; |
| 35 | +import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage; |
| 36 | +import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage; |
| 37 | +import com.oracle.graal.python.runtime.sequence.storage.EmptySequenceStorage; |
| 38 | +import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage; |
| 39 | +import com.oracle.graal.python.runtime.sequence.storage.ListSequenceStorage; |
| 40 | +import com.oracle.graal.python.runtime.sequence.storage.LongSequenceStorage; |
35 | 41 | import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
|
36 | 42 | import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
|
| 43 | +import com.oracle.graal.python.runtime.sequence.storage.TupleSequenceStorage; |
37 | 44 | import com.oracle.truffle.api.CompilerDirectives;
|
38 | 45 | import com.oracle.truffle.api.frame.VirtualFrame;
|
39 | 46 | import com.oracle.truffle.api.nodes.ExplodeLoop;
|
@@ -71,18 +78,51 @@ public Object execute(VirtualFrame frame) {
|
71 | 78 |
|
72 | 79 | @ExplodeLoop
|
73 | 80 | private PTuple expandingTuple(VirtualFrame frame) {
|
| 81 | + SequenceStorage storage; |
74 | 82 | // we will usually have more than 'values.length' elements
|
75 |
| - SequenceStorage storage = new ObjectSequenceStorage(values.length); |
| 83 | + switch (type) { |
| 84 | + case Uninitialized: |
| 85 | + case Empty: |
| 86 | + storage = EmptySequenceStorage.INSTANCE; |
| 87 | + break; |
| 88 | + case Boolean: |
| 89 | + storage = new BoolSequenceStorage(values.length); |
| 90 | + break; |
| 91 | + case Byte: |
| 92 | + storage = new ByteSequenceStorage(values.length); |
| 93 | + break; |
| 94 | + case Double: |
| 95 | + storage = new DoubleSequenceStorage(values.length); |
| 96 | + break; |
| 97 | + case List: |
| 98 | + storage = new ListSequenceStorage(values.length); |
| 99 | + break; |
| 100 | + case Tuple: |
| 101 | + storage = new TupleSequenceStorage(values.length); |
| 102 | + break; |
| 103 | + case Int: |
| 104 | + storage = new IntSequenceStorage(values.length); |
| 105 | + break; |
| 106 | + case Long: |
| 107 | + storage = new LongSequenceStorage(values.length); |
| 108 | + break; |
| 109 | + default: |
| 110 | + storage = new ObjectSequenceStorage(values.length); |
| 111 | + break; |
| 112 | + } |
76 | 113 | for (ExpressionNode n : values) {
|
77 | 114 | if (n instanceof StarredExpressionNode) {
|
78 | 115 | SequenceStorage addElements = ((StarredExpressionNode) n).getStorage(frame);
|
79 | 116 | storage = ensureConcatStoragesNode().execute(storage, addElements);
|
80 | 117 | } else {
|
81 | 118 | Object element = n.execute(frame);
|
82 |
| - storage = ensureAppendNode().execute(storage, element, NoGeneralizationNode.DEFAULT); |
| 119 | + storage = ensureAppendNode().execute(storage, element, ListGeneralizationNode.SUPPLIER); |
83 | 120 | }
|
84 | 121 | }
|
85 |
| - type = storage.getElementType(); |
| 122 | + if (type != storage.getElementType()) { |
| 123 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 124 | + type = storage.getElementType(); |
| 125 | + } |
86 | 126 | return factory.createTuple(storage);
|
87 | 127 | }
|
88 | 128 |
|
|
0 commit comments