comparison graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/objects/instancevariables/WriteInstanceVariableNode.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.instancevariables;
11
12 import com.oracle.truffle.api.*;
13 import com.oracle.truffle.ruby.nodes.*;
14 import com.oracle.truffle.ruby.runtime.*;
15 import com.oracle.truffle.ruby.runtime.objects.*;
16
17 public abstract class WriteInstanceVariableNode extends RubyNode implements WriteNode {
18
19 protected final String name;
20 @Child protected RubyNode receiver;
21 @Child protected RubyNode rhs;
22
23 public WriteInstanceVariableNode(RubyContext context, SourceSection sourceSection, String name, RubyNode receiver, RubyNode rhs) {
24 super(context, sourceSection);
25 this.name = name;
26 this.receiver = adoptChild(receiver);
27 this.rhs = adoptChild(rhs);
28 }
29
30 public WriteInstanceVariableNode respecialize(RubyBasicObject receiverObject) {
31 StorageLocation storageLocation = receiverObject.getObjectLayout().findStorageLocation(name);
32
33 if (storageLocation == null) {
34 throw new RuntimeException("Storage location should be found at this point");
35 }
36
37 if (storageLocation instanceof FixnumStorageLocation) {
38 return new WriteFixnumInstanceVariableNode(getContext(), getSourceSection(), name, receiver, rhs, storageLocation.getObjectLayout(), (FixnumStorageLocation) storageLocation);
39 } else if (storageLocation instanceof FloatStorageLocation) {
40 return new WriteFloatInstanceVariableNode(getContext(), getSourceSection(), name, receiver, rhs, storageLocation.getObjectLayout(), (FloatStorageLocation) storageLocation);
41 } else {
42 return new WriteObjectInstanceVariableNode(getContext(), getSourceSection(), name, receiver, rhs, storageLocation.getObjectLayout(), (ObjectStorageLocation) storageLocation);
43 }
44 }
45
46 @Override
47 public ReadInstanceVariableNode makeReadNode() {
48 return new UninitializedReadInstanceVariableNode(getContext(), getEncapsulatingSourceSection(), name, (RubyNode) receiver.copy());
49 }
50
51 public String getName() {
52 return name;
53 }
54
55 public RubyNode getReceiver() {
56 return receiver;
57 }
58
59 public RubyNode getRHS() {
60 return rhs;
61 }
62
63 }