Skip to content

Commit d9d7086

Browse files
committed
simplify local and generator frame read/write nodes
1 parent 913ff7f commit d9d7086

25 files changed

+359
-665
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import com.oracle.graal.python.nodes.argument.ReadVarArgsNode;
6262
import com.oracle.graal.python.nodes.argument.ReadVarKeywordsNode;
6363
import com.oracle.graal.python.nodes.expression.ExpressionNode;
64-
import com.oracle.graal.python.nodes.frame.FrameSlotIDs;
6564
import com.oracle.graal.python.nodes.frame.GlobalNode;
6665
import com.oracle.graal.python.nodes.function.FunctionDefinitionNode;
6766
import com.oracle.graal.python.nodes.function.FunctionRootNode;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ModuleRootNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ public Object execute(VirtualFrame frame) {
9494
public void initializeFrame(VirtualFrame frame) {
9595
addClosureCellsToLocals(frame);
9696
if (doc != null) {
97-
getWriteModuleDoc().doWrite(frame, doc);
97+
getWriteModuleDoc().writeObject(frame, doc);
9898
}
9999
if (hasAnnotations()) {
100-
getWriteAnnotations().doWrite(frame, new PDict(lookupLanguageReference(PythonLanguage.class).get()));
100+
getWriteAnnotations().writeObject(frame, new PDict(lookupLanguageReference(PythonLanguage.class).get()));
101101
}
102102
}
103103

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/SetAttributeNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static SetAttributeNode create(String key, ExpressionNode object, Express
8787
}
8888

8989
@Override
90-
public final void doWrite(VirtualFrame frame, Object value) {
90+
public final void writeObject(VirtualFrame frame, Object value) {
9191
executeVoid(frame, getObject().execute(frame), value);
9292
}
9393

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/cell/WriteLocalCellNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static WriteLocalCellNode create(FrameSlot frameSlot, ExpressionNode read
6262
}
6363

6464
@Override
65-
public void doWrite(VirtualFrame frame, Object value) {
65+
public void writeObject(VirtualFrame frame, Object value) {
6666
executeWithValue(frame, value);
6767
}
6868

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/classes/ReadClassAttributeNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,15 @@ public ExpressionNode getRhs() {
148148
return right;
149149
}
150150

151-
public void doWrite(VirtualFrame frame, Object value) {
152-
writeCellLocal.doWrite(frame, value);
153-
writeNsItem.doWrite(frame, value);
151+
public void writeObject(VirtualFrame frame, Object value) {
152+
writeCellLocal.writeObject(frame, value);
153+
writeNsItem.writeObject(frame, value);
154154
}
155155

156156
@Override
157157
public void executeVoid(VirtualFrame frame) {
158158
Object value = right.execute(frame);
159-
doWrite(frame, value);
159+
writeObject(frame, value);
160160
}
161161
}
162162
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/ForNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected boolean doIntegerIterator(VirtualFrame frame, PIntegerIterator iterato
109109
profiledIterator.setExhausted();
110110
return false;
111111
}
112-
((WriteNode) target).doWrite(frame, profiledIterator.next());
112+
((WriteNode) target).writeInt(frame, profiledIterator.next());
113113
return true;
114114
}
115115

@@ -120,7 +120,7 @@ protected boolean doLongIterator(VirtualFrame frame, PLongSequenceIterator itera
120120
iterator.setExhausted();
121121
return false;
122122
}
123-
((WriteNode) target).doWrite(frame, iterator.next());
123+
((WriteNode) target).writeLong(frame, iterator.next());
124124
return true;
125125
}
126126

@@ -131,7 +131,7 @@ protected boolean doDoubleIterator(VirtualFrame frame, PDoubleSequenceIterator i
131131
iterator.setExhausted();
132132
return false;
133133
}
134-
((WriteNode) target).doWrite(frame, iterator.next());
134+
((WriteNode) target).writeDouble(frame, iterator.next());
135135
return true;
136136
}
137137

