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;
|
|
11
|
|
12 import java.math.*;
|
|
13
|
|
14 import com.oracle.truffle.api.*;
|
|
15 import com.oracle.truffle.api.dsl.*;
|
|
16 import com.oracle.truffle.api.frame.*;
|
|
17 import com.oracle.truffle.api.nodes.*;
|
|
18 import com.oracle.truffle.ruby.nodes.call.*;
|
|
19 import com.oracle.truffle.ruby.nodes.debug.*;
|
|
20 import com.oracle.truffle.ruby.nodes.yield.*;
|
|
21 import com.oracle.truffle.ruby.runtime.*;
|
|
22 import com.oracle.truffle.ruby.runtime.core.*;
|
|
23 import com.oracle.truffle.ruby.runtime.core.array.*;
|
|
24 import com.oracle.truffle.ruby.runtime.core.range.*;
|
|
25 import com.oracle.truffle.ruby.runtime.methods.*;
|
|
26 import com.oracle.truffle.ruby.runtime.objects.*;
|
|
27
|
|
28 /**
|
|
29 * Base class for most nodes in Ruby.
|
|
30 *
|
|
31 * @see DispatchNode
|
|
32 * @see YieldDispatchNode
|
|
33 */
|
|
34 @TypeSystemReference(RubyTypes.class)
|
|
35 public abstract class RubyNode extends Node {
|
|
36
|
|
37 private final RubyContext context;
|
|
38
|
|
39 public RubyNode(RubyContext context, SourceSection sourceSection) {
|
|
40 super(sourceSection);
|
|
41
|
|
42 assert context != null;
|
|
43 assert sourceSection != null;
|
|
44
|
|
45 this.context = context;
|
|
46 }
|
|
47
|
|
48 public RubyNode(RubyNode prev) {
|
|
49 this(prev.context, prev.getSourceSection());
|
|
50 }
|
|
51
|
|
52 public abstract Object execute(VirtualFrame frame);
|
|
53
|
|
54 /**
|
|
55 * Ruby's parallel semantic path.
|
|
56 *
|
|
57 * @see DefinedNode
|
|
58 */
|
|
59 public Object isDefined(@SuppressWarnings("unused") VirtualFrame frame) {
|
|
60 throw new UnsupportedOperationException("no definition for " + getClass().getName());
|
|
61 }
|
|
62
|
|
63 public RubyArray executeArray(VirtualFrame frame) throws UnexpectedResultException {
|
|
64 return RubyTypesGen.RUBYTYPES.expectRubyArray(execute(frame));
|
|
65 }
|
|
66
|
|
67 public BigInteger executeBignum(VirtualFrame frame) throws UnexpectedResultException {
|
|
68 return RubyTypesGen.RUBYTYPES.expectBigInteger(execute(frame));
|
|
69 }
|
|
70
|
|
71 public boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultException {
|
|
72 return RubyTypesGen.RUBYTYPES.expectBoolean(execute(frame));
|
|
73 }
|
|
74
|
|
75 public RubyBignum executeBoxedBignum(VirtualFrame frame) throws UnexpectedResultException {
|
|
76 return RubyTypesGen.RUBYTYPES.expectRubyBignum(execute(frame));
|
|
77 }
|
|
78
|
|
79 public RubyFixnum executeBoxedFixnum(VirtualFrame frame) throws UnexpectedResultException {
|
|
80 return RubyTypesGen.RUBYTYPES.expectRubyFixnum(execute(frame));
|
|
81 }
|
|
82
|
|
83 public RubyFloat executeBoxedFloat(VirtualFrame frame) throws UnexpectedResultException {
|
|
84 return RubyTypesGen.RUBYTYPES.expectRubyFloat(execute(frame));
|
|
85 }
|
|
86
|
|
87 public int executeFixnum(VirtualFrame frame) throws UnexpectedResultException {
|
|
88 return RubyTypesGen.RUBYTYPES.expectInteger(execute(frame));
|
|
89 }
|
|
90
|
|
91 public FixnumRange executeFixnumRange(VirtualFrame frame) throws UnexpectedResultException {
|
|
92 return RubyTypesGen.RUBYTYPES.expectFixnumRange(execute(frame));
|
|
93 }
|
|
94
|
|
95 public double executeFloat(VirtualFrame frame) throws UnexpectedResultException {
|
|
96 return RubyTypesGen.RUBYTYPES.expectDouble(execute(frame));
|
|
97 }
|
|
98
|
|
99 public NilPlaceholder executeNilPlaceholder(VirtualFrame frame) throws UnexpectedResultException {
|
|
100 return RubyTypesGen.RUBYTYPES.expectNilPlaceholder(execute(frame));
|
|
101 }
|
|
102
|
|
103 public Node executeNode(VirtualFrame frame) throws UnexpectedResultException {
|
|
104 return RubyTypesGen.RUBYTYPES.expectNode(execute(frame));
|
|
105 }
|
|
106
|
|
107 public Object[] executeObjectArray(VirtualFrame frame) throws UnexpectedResultException {
|
|
108 return RubyTypesGen.RUBYTYPES.expectObjectArray(execute(frame));
|
|
109 }
|
|
110
|
|
111 public ObjectRange executeObjectRange(VirtualFrame frame) throws UnexpectedResultException {
|
|
112 return RubyTypesGen.RUBYTYPES.expectObjectRange(execute(frame));
|
|
113 }
|
|
114
|
|
115 public RubyBasicObject executeRubyBasicObject(VirtualFrame frame) throws UnexpectedResultException {
|
|
116 return RubyTypesGen.RUBYTYPES.expectRubyBasicObject(execute(frame));
|
|
117 }
|
|
118
|
|
119 public RubyBinding executeRubyBinding(VirtualFrame frame) throws UnexpectedResultException {
|
|
120 return RubyTypesGen.RUBYTYPES.expectRubyBinding(execute(frame));
|
|
121 }
|
|
122
|
|
123 public RubyClass executeRubyClass(VirtualFrame frame) throws UnexpectedResultException {
|
|
124 return RubyTypesGen.RUBYTYPES.expectRubyClass(execute(frame));
|
|
125 }
|
|
126
|
|
127 public RubyContinuation executeRubyContinuation(VirtualFrame frame) throws UnexpectedResultException {
|
|
128 return RubyTypesGen.RUBYTYPES.expectRubyContinuation(execute(frame));
|
|
129 }
|
|
130
|
|
131 public RubyException executeRubyException(VirtualFrame frame) throws UnexpectedResultException {
|
|
132 return RubyTypesGen.RUBYTYPES.expectRubyException(execute(frame));
|
|
133 }
|
|
134
|
|
135 public RubyFiber executeRubyFiber(VirtualFrame frame) throws UnexpectedResultException {
|
|
136 return RubyTypesGen.RUBYTYPES.expectRubyFiber(execute(frame));
|
|
137 }
|
|
138
|
|
139 public RubyFile executeRubyFile(VirtualFrame frame) throws UnexpectedResultException {
|
|
140 return RubyTypesGen.RUBYTYPES.expectRubyFile(execute(frame));
|
|
141 }
|
|
142
|
|
143 public RubyHash executeRubyHash(VirtualFrame frame) throws UnexpectedResultException {
|
|
144 return RubyTypesGen.RUBYTYPES.expectRubyHash(execute(frame));
|
|
145 }
|
|
146
|
|
147 public RubyMatchData executeRubyMatchData(VirtualFrame frame) throws UnexpectedResultException {
|
|
148 return RubyTypesGen.RUBYTYPES.expectRubyMatchData(execute(frame));
|
|
149 }
|
|
150
|
|
151 public RubyMethod executeRubyMethod(VirtualFrame frame) throws UnexpectedResultException {
|
|
152 return RubyTypesGen.RUBYTYPES.expectRubyMethod(execute(frame));
|
|
153 }
|
|
154
|
|
155 public RubyModule executeRubyModule(VirtualFrame frame) throws UnexpectedResultException {
|
|
156 return RubyTypesGen.RUBYTYPES.expectRubyModule(execute(frame));
|
|
157 }
|
|
158
|
|
159 public RubyNilClass executeRubyNilClass(VirtualFrame frame) throws UnexpectedResultException {
|
|
160 return RubyTypesGen.RUBYTYPES.expectRubyNilClass(execute(frame));
|
|
161 }
|
|
162
|
|
163 public RubyObject executeRubyObject(VirtualFrame frame) throws UnexpectedResultException {
|
|
164 return RubyTypesGen.RUBYTYPES.expectRubyObject(execute(frame));
|
|
165 }
|
|
166
|
|
167 public RubyProc executeRubyProc(VirtualFrame frame) throws UnexpectedResultException {
|
|
168 return RubyTypesGen.RUBYTYPES.expectRubyProc(execute(frame));
|
|
169 }
|
|
170
|
|
171 public RubyRange executeRubyRange(VirtualFrame frame) throws UnexpectedResultException {
|
|
172 return RubyTypesGen.RUBYTYPES.expectRubyRange(execute(frame));
|
|
173 }
|
|
174
|
|
175 public RubyRegexp executeRubyRegexp(VirtualFrame frame) throws UnexpectedResultException {
|
|
176 return RubyTypesGen.RUBYTYPES.expectRubyRegexp(execute(frame));
|
|
177 }
|
|
178
|
|
179 public RubySymbol executeRubySymbol(VirtualFrame frame) throws UnexpectedResultException {
|
|
180 return RubyTypesGen.RUBYTYPES.expectRubySymbol(execute(frame));
|
|
181 }
|
|
182
|
|
183 public RubyThread executeRubyThread(VirtualFrame frame) throws UnexpectedResultException {
|
|
184 return RubyTypesGen.RUBYTYPES.expectRubyThread(execute(frame));
|
|
185 }
|
|
186
|
|
187 public RubyTime executeRubyTime(VirtualFrame frame) throws UnexpectedResultException {
|
|
188 return RubyTypesGen.RUBYTYPES.expectRubyTime(execute(frame));
|
|
189 }
|
|
190
|
|
191 public RubyString executeString(VirtualFrame frame) throws UnexpectedResultException {
|
|
192 return RubyTypesGen.RUBYTYPES.expectRubyString(execute(frame));
|
|
193 }
|
|
194
|
|
195 public UndefinedPlaceholder executeUndefinedPlaceholder(VirtualFrame frame) throws UnexpectedResultException {
|
|
196 return RubyTypesGen.RUBYTYPES.expectUndefinedPlaceholder(execute(frame));
|
|
197 }
|
|
198
|
|
199 public void executeVoid(VirtualFrame frame) {
|
|
200 execute(frame);
|
|
201 }
|
|
202
|
|
203 /**
|
|
204 * If you aren't sure whether you have a normal {@link RubyNode} or a {@link RubyProxyNode},
|
|
205 * this method will return the real node, whether that is this node, or whether this node is a
|
|
206 * proxy and you actually need the child.
|
|
207 */
|
|
208 public RubyNode getNonProxyNode() {
|
|
209 return this;
|
|
210 }
|
|
211
|
|
212 public RubyContext getContext() {
|
|
213 return context;
|
|
214 }
|
|
215
|
|
216 }
|