Skip to content

Commit

Permalink
[Truffle] Add UnboundMethod#hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Fish committed Sep 16, 2016
1 parent ac60bbe commit 10ce714
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/unboundmethod/hash_tags.txt

This file was deleted.

Expand Up @@ -17,6 +17,7 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
Expand All @@ -30,6 +31,7 @@
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.methods.CanBindMethodToModuleNode;
import org.jruby.truffle.language.methods.CanBindMethodToModuleNodeGen;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.objects.MetaClassNode;
import org.jruby.truffle.language.objects.MetaClassNodeGen;

Expand Down Expand Up @@ -99,6 +101,20 @@ protected DynamicObject metaClass(Object object) {

}

@CoreMethod(names = "hash")
public abstract static class HashNode extends CoreMethodArrayArgumentsNode {

@Specialization
public long hash(DynamicObject rubyMethod) {
final InternalMethod method = Layouts.UNBOUND_METHOD.getMethod(rubyMethod);
long h = Helpers.hashStart(getContext().getJRubyRuntime(), method.getDeclaringModule().hashCode());
h = Helpers.murmurCombine(h, Layouts.UNBOUND_METHOD.getOrigin(rubyMethod).hashCode());
h = Helpers.murmurCombine(h, method.getSharedMethodInfo().hashCode());
return Helpers.hashEnd(h);
}

}

@CoreMethod(names = "name")
public abstract static class NameNode extends CoreMethodArrayArgumentsNode {

Expand Down

0 comments on commit 10ce714

Please sign in to comment.