13514
|
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.constants;
|
|
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 /**
|
|
20 * Represents writing a constant into some module.
|
|
21 */
|
|
22 @NodeInfo(shortName = "write-constant")
|
|
23 public class WriteConstantNode extends RubyNode {
|
|
24
|
|
25 private final String name;
|
|
26 @Child protected RubyNode module;
|
|
27 @Child protected RubyNode rhs;
|
|
28
|
|
29 public WriteConstantNode(RubyContext context, SourceSection sourceSection, String name, RubyNode module, RubyNode rhs) {
|
|
30 super(context, sourceSection);
|
|
31 this.name = name;
|
|
32 this.module = adoptChild(module);
|
|
33 this.rhs = adoptChild(rhs);
|
|
34 }
|
|
35
|
|
36 @Override
|
|
37 public Object execute(VirtualFrame frame) {
|
|
38 // TODO(cs): can module ever not evaluate to a RubyModule?
|
|
39
|
|
40 final RubyModule moduleObject = (RubyModule) module.execute(frame);
|
|
41
|
|
42 final Object rhsValue = rhs.execute(frame);
|
|
43
|
|
44 assert rhsValue != null;
|
|
45 assert !(rhsValue instanceof String);
|
|
46
|
|
47 moduleObject.setModuleConstant(name, rhsValue);
|
|
48
|
|
49 return rhsValue;
|
|
50 }
|
|
51
|
|
52 }
|