28
28
import org .truffleruby .builtins .NonStandard ;
29
29
import org .truffleruby .builtins .Primitive ;
30
30
import org .truffleruby .builtins .PrimitiveArrayArgumentsNode ;
31
+ import org .truffleruby .builtins .PrimitiveNode ;
31
32
import org .truffleruby .builtins .UnaryCoreMethodNode ;
32
33
import org .truffleruby .core .array .ArrayUtils ;
33
34
import org .truffleruby .core .array .RubyArray ;
@@ -544,10 +545,10 @@ private DispatchingNode allocateNode() {
544
545
}
545
546
}
546
547
547
- @ CoreMethod ( names = "clone" , keywordAsOptional = "freeze " )
548
- @ NodeChild (value = "self " , type = RubyNode .class )
548
+ @ Primitive ( name = "object_clone " )
549
+ @ NodeChild (value = "object " , type = RubyNode .class )
549
550
@ NodeChild (value = "freeze" , type = RubyNode .class )
550
- public abstract static class CloneNode extends CoreMethodNode {
551
+ public abstract static class CloneNode extends PrimitiveNode {
551
552
552
553
@ Child private CopyNode copyNode = CopyNode .create ();
553
554
@ Child private DispatchNode initializeCloneNode = DispatchNode .create ();
@@ -559,95 +560,95 @@ protected RubyNode coerceToBoolean(RubyNode freeze) {
559
560
}
560
561
561
562
@ Specialization (limit = "getRubyLibraryCacheLimit()" )
562
- protected RubyDynamicObject clone (RubyDynamicObject self , boolean freeze ,
563
+ protected RubyDynamicObject clone (RubyDynamicObject object , boolean freeze ,
563
564
@ Cached ConditionProfile isSingletonProfile ,
564
565
@ Cached ConditionProfile freezeProfile ,
565
566
@ Cached ConditionProfile isFrozenProfile ,
566
567
@ Cached ConditionProfile isRubyClass ,
567
- @ CachedLibrary ("self " ) RubyLibrary rubyLibrary ,
568
+ @ CachedLibrary ("object " ) RubyLibrary rubyLibrary ,
568
569
@ CachedLibrary (limit = "getRubyLibraryCacheLimit()" ) RubyLibrary rubyLibraryFreeze ) {
569
- final RubyDynamicObject newObject = copyNode .executeCopy (self );
570
+ final RubyDynamicObject newObject = copyNode .executeCopy (object );
570
571
571
572
// Copy the singleton class if any.
572
- final RubyClass selfMetaClass = self .getMetaClass ();
573
+ final RubyClass selfMetaClass = object .getMetaClass ();
573
574
if (isSingletonProfile .profile (selfMetaClass .isSingleton )) {
574
575
final RubyClass newObjectMetaClass = executeSingletonClass (newObject );
575
576
newObjectMetaClass .fields .initCopy (selfMetaClass );
576
577
}
577
578
578
- initializeCloneNode .call (newObject , "initialize_clone" , self );
579
+ initializeCloneNode .call (newObject , "initialize_clone" , object );
579
580
580
- if (freezeProfile .profile (freeze ) && isFrozenProfile .profile (rubyLibrary .isFrozen (self ))) {
581
+ if (freezeProfile .profile (freeze ) && isFrozenProfile .profile (rubyLibrary .isFrozen (object ))) {
581
582
rubyLibraryFreeze .freeze (newObject );
582
583
}
583
584
584
- if (isRubyClass .profile (self instanceof RubyClass )) {
585
- ((RubyClass ) newObject ).superclass = ((RubyClass ) self ).superclass ;
585
+ if (isRubyClass .profile (object instanceof RubyClass )) {
586
+ ((RubyClass ) newObject ).superclass = ((RubyClass ) object ).superclass ;
586
587
}
587
588
588
589
return newObject ;
589
590
}
590
591
591
592
@ Specialization
592
- protected Object cloneBoolean (boolean self , boolean freeze ,
593
+ protected Object cloneBoolean (boolean object , boolean freeze ,
593
594
@ Cached ConditionProfile freezeProfile ) {
594
595
if (freezeProfile .profile (!freeze )) {
595
- raiseCantUnfreezeError (self );
596
+ raiseCantUnfreezeError (object );
596
597
}
597
- return self ;
598
+ return object ;
598
599
}
599
600
600
601
@ Specialization
601
- protected Object cloneInteger (int self , boolean freeze ,
602
+ protected Object cloneInteger (int object , boolean freeze ,
602
603
@ Cached ConditionProfile freezeProfile ) {
603
604
if (freezeProfile .profile (!freeze )) {
604
- raiseCantUnfreezeError (self );
605
+ raiseCantUnfreezeError (object );
605
606
}
606
- return self ;
607
+ return object ;
607
608
}
608
609
609
610
@ Specialization
610
- protected Object cloneLong (long self , boolean freeze ,
611
+ protected Object cloneLong (long object , boolean freeze ,
611
612
@ Cached ConditionProfile freezeProfile ) {
612
613
if (freezeProfile .profile (!freeze )) {
613
- raiseCantUnfreezeError (self );
614
+ raiseCantUnfreezeError (object );
614
615
}
615
- return self ;
616
+ return object ;
616
617
}
617
618
618
619
@ Specialization
619
- protected Object cloneFloat (double self , boolean freeze ,
620
+ protected Object cloneFloat (double object , boolean freeze ,
620
621
@ Cached ConditionProfile freezeProfile ) {
621
622
if (freezeProfile .profile (!freeze )) {
622
- raiseCantUnfreezeError (self );
623
+ raiseCantUnfreezeError (object );
623
624
}
624
- return self ;
625
+ return object ;
625
626
}
626
627
627
- @ Specialization (guards = "!isImmutableRubyString(value )" )
628
- protected Object cloneImmutableObject (ImmutableRubyObject value , boolean freeze ,
628
+ @ Specialization (guards = "!isImmutableRubyString(object )" )
629
+ protected Object cloneImmutableObject (ImmutableRubyObject object , boolean freeze ,
629
630
@ Cached ConditionProfile freezeProfile ) {
630
631
if (freezeProfile .profile (!freeze )) {
631
- raiseCantUnfreezeError (value );
632
+ raiseCantUnfreezeError (object );
632
633
}
633
- return value ;
634
+ return object ;
634
635
}
635
636
636
637
@ Specialization
637
- protected RubyDynamicObject cloneImmutableRubyString (ImmutableRubyString self , boolean freeze ,
638
+ protected RubyDynamicObject cloneImmutableRubyString (ImmutableRubyString object , boolean freeze ,
638
639
@ Cached ConditionProfile freezeProfile ,
639
640
@ CachedLibrary (limit = "getRubyLibraryCacheLimit()" ) RubyLibrary rubyLibraryFreeze ,
640
641
@ Cached MakeStringNode makeStringNode ) {
641
- final RubyDynamicObject newObject = makeStringNode .fromRope (self .rope , self .encoding );
642
+ final RubyDynamicObject newObject = makeStringNode .fromRope (object .rope , object .encoding );
642
643
if (freezeProfile .profile (freeze )) {
643
644
rubyLibraryFreeze .freeze (newObject );
644
645
}
645
646
646
647
return newObject ;
647
648
}
648
649
649
- private void raiseCantUnfreezeError (Object self ) {
650
- throw new RaiseException (getContext (), coreExceptions ().argumentErrorCantUnfreeze (self , this ));
650
+ private void raiseCantUnfreezeError (Object object ) {
651
+ throw new RaiseException (getContext (), coreExceptions ().argumentErrorCantUnfreeze (object , this ));
651
652
}
652
653
653
654
private RubyClass executeSingletonClass (RubyDynamicObject newObject ) {
0 commit comments