Skip to content

Commit

Permalink
Showing 4 changed files with 52 additions and 7 deletions.
17 changes: 17 additions & 0 deletions spec/truffle/specs/truffle/interop/from_java_string_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2016 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

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.from_java_string" do

it "can be round-tripped with to_java_string" do
Truffle::Interop.from_java_string(Truffle::Interop.to_java_string("foo")).should == "foo"
end

end
17 changes: 17 additions & 0 deletions spec/truffle/specs/truffle/interop/to_java_string_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2016 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

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.to_java_string" do

it "can be round-tripped with from_java_string" do
Truffle::Interop.from_java_string(Truffle::Interop.to_java_string("foo")).should == "foo"
end

end
Original file line number Diff line number Diff line change
@@ -24,10 +24,6 @@
@NodeChild(value = "value", type = RubyNode.class)
public abstract class ForeignToRubyNode extends RubyNode {

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

public abstract Object executeConvert(VirtualFrame frame, Object value);

@Specialization(guards = "stringsEquals(cachedValue, value)", limit = "getLimit()")
21 changes: 18 additions & 3 deletions truffle/src/main/java/org/jruby/truffle/interop/InteropNodes.java
Original file line number Diff line number Diff line change
@@ -616,13 +616,28 @@ protected int getCacheLimit() {
@CoreMethod(names = "to_java_string", isModuleFunction = true, needsSelf = false, required = 1)
public abstract static class InteropToJavaStringNode extends CoreMethodArrayArgumentsNode {

@Child NameToJavaStringNode toJavaStringNode = NameToJavaStringNode.create();

@Specialization
public Object toJavaString(VirtualFrame frame, Object value) {
public Object toJavaString(
VirtualFrame frame, Object value,
@Cached("create()") NameToJavaStringNode toJavaStringNode) {
return toJavaStringNode.executeToJavaString(frame, value);
}

}

@CoreMethod(names = "from_java_string", isModuleFunction = true, needsSelf = false, required = 1)
public abstract static class InteropFromJavaStringNode extends CoreMethodArrayArgumentsNode {

@Specialization
public Object fromJavaString(VirtualFrame frame, Object value,
@Cached("createForeignToRubyNode()") ForeignToRubyNode foreignToRubyNode) {
return foreignToRubyNode.executeConvert(frame, value);
}

protected ForeignToRubyNode createForeignToRubyNode() {
return ForeignToRubyNodeGen.create(null);
}

}

}

0 comments on commit 192a408

Please sign in to comment.