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.methods.locals;
|
|
11
|
|
12 import com.oracle.truffle.api.*;
|
|
13 import com.oracle.truffle.api.dsl.*;
|
|
14 import com.oracle.truffle.api.frame.*;
|
|
15 import com.oracle.truffle.ruby.nodes.*;
|
|
16 import com.oracle.truffle.ruby.runtime.*;
|
|
17
|
|
18 @NodeChild(value = "rhs", type = RubyNode.class)
|
|
19 public abstract class WriteLevelVariableNode extends FrameSlotNode implements WriteNode {
|
|
20
|
|
21 private final int varLevel;
|
|
22
|
|
23 public WriteLevelVariableNode(RubyContext context, SourceSection sourceSection, FrameSlot frameSlot, int level) {
|
|
24 super(context, sourceSection, frameSlot);
|
|
25 this.varLevel = level;
|
|
26 }
|
|
27
|
|
28 protected WriteLevelVariableNode(WriteLevelVariableNode prev) {
|
|
29 this(prev.getContext(), prev.getSourceSection(), prev.frameSlot, prev.varLevel);
|
|
30 }
|
|
31
|
|
32 @Specialization(guards = "isBooleanKind")
|
|
33 public boolean doBoolean(VirtualFrame frame, boolean value) {
|
|
34 MaterializedFrame levelFrame = RubyArguments.getDeclarationFrame(frame, varLevel);
|
|
35 setBoolean(levelFrame, value);
|
|
36 return value;
|
|
37 }
|
|
38
|
|
39 @Specialization(guards = "isFixnumKind")
|
|
40 public int doFixnum(VirtualFrame frame, int value) {
|
|
41 MaterializedFrame levelFrame = RubyArguments.getDeclarationFrame(frame, varLevel);
|
|
42 setFixnum(levelFrame, value);
|
|
43 return value;
|
|
44 }
|
|
45
|
|
46 @Specialization(guards = "isFloatKind")
|
|
47 public double doFloat(VirtualFrame frame, double value) {
|
|
48 MaterializedFrame levelFrame = RubyArguments.getDeclarationFrame(frame, varLevel);
|
|
49 setFloat(levelFrame, value);
|
|
50 return value;
|
|
51 }
|
|
52
|
|
53 @Specialization(guards = "isObjectKind")
|
|
54 public Object doObject(VirtualFrame frame, Object value) {
|
|
55 MaterializedFrame levelFrame = RubyArguments.getDeclarationFrame(frame, varLevel);
|
|
56 setObject(levelFrame, value);
|
|
57 return value;
|
|
58 }
|
|
59
|
|
60 @Override
|
|
61 public RubyNode makeReadNode() {
|
|
62 return ReadLevelVariableNodeFactory.create(getContext(), getSourceSection(), frameSlot, varLevel);
|
|
63 }
|
|
64 }
|