12
12
import java .util .LinkedHashSet ;
13
13
import java .util .Set ;
14
14
15
+ import com .oracle .truffle .api .dsl .CachedContext ;
16
+ import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
17
+ import com .oracle .truffle .api .dsl .GenerateUncached ;
15
18
import org .jcodings .specific .UTF8Encoding ;
16
19
import org .truffleruby .RubyContext ;
17
20
import org .truffleruby .RubyLanguage ;
18
21
import org .truffleruby .builtins .CoreMethod ;
19
- import org .truffleruby .builtins .CoreMethodNode ;
20
22
import org .truffleruby .builtins .CoreModule ;
21
23
import org .truffleruby .builtins .Primitive ;
22
24
import org .truffleruby .builtins .PrimitiveArrayArgumentsNode ;
30
32
import org .truffleruby .core .string .StringNodes .MakeStringNode ;
31
33
import org .truffleruby .language .Nil ;
32
34
import org .truffleruby .language .RubyNode ;
35
+ import org .truffleruby .language .RubySourceNode ;
33
36
import org .truffleruby .language .Visibility ;
34
37
import org .truffleruby .language .arguments .ReadCallerFrameNode ;
35
38
import org .truffleruby .language .arguments .RubyArguments ;
@@ -153,10 +156,18 @@ protected RubyBinding dup(RubyBinding binding) {
153
156
}
154
157
155
158
@ ImportStatic ({ BindingNodes .class , FindDeclarationVariableNodes .class })
159
+ @ GenerateUncached
160
+ @ GenerateNodeFactory
156
161
@ CoreMethod (names = "local_variable_defined?" , required = 1 )
157
162
@ NodeChild (value = "binding" , type = RubyNode .class )
158
163
@ NodeChild (value = "name" , type = RubyNode .class )
159
- public abstract static class LocalVariableDefinedNode extends CoreMethodNode {
164
+ public abstract static class LocalVariableDefinedNode extends RubySourceNode {
165
+
166
+ public static LocalVariableDefinedNode create () {
167
+ return BindingNodesFactory .LocalVariableDefinedNodeFactory .create (null , null );
168
+ }
169
+
170
+ public abstract boolean execute (RubyBinding binding , String name );
160
171
161
172
@ CreateCast ("name" )
162
173
protected RubyNode coerceToString (RubyNode name ) {
@@ -177,30 +188,39 @@ protected boolean localVariableDefinedCached(RubyBinding binding, String name,
177
188
}
178
189
179
190
@ TruffleBoundary
180
- @ Specialization (guards = "!isHiddenVariable(name)" )
191
+ @ Specialization (guards = "!isHiddenVariable(name)" , replaces = "localVariableDefinedCached" )
181
192
protected boolean localVariableDefinedUncached (RubyBinding binding , String name ) {
182
193
return FindDeclarationVariableNodes .findFrameSlotOrNull (name , binding .getFrame ()) != null ;
183
194
}
184
195
185
196
@ TruffleBoundary
186
197
@ Specialization (guards = "isHiddenVariable(name)" )
187
- protected Object localVariableDefinedLastLine (RubyBinding binding , String name ) {
198
+ protected Object localVariableDefinedLastLine (RubyBinding binding , String name ,
199
+ @ CachedContext (RubyLanguage .class ) RubyContext context ) {
188
200
throw new RaiseException (
189
- getContext () ,
190
- coreExceptions ().nameError ("Bad local variable name" , binding , name , this ));
201
+ context ,
202
+ context . getCoreExceptions ().nameError ("Bad local variable name" , binding , name , this ));
191
203
}
192
204
193
205
protected int getCacheLimit () {
194
- return getContext ().getOptions ().BINDING_LOCAL_VARIABLE_CACHE ;
206
+ return RubyLanguage . getCurrentContext ().getOptions ().BINDING_LOCAL_VARIABLE_CACHE ;
195
207
}
196
208
197
209
}
198
210
199
- @ CoreMethod (names = "local_variable_get" , required = 1 )
211
+ @ GenerateUncached
212
+ @ GenerateNodeFactory
200
213
@ NodeChild (value = "binding" , type = RubyNode .class )
201
214
@ NodeChild (value = "name" , type = RubyNode .class )
202
215
@ ImportStatic (BindingNodes .class )
203
- public abstract static class LocalVariableGetNode extends CoreMethodNode {
216
+ @ CoreMethod (names = "local_variable_get" , required = 1 )
217
+ public abstract static class LocalVariableGetNode extends RubySourceNode {
218
+
219
+ public abstract Object execute (RubyBinding binding , String name );
220
+
221
+ public static LocalVariableGetNode create () {
222
+ return BindingNodesFactory .LocalVariableGetNodeFactory .create (null , null );
223
+ }
204
224
205
225
@ CreateCast ("name" )
206
226
protected RubyNode coerceToString (RubyNode name ) {
@@ -209,38 +229,48 @@ protected RubyNode coerceToString(RubyNode name) {
209
229
210
230
@ Specialization (guards = "!isHiddenVariable(name)" )
211
231
protected Object localVariableGet (RubyBinding binding , String name ,
212
- @ Cached FindAndReadDeclarationVariableNode readNode ) {
232
+ @ Cached FindAndReadDeclarationVariableNode readNode ,
233
+ @ CachedContext (RubyLanguage .class ) RubyContext context ) {
213
234
MaterializedFrame frame = binding .getFrame ();
214
- Object result = readNode .execute (frame , name );
235
+ Object result = readNode .execute (frame , name , null );
215
236
if (result == null ) {
216
237
throw new RaiseException (
217
- getContext () ,
218
- coreExceptions ().nameErrorLocalVariableNotDefined (name , binding , this ));
238
+ context ,
239
+ context . getCoreExceptions ().nameErrorLocalVariableNotDefined (name , binding , this ));
219
240
}
220
241
return result ;
221
242
}
222
243
223
244
@ TruffleBoundary
224
245
@ Specialization (guards = "isHiddenVariable(name)" )
225
- protected Object localVariableGetLastLine (RubyBinding binding , String name ) {
246
+ protected Object localVariableGetLastLine (RubyBinding binding , String name ,
247
+ @ CachedContext (RubyLanguage .class ) RubyContext context ) {
226
248
throw new RaiseException (
227
- getContext () ,
228
- coreExceptions ().nameError ("Bad local variable name" , binding , name , this ));
249
+ context ,
250
+ context . getCoreExceptions ().nameError ("Bad local variable name" , binding , name , this ));
229
251
}
230
252
231
253
protected int getCacheLimit () {
232
- return getContext ().getOptions ().BINDING_LOCAL_VARIABLE_CACHE ;
254
+ return RubyLanguage . getCurrentContext ().getOptions ().BINDING_LOCAL_VARIABLE_CACHE ;
233
255
}
234
256
235
257
}
236
258
237
259
@ ReportPolymorphism
260
+ @ GenerateUncached
261
+ @ GenerateNodeFactory
238
262
@ CoreMethod (names = "local_variable_set" , required = 2 )
239
263
@ NodeChild (value = "binding" , type = RubyNode .class )
240
264
@ NodeChild (value = "name" , type = RubyNode .class )
241
265
@ NodeChild (value = "value" , type = RubyNode .class )
242
266
@ ImportStatic ({ BindingNodes .class , FindDeclarationVariableNodes .class })
243
- public abstract static class LocalVariableSetNode extends CoreMethodNode {
267
+ public abstract static class LocalVariableSetNode extends RubySourceNode {
268
+
269
+ public static LocalVariableSetNode create () {
270
+ return BindingNodesFactory .LocalVariableSetNodeFactory .create (null , null , null );
271
+ }
272
+
273
+ public abstract Object execute (RubyBinding binding , String name , Object value );
244
274
245
275
@ CreateCast ("name" )
246
276
protected RubyNode coerceToString (RubyNode name ) {
@@ -285,7 +315,9 @@ protected Object localVariableSetNewCached(RubyBinding binding, String name, Obj
285
315
}
286
316
287
317
@ TruffleBoundary
288
- @ Specialization (guards = "!isHiddenVariable(name)" )
318
+ @ Specialization (
319
+ guards = "!isHiddenVariable(name)" ,
320
+ replaces = { "localVariableSetCached" , "localVariableSetNewCached" })
289
321
protected Object localVariableSetUncached (RubyBinding binding , String name , Object value ) {
290
322
MaterializedFrame frame = binding .getFrame ();
291
323
final FrameSlotAndDepth frameSlot = FindDeclarationVariableNodes .findFrameSlotOrNull (name , frame );
@@ -303,18 +335,19 @@ protected Object localVariableSetUncached(RubyBinding binding, String name, Obje
303
335
304
336
@ TruffleBoundary
305
337
@ Specialization (guards = "isHiddenVariable(name)" )
306
- protected Object localVariableSetLastLine (RubyBinding binding , String name , Object value ) {
338
+ protected Object localVariableSetLastLine (RubyBinding binding , String name , Object value ,
339
+ @ CachedContext (RubyLanguage .class ) RubyContext context ) {
307
340
throw new RaiseException (
308
- getContext () ,
309
- coreExceptions ().nameError ("Bad local variable name" , binding , name , this ));
341
+ context ,
342
+ context . getCoreExceptions ().nameError ("Bad local variable name" , binding , name , this ));
310
343
}
311
344
312
345
protected WriteFrameSlotNode createWriteNode (FrameSlotAndDepth frameSlot ) {
313
346
return WriteFrameSlotNodeGen .create (frameSlot .slot );
314
347
}
315
348
316
349
protected int getCacheLimit () {
317
- return getContext ().getOptions ().BINDING_LOCAL_VARIABLE_CACHE ;
350
+ return RubyLanguage . getCurrentContext ().getOptions ().BINDING_LOCAL_VARIABLE_CACHE ;
318
351
}
319
352
}
320
353
0 commit comments