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

Commits on Jun 22, 2016

  1. Copy the full SHA
    ee1d56f View commit details
  2. Copy the full SHA
    40da011 View commit details
  3. Copy the full SHA
    fa76aed View commit details
  4. Copy the full SHA
    e6cffcc View commit details
  5. 1
    Copy the full SHA
    0b202a9 View commit details
10 changes: 6 additions & 4 deletions truffle/src/main/java/org/jruby/truffle/JRubyTruffleImpl.java
Original file line number Diff line number Diff line change
@@ -37,8 +37,7 @@ public JRubyTruffleImpl(Ruby runtime) {
}

try {
context = (RubyContext) engine.eval(Source.fromText("Truffle::Boot.context", "context")
.withMimeType(RubyLanguage.MIME_TYPE)).get();
context = (RubyContext) engine.eval(loadSource("Truffle::Boot.context", "context")).get();
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -55,8 +54,7 @@ public Object execute(org.jruby.ast.RootNode rootNode) {
context.getJRubyInterop().setOriginalInputFile(rootNode.getPosition().getFile());

try {
return engine.eval(Source.fromText("Truffle::Boot.run_jruby_root", "run_jruby_root")
.withMimeType(RubyLanguage.MIME_TYPE)).get();
return engine.eval(loadSource("Truffle::Boot.run_jruby_root", "run_jruby_root")).get();
} catch (IOException e) {
if (e.getCause() instanceof ExitException) {
final ExitException exit = (ExitException) e.getCause();
@@ -71,5 +69,9 @@ public Object execute(org.jruby.ast.RootNode rootNode) {
public void dispose() {
engine.dispose();
}

private Source loadSource(String source, String name) {
return Source.newBuilder(source).name(name).mimeType(RubyLanguage.MIME_TYPE).build();
}

}
8 changes: 7 additions & 1 deletion truffle/src/main/java/org/jruby/truffle/RubyContext.java
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.instrumentation.Instrumenter;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.Source;
import org.jruby.Ruby;
import org.jruby.truffle.builtins.PrimitiveManager;
import org.jruby.truffle.core.CoreLibrary;
@@ -76,7 +77,8 @@ public class RubyContext extends ExecutionContext {
private final TraceManager traceManager;
private final ObjectSpaceManager objectSpaceManager = new ObjectSpaceManager(this);
private final AtExitManager atExitManager = new AtExitManager(this);
private final SourceCache sourceCache = new SourceCache(new SourceLoader(this));
private final SourceLoader sourceLoader = new SourceLoader(this);
private final SourceCache sourceCache = new SourceCache(sourceLoader);
private final CallStackManager callStack = new CallStackManager(this);
private final CoreStrings coreStrings = new CoreStrings(this);
private final FrozenStrings frozenStrings = new FrozenStrings(this);
@@ -305,6 +307,10 @@ public AttachmentsManager getAttachmentsManager() {
return attachmentsManager;
}

public SourceLoader getSourceLoader() {
return sourceLoader;
}

public SourceCache getSourceCache() {
return sourceCache;
}
Original file line number Diff line number Diff line change
@@ -171,7 +171,7 @@ public Object instanceEval(VirtualFrame frame, Object receiver, DynamicObject st

// TODO (pitr 15-Oct-2015): fix this ugly hack, required for AS, copy-paste
final String space = new String(new char[Math.max(line - 1, 0)]).replace("\0", "\n");
final Source source = Source.fromText(space + code.toString(), StringOperations.rope(fileName).toString());
final Source source = getContext().getSourceLoader().loadFragment(space + code.toString(), StringOperations.rope(fileName).toString());

final RubyRootNode rootNode = getContext().getCodeLoader().parse(source, code.getEncoding(), ParserContext.EVAL, null, true, this);
final CodeLoader.DeferredCall deferredCall = getContext().getCodeLoader().prepareExecute(ParserContext.EVAL, DeclarationContext.INSTANCE_EVAL, rootNode, null, receiver);
Original file line number Diff line number Diff line change
@@ -652,7 +652,7 @@ private CodeLoader.DeferredCall doEvalX(DynamicObject rubySource,
// TODO (pitr 15-Oct-2015): fix this ugly hack, required for AS, copy-paste
final String space = new String(new char[Math.max(line - 1, 0)]).replace("\0", "\n");
// TODO CS 14-Apr-15 concat space + code as a rope, otherwise the string will be copied after the rope is converted
final Source source = Source.fromText(space + RopeOperations.decodeRope(code), filename);
final Source source = getContext().getSourceLoader().loadFragment(space + RopeOperations.decodeRope(code), filename);

final MaterializedFrame frame = Layouts.BINDING.getFrame(binding);
final DeclarationContext declarationContext = RubyArguments.getDeclarationContext(frame);
@@ -669,7 +669,7 @@ protected RootNodeWrapper compileSource(VirtualFrame frame, DynamicObject source
final MaterializedFrame parentFrame = Layouts.BINDING.getFrame(callerBinding);

final Encoding encoding = Layouts.STRING.getRope(sourceText).getEncoding();
final Source source = Source.fromText(sourceText.toString(), "(eval)");
final Source source = getContext().getSourceLoader().loadFragment(sourceText.toString(), "(eval)");

final TranslatorDriver translator = new TranslatorDriver(getContext());

@@ -1445,7 +1445,7 @@ private String getFullPath(final String featureString) {
final Source source = getContext().getCallStack().getCallerFrameIgnoringSend().getCallNode().getEncapsulatingSourceSection().getSource();
String result;
if (source.getPath() == null) {
result = source.getShortName();
result = null;
} else {
result = source.getPath();
}
Original file line number Diff line number Diff line change
@@ -624,7 +624,7 @@ private CodeLoader.DeferredCall classEvalSource(DynamicObject module, DynamicObj

// TODO (pitr 15-Oct-2015): fix this ugly hack, required for AS, copy-paste
final String space = new String(new char[Math.max(line - 1, 0)]).replace("\0", "\n");
Source source = Source.fromText(space + code, file);
Source source = getContext().getSourceLoader().loadFragment(space + code, file);

final RubyRootNode rootNode = getContext().getCodeLoader().parse(source, encoding, ParserContext.MODULE, callerFrame, true, this);
return getContext().getCodeLoader().prepareExecute(ParserContext.MODULE, DeclarationContext.CLASS_EVAL, rootNode, callerFrame, module);
Original file line number Diff line number Diff line change
@@ -55,9 +55,7 @@ public Object execute(VirtualFrame frame, String expression, Object... arguments
parameterFrameSlots[n] = frameDescriptor.findOrAddFrameSlot(parameters[n]);
}

final Source source = Source.fromText(
StringOperations.createByteList(this.expression),
"(snippet)");
final Source source = getContext().getSourceLoader().loadFragment(this.expression, "(snippet)");

final RubyRootNode rootNode = getContext().getCodeLoader().parse(
source,
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ public void ensureCExtImplementationLoaded(VirtualFrame frame, IndirectCallNode
private CallTarget getCExtLibRuby() {
final String path = context.getJRubyRuntime().getJRubyHome() + "/lib/ruby/truffle/cext/ruby.su";
try {
return parseSource(Source.fromFileName(path));
return parseSource(context.getSourceLoader().load(path));
} catch (IOException e) {
throw new RuntimeException(e);
}
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@
import com.oracle.truffle.api.source.Source;
import org.jruby.Ruby;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.RubyLanguage;
import org.jruby.truffle.core.string.StringOperations;

import java.io.File;
import java.io.FileNotFoundException;
@@ -36,7 +38,7 @@ public SourceLoader(RubyContext context) {

public Source load(String canonicalPath) throws IOException {
if (canonicalPath.equals("-e")) {
return loadInlineScript();
return loadFragment(new String(context.getJRubyRuntime().getInstanceConfig().inlineScript(), StandardCharsets.UTF_8), "-e");
} else if (canonicalPath.startsWith(TRUFFLE_SCHEME) || canonicalPath.startsWith(JRUBY_SCHEME)) {
return loadResource(canonicalPath);
} else {
@@ -45,12 +47,13 @@ public Source load(String canonicalPath) throws IOException {
throw new IOException("Can't read file " + canonicalPath);
}
return Source.fromFileName(canonicalPath);
//return Source.newBuilder(new File(canonicalPath)).build();
}
}

private Source loadInlineScript() {
return Source.fromText(new String(context.getJRubyRuntime().getInstanceConfig().inlineScript(),
StandardCharsets.UTF_8), "-e");
public Source loadFragment(String fragment, String name) {
return Source.fromText(fragment, name);
//return Source.newBuilder(fragment).name(name).mimeType(RubyLanguage.MIME_TYPE).build();
}

private Source loadResource(String path) throws IOException {
@@ -79,6 +82,7 @@ private Source loadResource(String path) throws IOException {
}

return Source.fromReader(new InputStreamReader(stream, StandardCharsets.UTF_8), path);
//return Source.newBuilder(new InputStreamReader(stream, StandardCharsets.UTF_8)).name(path).mimeType(RubyLanguage.MIME_TYPE).build();
}

}
Original file line number Diff line number Diff line change
@@ -1131,7 +1131,7 @@ private String getSourcePath(SourceSection sourceSection) {
final String path = source.getPath();

if (path == null) {
return source.getShortName();
throw new UnsupportedOperationException();
}

return path;
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ public void run(MaterializedFrame frame, Node currentNode) {
default: {
try {
final RubyRootNode rootNode = context.getCodeLoader().parse(
Source.fromText(shellLine, "shell"),
context.getSourceLoader().loadFragment(shellLine, "(shell)"),
UTF8Encoding.INSTANCE,
ParserContext.EVAL,
currentFrame,