29
29
import org .truffleruby .annotations .Primitive ;
30
30
import org .truffleruby .annotations .Visibility ;
31
31
import org .truffleruby .builtins .CoreMethodArrayArgumentsNode ;
32
+ import org .truffleruby .builtins .CoreMethodNode ;
32
33
import org .truffleruby .builtins .PrimitiveArrayArgumentsNode ;
33
34
import org .truffleruby .core .array .ArrayHelpers ;
34
35
import org .truffleruby .core .array .RubyArray ;
44
45
import org .truffleruby .language .locals .FindDeclarationVariableNodes .FindAndReadDeclarationVariableNode ;
45
46
import org .truffleruby .language .locals .FindDeclarationVariableNodes .FrameSlotAndDepth ;
46
47
import org .truffleruby .language .locals .FrameDescriptorNamesIterator ;
47
- import org .truffleruby .language .locals .WriteFrameSlotNode ;
48
- import org .truffleruby .language .locals .WriteFrameSlotNodeGen ;
49
48
50
49
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
51
50
import com .oracle .truffle .api .Truffle ;
60
59
import com .oracle .truffle .api .frame .MaterializedFrame ;
61
60
import com .oracle .truffle .api .frame .VirtualFrame ;
62
61
import com .oracle .truffle .api .source .SourceSection ;
62
+ import org .truffleruby .language .locals .WriteFrameSlotNode ;
63
+ import org .truffleruby .language .locals .WriteFrameSlotNodeGen ;
63
64
import org .truffleruby .parser .ParentFrameDescriptor ;
64
65
import org .truffleruby .parser .TranslatorEnvironment ;
65
66
@@ -278,33 +279,29 @@ public RubyNode cloneUninitialized() {
278
279
279
280
}
280
281
281
- @ GenerateUncached
282
- @ GenerateNodeFactory
283
282
@ CoreMethod (names = "local_variable_get" , required = 1 )
284
283
@ NodeChild (value = "bindingNode" , type = RubyNode .class )
285
284
@ NodeChild (value = "nameNode" , type = RubyBaseNodeWithExecute .class )
286
285
@ ImportStatic (BindingNodes .class )
287
- public abstract static class LocalVariableGetNode extends RubySourceNode {
286
+ public abstract static class BindingLocalVariableGetNode extends CoreMethodNode {
288
287
289
- @ NeverDefault
290
- public static LocalVariableGetNode create ( ) {
291
- return BindingNodesFactory . LocalVariableGetNodeFactory . create (null , null );
288
+ @ CreateCast ( "nameNode" )
289
+ protected RubyBaseNodeWithExecute coerceToString ( RubyBaseNodeWithExecute name ) {
290
+ return NameToJavaStringNode . create (name );
292
291
}
293
292
294
- public static LocalVariableGetNode create (RubyNode bindingNode , RubyBaseNodeWithExecute nameNode ) {
295
- return BindingNodesFactory .LocalVariableGetNodeFactory .create (bindingNode , nameNode );
293
+ @ Specialization
294
+ protected Object localVariableGet (RubyBinding binding , String name ,
295
+ @ Cached LocalVariableGetNode localVariableGetNode ) {
296
+ return localVariableGetNode .execute (binding , name );
296
297
}
298
+ }
297
299
298
- public abstract Object execute (RubyBinding binding , String name );
299
-
300
- abstract RubyNode getBindingNode ();
301
-
302
- abstract RubyBaseNodeWithExecute getNameNode ();
300
+ @ GenerateUncached
301
+ @ ImportStatic (BindingNodes .class )
302
+ public abstract static class LocalVariableGetNode extends RubyBaseNode {
303
303
304
- @ CreateCast ("nameNode" )
305
- protected RubyBaseNodeWithExecute coerceToString (RubyBaseNodeWithExecute name ) {
306
- return NameToJavaStringNode .create (name );
307
- }
304
+ public abstract Object execute (RubyBinding binding , String name );
308
305
309
306
@ Specialization (guards = "!isHiddenVariable(name)" )
310
307
protected Object localVariableGet (RubyBinding binding , String name ,
@@ -326,56 +323,33 @@ protected Object localVariableGetLastLine(RubyBinding binding, String name) {
326
323
getContext (),
327
324
coreExceptions ().nameError ("Bad local variable name" , binding , name , this ));
328
325
}
329
-
330
- protected int getCacheLimit () {
331
- return getLanguage ().options .BINDING_LOCAL_VARIABLE_CACHE ;
332
- }
333
-
334
- private RubyBaseNodeWithExecute getNameNodeBeforeCasting () {
335
- return ((NameToJavaStringNode ) getNameNode ()).getValueNode ();
336
- }
337
-
338
- @ Override
339
- public RubyNode cloneUninitialized () {
340
- return create (
341
- getBindingNode ().cloneUninitialized (),
342
- getNameNodeBeforeCasting ().cloneUninitialized ()).copyFlags (this );
343
- }
344
-
345
326
}
346
327
347
328
@ ReportPolymorphism
348
- @ GenerateUncached
349
- @ GenerateNodeFactory
350
329
@ CoreMethod (names = "local_variable_set" , required = 2 )
351
330
@ NodeChild (value = "bindingNode" , type = RubyNode .class )
352
331
@ NodeChild (value = "nameNode" , type = RubyBaseNodeWithExecute .class )
353
332
@ NodeChild (value = "valueNode" , type = RubyNode .class )
354
- @ ImportStatic ({ BindingNodes .class , FindDeclarationVariableNodes .class })
355
- public abstract static class LocalVariableSetNode extends RubySourceNode {
333
+ public abstract static class BindingLocalVariableSetNode extends CoreMethodNode {
356
334
357
- @ NeverDefault
358
- public static LocalVariableSetNode create ( ) {
359
- return BindingNodesFactory . LocalVariableSetNodeFactory . create (null , null , null );
335
+ @ CreateCast ( "nameNode" )
336
+ protected RubyBaseNodeWithExecute coerceToString ( RubyBaseNodeWithExecute name ) {
337
+ return NameToJavaStringNode . create (name );
360
338
}
361
339
362
- public static LocalVariableSetNode create (RubyNode bindingNode , RubyBaseNodeWithExecute nameNode ,
363
- RubyNode valueNode ) {
364
- return BindingNodesFactory .LocalVariableSetNodeFactory .create (bindingNode , nameNode , valueNode );
340
+ @ Specialization
341
+ protected Object localVariableSet (RubyBinding binding , String name , Object value ,
342
+ @ Cached LocalVariableSetNode localVariableSetNode ) {
343
+ return localVariableSetNode .execute (binding , name , value );
365
344
}
345
+ }
366
346
367
- public abstract Object execute (RubyBinding binding , String name , Object value );
368
-
369
- abstract RubyNode getBindingNode ();
370
-
371
- abstract RubyBaseNodeWithExecute getNameNode ();
372
347
373
- abstract RubyNode getValueNode ();
348
+ @ GenerateUncached
349
+ @ ImportStatic ({ BindingNodes .class , FindDeclarationVariableNodes .class })
350
+ public abstract static class LocalVariableSetNode extends RubyBaseNode {
374
351
375
- @ CreateCast ("nameNode" )
376
- protected RubyBaseNodeWithExecute coerceToString (RubyBaseNodeWithExecute name ) {
377
- return NameToJavaStringNode .create (name );
378
- }
352
+ public abstract Object execute (RubyBinding binding , String name , Object value );
379
353
380
354
@ Specialization (
381
355
guards = {
@@ -449,19 +423,6 @@ protected WriteFrameSlotNode createWriteNode(int frameSlot) {
449
423
protected int getCacheLimit () {
450
424
return getLanguage ().options .BINDING_LOCAL_VARIABLE_CACHE ;
451
425
}
452
-
453
- private RubyBaseNodeWithExecute getNameNodeBeforeCasting () {
454
- return ((NameToJavaStringNode ) getNameNode ()).getValueNode ();
455
- }
456
-
457
- @ Override
458
- public RubyNode cloneUninitialized () {
459
- return create (
460
- getBindingNode ().cloneUninitialized (),
461
- getNameNodeBeforeCasting ().cloneUninitialized (),
462
- getValueNode ().cloneUninitialized ()).copyFlags (this );
463
- }
464
-
465
426
}
466
427
467
428
@ Primitive (name = "local_variable_names" )
0 commit comments