annotate truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLogicalAndNode.java @ 21951:9c8c0937da41

Moving all sources into truffle subdirectory
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 17 Jun 2015 10:58:08 +0200
parents graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLogicalAndNode.java@c0455554d45b
children c07e64ecb528
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7503
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
7503
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 10597
diff changeset
23 package com.oracle.truffle.sl.nodes.expression;
7503
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents: 9222
diff changeset
25 import com.oracle.truffle.api.dsl.*;
20953
c0455554d45b SL: some minor simplifications.
Christian Humer <christian.humer@gmail.com>
parents: 16512
diff changeset
26 import com.oracle.truffle.api.frame.*;
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
27 import com.oracle.truffle.api.nodes.*;
16512
abe7128ca473 SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13836
diff changeset
28 import com.oracle.truffle.api.source.*;
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 10597
diff changeset
29 import com.oracle.truffle.sl.nodes.*;
7503
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30
13836
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
31 /**
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
32 * This class declares specializations similar to the extensively documented {@link SLAddNode}. It
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
33 * uses one additional feature of the Truffle DSL: {@link ShortCircuit}.
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
34 * <p>
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
35 * Logical operations in SL use short circuit evaluation: if the evaluation of the left operand
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
36 * already decides the result of the operation, the right operand must not be executed. This is
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
37 * expressed in the Truffle DSL via a method annotated with {@link ShortCircuit}, which returns
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
38 * whether a child needs to be executed based on the result of already executed children.
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
39 */
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
40 @NodeInfo(shortName = "&&")
7503
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 @SuppressWarnings("unused")
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 10597
diff changeset
42 public abstract class SLLogicalAndNode extends SLBinaryNode {
7503
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43
16512
abe7128ca473 SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13836
diff changeset
44 public SLLogicalAndNode(SourceSection src) {
abe7128ca473 SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13836
diff changeset
45 super(src);
abe7128ca473 SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13836
diff changeset
46 }
abe7128ca473 SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13836
diff changeset
47
20953
c0455554d45b SL: some minor simplifications.
Christian Humer <christian.humer@gmail.com>
parents: 16512
diff changeset
48 @Override
c0455554d45b SL: some minor simplifications.
Christian Humer <christian.humer@gmail.com>
parents: 16512
diff changeset
49 public abstract boolean executeBoolean(VirtualFrame frame);
c0455554d45b SL: some minor simplifications.
Christian Humer <christian.humer@gmail.com>
parents: 16512
diff changeset
50
13836
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
51 /**
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
52 * This method is called after the left child was evaluated, but before the right child is
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
53 * evaluated. The right child is only evaluated when the return value is {code true}.
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
54 */
7503
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55 @ShortCircuit("rightNode")
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
56 protected boolean needsRightNode(boolean left) {
7503
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57 return left;
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 }
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59
13836
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
60 /**
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
61 * Similar to {@link #needsRightNode(boolean)}, but for generic cases where the type of the left
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
62 * child is not known.
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
63 */
7503
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 @ShortCircuit("rightNode")
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
65 protected boolean needsRightNode(Object left) {
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 10597
diff changeset
66 return left instanceof Boolean && needsRightNode(((Boolean) left).booleanValue());
7503
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 }
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
69 @Specialization
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
70 protected boolean doBoolean(boolean left, boolean hasRight, boolean right) {
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 10597
diff changeset
71 return left && right;
7503
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72 }
31da1716950f Updated truffle-sl for the changed operation code generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
73 }