Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: da5b603c0b9e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e58231aee086
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Dec 2, 2014

  1. Copy the full SHA
    4dbd038 View commit details
  2. Copy the full SHA
    e58231a View commit details
37 changes: 37 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/HashNodes.java
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
@@ -1004,6 +1005,42 @@ public RubyHash mergeObjectArrayObjectArray(VirtualFrame frame, RubyHash hash, R

}

@CoreMethod(names = "default", optional = 1)
public abstract static class DefaultNode extends HashCoreMethodNode {

public DefaultNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public DefaultNode(DefaultNode prev) {
super(prev);
}

@Specialization
public Object defaultElement(VirtualFrame frame, RubyHash hash, UndefinedPlaceholder undefined) {
Object ret = hash.getDefaultValue();

// TODO (nirvdrum Dec. 1, 2014): This needs to evaluate the defaultProc if it exists before it tries defaultValue.
if (ret != null) {
return ret;
} else {
return getContext().getCoreLibrary().getNilObject();
}
}

@Specialization
public Object defaultElement(VirtualFrame frame, RubyHash hash, Object key) {
Object ret = hash.getDefaultValue();

// TODO (nirvdrum Dec. 1, 2014): This really needs to do something with the key. Dummy stub for now.
if (ret != null) {
return ret;
} else {
return getContext().getCoreLibrary().getNilObject();
}
}
}

@CoreMethod(names = "size")
public abstract static class SizeNode extends HashCoreMethodNode {

17 changes: 17 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/NilClassNodes.java
Original file line number Diff line number Diff line change
@@ -120,6 +120,23 @@ public RubyString toS() {
}
}

@CoreMethod(names = "to_h", needsSelf = false)
public abstract static class ToHNode extends CoreMethodNode {

public ToHNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public ToHNode(ToHNode prev) {
super(prev);
}

@Specialization
public RubyHash toH() {
return new RubyHash(getContext().getCoreLibrary().getHashClass(), null, getContext().getCoreLibrary().getNilObject(), null, 0);
}
}

@CoreMethod(names = "dup", needsSelf = false)
public abstract static class DupNode extends CoreMethodNode {

1 change: 0 additions & 1 deletion spec/truffle/tags/core/hash/default_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fails:Hash#default returns the default value
fails:Hash#default uses the default proc to compute a default value, passing given key
fails:Hash#default calls default proc with nil arg if passed a default proc but no arg
fails:Hash#default= sets the default value
1 change: 0 additions & 1 deletion spec/truffle/tags/core/nil/to_h_tags.txt

This file was deleted.