Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/local/SLReadArgumentNode.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 |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.truffle.sl.nodes.local; | 23 package com.oracle.truffle.sl.nodes.local; |
24 | 24 |
25 import com.oracle.truffle.api.*; | |
25 import com.oracle.truffle.api.frame.*; | 26 import com.oracle.truffle.api.frame.*; |
26 import com.oracle.truffle.api.utilities.*; | 27 import com.oracle.truffle.api.utilities.*; |
27 import com.oracle.truffle.sl.nodes.*; | 28 import com.oracle.truffle.sl.nodes.*; |
29 import com.oracle.truffle.sl.parser.*; | |
28 import com.oracle.truffle.sl.runtime.*; | 30 import com.oracle.truffle.sl.runtime.*; |
29 | 31 |
32 /** | |
33 * Reads a function argument. Arguments are passed in as a {@link SLArguments} object, which | |
34 * encapsulates an {@link SLArguments#getFromFrame Object[] array}. Language-defined subclasses of | |
35 * {@link Arguments} are the standard Truffle way to pass values between function. | |
36 * <p> | |
37 * Arguments are not type-specialized. To ensure that repeated accesses within a method are | |
38 * specialized and can, e.g., accessed without unboxing, all arguments are loaded into local | |
39 * variables {@link SLNodeFactory#addFormalParameter in the method prologue}. | |
40 */ | |
30 public class SLReadArgumentNode extends SLExpressionNode { | 41 public class SLReadArgumentNode extends SLExpressionNode { |
31 | 42 |
43 /** The argument number, i.e., the index into the array of arguments. */ | |
32 private final int index; | 44 private final int index; |
33 | 45 |
46 /** | |
47 * Profiling information, collected by the interpreter, capturing whether the function was | |
48 * called with fewer actual arguments than formal arguments. | |
49 */ | |
34 private final BranchProfile outOfBoundsTaken = new BranchProfile(); | 50 private final BranchProfile outOfBoundsTaken = new BranchProfile(); |
35 | 51 |
36 public SLReadArgumentNode(int index) { | 52 public SLReadArgumentNode(int index) { |
37 this.index = index; | 53 this.index = index; |
38 } | 54 } |
41 public Object executeGeneric(VirtualFrame frame) { | 57 public Object executeGeneric(VirtualFrame frame) { |
42 Object[] args = SLArguments.getFromFrame(frame); | 58 Object[] args = SLArguments.getFromFrame(frame); |
43 if (index < args.length) { | 59 if (index < args.length) { |
44 return args[index]; | 60 return args[index]; |
45 } else { | 61 } else { |
62 /* In the interpreter, record profiling information that the branch was used. */ | |
46 outOfBoundsTaken.enter(); | 63 outOfBoundsTaken.enter(); |
64 /* Use the default null value. */ | |
47 return SLNull.SINGLETON; | 65 return SLNull.SINGLETON; |
48 } | 66 } |
49 } | 67 } |
50 } | 68 } |