|
25 | 25 | */ |
26 | 26 | package com.oracle.graal.python.nodes.generator; |
27 | 27 |
|
28 | | -import com.oracle.graal.python.builtins.objects.PNone; |
29 | 28 | import com.oracle.graal.python.builtins.objects.function.PArguments; |
30 | 29 | import com.oracle.graal.python.builtins.objects.ints.PInt; |
31 | 30 | import com.oracle.graal.python.nodes.expression.ExpressionNode; |
|
37 | 36 | import com.oracle.truffle.api.dsl.Specialization; |
38 | 37 | import com.oracle.truffle.api.frame.Frame; |
39 | 38 | import com.oracle.truffle.api.frame.FrameSlot; |
40 | | -import com.oracle.truffle.api.frame.FrameSlotKind; |
41 | 39 | import com.oracle.truffle.api.frame.VirtualFrame; |
42 | 40 | import com.oracle.truffle.api.nodes.NodeCost; |
43 | 41 | import com.oracle.truffle.api.profiles.ValueProfile; |
@@ -96,51 +94,43 @@ public final boolean executeBoolean(VirtualFrame frame) { |
96 | 94 |
|
97 | 95 | public abstract Object executeWith(VirtualFrame frame, Object value); |
98 | 96 |
|
99 | | - private Frame getGeneratorFrame(VirtualFrame frame) { |
| 97 | + protected Frame getGeneratorFrame(VirtualFrame frame) { |
100 | 98 | return frameProfile.profile(PArguments.getGeneratorFrame(frame)); |
101 | 99 | } |
102 | 100 |
|
103 | | - @Specialization(guards = "isBooleanKind(frame)") |
104 | | - public PNone write(VirtualFrame frame, PNone right) { |
105 | | - getGeneratorFrame(frame).setObject(frameSlot, PNone.NONE); |
106 | | - return right; |
107 | | - } |
108 | | - |
109 | | - @Specialization(guards = "isBooleanKind(frame)") |
| 101 | + @Specialization(guards = "isBooleanKind(getGeneratorFrame(frame))") |
110 | 102 | public boolean write(VirtualFrame frame, boolean right) { |
111 | 103 | getGeneratorFrame(frame).setBoolean(frameSlot, right); |
112 | 104 | return right; |
113 | 105 | } |
114 | 106 |
|
115 | | - @Specialization(guards = "isIntegerKind(frame)") |
| 107 | + @Specialization(guards = "isIntegerKind(getGeneratorFrame(frame))") |
116 | 108 | public int write(VirtualFrame frame, int value) { |
117 | 109 | getGeneratorFrame(frame).setInt(frameSlot, value); |
118 | 110 | return value; |
119 | 111 | } |
120 | 112 |
|
121 | | - @Specialization(guards = {"isLongOrObjectKind(frame)", "isPrimitiveInt(value)", "!value.isNative()"}, rewriteOn = ArithmeticException.class) |
122 | | - public PInt writePIntAsLong(VirtualFrame frame, PInt value) { |
123 | | - Frame generatorFrame = getGeneratorFrame(frame); |
124 | | - generatorFrame.getFrameDescriptor().setFrameSlotKind(frameSlot, FrameSlotKind.Long); |
125 | | - generatorFrame.setLong(frameSlot, value.longValueExact()); |
126 | | - return value; |
| 113 | + @Specialization(guards = {"isPrimitiveInt(value)", "!value.isNative()", "isLongKind(getGeneratorFrame(frame))"}, rewriteOn = ArithmeticException.class) |
| 114 | + public long writeSmallPIntAsLong(VirtualFrame frame, PInt value) { |
| 115 | + long longValue = value.longValueExact(); |
| 116 | + getGeneratorFrame(frame).setLong(frameSlot, longValue); |
| 117 | + return longValue; |
127 | 118 | } |
128 | 119 |
|
129 | | - @Specialization(guards = "isLongOrObjectKind(frame)") |
130 | | - public PInt writePIntAsObject(VirtualFrame frame, PInt value) { |
131 | | - Frame generatorFrame = getGeneratorFrame(frame); |
132 | | - generatorFrame.getFrameDescriptor().setFrameSlotKind(frameSlot, FrameSlotKind.Object); |
133 | | - generatorFrame.setObject(frameSlot, value); |
134 | | - return value; |
| 120 | + @Specialization(guards = {"isPrimitiveInt(value)", "!value.isNative()", "isOrSetObjectKind(getGeneratorFrame(frame))"}, rewriteOn = ArithmeticException.class) |
| 121 | + public long writeSmallPIntAsObject(VirtualFrame frame, PInt value) { |
| 122 | + long longValue = value.longValueExact(); |
| 123 | + getGeneratorFrame(frame).setObject(frameSlot, longValue); |
| 124 | + return longValue; |
135 | 125 | } |
136 | 126 |
|
137 | | - @Specialization(guards = "isDoubleKind(frame)") |
| 127 | + @Specialization(guards = "isDoubleKind(getGeneratorFrame(frame))") |
138 | 128 | public double write(VirtualFrame frame, double right) { |
139 | 129 | getGeneratorFrame(frame).setDouble(frameSlot, right); |
140 | 130 | return right; |
141 | 131 | } |
142 | 132 |
|
143 | | - @Specialization(guards = "isObjectKind(frame)") |
| 133 | + @Specialization(guards = "isOrSetObjectKind(getGeneratorFrame(frame))") |
144 | 134 | public Object write(VirtualFrame frame, Object right) { |
145 | 135 | getGeneratorFrame(frame).setObject(frameSlot, right); |
146 | 136 | return right; |
|
0 commit comments