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: a68080f0d2f8
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5b428b67cadf
Choose a head ref
  • 4 commits
  • 4 files changed
  • 1 contributor

Commits on Feb 14, 2016

  1. Copy the full SHA
    7a80f92 View commit details
  2. Copy the full SHA
    168a890 View commit details
  3. Copy the full SHA
    c4ddbba View commit details
  4. Copy the full SHA
    5b428b6 View commit details
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@
import org.jruby.truffle.core.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.core.RubiniusOnly;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;
import org.jruby.util.ByteList;
@@ -61,8 +63,8 @@ public DynamicObject initialize(DynamicObject self, Object source, Object destin
int[] ecflags = {0};
IRubyObject[] ecopts = {runtime.getNil()};

final IRubyObject sourceAsJRubyObj = getContext().getJRubyInterop().toJRuby(source);
final IRubyObject destinationAsJRubyObj = getContext().getJRubyInterop().toJRuby(destination);
final IRubyObject sourceAsJRubyObj = toJRuby(source);
final IRubyObject destinationAsJRubyObj = toJRuby(destination);

EncodingUtils.econvArgs(runtime.getCurrentContext(), new IRubyObject[]{sourceAsJRubyObj, destinationAsJRubyObj}, encNames, encs, ecflags, ecopts);

@@ -112,6 +114,16 @@ private int rubiniusToJRubyFlags(int flags) {
return flags;
}

private IRubyObject toJRuby(Object object) {
if (RubyGuards.isRubyString(object)) {
return getContext().getJRubyRuntime().newString(StringOperations.rope((DynamicObject) object).toByteListCopy());
} else if (RubyGuards.isRubyEncoding(object)) {
return getContext().getJRubyRuntime().getEncodingService().rubyEncodingFromObject(getContext().getJRubyRuntime().newString(Layouts.ENCODING.getName((DynamicObject) object)));
} else {
throw new UnsupportedOperationException();
}
}

}

@RubiniusOnly
27 changes: 12 additions & 15 deletions truffle/src/main/java/org/jruby/truffle/interop/JRubyInterop.java
Original file line number Diff line number Diff line change
@@ -31,21 +31,6 @@ public JRubyInterop(RubyContext context) {
this.context = context;
}

@CompilerDirectives.TruffleBoundary
public IRubyObject toJRuby(Object object) {
if (object == context.getCoreLibrary().getNilObject()) {
return context.getJRubyRuntime().getNil();
} else if (object instanceof Boolean) {
return context.getJRubyRuntime().newBoolean((boolean) object);
} else if (RubyGuards.isRubyString(object)) {
return context.getJRubyRuntime().newString(StringOperations.rope((DynamicObject) object).toByteListCopy());
} else if (RubyGuards.isRubyEncoding(object)) {
return context.getJRubyRuntime().getEncodingService().rubyEncodingFromObject(context.getJRubyRuntime().newString(Layouts.ENCODING.getName((DynamicObject) object)));
} else {
throw new UnsupportedOperationException();
}
}

@CompilerDirectives.TruffleBoundary
public Object toTruffle(IRubyObject object) {
if (object instanceof org.jruby.RubyFixnum) {
@@ -78,6 +63,10 @@ public DynamicObject toTruffle(org.jruby.RubyException jrubyException, RubyNode
throw new UnsupportedOperationException();
}

public String getArg0() {
return context.getJRubyRuntime().getGlobalVariables().get("$0").toString();
}

public String[] getArgv() {
final IRubyObject[] jrubyStrings = ((org.jruby.RubyArray) context.getJRubyRuntime().getObject().getConstant("ARGV")).toJavaArray();
final String[] strings = new String[jrubyStrings.length];
@@ -110,4 +99,12 @@ public String[] getOriginalLoadPath() {
return loadPath.toArray(new String[loadPath.size()]);
}

public void setVerbose(boolean verbose) {
context.getJRubyRuntime().setVerbose(context.getJRubyRuntime().newBoolean(verbose));
}

public void setVerboseNil() {
context.getJRubyRuntime().setVerbose(context.getJRubyRuntime().getNil());
}

}
Original file line number Diff line number Diff line change
@@ -9,10 +9,9 @@
*/
package org.jruby.truffle.language.globals;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

@@ -26,15 +25,20 @@ public UpdateVerbosityNode(RubyContext context, SourceSection sourceSection, Rub
}

public Object execute(VirtualFrame frame) {
CompilerDirectives.transferToInterpreter();

final Object childValue = child.execute(frame);

final IRubyObject jrubyValue = getContext().getJRubyInterop().toJRuby(childValue);

getContext().getJRubyRuntime().setVerbose(jrubyValue);

setVerbose(childValue);
return childValue;
}

@TruffleBoundary
private void setVerbose(Object childValue) {
if (childValue instanceof Boolean) {
getContext().getJRubyInterop().setVerbose((boolean) childValue);
} else if (childValue == nil()) {
getContext().getJRubyInterop().setVerboseNil();
} else {
throw new UnsupportedOperationException();
}
}

}
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ public Object execute(TranslatorDriver.ParserContext parserContext, DeclarationC
}

public Object execute(final org.jruby.ast.RootNode rootNode) {
context.getCoreLibrary().getGlobalVariablesObject().define("$0", context.getJRubyInterop().toTruffle(context.getJRubyRuntime().getGlobalVariables().get("$0")), 0);
context.getCoreLibrary().getGlobalVariablesObject().define("$0", StringOperations.createString(context, ByteList.create(context.getJRubyInterop().getArg0())), 0);

String inputFile = rootNode.getPosition().getFile();
final Source source;