Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.ruby.runtime/src/com/oracle/truffle/ruby/runtime/RubyArguments.java @ 13514:0fbee3eb71f0
Ruby: import project.
author | Chris Seaton <chris.seaton@oracle.com> |
---|---|
date | Mon, 06 Jan 2014 17:12:09 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13513:64a23ce736a0 | 13514:0fbee3eb71f0 |
---|---|
1 /* | |
2 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. This | |
3 * code is released under a tri EPL/GPL/LGPL license. You can use it, | |
4 * redistribute it and/or modify it under the terms of the: | |
5 * | |
6 * Eclipse Public License version 1.0 | |
7 * GNU General Public License version 2 | |
8 * GNU Lesser General Public License version 2.1 | |
9 */ | |
10 package com.oracle.truffle.ruby.runtime; | |
11 | |
12 import com.oracle.truffle.api.*; | |
13 import com.oracle.truffle.api.frame.*; | |
14 import com.oracle.truffle.api.nodes.*; | |
15 import com.oracle.truffle.ruby.runtime.core.*; | |
16 | |
17 /** | |
18 * Arguments and other context passed to a Ruby method. Includes the central Ruby context object, | |
19 * optionally the scope at the point of declaration (forming a closure), the value of self, a passed | |
20 * block, and the formal arguments. | |
21 */ | |
22 public final class RubyArguments extends Arguments { | |
23 | |
24 private final MaterializedFrame declarationFrame; | |
25 private final Object self; | |
26 private final RubyProc block; | |
27 private final Object[] arguments; | |
28 | |
29 public RubyArguments(MaterializedFrame declarationFrame, Object self, RubyProc block, Object... arguments) { | |
30 assert self != null; | |
31 assert arguments != null; | |
32 | |
33 this.declarationFrame = declarationFrame; | |
34 this.self = self; | |
35 this.block = block; | |
36 this.arguments = arguments; | |
37 } | |
38 | |
39 public MaterializedFrame getDeclarationFrame() { | |
40 return declarationFrame; | |
41 } | |
42 | |
43 /** | |
44 * Get the declaration frame a certain number of levels up from the current frame, where the | |
45 * current frame is 0. | |
46 */ | |
47 public static MaterializedFrame getDeclarationFrame(VirtualFrame frame, int level) { | |
48 assert level > 0; | |
49 | |
50 MaterializedFrame parentFrame = frame.getArguments(RubyArguments.class).getDeclarationFrame(); | |
51 return getDeclarationFrame(parentFrame, level - 1); | |
52 } | |
53 | |
54 /** | |
55 * Get the declaration frame a certain number of levels up from the current frame, where the | |
56 * current frame is 0. | |
57 */ | |
58 @ExplodeLoop | |
59 private static MaterializedFrame getDeclarationFrame(MaterializedFrame frame, int level) { | |
60 assert frame != null; | |
61 assert level >= 0; | |
62 | |
63 MaterializedFrame parentFrame = frame; | |
64 | |
65 for (int n = 0; n < level; n++) { | |
66 parentFrame = parentFrame.getArguments(RubyArguments.class).getDeclarationFrame(); | |
67 } | |
68 | |
69 return parentFrame; | |
70 } | |
71 | |
72 public Object getSelf() { | |
73 return self; | |
74 } | |
75 | |
76 public RubyProc getBlock() { | |
77 return block; | |
78 } | |
79 | |
80 public Object[] getArguments() { | |
81 return arguments; | |
82 } | |
83 | |
84 } |