Skip to content

Commit

Permalink
[Truffle] Delegate Kernel#trap to Signal#trap.
Browse files Browse the repository at this point in the history
* Add a few specilizations (importing Rubinius code is not trivial).
  • Loading branch information
eregon committed Feb 5, 2015
1 parent 5df6bce commit 463db3d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/kernel/trap_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.common.IRubyWarnings;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.RubySymbol;
import org.jruby.truffle.runtime.signal.ProcSignalHandler;

import sun.misc.Signal;
import sun.misc.SignalHandler;

Expand All @@ -36,10 +39,30 @@ public SignalNode(SignalNode prev) {
}

@Specialization
public Object trap(RubyString signalName, UndefinedPlaceholder command, final RubyProc block) {
public Object trap(RubySymbol signalName, UndefinedPlaceholder command, RubyProc block) {
return trap(signalName.toString(), block);
}

@Specialization
public Object trap(RubyString signalName, UndefinedPlaceholder command, RubyProc block) {
return trap(signalName.toString(), block);
}

@Specialization
public Object trap(RubySymbol signalName, RubyProc proc, UndefinedPlaceholder block) {
return trap(signalName.toString(), proc);
}

@Specialization
public Object trap(RubyString signalName, RubyProc proc, UndefinedPlaceholder block) {
return trap(signalName.toString(), proc);
}

@SuppressWarnings("restriction")
private Object trap(String signalName, RubyProc block) {
notDesignedForCompilation();

final Signal signal = new Signal(signalName.toString());
final Signal signal = new Signal(signalName);

final SignalHandler newHandler = new ProcSignalHandler(getContext(), block);
final SignalHandler oldHandler = Signal.handle(signal, newHandler);
Expand All @@ -51,8 +74,17 @@ public Object trap(RubyString signalName, UndefinedPlaceholder command, final Ru
return getContext().getCoreLibrary().getNilObject();
}

@Specialization
public Object trap(RubySymbol signalName, RubyString command, UndefinedPlaceholder block) {
return trap(signalName.toString(), command, block);
}

@Specialization
public Object trap(RubyString signalName, RubyString command, UndefinedPlaceholder block) {
return trap(signalName.toString(), command, block);
}

private Object trap(String signalName, RubyString command, UndefinedPlaceholder block) {
notDesignedForCompilation();
getContext().getRuntime().getWarnings().warn(IRubyWarnings.ID.TRUFFLE, Truffle.getRuntime().getCallerFrame().getCallNode().getEncapsulatingSourceSection().getSource().getName(), Truffle.getRuntime().getCallerFrame().getCallNode().getEncapsulatingSourceSection().getStartLine(), "Signal#trap with a string command not implemented yet");
return getContext().getCoreLibrary().getNilObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def object_id
raise PrimitiveFailure, "Kernel#object_id primitive failed"
end


def trap(sig, prc=nil, &block)
Signal.trap(sig, prc, &block)
end
module_function :trap

end
3 changes: 0 additions & 3 deletions truffle/src/main/ruby/jruby/truffle/core/shims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ def extended_modules(object)
[]
end

def trap(signal)
end

end

class File
Expand Down

0 comments on commit 463db3d

Please sign in to comment.