19
19
20
20
import com .oracle .truffle .api .CompilerDirectives ;
21
21
import com .oracle .truffle .api .frame .VirtualFrame ;
22
- import com . oracle . truffle . api . profiles . ConditionProfile ;
22
+ import org . truffleruby . language . library . RubyLibrary ;
23
23
24
24
public class WriteInstanceVariableNode extends RubyContextSourceNode implements AssignableNode {
25
25
26
26
private final String name ;
27
27
28
28
@ Child private RubyNode receiver ;
29
+ @ Child private RubyLibrary rubyLibrary ;
29
30
@ Child private RubyNode rhs ;
30
31
@ Child private WriteObjectFieldNode writeNode ;
31
32
32
- private final ConditionProfile objectProfile = ConditionProfile .create ();
33
-
34
33
public WriteInstanceVariableNode (String name , RubyNode receiver , RubyNode rhs ) {
35
34
this .name = name ;
36
35
this .receiver = receiver ;
@@ -52,23 +51,31 @@ public void assign(VirtualFrame frame, Object value) {
52
51
}
53
52
54
53
private void write (Object object , Object value ) {
55
- if (objectProfile .profile (object instanceof RubyDynamicObject )) {
56
- if (writeNode == null ) {
57
- CompilerDirectives .transferToInterpreterAndInvalidate ();
58
- writeNode = insert (WriteObjectFieldNode .create ());
59
- }
60
-
61
- writeNode .execute ((RubyDynamicObject ) object , name , value );
62
- } else {
54
+ if (getRubyLibrary ().isFrozen (object )) {
63
55
throw new RaiseException (getContext (), coreExceptions ().frozenError (object , this ));
64
56
}
57
+
58
+ if (writeNode == null ) {
59
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
60
+ writeNode = insert (WriteObjectFieldNode .create ());
61
+ }
62
+
63
+ writeNode .execute ((RubyDynamicObject ) object , name , value );
65
64
}
66
65
67
66
@ Override
68
67
public Object isDefined (VirtualFrame frame , RubyLanguage language , RubyContext context ) {
69
68
return coreStrings ().ASSIGNMENT .createInstance (context );
70
69
}
71
70
71
+ private RubyLibrary getRubyLibrary () {
72
+ if (rubyLibrary == null ) {
73
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
74
+ rubyLibrary = insert (RubyLibrary .getFactory ().createDispatched (getRubyLibraryCacheLimit ()));
75
+ }
76
+ return rubyLibrary ;
77
+ }
78
+
72
79
@ Override
73
80
public AssignableNode toAssignableNode () {
74
81
this .rhs = null ;
0 commit comments