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: 816e3e2190bb
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 14226fded5dd
Choose a head ref
  • 2 commits
  • 9 files changed
  • 2 contributors

Commits on Oct 30, 2014

  1. 1
    Copy the full SHA
    305e224 View commit details
  2. Copy the full SHA
    14226fd View commit details
10 changes: 8 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
@@ -41,4 +43,8 @@ public NodeType getNodeType() {
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();
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -2997,7 +2997,7 @@ public Operand buildPreExe(PreExeNode preExeNode, IRScope s) {
}

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

public Operand buildRedo(Node node, IRScope s) {
12 changes: 9 additions & 3 deletions core/src/main/java/org/jruby/ir/operands/Rational.java
Original file line number Diff line number Diff line change
@@ -7,17 +7,19 @@
* Literal Rational number.
*/
public class Rational extends ImmutableLiteral {
private long numerator;
private final long numerator;
private final long denominator;

public Rational(long numerator) {
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, 1);
return context.runtime.newRational(numerator, denominator);
}

@Override
@@ -33,4 +35,8 @@ public void visit(IRVisitor visitor) {
public double getNumerator() {
return numerator;
}

public double getDenominator() {
return denominator;
}
}
23 changes: 19 additions & 4 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) {
@@ -2513,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;
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;
2,133 changes: 0 additions & 2,133 deletions jruby/core/src/main/java/org/jruby/java/addons/ClassJavaAddons.java

This file was deleted.