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.objects.instancevariables;
|
|
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.objects.*;
|
|
18
|
|
19 @NodeInfo(shortName = "@Float=")
|
|
20 public class WriteFloatInstanceVariableNode extends WriteSpecializedInstanceVariableNode {
|
|
21
|
|
22 private final FloatStorageLocation storageLocation;
|
|
23
|
|
24 public WriteFloatInstanceVariableNode(RubyContext context, SourceSection sourceSection, String name, RubyNode receiver, RubyNode rhs, ObjectLayout objectLayout,
|
|
25 FloatStorageLocation storageLocation) {
|
|
26 super(context, sourceSection, name, receiver, rhs, objectLayout);
|
|
27 this.storageLocation = storageLocation;
|
|
28 }
|
|
29
|
|
30 @Override
|
|
31 public double executeFloat(VirtualFrame frame) throws UnexpectedResultException {
|
|
32 final RubyBasicObject receiverObject = (RubyBasicObject) receiver.execute(frame);
|
|
33
|
|
34 double value;
|
|
35
|
|
36 try {
|
|
37 value = rhs.executeFloat(frame);
|
|
38 } catch (UnexpectedResultException e) {
|
|
39 receiverObject.setInstanceVariable(name, e.getResult());
|
|
40 replace(respecialize(receiverObject));
|
|
41 throw e;
|
|
42 }
|
|
43
|
|
44 final ObjectLayout receiverLayout = receiverObject.getObjectLayout();
|
|
45
|
|
46 if (receiverLayout != objectLayout) {
|
|
47 CompilerDirectives.transferToInterpreter();
|
|
48 receiverObject.setInstanceVariable(name, value);
|
|
49 replace(respecialize(receiverObject));
|
|
50 return value;
|
|
51 }
|
|
52
|
|
53 assert receiverLayout != null;
|
|
54
|
|
55 storageLocation.writeFloat(receiverObject, value);
|
|
56 return value;
|
|
57 }
|
|
58
|
|
59 @Override
|
|
60 public Object execute(VirtualFrame frame) {
|
|
61 try {
|
|
62 return executeFloat(frame);
|
|
63 } catch (UnexpectedResultException e) {
|
|
64 return e.getResult();
|
|
65 }
|
|
66 }
|
|
67
|
|
68 }
|