Skip to content

Commit

Permalink
Showing 64 changed files with 168 additions and 158 deletions.
13 changes: 12 additions & 1 deletion truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.DynamicObjectFactory;
import com.oracle.truffle.api.source.SourceSection;
import org.jcodings.specific.USASCIIEncoding;

@TypeSystemReference(RubyTypes.class)
@ImportStatic(RubyGuards.class)
@@ -69,7 +70,7 @@ public RubyNode(RubyContext context, SourceSection sourceSection) {
public abstract Object execute(VirtualFrame frame);

public Object isDefined(VirtualFrame frame) {
return Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(getContext().getCoreLibrary().getStringClass()), StringOperations.encodeByteList("expression", UTF8Encoding.INSTANCE), StringSupport.CR_7BIT, null);
return create7BitString(StringOperations.encodeByteList("expression", UTF8Encoding.INSTANCE));
}

// Execute without returning the result
@@ -174,6 +175,16 @@ public DynamicObject getSymbol(ByteList name) {
return getContext().getSymbol(name);
}

/** Creates a String from the ByteList, with unknown CR */
protected DynamicObject createString(ByteList bytes) {
return StringOperations.createString(getContext(), bytes);
}

/** Creates a String from the ByteList, with 7-bit CR */
protected DynamicObject create7BitString(ByteList bytes) {
return StringOperations.create7BitString(getContext(), bytes);
}

protected POSIX posix() {
return getContext().getPosix();
}
Original file line number Diff line number Diff line change
@@ -117,7 +117,7 @@ object, getContext().getCoreLibrary().getArrayClass(), method, array, this)

@CompilerDirectives.TruffleBoundary
private DynamicObject makeMethodNameString(String methodName) {
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(methodName, UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
return createString(StringOperations.encodeByteList(methodName, UTF8Encoding.INSTANCE));
}

}
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ public Object isDefined(VirtualFrame frame) {
if (constant == null) {
return nil();
} else {
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList("constant", UTF8Encoding.INSTANCE), StringSupport.CR_7BIT, null);
return create7BitString(StringOperations.encodeByteList("constant", UTF8Encoding.INSTANCE));
}
}

Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ public Object isDefined(VirtualFrame frame) {
if (constant == null) {
return nil();
} else {
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList("constant", UTF8Encoding.INSTANCE), StringSupport.CR_7BIT, null);
return create7BitString(StringOperations.encodeByteList("constant", UTF8Encoding.INSTANCE));
}
}

Original file line number Diff line number Diff line change
@@ -45,8 +45,8 @@ public TraceNode(RubyContext context, SourceSection sourceSection) {
traceAssumption = context.getTraceManager().getTraceAssumption();
traceFunc = null;
callNode = null;
event = Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList("line", UTF8Encoding.INSTANCE), StringSupport.CR_7BIT, null);
file = Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(sourceSection.getSource().getName(), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
event = create7BitString(StringOperations.encodeByteList("line", UTF8Encoding.INSTANCE));
file = createString(StringOperations.encodeByteList(sourceSection.getSource().getName(), UTF8Encoding.INSTANCE));
line = sourceSection.getStartLine();
}

Original file line number Diff line number Diff line change
@@ -641,7 +641,7 @@ public ToSNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public DynamicObject toS(DynamicObject value, NotProvided base) {
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(Layouts.BIGNUM.getValue(value).toString(), USASCIIEncoding.INSTANCE), StringSupport.CR_7BIT, null);
return create7BitString(StringOperations.encodeByteList(Layouts.BIGNUM.getValue(value).toString(), USASCIIEncoding.INSTANCE));
}

@TruffleBoundary
@@ -652,7 +652,7 @@ public DynamicObject toS(DynamicObject value, int base) {
throw new RaiseException(getContext().getCoreLibrary().argumentErrorInvalidRadix(base, this));
}

