13
13
import com .oracle .truffle .api .dsl .CreateCast ;
14
14
import com .oracle .truffle .api .dsl .NodeChild ;
15
15
import com .oracle .truffle .api .dsl .Specialization ;
16
+ import com .oracle .truffle .api .frame .VirtualFrame ;
16
17
import com .oracle .truffle .api .source .SourceSection ;
17
18
import com .oracle .truffle .api .utilities .ConditionProfile ;
18
19
import org .jcodings .Encoding ;
23
24
import org .jcodings .util .Hash ;
24
25
import org .jruby .runtime .encoding .EncodingService ;
25
26
import org .jruby .truffle .nodes .RubyNode ;
27
+ import org .jruby .truffle .nodes .coerce .ToStrNode ;
26
28
import org .jruby .truffle .nodes .coerce .ToStrNodeFactory ;
27
29
import org .jruby .truffle .runtime .RubyContext ;
28
30
import org .jruby .truffle .runtime .core .RubyArray ;
@@ -199,6 +201,8 @@ public RubyEncoding defaultExternal(RubyEncoding encoding) {
199
201
@ CoreMethod (names = "default_internal=" , onSingleton = true , required = 1 )
200
202
public abstract static class SetDefaultInternalNode extends CoreMethodNode {
201
203
204
+ @ Child private ToStrNode toStrNode ;
205
+
202
206
public SetDefaultInternalNode (RubyContext context , SourceSection sourceSection ) {
203
207
super (context , sourceSection );
204
208
}
@@ -208,7 +212,7 @@ public SetDefaultInternalNode(SetDefaultInternalNode prev) {
208
212
}
209
213
210
214
@ Specialization
211
- public RubyEncoding defaultExternal (RubyEncoding encoding ) {
215
+ public RubyEncoding defaultInternal (RubyEncoding encoding ) {
212
216
notDesignedForCompilation ();
213
217
214
218
getContext ().getRuntime ().setDefaultInternalEncoding (encoding .getEncoding ());
@@ -217,14 +221,29 @@ public RubyEncoding defaultExternal(RubyEncoding encoding) {
217
221
}
218
222
219
223
@ Specialization
220
- public RubyNilClass defaultExternal (RubyNilClass encoding ) {
224
+ public RubyNilClass defaultInternal (RubyNilClass encoding ) {
221
225
notDesignedForCompilation ();
222
226
223
- getContext ().getRuntime ().setDefaultInternalEncoding (ASCIIEncoding . INSTANCE );
227
+ getContext ().getRuntime ().setDefaultInternalEncoding (null );
224
228
225
229
return encoding ;
226
230
}
227
231
232
+ @ Specialization
233
+ public RubyString defaultInternal (VirtualFrame frame , Object encoding ) {
234
+ notDesignedForCompilation ();
235
+
236
+ if (toStrNode == null ) {
237
+ CompilerDirectives .transferToInterpreter ();
238
+ toStrNode = insert (ToStrNodeFactory .create (getContext (), getSourceSection (), null ));
239
+ }
240
+
241
+ final RubyString encodingName = toStrNode .executeRubyString (frame , encoding );
242
+ getContext ().getRuntime ().setDefaultInternalEncoding (RubyEncoding .getEncoding (encodingName .toString ()).getEncoding ());
243
+
244
+ return encodingName ;
245
+ }
246
+
228
247
}
229
248
230
249
@ CoreMethod (names = "find" , onSingleton = true , required = 1 )
0 commit comments