15
15
import java .util .Set ;
16
16
17
17
import com .oracle .truffle .api .CompilerDirectives ;
18
+ import com .oracle .truffle .api .dsl .GenerateCached ;
19
+ import com .oracle .truffle .api .dsl .GenerateInline ;
18
20
import com .oracle .truffle .api .dsl .GenerateUncached ;
19
21
import com .oracle .truffle .api .dsl .Idempotent ;
20
22
import com .oracle .truffle .api .dsl .NeverDefault ;
21
23
import com .oracle .truffle .api .frame .FrameSlotKind ;
24
+ import com .oracle .truffle .api .nodes .Node ;
22
25
import com .oracle .truffle .api .strings .TruffleString ;
23
26
import org .truffleruby .Layouts ;
24
27
import org .truffleruby .RubyContext ;
@@ -214,20 +217,32 @@ protected int getCacheLimit() {
214
217
@ CoreMethod (names = "local_variable_defined?" , required = 1 )
215
218
@ NodeChild (value = "bindingNode" , type = RubyNode .class )
216
219
@ NodeChild (value = "nameNode" , type = RubyBaseNodeWithExecute .class )
217
- public abstract static class LocalVariableDefinedNode extends CoreMethodNode {
220
+ public abstract static class BindingLocalVariableDefinedNode extends CoreMethodNode {
218
221
219
- @ CreateCast ("nameNode" )
220
- protected RubyBaseNodeWithExecute coerceToString (RubyBaseNodeWithExecute name ) {
221
- return NameToJavaStringNode .create (name );
222
+ @ Specialization
223
+ protected boolean localVariableDefined (RubyBinding binding , Object nameObject ,
224
+ @ Cached NameToJavaStringNode nameToJavaStringNode ,
225
+ @ Cached LocalVariableDefinedNode localVariableDefinedNode ) {
226
+ final var name = nameToJavaStringNode .execute (nameObject );
227
+ return localVariableDefinedNode .execute (this , binding , name );
222
228
}
229
+ }
230
+
231
+
232
+ @ ImportStatic ({ BindingNodes .class , FindDeclarationVariableNodes .class })
233
+ @ GenerateCached (false )
234
+ @ GenerateInline
235
+ public abstract static class LocalVariableDefinedNode extends RubyBaseNode {
236
+
237
+ public abstract boolean execute (Node node , RubyBinding binding , String name );
223
238
224
239
@ Specialization (
225
240
guards = {
226
241
"name == cachedName" ,
227
242
"!isHiddenVariable(cachedName)" ,
228
243
"getFrameDescriptor(binding) == descriptor" },
229
244
limit = "getCacheLimit()" )
230
- protected boolean localVariableDefinedCached (RubyBinding binding , String name ,
245
+ protected static boolean localVariableDefinedCached (RubyBinding binding , String name ,
231
246
@ Cached ("name" ) String cachedName ,
232
247
@ Cached ("getFrameDescriptor(binding)" ) FrameDescriptor descriptor ,
233
248
@ Cached ("findFrameSlotOrNull(name, binding.getFrame())" ) FrameSlotAndDepth cachedFrameSlot ) {
@@ -236,16 +251,16 @@ protected boolean localVariableDefinedCached(RubyBinding binding, String name,
236
251
237
252
@ TruffleBoundary
238
253
@ Specialization (guards = "!isHiddenVariable(name)" , replaces = "localVariableDefinedCached" )
239
- protected boolean localVariableDefinedUncached (RubyBinding binding , String name ) {
254
+ protected static boolean localVariableDefinedUncached (RubyBinding binding , String name ) {
240
255
return FindDeclarationVariableNodes .findFrameSlotOrNull (name , binding .getFrame ()) != null ;
241
256
}
242
257
243
258
@ TruffleBoundary
244
259
@ Specialization (guards = "isHiddenVariable(name)" )
245
- protected Object localVariableDefinedLastLine (RubyBinding binding , String name ) {
260
+ protected static boolean localVariableDefinedLastLine (Node node , RubyBinding binding , String name ) {
246
261
throw new RaiseException (
247
- getContext (),
248
- coreExceptions ().nameError ("Bad local variable name" , binding , name , this ));
262
+ getContext (node ),
263
+ coreExceptions (node ).nameError ("Bad local variable name" , binding , name , node ));
249
264
}
250
265
251
266
protected int getCacheLimit () {
@@ -484,7 +499,6 @@ public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
484
499
protected Object allocate (RubyClass rubyClass ) {
485
500
throw new RaiseException (getContext (), coreExceptions ().typeErrorAllocatorUndefinedFor (rubyClass , this ));
486
501
}
487
-
488
502
}
489
503
490
504
@ Primitive (name = "create_empty_binding" )
@@ -493,7 +507,8 @@ public abstract static class CreateEmptyBindingNode extends PrimitiveArrayArgume
493
507
protected RubyBinding binding (VirtualFrame frame ) {
494
508
// Use the current frame to initialize the arguments, etc, correctly
495
509
final RubyBinding binding = BindingNodes
496
- .createBinding (getContext (), getLanguage (), frame .materialize (), getEncapsulatingSourceSection ());
510
+ .createBinding (getContext (), getLanguage (), frame .materialize (),
511
+ getEncapsulatingSourceSection ());
497
512
498
513
final MaterializedFrame newFrame = newFrame (binding , getLanguage ().emptyDeclarationDescriptor );
499
514
RubyArguments .setDeclarationFrame (newFrame , null ); // detach from the current frame
0 commit comments