43
43
import org .truffleruby .language .locals .FindDeclarationVariableNodes ;
44
44
import org .truffleruby .language .locals .FindDeclarationVariableNodes .FrameSlotAndDepth ;
45
45
import org .truffleruby .language .locals .FrameDescriptorNamesIterator ;
46
- import org .truffleruby .language .locals .WriteFrameSlotNode ;
47
- import org .truffleruby .language .locals .WriteFrameSlotNodeGen ;
48
46
49
47
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
50
48
import com .oracle .truffle .api .Truffle ;
@@ -312,26 +310,12 @@ public RubyNode cloneUninitialized() {
312
310
}
313
311
314
312
@ ReportPolymorphism
315
- @ GenerateUncached
316
313
@ GenerateNodeFactory
317
314
@ CoreMethod (names = "local_variable_set" , required = 2 )
318
315
@ NodeChild (value = "bindingNode" , type = RubyNode .class )
319
316
@ NodeChild (value = "nameNode" , type = RubyBaseNodeWithExecute .class )
320
317
@ NodeChild (value = "valueNode" , type = RubyNode .class )
321
- @ ImportStatic ({ BindingNodes .class , FindDeclarationVariableNodes .class })
322
- public abstract static class LocalVariableSetNode extends RubySourceNode {
323
-
324
- @ NeverDefault
325
- public static LocalVariableSetNode create () {
326
- return BindingNodesFactory .LocalVariableSetNodeFactory .create (null , null , null );
327
- }
328
-
329
- public static LocalVariableSetNode create (RubyNode bindingNode , RubyBaseNodeWithExecute nameNode ,
330
- RubyNode valueNode ) {
331
- return BindingNodesFactory .LocalVariableSetNodeFactory .create (bindingNode , nameNode , valueNode );
332
- }
333
-
334
- public abstract Object execute (RubyBinding binding , String name , Object value );
318
+ public abstract static class BindingLocalVariableSetNode extends RubySourceNode {
335
319
336
320
abstract RubyNode getBindingNode ();
337
321
@@ -344,77 +328,10 @@ protected RubyBaseNodeWithExecute coerceToString(RubyBaseNodeWithExecute name) {
344
328
return NameToJavaStringNode .create (name );
345
329
}
346
330
347
- @ Specialization (
348
- guards = {
349
- "name == cachedName" ,
350
- "!isHiddenVariable(cachedName)" ,
351
- "getFrameDescriptor(binding) == cachedFrameDescriptor" ,
352
- "cachedFrameSlot != null" },
353
- limit = "getCacheLimit()" )
354
- protected Object localVariableSetCached (RubyBinding binding , String name , Object value ,
355
- @ Cached ("name" ) String cachedName ,
356
- @ Cached ("getFrameDescriptor(binding)" ) FrameDescriptor cachedFrameDescriptor ,
357
- @ Cached ("findFrameSlotOrNull(name, binding.getFrame())" ) FrameSlotAndDepth cachedFrameSlot ,
358
- @ Cached ("createWriteNode(cachedFrameSlot.slot)" ) WriteFrameSlotNode writeLocalVariableNode ) {
359
- final MaterializedFrame frame = RubyArguments
360
- .getDeclarationFrame (binding .getFrame (), cachedFrameSlot .depth );
361
- writeLocalVariableNode .executeWrite (frame , value );
362
- return value ;
363
- }
364
-
365
- @ Specialization (
366
- guards = {
367
- "name == cachedName" ,
368
- "!isHiddenVariable(cachedName)" ,
369
- "getFrameDescriptor(binding) == cachedFrameDescriptor" ,
370
- "cachedFrameSlot == null" },
371
- limit = "getCacheLimit()" )
372
- protected Object localVariableSetNewCached (RubyBinding binding , String name , Object value ,
373
- @ Cached ("name" ) String cachedName ,
374
- @ Cached ("getFrameDescriptor(binding)" ) FrameDescriptor cachedFrameDescriptor ,
375
- @ Cached ("findFrameSlotOrNull(name, binding.getFrame())" ) FrameSlotAndDepth cachedFrameSlot ,
376
- @ Cached ("newFrameDescriptor(cachedFrameDescriptor, name)" ) FrameDescriptor newDescriptor ,
377
- @ Cached ("createWriteNode(NEW_VAR_INDEX)" ) WriteFrameSlotNode writeLocalVariableNode ) {
378
- final MaterializedFrame frame = newFrame (binding , newDescriptor );
379
- writeLocalVariableNode .executeWrite (frame , value );
380
- return value ;
381
- }
382
-
383
- @ TruffleBoundary
384
- @ Specialization (
385
- guards = "!isHiddenVariable(name)" ,
386
- replaces = { "localVariableSetCached" , "localVariableSetNewCached" })
387
- protected Object localVariableSetUncached (RubyBinding binding , String name , Object value ) {
388
- MaterializedFrame frame = binding .getFrame ();
389
- final FrameSlotAndDepth frameSlot = FindDeclarationVariableNodes .findFrameSlotOrNull (name , frame );
390
- final int slot ;
391
- if (frameSlot != null ) {
392
- frame = RubyArguments .getDeclarationFrame (frame , frameSlot .depth );
393
- slot = frameSlot .slot ;
394
- } else {
395
- var newDescriptor = newFrameDescriptor (getFrameDescriptor (binding ), name );
396
- frame = newFrame (binding , newDescriptor );
397
- assert newDescriptor .getSlotName (NEW_VAR_INDEX ) == name ;
398
- slot = NEW_VAR_INDEX ;
399
- }
400
- frame .setObject (slot , value );
401
- return value ;
402
- }
403
-
404
- @ TruffleBoundary
405
- @ Specialization (guards = "isHiddenVariable(name)" )
406
- protected Object localVariableSetLastLine (RubyBinding binding , String name , Object value ) {
407
- throw new RaiseException (
408
- getContext (),
409
- coreExceptions ().nameError ("Bad local variable name" , binding , name , this ));
410
- }
411
-
412
- protected WriteFrameSlotNode createWriteNode (int frameSlot ) {
413
- return WriteFrameSlotNodeGen .create (frameSlot );
414
- }
415
-
416
- protected int getCacheLimit () {
417
- return getLanguage ().options .BINDING_LOCAL_VARIABLE_CACHE ;
331
+ @ Specialization
332
+ protected Object localVariableSet (RubyBinding binding , String name , Object value ,
333
+ @ Cached LocalVariableSetNode localVariableSetNode ) {
334
+ return localVariableSetNode .execute (binding , name , value );
418
335
}
419
336
420
337
private RubyBaseNodeWithExecute getNameNodeBeforeCasting () {
@@ -423,12 +340,11 @@ private RubyBaseNodeWithExecute getNameNodeBeforeCasting() {
423
340
424
341
@ Override
425
342
public RubyNode cloneUninitialized () {
426
- return create (
343
+ return BindingNodesFactory . BindingLocalVariableSetNodeFactory . create (
427
344
getBindingNode ().cloneUninitialized (),
428
345
getNameNodeBeforeCasting ().cloneUninitialized (),
429
346
getValueNode ().cloneUninitialized ()).copyFlags (this );
430
347
}
431
-
432
348
}
433
349
434
350
@ Primitive (name = "local_variable_names" )
0 commit comments