comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLReturnNode.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
25 import com.oracle.truffle.api.frame.*; 25 import com.oracle.truffle.api.frame.*;
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 import com.oracle.truffle.sl.runtime.*; 28 import com.oracle.truffle.sl.runtime.*;
29 29
30 /**
31 * Implementation of the SL return statement. We need to unwind an unknown number of interpreter
32 * frames that are between this {@link SLReturnNode} and the {@link SLFunctionBodyNode} of the
33 * method we are exiting. This is done by throwing an {@link SLReturnException exception} that is
34 * caught by the {@link SLFunctionBodyNode#executeGeneric function body}. The exception transports
35 * the return value.
36 */
30 @NodeInfo(shortName = "return") 37 @NodeInfo(shortName = "return")
31 public class SLReturnNode extends SLStatementNode { 38 public class SLReturnNode extends SLStatementNode {
32 39
33 @Child private SLExpressionNode valueNode; 40 @Child private SLExpressionNode valueNode;
34 41
40 public void executeVoid(VirtualFrame frame) { 47 public void executeVoid(VirtualFrame frame) {
41 Object result; 48 Object result;
42 if (valueNode != null) { 49 if (valueNode != null) {
43 result = valueNode.executeGeneric(frame); 50 result = valueNode.executeGeneric(frame);
44 } else { 51 } else {
52 /* Return statement that was not followed by an expression, so return the SL null value. */
45 result = SLNull.SINGLETON; 53 result = SLNull.SINGLETON;
46 } 54 }
47 throw new SLReturnException(result); 55 throw new SLReturnException(result);
48 } 56 }
49 } 57 }