Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/objects/ReadClassVariableNode.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.nodes.objects; | |
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 | |
19 @NodeInfo(shortName = "read-class-variable") | |
20 public class ReadClassVariableNode extends RubyNode { | |
21 | |
22 protected final String name; | |
23 @Child protected RubyNode module; | |
24 | |
25 public ReadClassVariableNode(RubyContext context, SourceSection sourceSection, String name, RubyNode module) { | |
26 super(context, sourceSection); | |
27 this.name = name; | |
28 this.module = adoptChild(module); | |
29 } | |
30 | |
31 @Override | |
32 public Object execute(VirtualFrame frame) { | |
33 final RubyObject object = (RubyObject) module.execute(frame); | |
34 | |
35 RubyModule moduleObject; | |
36 | |
37 // TODO(CS): this cannot be right | |
38 | |
39 if (object instanceof RubyModule) { | |
40 moduleObject = (RubyModule) object; | |
41 } else { | |
42 moduleObject = object.getRubyClass(); | |
43 } | |
44 | |
45 final Object value = moduleObject.lookupClassVariable(name); | |
46 | |
47 if (value == null) { | |
48 // TODO(CS): is this right? | |
49 return NilPlaceholder.INSTANCE; | |
50 } | |
51 | |
52 return value; | |
53 } | |
54 | |
55 @Override | |
56 public Object isDefined(VirtualFrame frame) { | |
57 final RubyContext context = getContext(); | |
58 | |
59 final RubyObject object = (RubyObject) module.execute(frame); | |
60 | |
61 RubyModule moduleObject; | |
62 | |
63 if (object instanceof RubyModule) { | |
64 moduleObject = (RubyModule) object; | |
65 } else { | |
66 moduleObject = object.getRubyClass(); | |
67 } | |
68 | |
69 final Object value = moduleObject.lookupClassVariable(name); | |
70 | |
71 if (value == null) { | |
72 return NilPlaceholder.INSTANCE; | |
73 } else { | |
74 return context.makeString("class variable"); | |
75 } | |
76 } | |
77 | |
78 } |