Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLEqualNode.java @ 13836:64c77f0577bb
More documentation and improvements of Simple Language
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Thu, 30 Jan 2014 17:53:27 -0800 |
parents | b16ec83edc73 |
children | afd6fa5e8229 |
comparison
equal
deleted
inserted
replaced
13835:67e4e7f56911 | 13836:64c77f0577bb |
---|---|
27 import com.oracle.truffle.api.dsl.*; | 27 import com.oracle.truffle.api.dsl.*; |
28 import com.oracle.truffle.api.nodes.*; | 28 import com.oracle.truffle.api.nodes.*; |
29 import com.oracle.truffle.sl.nodes.*; | 29 import com.oracle.truffle.sl.nodes.*; |
30 import com.oracle.truffle.sl.runtime.*; | 30 import com.oracle.truffle.sl.runtime.*; |
31 | 31 |
32 /** | |
33 * The {@code ==} operator of SL is defined on all types. Therefore, we need a (@link | |
34 * {@link #equal(Object, Object) generic implementation} that can handle all possible types. But | |
35 * since {@code ==} can only return {@code true} when the type of the left and right operand are the | |
36 * same, the specializations already cover all possible cases that can return {@code true} and the | |
37 * generic case is trivial. | |
38 * <p> | |
39 * Note that we do not need the analogous {@code =!} operator, because we can just | |
40 * {@link SLLogicalNotNode negate} the {@code ==} operator. | |
41 */ | |
32 @NodeInfo(shortName = "==") | 42 @NodeInfo(shortName = "==") |
33 public abstract class SLEqualNode extends SLBinaryNode { | 43 public abstract class SLEqualNode extends SLBinaryNode { |
34 | 44 |
35 @Specialization | 45 @Specialization |
36 protected boolean equal(long left, long right) { | 46 protected boolean equal(long left, long right) { |
65 protected boolean equal(SLNull left, SLNull right) { | 75 protected boolean equal(SLNull left, SLNull right) { |
66 /* There is only the singleton instance of SLNull, so we do not need equals(). */ | 76 /* There is only the singleton instance of SLNull, so we do not need equals(). */ |
67 return left == right; | 77 return left == right; |
68 } | 78 } |
69 | 79 |
80 /** | |
81 * The {@link Generic} annotation informs that Truffle DSL that this method should be executed | |
82 * when no {@link Specialization specialized method} matches. The operand types must be | |
83 * {@link Object}. | |
84 */ | |
70 @Generic | 85 @Generic |
71 protected boolean equal(Object left, Object right) { | 86 protected boolean equal(Object left, Object right) { |
72 /* | 87 /* |
73 * We covered all the cases that can return true in specializations. If we compare two | 88 * We covered all the cases that can return true in specializations. If we compare two |
74 * values with different types, no specialization matches and we end up here. | 89 * values with different types, no specialization matches and we end up here. |