Skip to content

Commit 2b02300

Browse files
committed
Remove object layout handling and field access specialization.
Signed-off-by: Stefan Marr <git@stefan-marr.de>
1 parent b912103 commit 2b02300

File tree

8 files changed

+36
-1440
lines changed

8 files changed

+36
-1440
lines changed

src/som/interpreter/SNodeFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import som.interpreter.nodes.ExpressionNode;
1313
import som.interpreter.nodes.FieldNode.FieldReadNode;
1414
import som.interpreter.nodes.FieldNode.FieldWriteNode;
15+
import som.interpreter.nodes.FieldNodeFactory.FieldReadNodeFactory;
1516
import som.interpreter.nodes.FieldNodeFactory.FieldWriteNodeFactory;
1617
import som.interpreter.nodes.GlobalNode;
1718
import som.interpreter.nodes.GlobalNode.UninitializedGlobalReadNode;
@@ -56,7 +57,7 @@ public static CatchNonLocalReturnNode createCatchNonLocalReturn(
5657

5758
public static FieldReadNode createFieldRead(final ExpressionNode self,
5859
final int fieldIndex, final SourceSection source) {
59-
return new FieldReadNode(self, fieldIndex, source);
60+
return FieldReadNodeFactory.create(fieldIndex, source, self);
6061
}
6162

6263
public static GlobalNode createGlobalRead(final String name,

src/som/interpreter/nodes/FieldNode.java

Lines changed: 21 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,22 @@
2222
package som.interpreter.nodes;
2323

2424
import som.interpreter.nodes.UninitializedVariableNode.UninitializedVariableReadNode;
25-
import som.interpreter.objectstorage.FieldAccessorNode.AbstractReadFieldNode;
26-
import som.interpreter.objectstorage.FieldAccessorNode.AbstractWriteFieldNode;
27-
import som.interpreter.objectstorage.FieldAccessorNode.UninitializedReadFieldNode;
28-
import som.interpreter.objectstorage.FieldAccessorNode.UninitializedWriteFieldNode;
2925
import som.vmobjects.SObject;
3026

3127
import com.oracle.truffle.api.CompilerDirectives;
3228
import com.oracle.truffle.api.dsl.NodeChild;
3329
import com.oracle.truffle.api.dsl.NodeChildren;
3430
import com.oracle.truffle.api.dsl.Specialization;
3531
import com.oracle.truffle.api.frame.VirtualFrame;
36-
import com.oracle.truffle.api.nodes.UnexpectedResultException;
3732
import com.oracle.truffle.api.source.SourceSection;
3833

3934
public abstract class FieldNode extends ExpressionNode {
4035

41-
protected FieldNode(final SourceSection source) {
36+
protected final int fieldIndex;
37+
38+
protected FieldNode(final int fieldIndex, final SourceSection source) {
4239
super(source);
40+
this.fieldIndex = fieldIndex;
4341
}
4442

4543
protected abstract ExpressionNode getSelf();
@@ -53,108 +51,60 @@ public final boolean accessesLocalSelf() {
5351
return false;
5452
}
5553

56-
public static final class FieldReadNode extends FieldNode
54+
@NodeChild(value = "self", type = ExpressionNode.class)
55+
public abstract static class FieldReadNode extends FieldNode
5756
implements PreevaluatedExpression {
58-
@Child private ExpressionNode self;
59-
@Child private AbstractReadFieldNode read;
60-
61-
public FieldReadNode(final ExpressionNode self, final int fieldIndex,
62-
final SourceSection source) {
63-
super(source);
64-
this.self = self;
65-
read = new UninitializedReadFieldNode(fieldIndex);
57+
58+
public FieldReadNode(final int fieldIndex, final SourceSection source) {
59+
super(fieldIndex, source);
6660
}
6761

6862
public FieldReadNode(final FieldReadNode node) {
69-
this(node.self, node.read.getFieldIndex(), node.getSourceSection());
63+
this(node.fieldIndex, node.getSourceSection());
7064
}
7165

7266
@Override
73-
protected ExpressionNode getSelf() {
74-
return self;
75-
}
67+
protected abstract ExpressionNode getSelf();
7668

77-
public Object executeEvaluated(final SObject obj) {
78-
return read.read(obj);
69+
@Specialization
70+
public Object doObject(final SObject self) {
71+
return self.getField(fieldIndex);
7972
}
8073

8174
@Override
8275
public Object doPreEvaluated(final VirtualFrame frame,
8376
final Object[] arguments) {
84-
return executeEvaluated(CompilerDirectives.unsafeCast(
77+
return doObject(CompilerDirectives.unsafeCast(
8578
arguments[0], SObject.class, true, true));
8679
}
87-
88-
@Override
89-
public long executeLong(final VirtualFrame frame) throws UnexpectedResultException {
90-
SObject obj = self.executeSObject(frame);
91-
return read.readLong(obj);
92-
}
93-
94-
@Override
95-
public double executeDouble(final VirtualFrame frame) throws UnexpectedResultException {
96-
SObject obj = self.executeSObject(frame);
97-
return read.readDouble(obj);
98-
}
99-
100-
@Override
101-
public Object executeGeneric(final VirtualFrame frame) {
102-
SObject obj;
103-
try {
104-
obj = self.executeSObject(frame);
105-
} catch (UnexpectedResultException e) {
106-
CompilerDirectives.transferToInterpreter();
107-
throw new RuntimeException("This should never happen by construction");
108-
}
109-
return executeEvaluated(obj);
110-
}
11180
}
11281

11382
@NodeChildren({
11483
@NodeChild(value = "self", type = ExpressionNode.class),
11584
@NodeChild(value = "value", type = ExpressionNode.class)})
11685
public abstract static class FieldWriteNode extends FieldNode
11786
implements PreevaluatedExpression {
118-
@Child private AbstractWriteFieldNode write;
11987

12088
public FieldWriteNode(final int fieldIndex, final SourceSection source) {
121-
super(source);
122-
write = new UninitializedWriteFieldNode(fieldIndex);
89+
super(fieldIndex, source);
12390
}
12491

12592
public FieldWriteNode(final FieldWriteNode node) {
126-
this(node.write.getFieldIndex(), node.getSourceSection());
127-
}
128-
129-
public final Object executeEvaluated(final VirtualFrame frame,
130-
final SObject self, final Object value) {
131-
return write.write(self, value);
93+
this(node.fieldIndex, node.getSourceSection());
13294
}
13395

13496
@Override
13597
public final Object doPreEvaluated(final VirtualFrame frame,
13698
final Object[] arguments) {
137-
return executeEvaluated(frame,
99+
return doObject(
138100
CompilerDirectives.unsafeCast(arguments[0], SObject.class, true, true),
139101
CompilerDirectives.unsafeCast(arguments[1], Object.class, true, true));
140102
}
141103

142104
@Specialization
143-
public long doLong(final VirtualFrame frame, final SObject self,
144-
final long value) {
145-
return write.write(self, value);
146-
}
147-
148-
@Specialization
149-
public double doDouble(final VirtualFrame frame, final SObject self,
150-
final double value) {
151-
return write.write(self, value);
152-
}
153-
154-
@Specialization
155-
public Object doObject(final VirtualFrame frame, final SObject self,
156-
final Object value) {
157-
return executeEvaluated(frame, self, value);
105+
public Object doObject(final SObject self, final Object value) {
106+
self.setField(fieldIndex, value);
107+
return value;
158108
}
159109
}
160110
}

0 commit comments

Comments
 (0)