return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(Layouts.BIGNUM.getValue(value).toString(base), USASCIIEncoding.INSTANCE), StringSupport.CR_7BIT, null);
return create7BitString(StringOperations.encodeByteList(Layouts.BIGNUM.getValue(value).toString(base), USASCIIEncoding.INSTANCE));
}

}
Original file line number Diff line number Diff line change
@@ -142,11 +142,11 @@ public Object transcodingMap(VirtualFrame frame) {
final TranscoderDB.Entry e = destinationEntry.value;

if (key == null) {
final Object upcased = upcaseNode.call(frame, Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), new ByteList(e.getSource()), StringSupport.CR_UNKNOWN, null), "upcase", null);
final Object upcased = upcaseNode.call(frame, createString(new ByteList(e.getSource())), "upcase", null);
key = toSymNode.call(frame, upcased, "to_sym", null);
}

final Object upcasedLookupTableKey = upcaseNode.call(frame, Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), new ByteList(e.getDestination()), StringSupport.CR_UNKNOWN, null), "upcase", null);
final Object upcasedLookupTableKey = upcaseNode.call(frame, createString(new ByteList(e.getDestination())), "upcase", null);
final Object lookupTableKey = toSymNode.call(frame, upcasedLookupTableKey, "to_sym", null);
final Object lookupTableValue = newTranscodingNode.call(frame, getContext().getCoreLibrary().getTranscodingClass(), "create", null, key, lookupTableKey);
lookupTableWriteNode.call(frame, value, "[]=", null, lookupTableKey, lookupTableValue);
Original file line number Diff line number Diff line change
@@ -354,7 +354,7 @@ public LocaleCharacterMapNode(RubyContext context, SourceSection sourceSection)
public DynamicObject localeCharacterMap() {
CompilerDirectives.transferToInterpreter();
final ByteList name = new ByteList(getContext().getRuntime().getEncodingService().getLocaleEncoding().getName());
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), name, StringSupport.CR_UNKNOWN, null);
return createString(name);
}
}

@@ -396,7 +396,7 @@ public Object encodingMap(VirtualFrame frame) {

final DynamicObject[] encodings = cloneEncodingList();
for (int i = 0; i < encodings.length; i++) {
final Object upcased = upcaseNode.call(frame, Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), Layouts.ENCODING.getName(encodings[i]), StringSupport.CR_UNKNOWN, null), "upcase", null);
final Object upcased = upcaseNode.call(frame, createString(Layouts.ENCODING.getName(encodings[i])), "upcase", null);
final Object key = toSymNode.call(frame, upcased, "to_sym", null);
final Object value = newTupleNode.call(frame, getContext().getCoreLibrary().getTupleClass(), "create", null, nil(), i);

@@ -408,9 +408,9 @@ public Object encodingMap(VirtualFrame frame) {
final CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<EncodingDB.Entry> e =
((CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<EncodingDB.Entry>) i.next());

final Object upcased = upcaseNode.call(frame, Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), new ByteList(e.bytes, e.p, e.end - e.p), StringSupport.CR_UNKNOWN, null), "upcase", null);
final Object upcased = upcaseNode.call(frame, createString(new ByteList(e.bytes, e.p, e.end - e.p)), "upcase", null);
final Object key = toSymNode.call(frame, upcased, "to_sym", null);
final DynamicObject alias = Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), new ByteList(e.bytes, e.p, e.end - e.p), StringSupport.CR_UNKNOWN, null);
final DynamicObject alias = createString(new ByteList(e.bytes, e.p, e.end - e.p));
final int index = e.value.getIndex();


@@ -419,19 +419,19 @@ public Object encodingMap(VirtualFrame frame) {
}

