Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
Conflicts:
	core/src/main/java/org/jruby/truffle/nodes/RubyRootNode.java
	core/src/main/java/org/jruby/truffle/nodes/control/DoWhileNode.java
	core/src/main/java/org/jruby/truffle/nodes/control/WhileNode.java
	core/src/main/java/org/jruby/truffle/nodes/core/FixnumNodes.java
chrisseaton committed Oct 30, 2014
2 parents 84177f2 + af2cd60 commit 58bd0ec
Showing 61 changed files with 639 additions and 3,054 deletions.
5 changes: 0 additions & 5 deletions .classpath

This file was deleted.

113 changes: 58 additions & 55 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,76 +1,73 @@
!.gitignore

*.[oa]
*.bundle
*.gz
*.zip
*.md5
*.sha1
*.orig
*.rej
*.releaseBackup
release.properties
jruby-complete.jar
bin/*
!bin/gem
!bin/update_rubygems
*.sha1
*.so
*.sw[mnop]
*.versionsBackup
*.zip
*~

.DS_Store
.debug.properties
.redcar
/.rbx/
build
build.eclipse
build.properties
target
build_graph.png
core/src/main/java/org/jruby/runtime/Constants.java
dependency-reduced-pom.xml
dev_null
dist
ext/*/pom-*.gemspec.xml
lib/jruby*.jar
lib/native
lib/jni
lib/ruby/gems
lib/ruby/shared/rubygems/defaults/jruby_native.rb
lib/ruby/shared/krypt*
lib/ruby/shared/jopenssl*
lib/ruby/shared/org/
lib/ruby/shared/openssl
lib/ruby/shared/jar*
nbproject/private
share
latest_source_cache
docs/api
test/rails
test/prawn
ext/*/pom-*.gemspec.xml
gems/*/Manifest.txt
gems/*/lib/*.jar
gems/*/lib/jruby-jars/version.rb
gems/*/pkg
*.orig
*.rej
*~
tool/nailgun/Makefile
tool/nailgun/ng
tool/nailgun/config.log
tool/nailgun/config.status
jruby-findbugs.html
.debug.properties
test/testapp/testapp
glob_test
spaces test
.DS_Store
jruby-complete.jar
jruby-findbugs.html
latest_source_cache
lib/jni
lib/jruby*.jar
lib/native
lib/ruby/cext/
*.so
*.bundle
*.[oa]
*.versionsBackup
dev_null
.redcar
/.externalToolBuilders/
.metadata
.idea/workspace.xml
shared.iml
build_graph.png
/.idea/
/.rbx/
*.sw[mnop]
lib/ruby/gems
lib/ruby/shared/*jopenssl*.jar
lib/ruby/shared/bcpkix-jdk15on-*.jar
lib/ruby/shared/bcprov-jdk15on-*.jar
lib/ruby/shared/*jopenssl*.jar
lib/ruby/shared/readline/*readline*.jar
lib/ruby/shared/jar*
lib/ruby/shared/jline
lib/ruby/shared/jopenssl*
lib/ruby/shared/krypt*
lib/ruby/shared/openssl
lib/ruby/shared/org/
lib/ruby/shared/readline/*readline*.jar
lib/ruby/shared/ripper.jar
core/src/main/java/org/jruby/runtime/Constants.java
dependency-reduced-pom.xml
lib/ruby/shared/rubygems/defaults/jruby_native.rb
release.properties
share
spaces test
target
test/prawn
test/rails
test/testapp/testapp
tool/nailgun/Makefile
tool/nailgun/config.log
tool/nailgun/config.status
tool/nailgun/ng

# binaries
!bin/gem
!bin/update_rubygems
bin/*

# These files are bin files for default gems
!lib/ruby/gems/shared/gems/rake-10.1.0/bin/rake
@@ -87,5 +84,11 @@ maven/jruby-complete/src/it/osgi*
.idea
*.iml

# NetBeans files
nbproject/private

# Eclipse project files
/.metadata

# Truffle benchmark stuff
reference.txt
34 changes: 0 additions & 34 deletions .project

This file was deleted.

391 changes: 0 additions & 391 deletions .settings/org.eclipse.jdt.core.prefs

This file was deleted.

2 changes: 0 additions & 2 deletions .settings/org.eclipse.jdt.launching.prefs

This file was deleted.

110 changes: 0 additions & 110 deletions .settings/org.eclipse.jdt.ui.prefs

This file was deleted.

9 changes: 0 additions & 9 deletions .settings/org.maven.ide.eclipse.prefs

This file was deleted.

73 changes: 45 additions & 28 deletions core/.classpath
Original file line number Diff line number Diff line change
@@ -1,35 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src/main/java">
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
<classpathentry excluding="**/*.java" including="**/*rb" kind="src" path="src/main/ruby"/>
<classpathentry excluding="**/*.java" including="META-INF/**/*|org/jruby/runtime/Constants.java" kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm/5.0.3/asm-5.0.3.jar"/>
<classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm-commons/5.0.3/asm-commons-5.0.3.jar"/>
<classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm-tree/5.0.3/asm-tree-5.0.3.jar"/>
<classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm-analysis/5.0.3/asm-analysis-5.0.3.jar"/>
<classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm-util/5.0.3/asm-util-5.0.3.jar"/>
<classpathentry kind="var" path="M2_REPO/com/github/jnr/jnr-netdb/1.1.2/jnr-netdb-1.1.2.jar"/>
<classpathentry kind="var" path="M2_REPO/com/github/jnr/jnr-ffi/2.0.0-SNAPSHOT/jnr-ffi-2.0.0-SNAPSHOT.jar"/>
<classpathentry kind="var" path="M2_REPO/com/github/jnr/jffi/1.2.7/jffi-1.2.7.jar"/>
<classpathentry kind="var" path="M2_REPO/com/github/jnr/jffi/1.2.7/jffi-1.2.7-native.jar"/>
<classpathentry kind="var" path="M2_REPO/com/github/jnr/jnr-x86asm/1.0.2/jnr-x86asm-1.0.2.jar"/>
<classpathentry kind="var" path="M2_REPO/com/github/jnr/jnr-enxio/0.4/jnr-enxio-0.4.jar"/>
<classpathentry kind="var" path="M2_REPO/com/github/jnr/jnr-constants/0.8.6-SNAPSHOT/jnr-constants-0.8.6-SNAPSHOT.jar"/>
<classpathentry kind="var" path="M2_REPO/com/github/jnr/jnr-unixsocket/0.3/jnr-unixsocket-0.3.jar"/>
<classpathentry kind="var" path="M2_REPO/com/github/jnr/jnr-posix/3.0.2/jnr-posix-3.0.2.jar"/>
<classpathentry kind="var" path="M2_REPO/org/jruby/joni/joni/2.1.3/joni-2.1.3.jar"/>
<classpathentry kind="var" path="M2_REPO/org/jruby/jcodings/jcodings/1.0.12-SNAPSHOT/jcodings-1.0.12-SNAPSHOT.jar"/>
<classpathentry kind="var" path="M2_REPO/org/jruby/extras/bytelist/1.0.12-SNAPSHOT/bytelist-1.0.12-SNAPSHOT.jar"/>
<classpathentry kind="var" path="M2_REPO/org/jruby/yecht/1.0/yecht-1.0.jar"/>
<classpathentry kind="var" path="M2_REPO/com/headius/invokebinder/1.4-SNAPSHOT/invokebinder-1.4-SNAPSHOT.jar"/>
<classpathentry kind="var" path="M2_REPO/com/headius/options/1.1/options-1.1.jar"/>
<classpathentry kind="var" path="M2_REPO/com/headius/coro-mock/1.0/coro-mock-1.0.jar"/>
<classpathentry kind="var" path="M2_REPO/com/headius/unsafe-mock/8.0/unsafe-mock-8.0.jar"/>
<classpathentry kind="var" path="M2_REPO/com/headius/jsr292-mock/1.1/jsr292-mock-1.1.jar"/>
<classpathentry kind="var" path="M2_REPO/org/ow2/asm/asm-debug-all/5.0_BETA/asm-debug-all-5.0_BETA.jar"/>
<classpathentry kind="var" path="M2_REPO/bsf/bsf/2.4.0/bsf-2.4.0.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar"/>
<classpathentry kind="var" path="M2_REPO/com/jcraft/jzlib/1.1.2/jzlib-1.1.2.jar"/>
<classpathentry kind="var" path="M2_REPO/com/martiansoftware/nailgun-server/0.9.1/nailgun-server-0.9.1.jar"/>
<classpathentry kind="var" path="M2_REPO/com/oracle/truffle/0.5/truffle-0.5.jar"/>
<classpathentry kind="var" path="M2_REPO/com/oracle/truffle-dsl-processor/0.5/truffle-dsl-processor-0.5.jar"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/4.11/junit-4.11.jar"/>
<classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant/1.9.2/ant-1.9.2.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-launcher/1.9.2/ant-launcher-1.9.2.jar"/>
<classpathentry kind="var" path="M2_REPO/org/osgi/org.osgi.core/5.0.0/org.osgi.core-5.0.0.jar"/>
<classpathentry kind="var" path="M2_REPO/org/yaml/snakeyaml/1.13/snakeyaml-1.13.jar"/>
<classpathentry kind="var" path="M2_REPO/org/jruby/joda-timezones/2013d/joda-timezones-2013d.jar"/>
<classpathentry kind="var" path="M2_REPO/joda-time/joda-time/2.3/joda-time-2.3.jar"/>
<classpathentry excluding="org/jruby/gen/" kind="src" path="target/generated-sources">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/ruby">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
4 changes: 4 additions & 0 deletions core/.factorypath
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<factorypath>
<factorypathentry kind="VARJAR" id="M2_REPO/com/oracle/truffle/0.5/truffle-0.5.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/oracle/truffle-dsl-processor/0.5/truffle-dsl-processor-0.5.jar" enabled="true" runInBatchMode="false"/>
</factorypath>
14 changes: 14 additions & 0 deletions core/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>jruby-core</name>
<comment>JRuby is the effort to recreate the Ruby (http://www.ruby-lang.org) interpreter in Java. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
7 changes: 0 additions & 7 deletions core/.settings/org.eclipse.core.resources.prefs

This file was deleted.

4 changes: 4 additions & 0 deletions core/.settings/org.eclipse.jdt.apt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=target/generated-sources
org.eclipse.jdt.apt.reconcileEnabled=true
8 changes: 7 additions & 1 deletion core/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
eclipse.preferences.version=1
encoding/src/main/java=utf-8
encoding/src/main/resources=utf-8
encoding/src/main/ruby=utf-8
encoding/src/test/java=utf-8
encoding/src/test/resources=utf-8
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
@@ -8,5 +14,5 @@ org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.processAnnotations=enabled
org.eclipse.jdt.core.compiler.source=1.7
60 changes: 60 additions & 0 deletions core/.settings/org.eclipse.jdt.ui.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=false
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=true
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_functional_interfaces=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=false
sp_cleanup.format_source_code=false
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.insert_inferred_type_arguments=false
sp_cleanup.make_local_variable_final=true
sp_cleanup.make_parameters_final=false
sp_cleanup.make_private_fields_final=true
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=false
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
sp_cleanup.on_save_use_additional_actions=true
sp_cleanup.organize_imports=false
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_redundant_type_arguments=true
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_casts=false
sp_cleanup.remove_unnecessary_nls_tags=false
sp_cleanup.remove_unused_imports=false
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
sp_cleanup.remove_unused_private_methods=true
sp_cleanup.remove_unused_private_types=true
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.use_anonymous_class_creation=false
sp_cleanup.use_blocks=false
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_lambda=true
sp_cleanup.use_parentheses_in_expressions=false
sp_cleanup.use_this_for_non_static_field_access=false
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
sp_cleanup.use_type_arguments=false
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyComplex.java
Original file line number Diff line number Diff line change
@@ -133,7 +133,7 @@ public static RubyComplex newComplexRaw(Ruby runtime, IRubyObject x, IRubyObject
/** rb_complex_raw1
*
*/
static RubyComplex newComplexRaw(Ruby runtime, IRubyObject x) {
public static RubyComplex newComplexRaw(Ruby runtime, IRubyObject x) {
return new RubyComplex(runtime, runtime.getComplex(), x, RubyFixnum.zero(runtime));
}

4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/ast/ComplexNode.java
Original file line number Diff line number Diff line change
@@ -37,4 +37,8 @@ public List<Node> childNodes() {
public NodeType getNodeType() {
return NodeType.COMPLEXNODE;
}

public Node getNumber() {
return y;
}
}
14 changes: 12 additions & 2 deletions core/src/main/java/org/jruby/ast/RationalNode.java
Original file line number Diff line number Diff line change
@@ -15,12 +15,14 @@
* @author enebo
*/
public class RationalNode extends Node {
long numerator;
private final long numerator;
private final long denominator;

public RationalNode(ISourcePosition position, long numerator) {
public RationalNode(ISourcePosition position, long numerator, long denominator) {
super(position);

this.numerator = numerator;
this.denominator = denominator;
}

@Override
@@ -37,4 +39,12 @@ public List<Node> childNodes() {
public NodeType getNodeType() {
return NodeType.RATIONALNODE;
}

public long getNumerator() {
return numerator;
}

public long getDenominator() {
return denominator;
}
}
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/common/IRubyWarnings.java
Original file line number Diff line number Diff line change
@@ -97,7 +97,8 @@ public enum ID {
GC_STRESS_UNIMPLEMENTED,
GC_ENABLE_UNIMPLEMENTED,
GC_DISABLE_UNIMPLEMENTED,
TRUFFLE; // TODO(CS): divide up the Truffle warnings
TRUFFLE,
RATIONAL_OUT_OF_RANGE,; // TODO(CS): divide up the Truffle warnings

public String getID() {
return name();
14 changes: 13 additions & 1 deletion core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -376,6 +376,7 @@ private Operand buildOperand(Node node, IRScope s) throws NotCompilableException
case CLASSVARDECLNODE: return buildClassVarDecl((ClassVarDeclNode) node, s);
case COLON2NODE: return buildColon2((Colon2Node) node, s);
case COLON3NODE: return buildColon3((Colon3Node) node, s);
case COMPLEXNODE: return buildComplex((ComplexNode) node, s);
case CONSTDECLNODE: return buildConstDecl((ConstDeclNode) node, s);
case CONSTNODE: return searchConst(s, ((ConstNode) node).getName());
case DASGNNODE: return buildDAsgn((DAsgnNode) node, s);
@@ -425,6 +426,7 @@ private Operand buildOperand(Node node, IRScope s) throws NotCompilableException
case ORNODE: return buildOr((OrNode) node, s);
case PREEXENODE: return buildPreExe((PreExeNode) node, s);
case POSTEXENODE: return buildPostExe((PostExeNode) node, s);
case RATIONALNODE: return buildRational((RationalNode) node, s);
case REDONODE: return buildRedo(node, s);
case REGEXPNODE: return buildRegexp((RegexpNode) node, s);
case RESCUEBODYNODE:
@@ -1268,6 +1270,10 @@ public Operand buildColon3(Colon3Node node, IRScope s) {
return searchConstInInheritanceHierarchy(s, new ObjectClass(), node.getName());
}

public Operand buildComplex(ComplexNode node, IRScope s) {
return new Complex((ImmutableLiteral) build(node.getNumber(), s));
}

interface CodeBlock {
public Operand run();
}
@@ -2068,7 +2074,9 @@ public String buildType(Node typeNode) {
}

public Operand buildDot(final DotNode dotNode, IRScope s) {
return copyAndReturnValue(s, new Range(build(dotNode.getBeginNode(), s), build(dotNode.getEndNode(), s), dotNode.isExclusive()));
Variable res = s.createTemporaryVariable();
addInstr(s, new BuildRangeInstr(res, build(dotNode.getBeginNode(), s), build(dotNode.getEndNode(), s), dotNode.isExclusive()));
return res;
}

private Operand dynamicPiece(Node pieceNode, IRScope s) {
@@ -2988,6 +2996,10 @@ public Operand buildPreExe(PreExeNode preExeNode, IRScope s) {
return manager.getNil();
}

public Operand buildRational(RationalNode rationalNode, IRScope s) {
return new Rational(rationalNode.getNumerator(), rationalNode.getDenominator());
}

public Operand buildRedo(Node node, IRScope s) {
// If in a loop, a redo is a jump to the beginning of the loop.
// If not, for closures, a redo is a jump to the beginning of the closure.
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/ir/IREvalScript.java
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.log.Logger;
@@ -85,15 +84,15 @@ public boolean isModuleOrInstanceEval() {
/* Record a begin block -- not all scope implementations can handle them */
@Override
public void recordBeginBlock(IRClosure beginBlockClosure) {
if (beginBlocks == null) beginBlocks = new ArrayList<IRClosure>();
if (beginBlocks == null) beginBlocks = new ArrayList<>();
beginBlockClosure.setBeginEndBlock();
beginBlocks.add(beginBlockClosure);
}

/* Record an end block -- not all scope implementations can handle them */
@Override
public void recordEndBlock(IRClosure endBlockClosure) {
if (endBlocks == null) endBlocks = new ArrayList<IRClosure>();
if (endBlocks == null) endBlocks = new ArrayList<>();
endBlockClosure.setBeginEndBlock();
endBlocks.add(endBlockClosure);
}
6 changes: 5 additions & 1 deletion core/src/main/java/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
@@ -700,7 +700,11 @@ public void computeScopeFlags() {
// NOTE: bindingHasEscaped is the crucial flag and it effectively is
// unconditionally true whenever it has a call that receives a closure.
// See CallBase.computeRequiresCallersBindingFlag
if (this instanceof IREvalScript) { // for eval scopes, bindings are considered escaped ...
if (this instanceof IREvalScript || this instanceof IRScriptBody) {
// For eval scopes, bindings are considered escaped.
// For top-level script scopes, bindings are considered escaped as well
// because TOPLEVEL_BINDING can be used in places besides the file
// that is being parsed?
flags.add(BINDING_HAS_ESCAPED);
} else {
flags.remove(BINDING_HAS_ESCAPED);
11 changes: 11 additions & 0 deletions core/src/main/java/org/jruby/ir/IRScriptBody.java
Original file line number Diff line number Diff line change
@@ -4,22 +4,33 @@
import org.jruby.ir.interpreter.BeginEndInterpreterContext;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;

import java.util.ArrayList;
import java.util.List;

public class IRScriptBody extends IRScope {
private List<IRClosure> beginBlocks;
private List<IRClosure> endBlocks;
private DynamicScope tlbScope;

public IRScriptBody(IRManager manager, String sourceName, StaticScope staticScope) {
super(manager, null, sourceName, sourceName, 0, staticScope);
this.tlbScope = null;
if (!getManager().isDryRun() && staticScope != null) {
staticScope.setIRScope(this);
staticScope.setScopeType(this.getScopeType());
}
}

public DynamicScope getTopLevelBindingScope() {
return tlbScope;
}

public void setTopLevelBindingScope(DynamicScope tlbScope) {
this.tlbScope = tlbScope;
}

@Override
public InterpreterContext allocateInterpreterContext(Instr[] instructionList) {
return new BeginEndInterpreterContext(this, instructionList);
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ir/IRTranslator.java
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ public R execute(Ruby runtime, ParseResult result, S specificObject) {
scope = (IRScriptBody) result;
} else if (result instanceof RootNode) { // Need to perform create IR from AST
scope = IRBuilder.createIRBuilder(runtime, runtime.getIRManager()).buildRoot((RootNode) result);
scope.setTopLevelBindingScope(((RootNode)result).getScope());

if (RubyInstanceConfig.IR_WRITING) {
try {
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/ir/IRVisitor.java
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ private void error(Object object) {
public void BuildCompoundArrayInstr(BuildCompoundArrayInstr instr) { error(instr); }
public void BuildCompoundStringInstr(BuildCompoundStringInstr instr) { error(instr); }
public void BuildDynRegExpInstr(BuildDynRegExpInstr instr) { error(instr); }
public void BuildRangeInstr(BuildRangeInstr instr) { error(instr); }
public void CallInstr(CallInstr callinstr) { error(callinstr); }
public void CheckArgsArrayArityInstr(CheckArgsArrayArityInstr checkargsarrayarityinstr) { error(checkargsarrayarityinstr); }
public void CheckArityInstr(CheckArityInstr checkarityinstr) { error(checkarityinstr); }
@@ -139,6 +140,7 @@ private void error(Object object) {
public void Boolean(Boolean bool) { error(bool); }
public void UnboxedBoolean(UnboxedBoolean bool) { error(bool); }
public void ClosureLocalVariable(ClosureLocalVariable closurelocalvariable) { error(closurelocalvariable); }
public void Complex(Complex complex) { error(complex); }
public void CurrentScope(CurrentScope currentscope) { error(currentscope); }
public void DynamicSymbol(DynamicSymbol dynamicsymbol) { error(dynamicsymbol); }
public void Fixnum(Fixnum fixnum) { error(fixnum); }
@@ -155,7 +157,7 @@ private void error(Object object) {
public void Nil(Nil nil) { error(nil); }
public void NthRef(NthRef nthref) { error(nthref); }
public void ObjectClass(ObjectClass objectclass) { error(objectclass); }
public void Range(Range range) { error(range); }
public void Rational(Rational rational) { error(rational); }
public void Regexp(Regexp regexp) { error(regexp); }
public void ScopeModule(ScopeModule scopemodule) { error(scopemodule); }
public void Self(Self self) { error(self); }
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ir/Operation.java
Original file line number Diff line number Diff line change
@@ -143,6 +143,7 @@ public enum Operation {
BUILD_COMPOUND_ARRAY(OpFlags.f_can_raise_exception),
BUILD_COMPOUND_STRING(OpFlags.f_can_raise_exception),
BUILD_DREGEXP(OpFlags.f_can_raise_exception),
BUILD_RANGE(OpFlags.f_can_raise_exception),
BACKTICK_STRING(OpFlags.f_can_raise_exception),
CHECK_ARGS_ARRAY_ARITY(OpFlags.f_can_raise_exception),
CHECK_ARITY(OpFlags.f_is_book_keeping_op | OpFlags.f_can_raise_exception),
Original file line number Diff line number Diff line change
@@ -1,32 +1,51 @@
package org.jruby.ir.operands;
package org.jruby.ir.instructions;

import org.jruby.RubyRange;
import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

import java.util.List;
import java.util.Map;

// Represents a range (1..5) or (a..b) in ruby code
//
// NOTE: This operand is only used in the initial stages of optimization
// Further down the line, this range operand could get converted to calls
// that actually build the Range object
public class Range extends Operand {
final private Operand begin;
final private Operand end;
// that actually build the BuildRangeInstr object
public class BuildRangeInstr extends Instr implements ResultInstr {
private Variable result;
private Operand begin;
private Operand end;
private boolean exclusive;

public Range(Operand begin, Operand end, boolean exclusive) {
super(OperandType.RANGE);
public BuildRangeInstr(Variable result, Operand begin, Operand end, boolean exclusive) {
super(Operation.BUILD_RANGE);

this.begin = begin;
this.end = end;
this.exclusive = exclusive;
this.result = result;
}

@Override
public Variable getResult() {
return result;
}

@Override
public void updateResult(Variable v) {
this.result = v;
}

@Override
public Operand[] getOperands() {
return new Operand[] { begin, end };
}

public Operand getBegin() {
@@ -43,44 +62,30 @@ public boolean isExclusive() {

@Override
public String toString() {
return begin + (exclusive ? ".." : "...") + end;
return result + " = " + begin + (exclusive ? ".." : "...") + end;
}


// ---------- These methods below are used during compile-time optimizations -------
@Override
public boolean hasKnownValue() {
return begin.hasKnownValue() && end.hasKnownValue();
}

@Override
public Operand getSimplifiedOperand(Map<Operand, Operand> valueMap, boolean force) {
Operand newBegin = begin.getSimplifiedOperand(valueMap, force);
Operand newEnd = end.getSimplifiedOperand(valueMap, force);
return (newBegin == begin && newEnd == end) ? this : new Range(newBegin, newEnd, exclusive);
}

/** Append the list of variables used in this operand to the input list */
@Override
public void addUsedVariables(List<Variable> l) {
begin.addUsedVariables(l);
end.addUsedVariables(l);
public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
begin = begin.getSimplifiedOperand(valueMap, force);
end= end.getSimplifiedOperand(valueMap, force);
}

@Override
public Operand cloneForInlining(CloneInfo ii) {
return hasKnownValue() ? this : new Range(begin.cloneForInlining(ii), end.cloneForInlining(ii), exclusive);
public Instr clone(CloneInfo ii) {
return new BuildRangeInstr(ii.getRenamedVariable(result), begin.cloneForInlining(ii), end.cloneForInlining(ii), exclusive);
}

@Override
public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
return RubyRange.newRange(context.runtime, context,
(IRubyObject) begin.retrieve(context, self, currScope, currDynScope, temp),
(IRubyObject) end.retrieve(context, self, currScope, currDynScope, temp), exclusive);
}

@Override
public void visit(IRVisitor visitor) {
visitor.Range(this);
visitor.BuildRangeInstr(this);
}
}
10 changes: 8 additions & 2 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Original file line number Diff line number Diff line change
@@ -161,7 +161,13 @@ protected IRubyObject execute(Ruby runtime, IRScriptBody irScope, IRubyObject se
IRubyObject retVal;

scope.setModule(currModule);
if (!ic.isDynscopeEliminated()) context.preMethodScopeOnly(scope);
DynamicScope tlbScope = irScope.getTopLevelBindingScope();
if (tlbScope == null) {
context.preMethodScopeOnly(scope);
} else {
context.preScopedBody(tlbScope);
tlbScope.growIfNeeded();
}
context.setCurrentVisibility(Visibility.PRIVATE);

try {
@@ -173,7 +179,7 @@ protected IRubyObject execute(Ruby runtime, IRScriptBody irScope, IRubyObject se
throw IRException.BREAK_LocalJumpError.getException(context.runtime);
} finally {
Interpreter.runEndBlocks(ic.getEndBlocks(), context, self, scope, null);
if (!ic.isDynscopeEliminated()) context.popScope();
context.popScope();
}

return retVal;
39 changes: 39 additions & 0 deletions core/src/main/java/org/jruby/ir/operands/Complex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jruby.ir.operands;

import org.jruby.RubyComplex;
import org.jruby.ir.IRVisitor;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

/**
* Represents a Complex literal.
*/
public class Complex extends ImmutableLiteral {
private ImmutableLiteral number;

public Complex(ImmutableLiteral number) {
super(OperandType.COMPLEX);

this.number = number;
}

@Override
public Object createCacheObject(ThreadContext context) {
return RubyComplex.newComplexRaw(context.runtime,
context.runtime.newFixnum(0), (IRubyObject) number.cachedObject(context));
}

@Override
public String toString() {
return number + "i";
}

@Override
public void visit(IRVisitor visitor) {
visitor.Complex(this);
}

public Operand getNumber() {
return number;
}
}
5 changes: 0 additions & 5 deletions core/src/main/java/org/jruby/ir/operands/Float.java
Original file line number Diff line number Diff line change
@@ -12,11 +12,6 @@ public Float(double value) {
this.value = value;
}

@Override
public boolean hasKnownValue() {
return true;
}

@Override
public Object createCacheObject(ThreadContext context) {
return context.runtime.newFloat(value);
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/ir/operands/OperandType.java
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ public enum OperandType {
BIGNUM((byte) 'B'),
BOOLEAN((byte) 'b'),
LOCAL_VARIABLE((byte) 'l'), // Also applicable for ClosureLocalVariable
COMPLEX((byte) 'C'),
COMPOUND_ARRAY((byte) 'c'),
COMPOUND_STRING((byte) '"'),
CURRENT_SCOPE((byte) 's'),
@@ -30,6 +31,7 @@ public enum OperandType {
NTH_REF((byte) '1'),
OBJECT_CLASS((byte) 'O'),
RANGE((byte) '.'),
RATIONAL((byte) 'r'),
REGEXP((byte) '/'),
SCOPE_MODULE((byte) '_'),
SELF((byte) 'S'),
42 changes: 42 additions & 0 deletions core/src/main/java/org/jruby/ir/operands/Rational.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.jruby.ir.operands;

import org.jruby.ir.IRVisitor;
import org.jruby.runtime.ThreadContext;

/**
* Literal Rational number.
*/
public class Rational extends ImmutableLiteral {
private final long numerator;
private final long denominator;

public Rational(long numerator, long denominator) {
super(OperandType.RATIONAL);

this.numerator = numerator;
this.denominator = denominator;
}

@Override
public Object createCacheObject(ThreadContext context) {
return context.runtime.newRational(numerator, denominator);
}

@Override
public String toString() {
return "Rational:" + numerator + "/1";
}

@Override
public void visit(IRVisitor visitor) {
visitor.Rational(this);
}

public double getNumerator() {
return numerator;
}

public double getDenominator() {
return denominator;
}
}
Original file line number Diff line number Diff line change
@@ -53,10 +53,10 @@ public Instr decodeInner(Operation operation) {
case CHECK_ARITY: return new CheckArityInstr(d.decodeInt(), d.decodeInt(), d.decodeInt(), d.decodeBoolean(), d.decodeInt());
case CLASS_VAR_MODULE: return new GetClassVarContainerModuleInstr(d.decodeVariable(), d.decodeOperand(), d.decodeVariable());
case CONST_MISSING: return decodeConstMissingInstr();
// SSS FIXME: Might need fixing
// case BUILD_COMPOUND_INSTR: return decodeBuildCompoundStringInstr();
// SSS FIXME: TODO
// case BUILD_COMPOUND_INSTR: return decodeBuildCompoundStringInstr();
// case BUILD_DREGEXP: return decodeBuildDynRegExpInstr();
// case BUILD_RANGE: return new Range(d.decodeOperand(), d.decodeOperand(), d.decodeBoolean());
case COPY: return decodeCopy();
case DEF_CLASS: return new DefineClassInstr((d.decodeVariable()), (IRClassBody) d.decodeScope(), d.decodeOperand(), d.decodeOperand());
case DEF_CLASS_METH: return new DefineClassMethodInstr(d.decodeOperand(), (IRMethod) d.decodeScope());
Original file line number Diff line number Diff line change
@@ -47,10 +47,9 @@ public void encode(Instr instr) {
case CHECK_ARGS_ARRAY_ARITY: encodeCheckArgsArrayArityInstr((CheckArgsArrayArityInstr) instr); break;
case CHECK_ARITY: encodeCheckArityInstr((CheckArityInstr) instr); break;
case CLASS_VAR_MODULE: encodeGetClassVarContainerModuleInstr((GetClassVarContainerModuleInstr) instr); break;
// SSS FIXME: Needs fixing
// case BUILD_COMPOUND_STRING: encodeBuildCompoundStringInstr((BuildCompoundStringInstr) instr); break;
// SSS FIXME: TODO
// case BUILD_DREGEXP: return encodeBuildDynRegExpInstr();
// case BUILD_RANGE: return encodeBuildRangeInstr();
case CONST_MISSING: encodeConstMissingInstr((ConstMissingInstr) instr); break;
case COPY: encodeCopyInstr((CopyInstr) instr); break;
case DEF_CLASS: encodeDefineClassInstr((DefineClassInstr) instr); break;
Original file line number Diff line number Diff line change
@@ -50,7 +50,6 @@ public Operand decode(OperandType type) {
case NIL: return manager.getNil();
case NTH_REF: return new NthRef(d.decodeInt());
case OBJECT_CLASS: return new ObjectClass();
case RANGE: return new Range(d.decodeOperand(), d.decodeOperand(), d.decodeBoolean());
case REGEXP: return decodeRegexp();
case SCOPE_MODULE: return new ScopeModule(d.decodeInt());
case SELF: return Self.SELF;
Original file line number Diff line number Diff line change
@@ -93,12 +93,6 @@ public void encode(Operand operand) {

@Override public void ObjectClass(ObjectClass objectclass) {} // No data

@Override public void Range(Range range) {
encoder.encode(range.getBegin());
encoder.encode(range.getEnd());
encoder.encode(range.isExclusive());
}

@Override public void Regexp(Regexp regexp) {
encode(regexp.getRegexp());
encoder.encode(regexp.options.isEncodingNone());
21 changes: 11 additions & 10 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
@@ -767,6 +767,17 @@ public void run() {
jvmStoreLocal(instr.getResult());
}

@Override
public void BuildRangeInstr(BuildRangeInstr instr) {
jvmMethod().loadRuntime();
jvmMethod().loadContext();
visit(instr.getBegin());
visit(instr.getEnd());
jvmAdapter().ldc(instr.isExclusive());
jvmAdapter().invokestatic(p(RubyRange.class), "newRange", sig(RubyRange.class, Ruby.class, ThreadContext.class, IRubyObject.class, IRubyObject.class, boolean.class));
jvmStoreLocal(instr.getResult());
}

@Override
public void CallInstr(CallInstr callInstr) {
IRBytecodeAdapter m = jvmMethod();
@@ -2017,16 +2028,6 @@ public void ObjectClass(ObjectClass objectclass) {
jvmMethod().pushObjectClass();
}

@Override
public void Range(Range range) {
jvmMethod().loadRuntime();
jvmMethod().loadContext();
visit(range.getBegin());
visit(range.getEnd());
jvmAdapter().ldc(range.isExclusive());
jvmAdapter().invokestatic(p(RubyRange.class), "newRange", sig(RubyRange.class, Ruby.class, ThreadContext.class, IRubyObject.class, IRubyObject.class, boolean.class));
}

@Override
public void Regexp(Regexp regexp) {
if (!regexp.hasKnownValue() && !regexp.options.isOnce()) {
38 changes: 33 additions & 5 deletions core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@

import java.io.IOException;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.HashMap;

@@ -136,8 +137,21 @@ public Encoding getEncoding() {
return encoding;
}

private int getFloatToken(String number) {
// FIXME: Rational support is needed here.
private int getFloatToken(String number, int suffix) {
if ((suffix & SUFFIX_R) != 0) {
BigDecimal bd = new BigDecimal(number);
BigDecimal denominator = BigDecimal.ONE.scaleByPowerOfTen(bd.scale());
BigDecimal numerator = bd.multiply(denominator);

try {
yaccValue = new RationalNode(getPosition(), numerator.longValueExact(), denominator.longValueExact());
} catch (ArithmeticException ae) {
// FIXME: Rational supports Bignum numerator and denominator
throw new SyntaxException(PID.RATIONAL_OUT_OF_RANGE, getPosition(), getCurrentLine(), "Rational (" + numerator + "/" + denominator + ") out of range.");
}
return Tokens.tRATIONAL;
}

double d;
try {
d = SafeDoubleParser.parseDouble(number);
@@ -159,7 +173,7 @@ private FixnumNode newFixnumNode(String value, int radix) throws NumberFormatExc
}

private RationalNode newRationalNode(String value, int radix) throws NumberFormatException {
return new RationalNode(getPosition(), Long.parseLong(value, radix));
return new RationalNode(getPosition(), Long.parseLong(value, radix), 1);
}

private ComplexNode newComplexNode(Node number) {
@@ -1637,7 +1651,20 @@ private int dollar() throws IOException {
return identifierToken(Tokens.tGVAR, tokenBuffer.toString().intern());
}
}


// FIXME: I added number gvars here and they did not.
public boolean isGlobalCharPunct(int c) {
switch (c) {
case '_': case '~': case '*': case '$': case '?': case '!': case '@':
case '/': case '\\': case ';': case ',': case '.': case '=': case ':':
case '<': case '>': case '\"': case '-': case '&': case '`': case '\'':
case '+': case '1': case '2': case '3': case '4': case '5': case '6':
case '7': case '8': case '9': case '0':
return true;
}
return isIdentifierChar(c);
}

private int dot() throws IOException {
int c;

@@ -2500,7 +2527,8 @@ private int getNumberToken(String number, boolean seen_e, boolean seen_point, in
throw new SyntaxException(PID.TRAILING_UNDERSCORE_IN_NUMBER, getPosition(),
getCurrentLine(), "Trailing '_' in number.");
} else if (isFloat) {
return getFloatToken(number);
int suffix = numberLiteralSuffix(seen_e ? SUFFIX_I : SUFFIX_ALL);
return getFloatToken(number, suffix);
}
yaccValue = getInteger(number, 10, numberLiteralSuffix(SUFFIX_ALL));
return Tokens.tINTEGER;
84 changes: 72 additions & 12 deletions core/src/main/java/org/jruby/lexer/yacc/StringTerm.java
Original file line number Diff line number Diff line change
@@ -79,6 +79,75 @@ private int endFound(RubyLexer lexer, LexerSource src) throws IOException {
return Tokens.tSTRING_END;
}

// Return of 0 means failed to find anything. Non-zero means return that from lexer.
private int parsePeekVariableName(RubyLexer lexer, LexerSource src) throws IOException {
int c = src.read(); // byte right after #
int significant = -1;
switch (c) {
case '$': { // we unread back to before the $ so next lex can read $foo
int c2 = src.read();

if (c2 == '-') {
int c3 = src.read();

if (c3 == RubyLexer.EOF) {
src.unread(c3); src.unread(c2);
return 0;
}

significant = c3; // $-0 potentially
src.unread(c3); src.unread(c2);
break;
} else if (lexer.isGlobalCharPunct(c2)) { // $_ potentially
lexer.setValue("#" + c2);

src.unread(c2); src.unread(c);
return Tokens.tSTRING_DVAR;
}

significant = c2; // $FOO potentially
src.unread(c2);
break;
}
case '@': { // we unread back to before the @ so next lex can read @foo
int c2 = src.read();

if (c2 == '@') {
int c3 = src.read();

if (c3 == RubyLexer.EOF) {
src.unread(c3); src.unread(c2);
return 0;
}

significant = c3; // #@@foo potentially
src.unread(c3); src.unread(c2);
break;
}

significant = c2; // #@foo potentially
src.unread(c2);
break;
}
case '{':
lexer.setValue("#" + c);
return Tokens.tSTRING_DBEG;
default:
// We did not find significant char after # so push it back to
// be processed as an ordinary string.
src.unread(c);
return 0;
}

if (significant != -1 && Character.isAlphabetic(significant) || significant == '_') {
src.unread(c);
lexer.setValue("#" + significant);
return Tokens.tSTRING_DVAR;
}

return 0;
}

public int parseString(RubyLexer lexer, LexerSource src) throws IOException {
boolean spaceSeen = false;
int c;
@@ -107,18 +176,9 @@ public int parseString(RubyLexer lexer, LexerSource src) throws IOException {
ByteList buffer = createByteList(lexer);
lexer.newtok();
if ((flags & RubyLexer.STR_FUNC_EXPAND) != 0 && c == '#') {
c = src.read();
switch (c) {
case '$':
case '@':
src.unread(c);
lexer.setValue("#" + c);
return Tokens.tSTRING_DVAR;
case '{':
lexer.setValue("#" + c);
return Tokens.tSTRING_DBEG;
}
buffer.append((byte) '#');
int token = parsePeekVariableName(lexer, src);

if (token != 0) return token;
}
src.unread(c);

3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/lexer/yacc/SyntaxException.java
Original file line number Diff line number Diff line change
@@ -58,7 +58,8 @@ public enum PID {
MIXED_ENCODING("MIXED_ENCODNIG"),
NUL_IN_SYMBOL("NUL_IN_SYMBOL"),
REGEXP_ENCODING_MISMATCH("REGEXP_ENCODING_MISMATCH"),
INVALID_MULTIBYTE_CHAR("INVALID_MULTIBYTE_CHAR")
INVALID_MULTIBYTE_CHAR("INVALID_MULTIBYTE_CHAR"),
RATIONAL_OUT_OF_RANGE("RATIONAL_OUT_OF_RANGE")
;

private String id;
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/parser/Parser.java
Original file line number Diff line number Diff line change
@@ -122,6 +122,7 @@ public Node parse(String file, LexerSource lexerSource, DynamicScope blockScope,
// but I am not sure which conditions leads to this...so lame message.
throw runtime.newSyntaxError("Problem reading source: " + e);
} catch (SyntaxException e) {
e.printStackTrace();
switch (e.getPid()) {
case UNKNOWN_ENCODING:
case NOT_ASCII_COMPATIBLE:
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/parser/Tokens.java
Original file line number Diff line number Diff line change
@@ -89,6 +89,7 @@ public interface Tokens {
int tCVAR = RubyParser.tCVAR;
int tINTEGER = RubyParser.tINTEGER;
int tFLOAT = RubyParser.tFLOAT;
int tRATIONAL = RubyParser.tRATIONAL;
int tSTRING_CONTENT = RubyParser.tSTRING_CONTENT;
int tSTRING_BEG = RubyParser.tSTRING_BEG;
int tSTRING_END = RubyParser.tSTRING_END;
41 changes: 1 addition & 40 deletions core/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -10,19 +10,14 @@
package org.jruby.truffle.nodes;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import org.jruby.truffle.nodes.dispatch.Dispatch;
import org.jruby.truffle.nodes.yield.YieldDispatchNode;
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.RubyCallStack;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.backtrace.Backtrace;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyHash;
@@ -219,38 +214,4 @@ public static void notDesignedForCompilation() {
CompilerAsserts.neverPartOfCompilation();
}

private static void panic(RubyContext context, RubyNode currentNode, String message) {
CompilerDirectives.transferToInterpreter();

System.err.println("PANIC");

if (message != null) {
System.err.println(message);
}

for (String line : Backtrace.PANIC_FORMATTER.format(context, null, RubyCallStack.getBacktrace(currentNode))) {
System.err.println(line);
}

new Exception().printStackTrace();

System.exit(1);
}

public void panic(String format, Object... args) {
panic(String.format(format, args));
}

public void panic(String message) {
panic(getContext(), this, message);
}

public void panic() {
panic(getContext(), this, null);
}

public static void panic(RubyContext context) {
panic(context, null, null);
}

}
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/RubyRootNode.java
Original file line number Diff line number Diff line change
@@ -49,6 +49,8 @@ public boolean isCloningAllowed() {

@Override
public Object execute(VirtualFrame frame) {
context.getSafepointManager().poll();

return body.execute(frame);
}

6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/RubyTypes.java
Original file line number Diff line number Diff line change
@@ -73,6 +73,12 @@

public class RubyTypes {

@ImplicitCast
public long int2long(int value) {
return value;
}


@ImplicitCast
public boolean unboxBoolean(RubyTrueClass value) {
return true;
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ public class DoWhileNode extends RubyNode {

public DoWhileNode(RubyContext context, SourceSection sourceSection, BooleanCastNode condition, RubyNode body) {
super(context, sourceSection);
loopNode = Truffle.getRuntime().createLoopNode(new DoWhileRepeatingNode(condition, body));
loopNode = Truffle.getRuntime().createLoopNode(new DoWhileRepeatingNode(context, condition, body));
}

@Override
@@ -44,17 +44,22 @@ public Object execute(VirtualFrame frame) {

private static class DoWhileRepeatingNode extends Node implements RepeatingNode {

private final RubyContext context;

@Child protected BooleanCastNode condition;
@Child protected RubyNode body;

public DoWhileRepeatingNode(BooleanCastNode condition, RubyNode body) {
public DoWhileRepeatingNode(RubyContext context, BooleanCastNode condition, RubyNode body) {
this.context = context;
this.condition = condition;
this.body = body;
}

@Override
public boolean executeRepeating(VirtualFrame frame) {
while (true) { // for redo
context.getSafepointManager().poll();

try {
body.execute(frame);
break;
Original file line number Diff line number Diff line change
@@ -44,6 +44,8 @@ public TryNode(RubyContext context, SourceSection sourceSection, ExceptionTransl
@Override
public Object execute(VirtualFrame frame) {
while (true) {
getContext().getSafepointManager().poll();

try {
final Object result = tryPart.execute(frame);
elseProfile.enter();
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ public class WhileNode extends RubyNode {

public WhileNode(RubyContext context, SourceSection sourceSection, BooleanCastNode condition, RubyNode body) {
super(context, sourceSection);
loopNode = Truffle.getRuntime().createLoopNode(new WhileRepeatingNode(condition, body));
loopNode = Truffle.getRuntime().createLoopNode(new WhileRepeatingNode(context, condition, body));
}

@Override
@@ -41,10 +41,13 @@ public Object execute(VirtualFrame frame) {

private static class WhileRepeatingNode extends Node implements RepeatingNode {

private final RubyContext context;

@Child protected BooleanCastNode condition;
@Child protected RubyNode body;

public WhileRepeatingNode(BooleanCastNode condition, RubyNode body) {
public WhileRepeatingNode(RubyContext context, BooleanCastNode condition, RubyNode body) {
this.context = context;
this.condition = condition;
this.body = body;
}
@@ -56,6 +59,8 @@ public boolean executeRepeating(VirtualFrame frame) {
}

while (true) { // for redo
context.getSafepointManager().poll();

try {
body.execute(frame);
return true;
Original file line number Diff line number Diff line change
@@ -122,12 +122,10 @@ public ReferenceEqualNode(ReferenceEqualNode prev) {
@Specialization public boolean equal(boolean a, BigInteger b) { return false; }

@Specialization public boolean equal(int a, boolean b) { return false; }
@Specialization public boolean equal(int a, long b) { return false; }
@Specialization public boolean equal(int a, double b) { return false; }
@Specialization public boolean equal(int a, BigInteger b) { return false; }

@Specialization public boolean equal(long a, boolean b) { return false; }
@Specialization public boolean equal(long a, int b) { return false; }
@Specialization public boolean equal(long a, double b) { return false; }
@Specialization public boolean equal(long a, BigInteger b) { return false; }

43 changes: 9 additions & 34 deletions core/src/main/java/org/jruby/truffle/nodes/core/FixnumNodes.java
Original file line number Diff line number Diff line change
@@ -107,26 +107,16 @@ public int add(int a, int b) {
return ExactMath.addExact(a, b);
}

@Specialization(rewriteOn = ArithmeticException.class)
public long addWithLongOverflow(int a, int b) {
return ExactMath.addExact((long) a, (long) b);
}

@Specialization
public Object addWithBigIntegerOverflow(int a, int b) {
return fixnumOrBignum.fixnumOrBignum(RuntimeBigInteger.add(BigInteger.valueOf(a), BigInteger.valueOf(b)));
public long addWithLongOverflow(int a, int b) {
return (long) a + (long) b;
}

@Specialization
public double add(int a, double b) {
return a + b;
}

@Specialization
public long add(int a, long b) {
return ExactMath.addExact(a, b);
}

@Specialization
public Object add(int a, BigInteger b) {
return fixnumOrBignum.fixnumOrBignum(RuntimeBigInteger.add(BigInteger.valueOf(a), b));
@@ -137,14 +127,9 @@ public long add(long a, int b) {
return ExactMath.addExact(a, b);
}

@Specialization(rewriteOn = ArithmeticException.class)
public long addWithLong(long a, int b) {
return ExactMath.addExact(a, (long) b);
}

@Specialization
public Object addWithBigIntegerOverflow(long a, int b) {
return fixnumOrBignum.fixnumOrBignum(BigInteger.valueOf(a).add(BigInteger.valueOf(b)));
return fixnumOrBignum.fixnumOrBignum(RuntimeBigInteger.add(BigInteger.valueOf(a), BigInteger.valueOf(b)));
}

@Specialization(rewriteOn = ArithmeticException.class)
@@ -154,7 +139,7 @@ public long add(long a, long b) {

@Specialization
public Object addWithBigIntegerOverflow(long a, long b) {
return fixnumOrBignum.fixnumOrBignum(BigInteger.valueOf(a).add(BigInteger.valueOf(b)));
return fixnumOrBignum.fixnumOrBignum(RuntimeBigInteger.add(BigInteger.valueOf(a), BigInteger.valueOf(b)));
}

@Specialization
@@ -189,14 +174,9 @@ public int sub(int a, int b) {
return ExactMath.subtractExact(a, b);
}

@Specialization(rewriteOn = ArithmeticException.class)
public long subWithLongOverflow(int a, int b) {
return ExactMath.subtractExact((long) a, (long) b);
}

@Specialization
public Object subWithBigIntegerOverflow(int a, int b) {
return fixnumOrBignum.fixnumOrBignum(RuntimeBigInteger.subtract(BigInteger.valueOf(a), BigInteger.valueOf(b)));
public long subWithLongOverflow(int a, int b) {
return (long) a - (long) b;
}

@Specialization
@@ -271,14 +251,9 @@ public int mul(int a, int b) {
return ExactMath.multiplyExact(a, b);
}

@Specialization(rewriteOn = ArithmeticException.class)
public long mulWithLong(int a, int b) {
return ExactMath.multiplyExact((long) a, (long) b);
}

@Specialization
public Object mulWithBigInteger(int a, int b) {
return fixnumOrBignum.fixnumOrBignum(BigInteger.valueOf(a).multiply(BigInteger.valueOf(b)));
public long mulWithLong(int a, int b) {
return (long) a * (long) b;
}

@Specialization(rewriteOn = ArithmeticException.class)
@@ -312,7 +287,7 @@ public Object mulWithBigInteger(long a, int b) {
}

@Specialization(rewriteOn = ArithmeticException.class)
public Object mul(long a, long b) {
public long mul(long a, long b) {
return ExactMath.multiplyExact(a, b);
}

Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ public Object fixnumOrBignum(BigInteger value) {
return (int) longValue;
} else {
longProfile.enter();
return value;
return longValue;
}
} else {
return value;
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ public PanicNode(PanicNode prev) {

@Specialization
public RubyNilClass doPanic() {
panic();
DebugOperations.panic(getContext(), this, null);
return getContext().getCoreLibrary().getNilObject();
}

Original file line number Diff line number Diff line change
@@ -22,13 +22,7 @@ public class RubyASTProber implements ASTProber {
private final List<RubyNodeProber> probers = new ArrayList<>();

public RubyASTProber() {
if ((boolean) Options.TRUFFLE_TRACE.load()) {
probers.add(new TraceProber());
}

if ((boolean) Options.TRUFFLE_OBJECTSPACE.load()) {
probers.add(new SafepointProber());
}
probers.add(new TraceProber());
}

@Override

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@

public final class UnresolvedDispatchNode extends DispatchNode {

private int depth = 0;

private final boolean ignoreVisibility;
private final Dispatch.MissingBehavior missingBehavior;

@@ -46,14 +48,16 @@ public Object executeDispatch(
Dispatch.DispatchAction dispatchAction) {
CompilerDirectives.transferToInterpreterAndInvalidate();

if (getDepth() == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
if (depth == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
return getHeadNode().getFirstDispatchNode()
.replace(UncachedDispatchNodeFactory.create(getContext(), ignoreVisibility,
null, null, null, null, null, null, null))
.executeDispatch(frame, methodReceiverObject, lexicalScope, receiverObject,
methodName, blockObject, argumentsObjects, dispatchAction);
}

depth++;

final DispatchNode first = getHeadNode().getFirstDispatchNode();

if (receiverObject instanceof RubyBasicObject) {
@@ -276,18 +280,4 @@ private DispatchNode createMethodMissingNode(
}
}

private int getDepth() {
final DispatchHeadNode head = getHeadNode();
Node parent = getParent();

int depth = 1;

while (parent != head) {
depth++;
parent = parent.getParent();
}

return depth;
}

}
Original file line number Diff line number Diff line change
@@ -43,21 +43,11 @@ public RubyRange.IntegerFixnumRange doRange(int begin, int end) {
return new RubyRange.IntegerFixnumRange(getContext().getCoreLibrary().getRangeClass(), begin, end, excludeEnd);
}

@Specialization
public RubyRange.LongFixnumRange doRange(int begin, long end) {
return new RubyRange.LongFixnumRange(getContext().getCoreLibrary().getRangeClass(), begin, end, excludeEnd);
}

@Specialization
public RubyRange.LongFixnumRange doRange(long begin, long end) {
return new RubyRange.LongFixnumRange(getContext().getCoreLibrary().getRangeClass(), begin, end, excludeEnd);
}

@Specialization
public RubyRange.LongFixnumRange doRange(long begin, int end) {
return new RubyRange.LongFixnumRange(getContext().getCoreLibrary().getRangeClass(), begin, end, excludeEnd);
}

@Specialization
public Object doRange(Object begin, Object end) {
if (begin instanceof Integer) {
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.DebugOperations;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.control.ThreadExitException;
@@ -123,7 +124,7 @@ public RubyBasicObject translate(Throwable throwable) {
}

if (Options.TRUFFLE_PANIC_ON_JAVA_ASSERT.load() && throwable instanceof AssertionError) {
panic(throwable.toString());
DebugOperations.panic(getContext(), this, throwable.toString());
}

return getContext().getCoreLibrary().internalError(throwable.getClass().getSimpleName(), this);
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@ public RedoableNode(RubyContext context, SourceSection sourceSection, RubyNode b
@Override
public Object execute(VirtualFrame frame) {
while (true) {
getContext().getSafepointManager().poll();

try {
return body.execute(frame);
} catch (RedoException e) {
96 changes: 96 additions & 0 deletions core/src/main/java/org/jruby/truffle/runtime/DebugOperations.java
Original file line number Diff line number Diff line change
@@ -10,12 +10,23 @@
package org.jruby.truffle.runtime;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.FrameInstanceVisitor;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeUtil;
import com.oracle.truffle.api.nodes.RootNode;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.*;
import org.jruby.truffle.runtime.backtrace.Backtrace;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.methods.RubyMethod;

import java.math.BigInteger;
import java.util.List;

public abstract class DebugOperations {

@@ -46,4 +57,89 @@ public static Object send(RubyContext context, Object object, String methodName,
RubyArguments.pack(method, method.getDeclarationFrame(), rubyObject, block, arguments));
}

public static void panic(RubyContext context, Node currentNode, String message) {
CompilerDirectives.transferToInterpreter();

System.err.println("=========================== JRuby+Truffle Debug Report ========================");

if (message != null) {
System.err.println();
System.err.println("Stopped because: " + message);
}

System.err.println();
System.err.println(" =========================== Ruby Bracktrace =========================== ");
System.err.println();

try {
for (String line : Backtrace.PANIC_FORMATTER.format(context, null, RubyCallStack.getBacktrace(currentNode))) {
System.err.println(line);
}
} catch (Throwable e) {
e.printStackTrace();
}

System.err.println();
System.err.println(" ========================== AST Backtrace ========================== ");
System.err.println();

try {
printASTBacktrace(currentNode);
} catch (Throwable e) {
e.printStackTrace();
}

System.err.println();
System.err.println(" =========================== Java Backtrace ============================ ");
System.err.println();

new Exception().printStackTrace();

System.err.println();
System.err.println("===============================================================================");

System.exit(1);
}

public static void printASTBacktrace(final Node currentNode) {
if (currentNode != null) {
printMethodASTBacktrace(currentNode);
}

Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Object>() {

@Override
public Object visitFrame(FrameInstance frameInstance) {
printMethodASTBacktrace(frameInstance.getCallNode());
return null;
}

});
}

private static void printMethodASTBacktrace(Node currentNode) {
final List<Node> activeNodes = NodeUtil.findAllParents(currentNode, Node.class);
printASTForBacktrace(currentNode.getRootNode(), activeNodes, 0);
}

private static void printASTForBacktrace(Node node, List<Node> activeNodes, int indentation) {
for (int n = 0; n < indentation; n++) {
System.err.print(" ");
}

if (activeNodes.contains(node)) {
System.err.print("-> ");
} else {
System.err.print(" ");
}

System.err.println(node);

for (Node child : node.getChildren()) {
if (child != null) {
printASTForBacktrace(child, activeNodes, indentation + 1);
}
}
}

}
4 changes: 1 addition & 3 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
@@ -129,9 +129,7 @@ public class Options {
public static final Option<Boolean> TRUFFLE_LOAD_CORE = bool(TRUFFLE, "truffle.load_core", true, "Load the Truffle core library.");
public static final Option<Boolean> TRUFFLE_PRINT_RUNTIME = bool(TRUFFLE, "truffle.printRuntime", false, "Print the name of the Truffle runtime on startup.");
public static final Option<Boolean> TRUFFLE_RUNTIME_VERSION_CHECK = bool(TRUFFLE, "truffle.runtime.version_check", true, "Check the version of Truffle supplied by the JVM before starting.");
public static final Option<Boolean> TRUFFLE_TRACE = bool(TRUFFLE, "truffle.trace", true, "Install trace probes needed for set_trace_func.");
public static final Option<Boolean> TRUFFLE_OBJECTSPACE = bool(TRUFFLE, "truffle.object_space", true, "Install safepoints needed for ObjectSpace.");
public static final Option<Boolean> TRUFFLE_PROC_BINDING = bool(TRUFFLE, "truffle.proc.binding", true, "Implements Proc#binding.");
public static final Option<Boolean> TRUFFLE_PROC_BINDING = bool(TRUFFLE, "truffle.proc.binding", true, "Enable Proc#binding.");
public static final Option<Boolean> TRUFFLE_EXCEPTIONS_PRINT_JAVA = bool(TRUFFLE, "truffle.exceptions.print_java", false, "Print Java exceptions at the point of translating them to Ruby exceptions.");
public static final Option<Integer> TRUFFLE_ARRAYS_UNINITIALIZED_SIZE = integer(TRUFFLE, "truffle.arrays.uninitialized_size", 32, "How large an array to allocate when we have no other information to go on.");
public static final Option<Boolean> TRUFFLE_ARRAYS_OPTIMISTIC_LONG = bool(TRUFFLE, "truffle.arrays.optimistic.long", true, "If we allocate an int[] for an Array and it has been converted to a long[], directly allocate a long[] next time.");
2,133 changes: 0 additions & 2,133 deletions jruby/core/src/main/java/org/jruby/java/addons/ClassJavaAddons.java

This file was deleted.

0 comments on commit 58bd0ec

Please sign in to comment.