@@ -141,7 +141,7 @@ protected boolean doIterator(VirtualFrame frame, Object object,
141141
@Cached("create()") IsBuiltinClassProfile errorProfile,
142142
@Cached PRaiseNode raise) {
143143
try {
144-
((WriteNode) target).doWrite(frame, next.execute(frame, object));
144+
((WriteNode) target).writeObject(frame, next.execute(frame, object));
145145
return true;
146146
} catch (PException e) {
147147
e.expectStopIteration(errorProfile, raise, object);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/DestructuringAssignmentNode.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public final void executeVoid(VirtualFrame frame) {
8181
executeWith(frame, rhsValue);
8282
}
8383

84-
public final void doWrite(VirtualFrame frame, Object rhsValue) {
84+
public final void writeObject(VirtualFrame frame, Object rhsValue) {
8585
executeWith(frame, rhsValue);
8686
}
8787

@@ -128,7 +128,7 @@ private void writeSequenceStorage(VirtualFrame frame, SequenceStorage sequenceSt
128128
} else {
129129
for (int i = 0; i < slots.length; i++) {
130130
Object value = getItemNode.execute(frame, sequenceStorage, i);
131-
slots[i].doWrite(frame, value);
131+
slots[i].writeObject(frame, value);
132132
}
133133
}
134134
}
@@ -217,7 +217,7 @@ void doExploded(VirtualFrame frame, SequenceStorage storage, WriteNode[] slots,
217217
CompilerAsserts.partialEvaluationConstant(starredLength);
218218
Object[] array = consumeStarredItems(frame, storage, starredLength, getItemNode, starredIndex);
219219
assert starredLength == array.length;
220-
slots[starredIndex].doWrite(frame, factory().createList(array));
220+
slots[starredIndex].writeObject(frame, factory().createList(array));
221221
performAssignmentsAfterStar(frame, storage, starredIndex + starredLength, getItemNode, slots, starredIndex);
222222
}
223223
}
@@ -239,10 +239,10 @@ void doGeneric(VirtualFrame frame, SequenceStorage storage, WriteNode[] slots, i
239239
for (int i = 0; i < starredLength; i++) {
240240
array[i] = getItemNode.execute(frame, storage, pos++);
241241
}
242-
slots[starredIndex].doWrite(frame, factory().createList(array));
242+
slots[starredIndex].writeObject(frame, factory().createList(array));
243243
for (int i = starredIndex + 1; i < slots.length; i++) {
244244
Object value = getItemNode.execute(frame, storage, pos++);
245-
slots[i].doWrite(frame, value);
245+
slots[i].writeObject(frame, value);
246246
}
247247
}
248248
}
@@ -251,7 +251,7 @@ void doGeneric(VirtualFrame frame, SequenceStorage storage, WriteNode[] slots, i
251251
private static void writeSlots(VirtualFrame frame, SequenceStorage storage, SequenceStorageNodes.GetItemNode getItemNode, WriteNode[] slots, int starredIndex) {
252252
for (int i = 0; i < starredIndex; i++) {
253253
Object value = getItemNode.execute(frame, storage, i);
254-
slots[i].doWrite(frame, value);
254+
slots[i].writeObject(frame, value);
255255
}
256256
}
257257

@@ -270,7 +270,7 @@ private static void performAssignmentsAfterStar(VirtualFrame frame, SequenceStor
270270
int starredIndex) {
271271
for (int i = starredIndex + 1, pos = startPos; i < slots.length; i++, pos++) {
272272
Object value = getItemNode.execute(frame, sequenceStorage, pos);
273-
slots[i].doWrite(frame, value);
273+
slots[i].writeObject(frame, value);
274274
}
275275
}
276276

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.nodes.frame;
42+
43+
import com.oracle.truffle.api.CompilerDirectives;
44+
import com.oracle.truffle.api.frame.Frame;
45+
import com.oracle.truffle.api.frame.FrameSlot;
46+
import com.oracle.truffle.api.frame.FrameSlotKind;
47+
48+
public abstract class FrameSlotGuards {
49+
50+
private FrameSlotGuards() {
51+
// no instances
52+
}
53+
54+
public static boolean isNotIllegal(Frame frame, FrameSlot frameSlot) {
55+
return frame.getFrameDescriptor().getFrameSlotKind(frameSlot) != FrameSlotKind.Illegal;
56+
}
57+
58+
public static boolean isBooleanKind(Frame frame, FrameSlot frameSlot) {
59+
return isKind(frame, frameSlot, FrameSlotKind.Boolean);
60+
}
61+
62+
public static boolean isIntegerKind(Frame frame, FrameSlot frameSlot) {
63+
return isKind(frame, frameSlot, FrameSlotKind.Int);
64+
}
65+
66+
public static boolean isLongKind(Frame frame, FrameSlot frameSlot) {
67+
return isKind(frame, frameSlot, FrameSlotKind.Long);
68+
}
69+
70+
public static boolean isDoubleKind(Frame frame, FrameSlot frameSlot) {
71+
return isKind(frame, frameSlot, FrameSlotKind.Double);
72+
}
73+
74+
public static boolean isIntOrObjectKind(Frame frame, FrameSlot frameSlot) {
75+
return isKind(frame, frameSlot, FrameSlotKind.Int) || isKind(frame, frameSlot, FrameSlotKind.Object);
76+
}
77+
78+
public static boolean isLongOrObjectKind(Frame frame, FrameSlot frameSlot) {
79+
return isKind(frame, frameSlot, FrameSlotKind.Long) || isKind(frame, frameSlot, FrameSlotKind.Object);
80+
}
81+
82+
public static boolean ensureObjectKind(Frame frame, FrameSlot frameSlot) {
83+
if (frame.getFrameDescriptor().getFrameSlotKind(frameSlot) != FrameSlotKind.Object) {
84+
CompilerDirectives.transferToInterpreterAndInvalidate();
85+
frame.getFrameDescriptor().setFrameSlotKind(frameSlot, FrameSlotKind.Object);
86+
}
87+
return true;
88+
}
89+
90+
private static boolean isKind(Frame frame, FrameSlot frameSlot, FrameSlotKind kind) {
91+
return frame.getFrameDescriptor().getFrameSlotKind(frameSlot) == kind || initialSetKind(frame, frameSlot, kind);
92+
}
93+
94+
private static boolean initialSetKind(Frame frame, FrameSlot frameSlot, FrameSlotKind kind) {
95+
if (frame.getFrameDescriptor().getFrameSlotKind(frameSlot) == FrameSlotKind.Illegal) {
96+
CompilerDirectives.transferToInterpreterAndInvalidate();
97+
frame.getFrameDescriptor().setFrameSlotKind(frameSlot, kind);
98+
return true;
99+
}
100+
return false;
101+
}
102+
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/FrameSlotNode.java

Lines changed: 2 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -25,95 +25,9 @@
2525
*/
2626
package com.oracle.graal.python.nodes.frame;
2727

28-
import com.oracle.graal.python.nodes.expression.ExpressionNode;
29-
import com.oracle.truffle.api.CompilerDirectives;
30-
import com.oracle.truffle.api.frame.Frame;
3128
import com.oracle.truffle.api.frame.FrameSlot;
32-
import com.oracle.truffle.api.frame.FrameSlotKind;
33-
import com.oracle.truffle.api.frame.FrameUtil;
3429

35-
public abstract class FrameSlotNode extends ExpressionNode {
30+
public interface FrameSlotNode {
3631

37-
protected final FrameSlot frameSlot;
38-
39-
public FrameSlotNode(FrameSlot slot) {
40-
this.frameSlot = slot;
41-
}
42-
43-
public final FrameSlot getSlot() {
44-
return frameSlot;
45-
}
46-
47-
protected final void setObject(Frame frame, Object value) {
48-
frame.setObject(frameSlot, value);
49-
}
50-
51-
protected final int getInteger(Frame frame) {
52-
return FrameUtil.getIntSafe(frame, frameSlot);
53-
}
54-
55-
protected final long getLong(Frame frame) {
56-
return FrameUtil.getLongSafe(frame, frameSlot);
57-
}
58-
59-
protected final boolean getBoolean(Frame frame) {
60-
return FrameUtil.getBooleanSafe(frame, frameSlot);
61-
}
62-
63-
protected final double getDouble(Frame frame) {
64-
return FrameUtil.getDoubleSafe(frame, frameSlot);
65-
}
66-
67-
protected final Object getObject(Frame frame) {
68-
return FrameUtil.getObjectSafe(frame, frameSlot);
69-
}
70-
71-
protected final boolean isNotIllegal(Frame frame) {
72-
return frame.getFrameDescriptor().getFrameSlotKind(frameSlot) != FrameSlotKind.Illegal;
73-
}
74-
75-
protected final boolean isBooleanKind(Frame frame) {
76-
return isKind(frame, FrameSlotKind.Boolean);
77-
}
78-
79-
protected final boolean isIntegerKind(Frame frame) {
80-
return isKind(frame, FrameSlotKind.Int);
81-
}
82-
83-
protected final boolean isLongKind(Frame frame) {
84-
return isKind(frame, FrameSlotKind.Long);
85-
}
86-
87-
protected final boolean isDoubleKind(Frame frame) {
88-
return isKind(frame, FrameSlotKind.Double);
89-
}
90-
91-
protected final boolean isIntOrObjectKind(Frame frame) {
92-
return isKind(frame, FrameSlotKind.Int) || isKind(frame, FrameSlotKind.Object);
93-
}
94-
95-
protected final boolean isLongOrObjectKind(Frame frame) {
96-
return isKind(frame, FrameSlotKind.Long) || isKind(frame, FrameSlotKind.Object);
97-
}
98-
99-
protected final boolean ensureObjectKind(Frame frame) {
100-
if (frame.getFrameDescriptor().getFrameSlotKind(frameSlot) != FrameSlotKind.Object) {
101-
CompilerDirectives.transferToInterpreterAndInvalidate();
102-
frame.getFrameDescriptor().setFrameSlotKind(frameSlot, FrameSlotKind.Object);
103-
}
104-
return true;
105-
}
106-
107-
private boolean isKind(Frame frame, FrameSlotKind kind) {
108-
return frame.getFrameDescriptor().getFrameSlotKind(frameSlot) == kind || initialSetKind(frame, kind);
109-
}
110-
111-
private boolean initialSetKind(Frame frame, FrameSlotKind kind) {
112-
if (frame.getFrameDescriptor().getFrameSlotKind(frameSlot) == FrameSlotKind.Illegal) {
113-
CompilerDirectives.transferToInterpreterAndInvalidate();
114-
frame.getFrameDescriptor().setFrameSlotKind(frameSlot, kind);
115-
return true;
116-
}
117-
return false;
118-
}
32+
FrameSlot getSlot();
11933
}

0 commit comments

Comments
 (0)