final Encoding defaultInternalEncoding = getContext().getRuntime().getDefaultInternalEncoding();
final Object internalTuple = getContext().makeTuple(frame, newTupleNode, Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList("internal", UTF8Encoding.INSTANCE), StringSupport.CR_7BIT, null), indexLookup(encodings, defaultInternalEncoding));
final Object internalTuple = getContext().makeTuple(frame, newTupleNode, create7BitString(StringOperations.encodeByteList("internal", UTF8Encoding.INSTANCE)), indexLookup(encodings, defaultInternalEncoding));
lookupTableWriteNode.call(frame, ret, "[]=", null, getSymbol("INTERNAL"), internalTuple);

final Encoding defaultExternalEncoding = getContext().getRuntime().getDefaultExternalEncoding();
final Object externalTuple = getContext().makeTuple(frame, newTupleNode, Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList("external", UTF8Encoding.INSTANCE), StringSupport.CR_7BIT, null), indexLookup(encodings, defaultExternalEncoding));
final Object externalTuple = getContext().makeTuple(frame, newTupleNode, create7BitString(StringOperations.encodeByteList("external", UTF8Encoding.INSTANCE)), indexLookup(encodings, defaultExternalEncoding));
lookupTableWriteNode.call(frame, ret, "[]=", null, getSymbol("EXTERNAL"), externalTuple);

final Encoding localeEncoding = getLocaleEncoding();
final Object localeTuple = getContext().makeTuple(frame, newTupleNode, Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList("locale", UTF8Encoding.INSTANCE), StringSupport.CR_7BIT, null), indexLookup(encodings, localeEncoding));
final Object localeTuple = getContext().makeTuple(frame, newTupleNode, create7BitString(StringOperations.encodeByteList("locale", UTF8Encoding.INSTANCE)), indexLookup(encodings, localeEncoding));
lookupTableWriteNode.call(frame, ret, "[]=", null, getSymbol("LOCALE"), localeTuple);

final Encoding filesystemEncoding = getLocaleEncoding();
final Object filesystemTuple = getContext().makeTuple(frame, newTupleNode, Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList("filesystem", UTF8Encoding.INSTANCE), StringSupport.CR_7BIT, null), indexLookup(encodings, filesystemEncoding));
final Object filesystemTuple = getContext().makeTuple(frame, newTupleNode, create7BitString(StringOperations.encodeByteList("filesystem", UTF8Encoding.INSTANCE)), indexLookup(encodings, filesystemEncoding));
lookupTableWriteNode.call(frame, ret, "[]=", null, getSymbol("FILESYSTEM"), filesystemTuple);

return ret;
@@ -473,7 +473,7 @@ public ToSNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject toS(DynamicObject encoding) {
final ByteList name = Layouts.ENCODING.getName(encoding).dup();
name.setEncoding(ASCIIEncoding.INSTANCE);
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), name, StringSupport.CR_UNKNOWN, null);
return createString(name);
}
}

Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ public static DynamicObject asRubyStringArray(RubyContext context, DynamicObject
final Object[] array = new Object[lines.size()];

for (int n = 0;n < lines.size(); n++) {
array[n] = Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(context.getCoreLibrary().getStringClass()), StringOperations.encodeByteList(lines.get(n), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
array[n] = StringOperations.createString(context, StringOperations.encodeByteList(lines.get(n), UTF8Encoding.INSTANCE));
}

return Layouts.ARRAY.createArray(context.getCoreLibrary().getArrayFactory(), array, array.length);
@@ -140,7 +140,7 @@ public Object message(DynamicObject exception) {
final Object message = Layouts.EXCEPTION.getMessage(exception);
if (message == null) {
final String className = Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(exception)).getName();
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(className, UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
return createString(StringOperations.encodeByteList(className, UTF8Encoding.INSTANCE));
} else {
return message;
}
Original file line number Diff line number Diff line change
@@ -716,7 +716,7 @@ public ToSNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public DynamicObject toS(double value) {
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(Double.toString(value), USASCIIEncoding.INSTANCE), StringSupport.CR_7BIT, null);
return create7BitString(StringOperations.encodeByteList(Double.toString(value), USASCIIEncoding.INSTANCE));
}

}
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ public DynamicObject backtick(VirtualFrame frame, DynamicObject command) {
}

// TODO (nirvdrum 10-Mar-15) This should be using the default external encoding, rather than hard-coded to UTF-8.
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(resultBuilder.toString(), EncodingOperations.getEncoding(EncodingNodes.getEncoding("UTF-8"))), StringSupport.CR_UNKNOWN, null);
return createString(StringOperations.encodeByteList(resultBuilder.toString(), EncodingOperations.getEncoding(EncodingNodes.getEncoding("UTF-8"))));
}

}
@@ -837,7 +837,7 @@ public String block() throws InterruptedException {
}
});

