Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into truffle-head
- Loading branch information
Showing
40 changed files
with
665 additions
and
167 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
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
101 changes: 101 additions & 0 deletions
101
core/src/main/java/org/jruby/truffle/nodes/cast/HashCastNode.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,101 @@ | ||
/* | ||
* Copyright (c) 2014 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.jruby.truffle.nodes.cast; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.NodeChild; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.nodes.RubyNode; | ||
import org.jruby.truffle.nodes.dispatch.Dispatch; | ||
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode; | ||
import org.jruby.truffle.runtime.RubyContext; | ||
import org.jruby.truffle.runtime.control.RaiseException; | ||
import org.jruby.truffle.runtime.core.*; | ||
|
||
// TODO(CS): copy and paste of ArrayCastNode | ||
|
||
@NodeChild("child") | ||
public abstract class HashCastNode extends RubyNode { | ||
|
||
@Child protected DispatchHeadNode toHashNode; | ||
|
||
public HashCastNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
toHashNode = new DispatchHeadNode(context, Dispatch.MissingBehavior.RETURN_MISSING); | ||
} | ||
|
||
public HashCastNode(HashCastNode prev) { | ||
super(prev); | ||
toHashNode = prev.toHashNode; | ||
} | ||
|
||
protected abstract RubyNode getChild(); | ||
|
||
@Specialization | ||
public RubyNilClass cast(boolean value) { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
|
||
@Specialization | ||
public RubyNilClass cast(int value) { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
|
||
@Specialization | ||
public RubyNilClass cast(long value) { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
|
||
@Specialization | ||
public RubyNilClass cast(double value) { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
|
||
@Specialization | ||
public RubyNilClass cast(RubyBignum value) { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
|
||
@Specialization | ||
public RubyHash cast(RubyHash hash) { | ||
return hash; | ||
} | ||
|
||
@Specialization | ||
public RubyNilClass cast(RubyNilClass nil) { | ||
return nil; | ||
} | ||
|
||
@Specialization(guards = {"!isRubyNilClass", "!isRubyHash"}) | ||
public Object cast(VirtualFrame frame, RubyBasicObject object) { | ||
notDesignedForCompilation(); | ||
|
||
final Object result = toHashNode.call(frame, object, "to_hash", null, new Object[]{}); | ||
|
||
if (result == Dispatch.MISSING) { | ||
return getContext().getCoreLibrary().getNilObject(); | ||
} | ||
|
||
if (!(result instanceof RubyHash)) { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new RaiseException(getContext().getCoreLibrary().typeErrorShouldReturn(object.toString(), "to_hash", "HAsh", this)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
@Override | ||
public void executeVoid(VirtualFrame frame) { | ||
getChild().executeVoid(frame); | ||
} | ||
|
||
} |
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
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
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
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
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
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
Oops, something went wrong.