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

Commits on Feb 17, 2015

  1. [Truffle] Moved Kernel#print to Rubinius.

    To make this work I needed to move the writing to STDOUT elsewhere.  IO#write is the natural place for this to go, although it shouldn't be couple to STDOUT like it currently is.  The implementation is wrong, as was the old one, but wrong in a different way.  The big difference now is /STDOUT can be redefined and Kernel#print will react accordingly.
    nirvdrum committed Feb 17, 2015
    2
    Copy the full SHA
    a18125f View commit details
  2. Copy the full SHA
    845da02 View commit details
3 changes: 0 additions & 3 deletions spec/truffle/tags/rubysl/rubysl-erb/spec/run_tags.txt

This file was deleted.

57 changes: 57 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/IONodes.java
Original file line number Diff line number Diff line change
@@ -9,16 +9,23 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.CreateCast;
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.cast.ToSNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyFile;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.subsystems.ThreadManager;
import org.jruby.util.ByteList;

import java.io.BufferedReader;
import java.io.FileInputStream;
@@ -68,4 +75,54 @@ public RubyArray readLines(RubyString file) {

}

@CoreMethod(names = "write", needsSelf = false, required = 1)
@NodeChild(value = "string")
public abstract static class WriteNode extends RubyNode {

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

public WriteNode(WriteNode prev) {
super(prev);
}

@CreateCast("string") public RubyNode callToS(RubyNode other) {
return ToSNodeFactory.create(getContext(), getSourceSection(), other);
}

@Specialization
public int write(RubyString string) {
notDesignedForCompilation();

final ByteList byteList = string.getByteList();

final int offset = byteList.getBegin();
final int length = byteList.getRealSize();
final byte[] bytes = byteList.getUnsafeBytes();

getContext().getThreadManager().runUntilResult(new ThreadManager.BlockingActionWithoutGlobalLock<Boolean>() {
@Override
public Boolean block() throws InterruptedException {
write(bytes, offset, length);

return SUCCESS;
}
});

return length;
}

@CompilerDirectives.TruffleBoundary
private void write(byte[] bytes, int offset, int length) throws InterruptedException {
if (Thread.interrupted()) {
throw new InterruptedException();
}

// TODO (nirvdrum 17-Feb-15) This shouldn't always just write to STDOUT, but that's the only use case we're supporting currently.
getContext().getRuntime().getInstanceConfig().getOutput().write(bytes, offset, length);
}

}

}
Original file line number Diff line number Diff line change
@@ -1355,62 +1355,6 @@ public boolean nil() {
}
}

@CoreMethod(names = "print", isModuleFunction = true, argumentsAsArray = true)
public abstract static class PrintNode extends CoreMethodNode {

@Child private CallDispatchHeadNode toS;

public PrintNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
toS = DispatchHeadNodeFactory.createMethodCall(context);
}

public PrintNode(PrintNode prev) {
super(prev);
toS = prev.toS;
}

@Specialization
public RubyNilClass print(VirtualFrame frame, Object[] args) {
final byte[][] bytes = new byte[args.length][];

for (int i = 0; i < args.length; i++) {
bytes[i] = ((RubyString) toS.call(frame, args[i], "to_s", null)).getBytes().bytes();
}

getContext().getThreadManager().runUntilResult(new BlockingActionWithoutGlobalLock<Boolean>() {
int i = 0;

@Override
public Boolean block() throws InterruptedException {
while (i < bytes.length) {
write(bytes[i]);
i++;

}
return SUCCESS;
}
});

return getContext().getCoreLibrary().getNilObject();
}

@TruffleBoundary
private void write(byte[] bytes) throws InterruptedException {
if (Thread.interrupted()) {
throw new InterruptedException();
}

// TODO (eregon, 11 Nov. 2015): the write itself should throw InterruptedException
try{
getContext().getRuntime().getInstanceConfig().getOutput().write(bytes);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

}

@CoreMethod(names = "private_methods", optional = 1)
public abstract static class PrivateMethodsNode extends CoreMethodNode {

8 changes: 8 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/kernel.rb
Original file line number Diff line number Diff line change
@@ -105,6 +105,14 @@ def object_id
raise PrimitiveFailure, "Kernel#object_id primitive failed"
end

def print(*args)
args.each do |obj|
$stdout.write obj.to_s
end
nil
end
module_function :print

def trap(sig, prc=nil, &block)
Signal.trap(sig, prc, &block)
end
4 changes: 2 additions & 2 deletions truffle/src/main/ruby/core/shims.rb
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ def self.set_encoding(external, internal)
end
end

module STDOUT
class STDOUT < IO
def self.puts(*values)
Kernel.send(:puts, *values)
end
@@ -42,7 +42,7 @@ def self.printf(*values)
end

def self.write(value)
print value
IO.new.write value
end

def self.flush