Skip to content

Commit

Permalink
Showing 236 changed files with 4,166 additions and 2,534 deletions.
2 changes: 1 addition & 1 deletion .mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@
<extension>
<groupId>io.takari.polyglot</groupId>
<artifactId>polyglot-ruby</artifactId>
<version>0.1.10</version>
<version>0.1.11</version>
</extension>
</extensions>
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -70,6 +70,8 @@ matrix:
jdk: oraclejdk8
- env: COMMAND=tool/truffle-findbugs.sh
jdk: oraclejdk8
- env: COMMAND='ruby tool/jt.rb check_ambiguous_arguments'
jdk: oraclejdk8
- env: COMMAND=test/truffle/run.sh
jdk: oraclejdk8
fast_finish: true
7 changes: 7 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT MODIFIY - GENERATED CODE
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
36 changes: 0 additions & 36 deletions core/src/main/java/org/jruby/ParsingAndRunManager.java

This file was deleted.

54 changes: 23 additions & 31 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -491,14 +491,14 @@ public IRubyObject evalScriptlet(String script, DynamicScope scope) {
public IRubyObject executeScript(String script, String filename) {
byte[] bytes = script.getBytes();

Node node = parseInline(new ByteArrayInputStream(bytes), filename, null);
RootNode root = (RootNode) parseInline(new ByteArrayInputStream(bytes), filename, null);
ThreadContext context = getCurrentContext();

String oldFile = context.getFile();
int oldLine = context.getLine();
try {
context.setFileAndLine(node.getPosition());
return runInterpreter(node);
context.setFileAndLine(root.getFile(), root.getLine());
return runInterpreter(root);
} finally {
context.setFileAndLine(oldFile, oldLine);
}
@@ -564,7 +564,7 @@ public void runFromMain(InputStream inputStream, String filename) {
String oldFile = context.getFile();
int oldLine = context.getLine();
try {
context.setFileAndLine(scriptNode.getPosition());
context.setFileAndLine(scriptNode.getFile(), scriptNode.getLine());

if (config.isAssumePrinting() || config.isAssumeLoop()) {
runWithGetsLoop(scriptNode, config.isAssumePrinting(), config.isProcessLineEnds(),
@@ -622,7 +622,7 @@ public ParseResult parseFromMain(String fileName, InputStream in) {
*/
@Deprecated
public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean processLineEnds, boolean split, boolean unused) {
return runWithGetsLoop(scriptNode, printing, processLineEnds, split);
return runWithGetsLoop((RootNode) scriptNode, printing, processLineEnds, split);
}

/**
@@ -639,24 +639,24 @@ public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean pr
* bytecode before executing.
* @return The result of executing the specified script
*/
public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean processLineEnds, boolean split) {
public IRubyObject runWithGetsLoop(RootNode scriptNode, boolean printing, boolean processLineEnds, boolean split) {
ThreadContext context = getCurrentContext();

// We do not want special scope types in IR so we ammend the AST tree to contain the elements representing
// a while gets; ...your code...; end
scriptNode = addGetsLoop((RootNode) scriptNode, printing, processLineEnds, split);
scriptNode = addGetsLoop(scriptNode, printing, processLineEnds, split);

Script script = null;
boolean compile = getInstanceConfig().getCompileMode().shouldPrecompileCLI();
if (compile) {
try {
script = tryCompile(scriptNode);
if (Options.JIT_LOGGING.load()) {
LOG.info("Successfully compiled: " + scriptNode.getPosition().getFile());
LOG.info("Successfully compiled: " + scriptNode.getFile());
}
} catch (Throwable e) {
if (Options.JIT_LOGGING.load()) {
LOG.error("Failed to compile: " + scriptNode.getPosition().getFile());
LOG.error("Failed to compile: " + scriptNode.getFile());
if (Options.JIT_LOGGING_VERBOSE.load()) {
LOG.error(e);
}
@@ -709,7 +709,7 @@ private RootNode addGetsLoop(RootNode oldRoot, boolean printing, boolean process
whileBody.add(oldRoot.getBodyNode());
}

return new RootNode(pos, oldRoot.getScope(), newBody);
return new RootNode(pos, oldRoot.getScope(), newBody, oldRoot.getFile());
}

/**
@@ -737,7 +737,7 @@ public IRubyObject runNormally(Node scriptNode) {
ScriptAndCode scriptAndCode = null;
boolean compile = getInstanceConfig().getCompileMode().shouldPrecompileCLI();
if (compile || config.isShowBytecode()) {
scriptAndCode = precompileCLI(scriptNode);
scriptAndCode = precompileCLI((RootNode) scriptNode);
}

if (scriptAndCode != null) {
@@ -757,19 +757,19 @@ public IRubyObject runNormally(Node scriptNode) {
}
}

private ScriptAndCode precompileCLI(Node scriptNode) {
private ScriptAndCode precompileCLI(RootNode scriptNode) {
ScriptAndCode scriptAndCode = null;

// IR JIT does not handle all scripts yet, so let those that fail run in interpreter instead
// FIXME: restore error once JIT should handle everything
try {
scriptAndCode = tryCompile(scriptNode, new ClassDefiningJRubyClassLoader(getJRubyClassLoader()));
if (scriptAndCode != null && Options.JIT_LOGGING.load()) {
LOG.info("done compiling target script: " + scriptNode.getPosition().getFile());
LOG.info("done compiling target script: " + scriptNode.getFile());
}
} catch (Exception e) {
if (Options.JIT_LOGGING.load()) {
LOG.error("failed to compile target script '" + scriptNode.getPosition().getFile() + "'");
LOG.error("failed to compile target script '" + scriptNode.getFile() + "'");
if (Options.JIT_LOGGING_VERBOSE.load()) {
e.printStackTrace();
}
@@ -787,31 +787,23 @@ private ScriptAndCode precompileCLI(Node scriptNode) {
* @return an instance of the successfully-compiled Script, or null.
*/
public Script tryCompile(Node node) {
return tryCompile(node, new ClassDefiningJRubyClassLoader(getJRubyClassLoader())).script();
return tryCompile((RootNode) node, new ClassDefiningJRubyClassLoader(getJRubyClassLoader())).script();
}

private void failForcedCompile(Node scriptNode) throws RaiseException {
private void failForcedCompile(RootNode scriptNode) throws RaiseException {
if (config.getCompileMode().shouldPrecompileAll()) {
throw newRuntimeError("could not compile and compile mode is 'force': " + scriptNode.getPosition().getFile());
throw newRuntimeError("could not compile and compile mode is 'force': " + scriptNode.getFile());
}
}

private void handeCompileError(Node node, Throwable t) {
if (config.isJitLoggingVerbose() || config.isDebug()) {
LOG.error("warning: could not compile: {}; full trace follows", node.getPosition().getFile());
LOG.error(t.getMessage(), t);
}
}

private ScriptAndCode tryCompile(Node node, ClassDefiningClassLoader classLoader) {
private ScriptAndCode tryCompile(RootNode root, ClassDefiningClassLoader classLoader) {
try {
return Compiler.getInstance().execute(this, node, classLoader);
return Compiler.getInstance().execute(this, root, classLoader);
} catch (NotCompilableException e) {
if (Options.JIT_LOGGING.load()) {
LOG.error("failed to compile target script " + node.getPosition().getFile() + ": " + e.getLocalizedMessage());
if (Options.JIT_LOGGING_VERBOSE.load()) {
LOG.error(e);
}
LOG.error("failed to compile target script " + root.getFile() + ": " + e.getLocalizedMessage());

if (Options.JIT_LOGGING_VERBOSE.load()) LOG.error(e);
}
return null;
}
@@ -2984,7 +2976,7 @@ public void compileAndLoadFile(String filename, InputStream in, boolean wrap) {
}

// script was not found in cache above, so proceed to compile
Node scriptNode = parseFile(readStream, filename, null);
RootNode scriptNode = (RootNode) parseFile(readStream, filename, null);
if (script == null) {
scriptAndCode = tryCompile(scriptNode, new ClassDefiningJRubyClassLoader(jrubyClassLoader));
if (scriptAndCode != null) script = scriptAndCode.script();
104 changes: 71 additions & 33 deletions core/src/main/java/org/jruby/RubyArgsFile.java
Original file line number Diff line number Diff line change
@@ -34,38 +34,95 @@

import java.io.File;
import java.io.IOException;

import static org.jruby.RubyEnumerator.enumeratorize;
import static org.jruby.runtime.Visibility.PRIVATE;

import org.jruby.anno.FrameField;
import org.jruby.anno.JRubyMethod;
import org.jruby.exceptions.RaiseException;

import jnr.posix.FileStat;
import jnr.posix.util.Platform;

import org.jruby.runtime.Block;
import org.jruby.runtime.IAccessor;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;
import org.jruby.internal.runtime.GlobalVariable;

public class RubyArgsFile {
static final class ArgsFileData {
private final Ruby runtime;
public ArgsFileData(Ruby runtime) {
this.runtime = runtime;
this.currentFile = runtime.getNil();
public class RubyArgsFile extends RubyObject {

public RubyArgsFile(Ruby runtime, RubyClass metaClass) {
super(runtime, metaClass);
}

public static void initArgsFile(final Ruby runtime) {
RubyClass argfClass = runtime.defineClass("ARGFClass", runtime.getObject(), ARGF_ALLOCATOR);
argfClass.includeModule(runtime.getEnumerable());

argfClass.defineAnnotatedMethods(RubyArgsFile.class);

IRubyObject argsFile = argfClass.newInstance(runtime.getCurrentContext(), new IRubyObject[] { null }, (Block) null);

runtime.setArgsFile(argsFile);
runtime.getGlobalVariables().defineReadonly("$<", new IAccessor() {
@Override
public IRubyObject getValue() {
return runtime.getArgsFile();
}

@Override
public IRubyObject setValue(IRubyObject newValue) {
throw new UnsupportedOperationException("Not supported yet.");
}
}, GlobalVariable.Scope.GLOBAL);
runtime.defineGlobalConstant("ARGF", argsFile);
runtime.defineReadonlyVariable("$FILENAME", runtime.newString("-"), GlobalVariable.Scope.GLOBAL);
}

private static final ObjectAllocator ARGF_ALLOCATOR = new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
return new RubyArgsFile(runtime, klass);
}
};

@JRubyMethod(name = "initialize", visibility = PRIVATE, rest = true)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
final RubyArray argv;
if (args.length == 1 && args[0] == null) {
argv = context.getRuntime().getObject().getConstant("ARGV").convertToArray();
} else {
argv = context.getRuntime().newArray(args);
}

ArgsFileData data = new ArgsFileData(context.getRuntime(), argv);
this.dataWrapStruct(data);
return this;
}

static final class ArgsFileData {

private final Ruby runtime;
private final RubyArray argv;
public IRubyObject currentFile;
public int currentLineNumber;
public int minLineNumber;
private boolean inited = false;
public int next_p = 0;

public ArgsFileData(Ruby runtime, RubyArray argv) {
this.runtime = runtime;
this.argv = argv;
this.currentFile = runtime.getNil();
}

public boolean next_argv(ThreadContext context) {
RubyArray args = (RubyArray)runtime.getGlobalVariables().get("$*");
if (!inited) {
if (args.getLength() > 0) {
if (argv.getLength() > 0) {
next_p = 1;
} else {
next_p = -1;
@@ -76,8 +133,8 @@ public boolean next_argv(ThreadContext context) {

if (next_p == 1) {
next_p = 0;
if (args.getLength() > 0) {
IRubyObject arg = args.shift(context);
if (argv.getLength() > 0) {
IRubyObject arg = argv.shift(context);
RubyString filename = (RubyString)((RubyObject)arg).to_s();
ByteList filenameBytes = filename.getByteList();
if (!filename.op_equal(context, (RubyString) runtime.getGlobalVariables().get("$FILENAME")).isTrue()) {
@@ -117,7 +174,7 @@ public static ArgsFileData getDataFrom(IRubyObject recv) {
ArgsFileData data = (ArgsFileData)recv.dataGetStruct();

if (data == null) {
data = new ArgsFileData(recv.getRuntime());
data = new ArgsFileData(recv.getRuntime(), recv.getRuntime().newEmptyArray());
recv.dataWrapStruct(data);
}

@@ -181,28 +238,9 @@ public static void setCurrentLineNumber(IRubyObject recv, int newLineNumber) {
}
}

public static void initArgsFile(final Ruby runtime) {
RubyObject argsFile = new RubyObject(runtime, runtime.getObject());

runtime.getEnumerable().extend_object(argsFile);

runtime.setArgsFile(argsFile);
runtime.getGlobalVariables().defineReadonly("$<", new IAccessor() {
@Override
public IRubyObject getValue() {
return runtime.getArgsFile();
}

@Override
public IRubyObject setValue(IRubyObject newValue) {
throw new UnsupportedOperationException("Not supported yet.");
}
}, GlobalVariable.Scope.GLOBAL);
runtime.defineGlobalConstant("ARGF", argsFile);

RubyClass argfClass = argsFile.getMetaClass();
argfClass.defineAnnotatedMethods(RubyArgsFile.class);
runtime.defineReadonlyVariable("$FILENAME", runtime.newString("-"), GlobalVariable.Scope.GLOBAL);
@JRubyMethod(name = "argv")
public static IRubyObject argv(ThreadContext context, IRubyObject recv) {
return ArgsFileData.getDataFrom(recv).argv;
}

@JRubyMethod(name = {"fileno", "to_i"})
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
@@ -1001,7 +1001,7 @@ public static IRubyObject each_with_objectCommon19(ThreadContext context, IRubyO
final Ruby runtime = context.runtime;
RubyEnumerable.callEach(runtime, context, self, Signature.OPTIONAL, new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
return block.call(ctx, new IRubyObject[]{runtime.newArray(packEnumValues(ctx, largs), arg)});
return block.call(ctx, packEnumValues(ctx, largs), arg);
}
});
return arg;
@@ -1016,7 +1016,7 @@ public static IRubyObject each_with_index19(ThreadContext context, IRubyObject s
return block.isGiven() ? each_with_indexCommon19(context, self, block, args) : enumeratorizeWithSize(context, self, "each_with_index", args, enumSizeFn(context, self));
}

@JRubyMethod
@JRubyMethod(required = 1)
public static IRubyObject each_with_object(ThreadContext context, IRubyObject self, IRubyObject arg, Block block) {
return block.isGiven() ? each_with_objectCommon19(context, self, block, arg) : enumeratorizeWithSize(context, self, "each_with_object", new IRubyObject[] { arg }, enumSizeFn(context, self));
}
Loading

0 comments on commit 2843d14

Please sign in to comment.