comparison graal/com.oracle.truffle.ruby.runtime/src/com/oracle/truffle/ruby/runtime/objects/FloatStorageLocation.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.runtime.objects;
11
12 import com.oracle.truffle.api.*;
13 import com.oracle.truffle.api.nodes.*;
14 import com.oracle.truffle.ruby.runtime.*;
15
16 /**
17 * A storage location for Floats.
18 */
19 public class FloatStorageLocation extends PrimitiveStorageLocation {
20
21 public FloatStorageLocation(ObjectLayout objectLayout, long offset, int mask) {
22 super(objectLayout, offset, mask);
23 }
24
25 @Override
26 public Object read(RubyBasicObject object, boolean condition) {
27 try {
28 return readFloat(object, condition);
29 } catch (UnexpectedResultException e) {
30 return e.getResult();
31 }
32 }
33
34 public double readFloat(RubyBasicObject object, boolean condition) throws UnexpectedResultException {
35 if (isSet(object)) {
36 return CompilerDirectives.unsafeGetDouble(object, offset, condition, this);
37 } else {
38 throw new UnexpectedResultException(NilPlaceholder.INSTANCE);
39 }
40 }
41
42 @Override
43 public void write(RubyBasicObject object, Object value) throws GeneralizeStorageLocationException {
44 if (value instanceof Double) {
45 writeFloat(object, (double) value);
46 } else if (value instanceof NilPlaceholder) {
47 markAsUnset(object);
48 } else {
49 throw new GeneralizeStorageLocationException();
50 }
51 }
52
53 public void writeFloat(RubyBasicObject object, Double value) {
54 CompilerDirectives.unsafePutDouble(object, offset, value, null);
55 markAsSet(object);
56 }
57
58 @Override
59 public Class getStoredClass() {
60 return Double.class;
61 }
62
63 }