comparison graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/methods/locals/FrameSlotNode.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.methods.locals;
11
12 import com.oracle.truffle.api.*;
13 import com.oracle.truffle.api.frame.*;
14 import com.oracle.truffle.ruby.nodes.*;
15 import com.oracle.truffle.ruby.runtime.*;
16
17 public abstract class FrameSlotNode extends RubyNode {
18
19 protected final FrameSlot frameSlot;
20
21 protected FrameSlotNode(RubyContext context, SourceSection sourceSection, FrameSlot frameSlot) {
22 super(context, sourceSection);
23 this.frameSlot = frameSlot;
24 }
25
26 public final FrameSlot getFrameSlot() {
27 return frameSlot;
28 }
29
30 @Override
31 public FrameSlotNode copy() {
32 return (FrameSlotNode) super.copy();
33 }
34
35 protected final void setBoolean(Frame frame, boolean value) {
36 frame.setBoolean(frameSlot, value);
37 }
38
39 protected final void setFixnum(Frame frame, int value) {
40 frame.setInt(frameSlot, value);
41 }
42
43 protected final void setFloat(Frame frame, double value) {
44 frame.setDouble(frameSlot, value);
45 }
46
47 protected final void setObject(Frame frame, Object value) {
48 frame.setObject(frameSlot, value);
49 }
50
51 protected final boolean getBoolean(Frame frame) throws FrameSlotTypeException {
52 return frame.getBoolean(frameSlot);
53 }
54
55 protected final int getFixnum(Frame frame) throws FrameSlotTypeException {
56 return frame.getInt(frameSlot);
57 }
58
59 protected final double getFloat(Frame frame) throws FrameSlotTypeException {
60 return frame.getDouble(frameSlot);
61 }
62
63 protected final Object getObject(Frame frame) {
64 try {
65 return frame.getObject(frameSlot);
66 } catch (FrameSlotTypeException e) {
67 throw new IllegalStateException();
68 }
69 }
70
71 protected final boolean isBooleanKind() {
72 return isKind(FrameSlotKind.Boolean);
73 }
74
75 protected final boolean isFixnumKind() {
76 return isKind(FrameSlotKind.Int);
77 }
78
79 protected final boolean isFloatKind() {
80 return isKind(FrameSlotKind.Double);
81 }
82
83 protected final boolean isObjectKind() {
84 if (frameSlot.getKind() != FrameSlotKind.Object) {
85 CompilerDirectives.transferToInterpreter();
86 frameSlot.setKind(FrameSlotKind.Object);
87 }
88 return true;
89 }
90
91 private boolean isKind(FrameSlotKind kind) {
92 return frameSlot.getKind() == kind || initialSetKind(kind);
93 }
94
95 private boolean initialSetKind(FrameSlotKind kind) {
96 if (frameSlot.getKind() == FrameSlotKind.Illegal) {
97 CompilerDirectives.transferToInterpreter();
98 frameSlot.setKind(kind);
99 return true;
100 }
101 return false;
102 }
103
104 }