/
CachedDispatchSimpleCheckNode.java
65 lines (54 loc) · 1.96 KB
/
CachedDispatchSimpleCheckNode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package som.interpreter.nodes.dispatch;
import som.interpreter.nodes.dispatch.AbstractDispatchNode.AbstractCachedDispatchNode;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.frame.VirtualFrame;
public final class CachedDispatchSimpleCheckNode extends AbstractCachedDispatchNode {
private final Class<?> expectedClass;
public CachedDispatchSimpleCheckNode(final Class<?> rcvrClass,
final CallTarget callTarget, final AbstractDispatchNode nextInCache) {
super(callTarget, nextInCache);
this.expectedClass = rcvrClass;
}
@Override
public Object executeDispatch(final VirtualFrame frame,
final Object[] arguments) {
Object rcvr = arguments[0];
if (rcvr.getClass() == expectedClass) {
return cachedMethod.call(frame, arguments);
} else {
return nextInCache.executeDispatch(frame, arguments);
}
}
public static final class CachedDispatchTrueCheckNode
extends AbstractCachedDispatchNode {
public CachedDispatchTrueCheckNode(final CallTarget callTarget,
final AbstractDispatchNode nextInCache) {
super(callTarget, nextInCache);
}
@Override
public Object executeDispatch(final VirtualFrame frame,
final Object[] arguments) {
if (arguments[0] == Boolean.TRUE) {
return cachedMethod.call(frame, arguments);
} else {
return nextInCache.executeDispatch(frame, arguments);
}
}
}
public static final class CachedDispatchFalseCheckNode
extends AbstractCachedDispatchNode {
public CachedDispatchFalseCheckNode(final CallTarget callTarget,
final AbstractDispatchNode nextInCache) {
super(callTarget, nextInCache);
}
@Override
public Object executeDispatch(final VirtualFrame frame,
final Object[] arguments) {
if (arguments[0] == Boolean.FALSE) {
return cachedMethod.call(frame, arguments);
} else {
return nextInCache.executeDispatch(frame, arguments);
}
}
}
}