Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLFunctionBodyNode.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 |
---|---|
26 import com.oracle.truffle.api.nodes.*; | 26 import com.oracle.truffle.api.nodes.*; |
27 import com.oracle.truffle.api.utilities.*; | 27 import com.oracle.truffle.api.utilities.*; |
28 import com.oracle.truffle.sl.nodes.*; | 28 import com.oracle.truffle.sl.nodes.*; |
29 import com.oracle.truffle.sl.runtime.*; | 29 import com.oracle.truffle.sl.runtime.*; |
30 | 30 |
31 /** | |
32 * The body of a user-defined SL function. This is the node references by a {@link SLRootNode} for | |
33 * user-defined functions. It handles the return value of a function: the {@link SLReturnNode return | |
34 * statement} throws an {@link SLReturnException exception} with the return value. This node catches | |
35 * the exception. If the method ends without an explicit {@code return}, return the | |
36 * {@link SLNull#SINGLETON default null value}. | |
37 */ | |
31 @NodeInfo(shortName = "body") | 38 @NodeInfo(shortName = "body") |
32 public class SLFunctionBodyNode extends SLExpressionNode { | 39 public class SLFunctionBodyNode extends SLExpressionNode { |
33 | 40 |
41 /** The body of the function. */ | |
34 @Child private SLStatementNode bodyNode; | 42 @Child private SLStatementNode bodyNode; |
35 | 43 |
44 /** | |
45 * Profiling information, collected by the interpreter, capturing whether the function had an | |
46 * {@link SLReturnNode explicit return statement}. This allows the compiler to generate better | |
47 * code. | |
48 */ | |
36 private final BranchProfile exceptionTaken = new BranchProfile(); | 49 private final BranchProfile exceptionTaken = new BranchProfile(); |
37 private final BranchProfile nullTaken = new BranchProfile(); | 50 private final BranchProfile nullTaken = new BranchProfile(); |
38 | 51 |
39 public SLFunctionBodyNode(SLStatementNode bodyNode) { | 52 public SLFunctionBodyNode(SLStatementNode bodyNode) { |
53 /* | |
54 * It is a Truffle requirement to call adoptChild(), which performs all the necessary steps | |
55 * to add the new child to the node tree. | |
56 */ | |
40 this.bodyNode = adoptChild(bodyNode); | 57 this.bodyNode = adoptChild(bodyNode); |
41 } | 58 } |
42 | 59 |
43 @Override | 60 @Override |
44 public Object executeGeneric(VirtualFrame frame) { | 61 public Object executeGeneric(VirtualFrame frame) { |
45 try { | 62 try { |
63 /* Execute the function body. */ | |
46 bodyNode.executeVoid(frame); | 64 bodyNode.executeVoid(frame); |
65 | |
47 } catch (SLReturnException ex) { | 66 } catch (SLReturnException ex) { |
67 /* | |
68 * In the interpreter, record profiling information that the function has an explicit | |
69 * return. | |
70 */ | |
48 exceptionTaken.enter(); | 71 exceptionTaken.enter(); |
72 /* The exception transports the actual return value. */ | |
49 return ex.getResult(); | 73 return ex.getResult(); |
50 } | 74 } |
75 | |
76 /* | |
77 * In the interpreter, record profiling information that the function ends without an | |
78 * explicit return. | |
79 */ | |
51 nullTaken.enter(); | 80 nullTaken.enter(); |
81 /* Return the default null value. */ | |
52 return SLNull.SINGLETON; | 82 return SLNull.SINGLETON; |
53 } | 83 } |
54 } | 84 } |