From b4094a8acf9f7b41085f5c3aa0d548638ea8cb48 Mon Sep 17 00:00:00 2001 From: Alex Vong Date: Tue, 22 Dec 2015 01:06:33 +0800 Subject: [PATCH] fix gcj build --- build.xml | 29 ++++++++++++++++++++++------- src/jvm/clojure/lang/Compiler.java | 26 +++++++++++++------------- src/jvm/clojure/lang/Numbers.java | 35 ++++++++++++++++++++++++----------- src/jvm/clojure/lang/Ratio.java | 22 ++++++++++++++++++++-- 4 files changed, 79 insertions(+), 33 deletions(-) diff --git a/build.xml b/build.xml index cae30b2..2427d68 100644 --- a/build.xml +++ b/build.xml @@ -40,8 +40,10 @@ + includeAntRuntime="false" compiler="gcj" + debug="true" source="1.6" target="1.6"> + + + @@ -88,13 +92,18 @@ description="Compile the subset of tests that require compilation." unless="maven.test.skip"> - + + + Direct linking = ${directlinking} + jvm="gij" + fork="true"> + @@ -110,7 +119,10 @@ description="Run clojure tests without recompiling clojure." depends="compile-tests" unless="maven.test.skip"> - + + @@ -129,7 +141,10 @@ description="Run test generative tests without recompiling clojure." depends="compile-tests" unless="maven.test.skip"> - + + diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java index 6066825..d40099b 100644 --- a/src/jvm/clojure/lang/Compiler.java +++ b/src/jvm/clojure/lang/Compiler.java @@ -5347,19 +5347,19 @@ public static class FnMethod extends ObjMethod{ registerLocal(p, null, new MethodParamExpr(pc), true) : registerLocal(p, state == PSTATE.REST ? ISEQ : tagOf(p), null, true); argLocals = argLocals.cons(lb); - switch(state) - { - case REQ: - method.reqParms = method.reqParms.cons(lb); - break; - case REST: - method.restParm = lb; - state = PSTATE.DONE; - break; - - default: - throw Util.runtimeException("Unexpected parameter"); - } + if (state == PSTATE.REQ) + { + method.reqParms = method.reqParms.cons(lb); + } + else if (state == PSTATE.REST) + { + method.restParm = lb; + state = PSTATE.DONE; + } + else + { + throw Util.runtimeException("Unexpected parameter"); + } } } if(method.reqParms.count() > MAX_POSITIONAL_ARITY) diff --git a/src/jvm/clojure/lang/Numbers.java b/src/jvm/clojure/lang/Numbers.java index 623743b..9b828de 100644 --- a/src/jvm/clojure/lang/Numbers.java +++ b/src/jvm/clojure/lang/Numbers.java @@ -15,6 +15,7 @@ package clojure.lang; import java.math.BigInteger; import java.math.BigDecimal; import java.math.MathContext; +import java.math.RoundingMode; public class Numbers{ @@ -941,23 +942,35 @@ final static class BigDecimalOps extends OpsP{ public Number divide(Number x, Number y){ MathContext mc = (MathContext) MATH_CONTEXT.deref(); - return mc == null - ? toBigDecimal(x).divide(toBigDecimal(y)) - : toBigDecimal(x).divide(toBigDecimal(y), mc); + RoundingMode mode = mc.getRoundingMode(); + int vals[] = + { + BigDecimal.ROUND_UP, + BigDecimal.ROUND_DOWN, + BigDecimal.ROUND_CEILING, + BigDecimal.ROUND_FLOOR, + BigDecimal.ROUND_HALF_UP, + BigDecimal.ROUND_HALF_DOWN, + BigDecimal.ROUND_HALF_EVEN, + BigDecimal.ROUND_UNNECESSARY + }; + int i; + + for (i = 0; i < vals.length; ++i) + if (mode == RoundingMode.valueOf(vals[i])) + return mc == null + ? toBigDecimal(x).divide(toBigDecimal(y)) + : toBigDecimal(x).divide(toBigDecimal(y), vals[i]); + + throw new IllegalArgumentException("invalid rounding mode"); } public Number quotient(Number x, Number y){ - MathContext mc = (MathContext) MATH_CONTEXT.deref(); - return mc == null - ? toBigDecimal(x).divideToIntegralValue(toBigDecimal(y)) - : toBigDecimal(x).divideToIntegralValue(toBigDecimal(y), mc); + return toBigDecimal(x).divideToIntegralValue(toBigDecimal(y)); } public Number remainder(Number x, Number y){ - MathContext mc = (MathContext) MATH_CONTEXT.deref(); - return mc == null - ? toBigDecimal(x).remainder(toBigDecimal(y)) - : toBigDecimal(x).remainder(toBigDecimal(y), mc); + return toBigDecimal(x).remainder(toBigDecimal(y)); } public boolean equiv(Number x, Number y){ diff --git a/src/jvm/clojure/lang/Ratio.java b/src/jvm/clojure/lang/Ratio.java index 6c7a9bb..c7d2ff5 100644 --- a/src/jvm/clojure/lang/Ratio.java +++ b/src/jvm/clojure/lang/Ratio.java @@ -15,6 +15,7 @@ package clojure.lang; import java.math.BigInteger; import java.math.BigDecimal; import java.math.MathContext; +import java.math.RoundingMode; public class Ratio extends Number implements Comparable{ final public BigInteger numerator; @@ -63,8 +64,25 @@ public BigDecimal decimalValue(){ public BigDecimal decimalValue(MathContext mc){ BigDecimal numerator = new BigDecimal(this.numerator); BigDecimal denominator = new BigDecimal(this.denominator); - - return numerator.divide(denominator, mc); + RoundingMode mode = mc.getRoundingMode(); + int vals[] = + { + BigDecimal.ROUND_UP, + BigDecimal.ROUND_DOWN, + BigDecimal.ROUND_CEILING, + BigDecimal.ROUND_FLOOR, + BigDecimal.ROUND_HALF_UP, + BigDecimal.ROUND_HALF_DOWN, + BigDecimal.ROUND_HALF_EVEN, + BigDecimal.ROUND_UNNECESSARY + }; + int i; + + for (i = 0; i < vals.length; ++i) + if (mode == RoundingMode.valueOf(vals[i])) + return numerator.divide(denominator, vals[i]); + + throw new IllegalArgumentException("invalid rounding mode"); } public BigInteger bigIntegerValue(){ -- 2.6.3