Skip to content

Commit

Permalink
[Truffle] Implemented Kernel#eval with a String-coerced argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Dec 5, 2014
1 parent aaed4a6 commit 3c98a0f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ public static boolean isSecondFloat(Object a, Object b) {
return b instanceof Double;
}

public static boolean isString(Object o) {
return o instanceof RubyString;
}

public RubyBignum bignum(int value) {
return bignum((long) value);
}
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,16 @@ public EqlNode(EqlNode prev) {
@CoreMethod(names = "eval", isModuleFunction = true, required = 1, optional = 1)
public abstract static class EvalNode extends CoreMethodNode {

@Child protected DispatchHeadNode toStr;

public EvalNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
toStr = new DispatchHeadNode(context);
}

public EvalNode(EvalNode prev) {
super(prev);
toStr = prev.toStr;
}

@Specialization
Expand All @@ -501,6 +505,14 @@ public Object eval(RubyString source, RubyBinding binding) {
return getContext().eval(source.toString(), binding, this);
}

@Specialization(guards = "!isString")
public Object eval(VirtualFrame frame, RubyBasicObject object, UndefinedPlaceholder binding) {
notDesignedForCompilation();

RubyString coerced = (RubyString) toStr.call(frame, object, "to_str", null);

return getContext().eval(coerced.toString(), this);
}
}

@CoreMethod(names = "exec", isModuleFunction = true, required = 1, argumentsAsArray = true)
Expand Down
2 changes: 1 addition & 1 deletion spec/truffle/tags/core/kernel/eval_tags.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fails:Kernel#eval is a private method
fails:Kernel#eval is a module function
fails:Kernel#eval evaluates the code within
fails:Kernel#eval coerces an object to string
passes:Kernel#eval coerces an object to string
fails:Kernel#eval evaluates within the scope of the eval
fails:Kernel#eval evaluates such that consts are scoped to the class of the eval
fails:Kernel#eval finds a local in an enclosing scope
Expand Down

0 comments on commit 3c98a0f

Please sign in to comment.