final DynamicObject rubyLine = Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(line, UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
final DynamicObject rubyLine = createString(StringOperations.encodeByteList(line, UTF8Encoding.INSTANCE));

// Set the local variable $_ in the caller

@@ -1933,7 +1933,7 @@ private RuntimeException handleException(PackException exception) {
}

private DynamicObject finishFormat(ByteList format, PackResult result) {
final DynamicObject string = Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), new ByteList(result.getOutput(), 0, result.getOutputLength()), StringSupport.CR_UNKNOWN, null);
final DynamicObject string = createString(new ByteList(result.getOutput(), 0, result.getOutputLength()));

if (format.length() == 0) {
StringOperations.forceEncoding(string, USASCIIEncoding.INSTANCE);
@@ -2068,7 +2068,7 @@ public DynamicObject toS(VirtualFrame frame, Object self) {
Object id = objectIDNode.executeObjectID(frame, self);
String hexID = toHexStringNode.executeToHexString(frame, id);

return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList("#<" + className + ":0x" + hexID + ">", UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
return createString(StringOperations.encodeByteList("#<" + className + ":0x" + hexID + ">", UTF8Encoding.INSTANCE));
}

}
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public Object execute(VirtualFrame frame) {
Collection<String> requiredLibraries = getContext().getRuntime().getInstanceConfig().getRequiredLibraries();

for (String requiredLibrary : requiredLibraries) {
requireNode.call(frame, self, "require", null, Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(requiredLibrary, UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null));
requireNode.call(frame, self, "require", null, createString(StringOperations.encodeByteList(requiredLibrary, UTF8Encoding.INSTANCE)));
}

return nil();
Original file line number Diff line number Diff line change
@@ -456,7 +456,7 @@ public ToSNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public DynamicObject toS(DynamicObject matchData) {
final ByteList bytes = StringOperations.getByteList(Layouts.MATCH_DATA.getGlobal(matchData)).dup();
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), bytes, StringSupport.CR_UNKNOWN, null);
return createString(bytes);
}
}

Original file line number Diff line number Diff line change
@@ -200,7 +200,7 @@ public Object sourceLocation(DynamicObject method) {
if (sourceSection instanceof NullSourceSection) {
return nil();
} else {
DynamicObject file = Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(sourceSection.getSource().getName(), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
DynamicObject file = createString(StringOperations.encodeByteList(sourceSection.getSource().getName(), UTF8Encoding.INSTANCE));
Object[] objects = new Object[]{file, sourceSection.getStartLine()};
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
}
Original file line number Diff line number Diff line change
@@ -1314,7 +1314,7 @@ public Object name(DynamicObject module) {
return nil();
}

return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(Layouts.MODULE.getFields(module).getName(), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
return createString(StringOperations.encodeByteList(Layouts.MODULE.getFields(module).getName(), UTF8Encoding.INSTANCE));
}
}

@@ -1851,7 +1851,7 @@ public ToSNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public DynamicObject toS(DynamicObject module) {
final String name = Layouts.MODULE.getFields(module).getName();
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(name, UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
return createString(StringOperations.encodeByteList(name, UTF8Encoding.INSTANCE));
}

}
Loading

0 comments on commit 2ba17e0

Please sign in to comment.