Mercurial > hg > truffle
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLogicalAndNode.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 | abe7128ca473 |
comparison
equal
deleted
inserted
replaced
13835:67e4e7f56911 | 13836:64c77f0577bb |
---|---|
24 | 24 |
25 import com.oracle.truffle.api.dsl.*; | 25 import com.oracle.truffle.api.dsl.*; |
26 import com.oracle.truffle.api.nodes.*; | 26 import com.oracle.truffle.api.nodes.*; |
27 import com.oracle.truffle.sl.nodes.*; | 27 import com.oracle.truffle.sl.nodes.*; |
28 | 28 |
29 /** | |
30 * This class declares specializations similar to the extensively documented {@link SLAddNode}. It | |
31 * uses one additional feature of the Truffle DSL: {@link ShortCircuit}. | |
32 * <p> | |
33 * Logical operations in SL use short circuit evaluation: if the evaluation of the left operand | |
34 * already decides the result of the operation, the right operand must not be executed. This is | |
35 * expressed in the Truffle DSL via a method annotated with {@link ShortCircuit}, which returns | |
36 * whether a child needs to be executed based on the result of already executed children. | |
37 */ | |
29 @NodeInfo(shortName = "&&") | 38 @NodeInfo(shortName = "&&") |
30 @SuppressWarnings("unused") | 39 @SuppressWarnings("unused") |
31 public abstract class SLLogicalAndNode extends SLBinaryNode { | 40 public abstract class SLLogicalAndNode extends SLBinaryNode { |
32 | 41 |
42 /** | |
43 * This method is called after the left child was evaluated, but before the right child is | |
44 * evaluated. The right child is only evaluated when the return value is {code true}. | |
45 */ | |
33 @ShortCircuit("rightNode") | 46 @ShortCircuit("rightNode") |
34 protected boolean needsRightNode(boolean left) { | 47 protected boolean needsRightNode(boolean left) { |
35 return left; | 48 return left; |
36 } | 49 } |
37 | 50 |
51 /** | |
52 * Similar to {@link #needsRightNode(boolean)}, but for generic cases where the type of the left | |
53 * child is not known. | |
54 */ | |
38 @ShortCircuit("rightNode") | 55 @ShortCircuit("rightNode") |
39 protected boolean needsRightNode(Object left) { | 56 protected boolean needsRightNode(Object left) { |
40 return left instanceof Boolean && needsRightNode(((Boolean) left).booleanValue()); | 57 return left instanceof Boolean && needsRightNode(((Boolean) left).booleanValue()); |
41 } | 58 } |
42 | 59 |