Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/methods/MethodDefinitionNode.java @ 13568:f29a358cf3da
Ruby: minor tweaks to implementation nodes for debugging access
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Wed, 08 Jan 2014 14:00:21 -0800 |
parents | 0fbee3eb71f0 |
children | 62bfc12dc9e1 |
rev | line source |
---|---|
13514 | 1 /* |
13568
f29a358cf3da
Ruby: minor tweaks to implementation nodes for debugging access
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13514
diff
changeset
|
2 * Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This |
13514 | 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.nodes.methods; | |
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.nodes.*; | |
16 import com.oracle.truffle.ruby.runtime.*; | |
17 import com.oracle.truffle.ruby.runtime.core.*; | |
18 import com.oracle.truffle.ruby.runtime.methods.*; | |
19 | |
20 /** | |
21 * Define a method. That is, store the definition of a method and when executed produce the | |
22 * executable object that results. | |
23 */ | |
24 @NodeInfo(shortName = "method-def") | |
25 public class MethodDefinitionNode extends RubyNode { | |
26 | |
27 protected final String name; | |
28 protected final UniqueMethodIdentifier uniqueIdentifier; | |
29 | |
30 protected final FrameDescriptor frameDescriptor; | |
31 protected final RubyRootNode pristineRootNode; | |
32 | |
33 protected final CallTarget callTarget; | |
34 | |
35 protected final boolean requiresDeclarationFrame; | |
36 | |
37 public MethodDefinitionNode(RubyContext context, SourceSection sourceSection, String name, UniqueMethodIdentifier uniqueIdentifier, FrameDescriptor frameDescriptor, | |
38 boolean requiresDeclarationFrame, RubyRootNode pristineRootNode, CallTarget callTarget) { | |
39 super(context, sourceSection); | |
40 this.name = name; | |
41 this.uniqueIdentifier = uniqueIdentifier; | |
42 this.frameDescriptor = frameDescriptor; | |
43 this.requiresDeclarationFrame = requiresDeclarationFrame; | |
44 this.pristineRootNode = pristineRootNode; | |
45 this.callTarget = callTarget; | |
46 } | |
47 | |
48 public RubyMethod executeMethod(VirtualFrame frame) { | |
49 CompilerDirectives.transferToInterpreter(); | |
50 | |
51 MaterializedFrame declarationFrame; | |
52 | |
53 if (requiresDeclarationFrame) { | |
54 declarationFrame = frame.materialize(); | |
55 } else { | |
56 declarationFrame = null; | |
57 } | |
58 | |
59 final FrameSlot visibilitySlot = frame.getFrameDescriptor().findFrameSlot(RubyModule.VISIBILITY_FRAME_SLOT_ID); | |
60 | |
61 Visibility visibility; | |
62 | |
63 if (visibilitySlot == null) { | |
64 visibility = Visibility.PUBLIC; | |
65 } else { | |
66 Object visibilityObject; | |
67 | |
68 try { | |
69 visibilityObject = frame.getObject(visibilitySlot); | |
70 } catch (FrameSlotTypeException e) { | |
71 throw new RuntimeException(e); | |
72 } | |
73 | |
74 if (visibilityObject instanceof Visibility) { | |
75 visibility = (Visibility) visibilityObject; | |
76 } else { | |
77 visibility = Visibility.PUBLIC; | |
78 } | |
79 } | |
80 | |
81 final InlinableMethodImplementation methodImplementation = new InlinableMethodImplementation(callTarget, declarationFrame, frameDescriptor, pristineRootNode, false, false); | |
82 return new RubyMethod(getSourceSection(), null, uniqueIdentifier, null, name, visibility, false, methodImplementation); | |
83 } | |
84 | |
85 @Override | |
86 public Object execute(VirtualFrame frame) { | |
87 return executeMethod(frame); | |
88 } | |
89 | |
13568
f29a358cf3da
Ruby: minor tweaks to implementation nodes for debugging access
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13514
diff
changeset
|
90 public String getName() { |
f29a358cf3da
Ruby: minor tweaks to implementation nodes for debugging access
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13514
diff
changeset
|
91 return name; |
f29a358cf3da
Ruby: minor tweaks to implementation nodes for debugging access
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13514
diff
changeset
|
92 } |
f29a358cf3da
Ruby: minor tweaks to implementation nodes for debugging access
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13514
diff
changeset
|
93 |
13514 | 94 } |