-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Unfortunately, this requires NilClass#nil? to be defined in Java, as otherwise we cannot replace nil? calls in the core library safely.
- Loading branch information
Showing
5 changed files
with
93 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/org/truffleruby/core/bool/NilClassNodes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.truffleruby.core.bool; | ||
|
||
import org.truffleruby.builtins.CoreClass; | ||
import org.truffleruby.builtins.CoreMethod; | ||
import org.truffleruby.builtins.CoreMethodNode; | ||
import org.truffleruby.core.inlined.InlinedIsNilNode; | ||
|
||
import com.oracle.truffle.api.dsl.Specialization; | ||
|
||
@CoreClass("NilClass") | ||
public abstract class NilClassNodes { | ||
|
||
/** Needs to be in Java for {@link InlinedIsNilNode} */ | ||
@CoreMethod(names = "nil?", needsSelf = false) | ||
public abstract static class AndNode extends CoreMethodNode { | ||
|
||
@Specialization | ||
public boolean isNil() { | ||
return true; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/org/truffleruby/core/inlined/InlinedIsNilNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.truffleruby.core.inlined; | ||
|
||
import org.truffleruby.RubyContext; | ||
import org.truffleruby.language.dispatch.RubyCallNodeParameters; | ||
import org.truffleruby.language.methods.LookupMethodNode; | ||
|
||
import com.oracle.truffle.api.dsl.Cached; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
|
||
public abstract class InlinedIsNilNode extends UnaryInlinedOperationNode { | ||
|
||
protected static final String METHOD = "nil?"; | ||
|
||
public InlinedIsNilNode(RubyContext context, RubyCallNodeParameters callNodeParameters) { | ||
super(callNodeParameters, | ||
context.getCoreMethods().nilClassIsNilAssumption); | ||
} | ||
|
||
@Specialization(guards = "isNil(self)", assumptions = "assumptions") | ||
boolean nil(Object self) { | ||
return true; | ||
} | ||
|
||
@Specialization(guards = { | ||
"!isForeignObject(self)", | ||
"lookupNode.lookup(frame, self, METHOD) == coreMethods().KERNEL_IS_NIL", | ||
}, assumptions = "assumptions", limit = "1") | ||
boolean notNil(VirtualFrame frame, Object self, | ||
@Cached("create()") LookupMethodNode lookupNode) { | ||
return false; | ||
} | ||
|
||
@Specialization | ||
Object fallback(VirtualFrame frame, Object self) { | ||
return rewriteAndCall(frame, self); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,10 +41,6 @@ def inspect | |
'nil' | ||
end | ||
|
||
def nil? | ||
true | ||
end | ||
|
||
def to_a | ||
[] | ||
end | ||
|