Skip to content

Commit

Permalink
[Truffle] Added a factory method for creating Rubinius tuples.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Mar 27, 2015
1 parent 46f7a78 commit baf122f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
Expand Up @@ -396,47 +396,19 @@ public Object encodingMap(VirtualFrame frame) {
}

final Encoding defaultInternalEncoding = getContext().getRuntime().getDefaultInternalEncoding();
final Object internalTuple = newTupleNode.call(
frame,
getContext().getCoreLibrary().getTupleClass(),
"create",
null,
getContext().makeString("internal"),
indexLookup(encodings, defaultInternalEncoding)
);
final Object internalTuple = getContext().makeTuple(frame, newTupleNode, getContext().makeString("internal"), indexLookup(encodings, defaultInternalEncoding));
lookupTableWriteNode.call(frame, ret, "[]=", null, getContext().newSymbol("INTERNAL"), internalTuple);

final Encoding defaultExternalEncoding = getContext().getRuntime().getDefaultExternalEncoding();
final Object externalTuple = newTupleNode.call(
frame,
getContext().getCoreLibrary().getTupleClass(),
"create",
null,
getContext().makeString("external"),
indexLookup(encodings, defaultExternalEncoding)
);
final Object externalTuple = getContext().makeTuple(frame, newTupleNode, getContext().makeString("external"), indexLookup(encodings, defaultExternalEncoding));
lookupTableWriteNode.call(frame, ret, "[]=", null, getContext().newSymbol("EXTERNAL"), externalTuple);

final Encoding localeEncoding = getContext().getRuntime().getEncodingService().getLocaleEncoding();
final Object localeTuple = newTupleNode.call(
frame,
getContext().getCoreLibrary().getTupleClass(),
"create",
null,
getContext().makeString("locale"),
indexLookup(encodings, localeEncoding)
);
final Object localeTuple = getContext().makeTuple(frame, newTupleNode, getContext().makeString("locale"), indexLookup(encodings, localeEncoding));
lookupTableWriteNode.call(frame, ret, "[]=", null, getContext().newSymbol("LOCALE"), localeTuple);

final Encoding filesystemEncoding = getContext().getRuntime().getEncodingService().getLocaleEncoding();
final Object filesystemTuple = newTupleNode.call(
frame,
getContext().getCoreLibrary().getTupleClass(),
"create",
null,
getContext().makeString("filesystem"),
indexLookup(encodings, filesystemEncoding)
);
final Object filesystemTuple = getContext().makeTuple(frame, newTupleNode, getContext().makeString("filesystem"), indexLookup(encodings, filesystemEncoding));
lookupTableWriteNode.call(frame, ret, "[]=", null, getContext().newSymbol("FILESYSTEM"), filesystemTuple);

return ret;
Expand Down
Expand Up @@ -12,6 +12,7 @@
import com.oracle.truffle.api.*;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.source.BytesDecoder;
Expand All @@ -27,6 +28,7 @@
import org.jruby.truffle.TruffleHooks;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.methods.SetMethodDeclarationContext;
import org.jruby.truffle.nodes.rubinius.RubiniusPrimitiveManager;
import org.jruby.truffle.runtime.control.RaiseException;
Expand Down Expand Up @@ -310,6 +312,10 @@ public RubyString makeString(RubyClass stringClass, ByteList bytes) {
return RubyString.fromByteList(stringClass, bytes);
}

public Object makeTuple(VirtualFrame frame, CallDispatchHeadNode newTupleNode, Object... values) {
return newTupleNode.call(frame, getCoreLibrary().getTupleClass(), "create", null, values);
}

public IRubyObject toJRuby(Object object) {
RubyNode.notDesignedForCompilation();

Expand Down

0 comments on commit baf122f

Please sign in to comment.