SmallInteger.st
branchjv
changeset 18237 8457ae63fa44
parent 18120 e3a375d5f6a8
parent 18236 f5b870afebf4
child 18261 22bdfc405bca
--- a/SmallInteger.st	Sat Apr 18 06:57:35 2015 +0200
+++ b/SmallInteger.st	Mon Apr 20 06:40:26 2015 +0200
@@ -114,10 +114,16 @@
      For very special uses only - not constant across implementations"
 
 %{  /* NOCONTEXT */
+#ifdef __JAVA__
+    // longs are always 64bits
+    return context._RETURN ( STInteger._new(64) );
+#else
     RETURN ( __mkSmallInteger(N_INT_BITS) );
+#endif
 %}
-
-    "SmallInteger maxBits"
+    "
+     SmallInteger maxBits
+    "
 !
 
 maxBytes
@@ -125,9 +131,13 @@
      For very special uses only - not constant across implementations"
 
 %{  /* NOCONTEXT */
+#ifdef __JAVA__
+    // longs are always 8 bytes
+    return context._RETURN ( STInteger._new(8) );
+#else
     RETURN ( __mkSmallInteger(N_INT_BITS / 8 + 1) );
+#endif
 %}
-
     "
      SmallInteger maxBytes
     "
@@ -138,10 +148,15 @@
      For very special uses only - not constant across implementations"
 
 %{  /* NOCONTEXT */
+#ifdef __JAVA__
+    return context._RETURN ( STInteger._MAX_INTVAL );
+#else
     RETURN ( __mkSmallInteger(_MAX_INT) );
+#endif
 %}
-
-    "SmallInteger maxVal"
+    "
+     SmallInteger maxVal
+    "
 !
 
 minVal
@@ -149,10 +164,15 @@
      For very special uses only - not constant across implementations"
 
 %{  /* NOCONTEXT */
+#ifdef __JAVA__
+    return context._RETURN ( STInteger._MIN_INTVAL );
+#else
     RETURN ( __mkSmallInteger(_MIN_INT) );
+#endif
 %}
-
-    "SmallInteger minVal"
+    "
+     SmallInteger minVal
+    "
 ! !
 
 !SmallInteger class methodsFor:'queries'!
@@ -193,7 +213,9 @@
     "return the product of the receiver and the argument"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.times( aNumber ));
+#else
     /*
      * notice:
      * the following inline code handles some common cases,
@@ -220,25 +242,25 @@
      * (took me a while to find this out :-(
      * (try 10000 * 10000)
      */
-#if defined(__sparc__) && defined(__GNUC__) && (__GNUC__ >= 2)
-# define USE_LONGLONG_FOR_MUL
-#endif
-
-#if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 2)
-# define USE_LONGLONG_FOR_MUL
-#endif
+# if defined(__sparc__) && defined(__GNUC__) && (__GNUC__ >= 2)
+#  define USE_LONGLONG_FOR_MUL
+# endif
+
+# if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 2)
+#  define USE_LONGLONG_FOR_MUL
+# endif
 
     if (__isSmallInteger(aNumber)) {
 	myValue = __intVal(self);
 	otherValue = __intVal(aNumber);
 
-#if defined(USE_LONGLONG_FOR_MUL)
+# if defined(USE_LONGLONG_FOR_MUL)
 	{
-# if defined(__alpha__) && !defined(__alpha64__)
-#  define LONGLONG      INT64
-# else
-#  define LONGLONG      long long
-# endif
+#  if defined(__alpha__) && !defined(__alpha64__)
+#   define LONGLONG      INT64
+#  else
+#   define LONGLONG      long long
+#  endif
 	    LONGLONG product;
 
 	    product = (LONGLONG)myValue * (LONGLONG)otherValue;
@@ -255,7 +277,7 @@
 	    productHi = product >> 32;
 	    productLow = product & 0xFFFFFFFFL;
 	}
-#else /* no long-long */
+# else /* no long-long */
 	negative = 1;
 	if (myValue < 0) {
 	    negative = -1;
@@ -266,21 +288,21 @@
 	    otherValue = -otherValue;
 	}
 
-# if defined(__GNUC__) && defined(__mc68k__)
+#  if defined(__GNUC__) && defined(__mc68k__)
 	asm ("mulu%.l %3,%1:%0"
 		: "=d"  ((unsigned long)(productLow)),
 		  "=d"  ((unsigned long)(productHi))
 		: "%0"  ((unsigned long)(myValue)),
 		  "dmi" ((unsigned long)(otherValue)));
-# else
-#  if defined (__GNUC__) && defined(__i386__)
+#  else
+#   if defined (__GNUC__) && defined(__i386__)
 	asm ("mull %3"
 		: "=a"  ((unsigned long)(productLow)),
 		  "=d"  ((unsigned long)(productHi))
 		: "%0"  ((unsigned long)(myValue)),
 		  "rm"  ((unsigned long)(otherValue)));
-#  else
-#   if defined(WIN32) && defined(__BORLANDC__)
+#   else
+#    if defined(WIN32) && defined(__BORLANDC__)
 	asm {
 	    mov   eax, myValue
 	    mov   edx, otherValue
@@ -288,7 +310,7 @@
 	    mov   productLow, eax
 	    mov   productHi, edx
 	}
-#   else /* generic */
+#    else /* generic */
 	{
 	    unsigned INT pHH, pHL, pLH, pLL;
 	    unsigned INT low1, low2, hi1, hi2;
@@ -301,19 +323,19 @@
 	     * (or at least 32*32 with Overflow check)
 	     * - need more assembler (inline) functions here
 	     */
-#    if __POINTER_SIZE__ == 8
+#     if __POINTER_SIZE__ == 8
 	    low1 = low32Bits((unsigned INT)myValue);
 	    hi1 = hi32Bits((unsigned INT)myValue);
 	    low2 = low32Bits((unsigned INT)otherValue);
 	    hi2 = hi32Bits((unsigned INT)otherValue);
-#     define LLMASK 0xC000000000000000L
-#    else
+#      define LLMASK 0xC000000000000000L
+#     else
 	    low1 = low16Bits((unsigned INT)myValue);
 	    hi1 = hi16Bits((unsigned INT)myValue);
 	    low2 = low16Bits((unsigned INT)otherValue);
 	    hi2 = hi16Bits((unsigned INT)otherValue);
-#     define LLMASK 0xC0000000
-#    endif
+#      define LLMASK 0xC0000000
+#     endif
 
 	    pLH = low1 * hi2;
 	    pHL = hi1 * low2;
@@ -340,19 +362,19 @@
 	     *   pLL                   |--------|--------|
 	     */
 
-#    if __POINTER_SIZE__ == 8
+#     if __POINTER_SIZE__ == 8
 	    t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL);
 	    productLow = (t << 32) + low32Bits(pLL);
 	    productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH);
-#    else
+#     else
 	    t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL);
 	    productLow = (t << 16) + low16Bits(pLL);
 	    productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH);
-#    endif
+#     endif
 	}
-#   endif /* ! WIN32 */
-#  endif /* ! (__GNUC__ && __i386__) */
-# endif /* ! (__GNUC__ && __mc68k__) */
+#    endif /* ! WIN32 */
+#   endif /* ! (__GNUC__ && __i386__) */
+#  endif /* ! (__GNUC__ && __mc68k__) */
 
 	if (productHi == 0) {
 	    if (negative < 0) {
@@ -365,13 +387,13 @@
 		}
 	    }
 	}
-#endif /* ! USE_LONGLONG */
-
-#if __POINTER_SIZE__ == 8
+# endif /* ! USE_LONGLONG */
+
+# if __POINTER_SIZE__ == 8
 	RETURN (__MKLARGEINT128(negative, productLow, productHi));
-#else
+# else
 	RETURN (__MKLARGEINT64(negative, productLow, productHi));
-#endif
+# endif
     } else if (__isFloatLike(aNumber)) {
 	OBJ newFloat;
 	double val = (double)__intVal(self) * __floatVal(aNumber);
@@ -385,6 +407,7 @@
 	__qMKSFLOAT(newFloat, val);
 	RETURN ( newFloat );
     }
+#endif /* not JAVA */
 %}.
     ^ aNumber productFromInteger:self
 !
@@ -393,7 +416,9 @@
     "return the sum of the receivers value and the arguments value"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.plus( aNumber ));
+#else
     /*
      * notice:
      * the following inline code handles some common cases,
@@ -405,9 +430,9 @@
      */
 
     if (__isSmallInteger(aNumber)) {
-#ifdef _ADD_IO_IO
+# ifdef _ADD_IO_IO
 	RETURN ( _ADD_IO_IO(self, aNumber) );
-#else
+# else
 	REGISTER INT sum;
 
 	sum =  __intVal(self) + __intVal(aNumber);
@@ -415,7 +440,7 @@
 	    RETURN ( __mkSmallInteger(sum) );
 	}
 	RETURN ( __MKLARGEINT(sum) );
-#endif
+# endif
     }
     if (__isFloatLike(aNumber)) {
 	OBJ newFloat;
@@ -431,6 +456,7 @@
 	__qMKSFLOAT(newFloat, val);
 	RETURN ( newFloat );
     }
+#endif /* not JAVA */
 %}.
     ^ aNumber sumFromInteger:self
 !
@@ -439,7 +465,9 @@
     "return the difference of the receivers value and the arguments value"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.minus( aNumber ));
+#else
     /*
      * notice:
      * the following inline code handles some common cases,
@@ -451,9 +479,9 @@
      */
 
     if (__isSmallInteger(aNumber)) {
-#ifdef _SUB_IO_IO
+# ifdef _SUB_IO_IO
 	RETURN ( _SUB_IO_IO(self, aNumber) );
-#else
+# else
 	REGISTER INT diff;
 
 	diff =  __intVal(self) - __intVal(aNumber);
@@ -461,7 +489,7 @@
 	    RETURN ( __mkSmallInteger(diff) );
 	}
 	RETURN ( __MKLARGEINT(diff) );
-#endif
+# endif
     }
     if (__isFloatLike(aNumber)) {
 	OBJ newFloat;
@@ -477,6 +505,7 @@
 	__qMKSFLOAT(newFloat, val);
 	RETURN ( newFloat );
     }
+#endif /* not JAVA */
 %}.
     ^ aNumber differenceFromInteger:self
 !
@@ -485,6 +514,9 @@
     "return the quotient of the receivers value and the arguments value"
 
 %{  /* NOCONTEXT */
+#ifdef __JAVA__
+    return context._RETURN( self.quotient( aNumber ));
+#else
 
     /*
      * notice:
@@ -504,9 +536,9 @@
 	if (val != 0) {
 	    me = __intVal(self);
 	    t = me / val;
-#ifdef GOOD_OPTIMIZER
+# ifdef GOOD_OPTIMIZER
 	    if (me % val == 0) {
-#else
+# else
 	    /* this is stupid - all I want is to look for a remainder ...
 	       but most compilers are too stupid and generate an extra modulus
 	       instruction for "if (me % val)".
@@ -516,7 +548,7 @@
 	       on most machines. Hint to GNU people :-)
 	    */
 	    if ((t * val) == me) {
-#endif
+# endif
 		RETURN ( __mkSmallInteger(t) );
 	    }
 	}
@@ -532,6 +564,7 @@
 	    }
 	}
     }
+#endif /* not JAVA */
 %}.
     aNumber isInteger ifTrue:[
 	aNumber == 0 ifTrue:[
@@ -556,21 +589,23 @@
 
 // aNumber
     "return the integer part of the quotient of the receivers value
-     and the arguments value. 
+     and the arguments value.
      The result is truncated toward negative infinity
      and will be negative, if the operands signs differ.
      The following is always true:
-        (receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
+	(receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
 
      Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
-     Especially surprising:     
-        -1 // 10 -> -1 (because -(1/10) is truncated towards next smaller integer, which is -1.
-        -10 // 3 -> -4 (because -(10/3) is truncated towards next smaller integer, which is -4.
+     Especially surprising:
+	-1 // 10 -> -1 (because -(1/10) is truncated towards next smaller integer, which is -1.
+	-10 // 3 -> -4 (because -(10/3) is truncated towards next smaller integer, which is -4.
 
      See #quo: which returns -2 in the above case and #rem: which is the corresponding remainder."
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.quotientTruncated( aNumber ));
+#else
     /*
      * notice:
      * the following inline code handles some common cases,
@@ -584,59 +619,60 @@
     INT dividend, divisor, rslt;
 
     if (__isSmallInteger(aNumber)) {
-        divisor = __intVal(aNumber);
-        if (divisor != 0) {
-            dividend = __intVal(self);
-            rslt = dividend / divisor;
-            /*
-             * Optimized to speed up positive result
-             */
-            if (rslt <= 0) {
-                if (rslt == 0) {
-                    if ((dividend ^ divisor) < 0) {
-                        /*
-                         * result (negative) has been truncated toward 0.
-                         * Return -1, because we truncate toward negative inf.
-                         */
-                         rslt = -1;
-                    }
-                } else {
-                    /*
-                     * If result (negative) has been truncated toward 0,
-                     * subtract 1, because we truncate toward negative inf.
-                     */
-                    if (divisor > 0) {
-                        if (rslt * divisor > dividend) {
-                            rslt--;
-                        }
-                    } else {
-                        if (rslt * divisor < dividend) {
-                            rslt--;
-                        }
-                    }
-                }
-            }
-            RETURN ( __mkSmallInteger(rslt) );
-        }
+	divisor = __intVal(aNumber);
+	if (divisor != 0) {
+	    dividend = __intVal(self);
+	    rslt = dividend / divisor;
+	    /*
+	     * Optimized to speed up positive result
+	     */
+	    if (rslt <= 0) {
+		if (rslt == 0) {
+		    if ((dividend ^ divisor) < 0) {
+			/*
+			 * result (negative) has been truncated toward 0.
+			 * Return -1, because we truncate toward negative inf.
+			 */
+			 rslt = -1;
+		    }
+		} else {
+		    /*
+		     * If result (negative) has been truncated toward 0,
+		     * subtract 1, because we truncate toward negative inf.
+		     */
+		    if (divisor > 0) {
+			if (rslt * divisor > dividend) {
+			    rslt--;
+			}
+		    } else {
+			if (rslt * divisor < dividend) {
+			    rslt--;
+			}
+		    }
+		}
+	    }
+	    RETURN ( __mkSmallInteger(rslt) );
+	}
     } else {
-        if (__isFraction(aNumber)) {
-            OBJ t;
-            INT num, den;
-
-            t = __FractionInstPtr(aNumber)->f_numerator;
-            if (__isSmallInteger(t)) {
-                num = __intVal(t);
-                t = __FractionInstPtr(aNumber)->f_denominator;
-                if (__isSmallInteger(t)) {
-                    den = __intVal(t);
-                    RETURN ( __mkSmallInteger(__intVal(self) * den / num ));
-                }
-            }
-        }
+	if (__isFraction(aNumber)) {
+	    OBJ t;
+	    INT num, den;
+
+	    t = __FractionInstPtr(aNumber)->f_numerator;
+	    if (__isSmallInteger(t)) {
+		num = __intVal(t);
+		t = __FractionInstPtr(aNumber)->f_denominator;
+		if (__isSmallInteger(t)) {
+		    den = __intVal(t);
+		    RETURN ( __mkSmallInteger(__intVal(self) * den / num ));
+		}
+	    }
+	}
     }
+#endif /* not JAVA */
 %}.
     (aNumber = 0) ifTrue:[
-        ^ ZeroDivide raiseRequestWith:thisContext.
+	^ ZeroDivide raiseRequestWith:thisContext.
     ].
     ^ aNumber integerQuotientFromInteger:self
 
@@ -662,26 +698,28 @@
 
 \\ aNumber
     "Answer the integer remainder m defined by division with truncation toward
-     negative infinity. 
+     negative infinity.
      m < |aNumber| AND there is an integer k with (k * aNumber + m) = self
 
      The returned remainder has the same sign as aNumber.
      The following is always true:
-        (receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
+	(receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
 
      Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
-     Especially surprising:     
-        -1 \\ 10 -> 9  (because -(1/10) is truncated towards next smaller integer, which is -1,
-                        and -1 multiplied by 10 gives -10, so we have to add 9 to get the original -1).
-        -10 \\ 3 -> 2 (because -(10/3) is truncated towards next smaller integer, which is -4,
-                        and -4 * 4 gives -12, so we need to add 2 to get the original -10.
+     Especially surprising:
+	-1 \\ 10 -> 9  (because -(1/10) is truncated towards next smaller integer, which is -1,
+			and -1 multiplied by 10 gives -10, so we have to add 9 to get the original -1).
+	-10 \\ 3 -> 2 (because -(10/3) is truncated towards next smaller integer, which is -4,
+			and -4 * 4 gives -12, so we need to add 2 to get the original -10.
 
      See #rem: which is the corresponding remainder for division via #quo:.
 
      Redefined here for speed."
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.remainder( aNumber ));
+#else
     /*
      * notice:
      * the following inline code handles some common cases,
@@ -695,32 +733,33 @@
     INT dividend, divisor, rem;
 
     if (__isSmallInteger(aNumber)
-        && (divisor = __intVal(aNumber)) != 0) {
-        /*
-         * Note that the sign of something modulo a negative number is undefined
-         * in C!
-         */
-        dividend = __intVal(self);
-        rem = dividend % divisor;
-        if (rem) {
-            if ((rem ^ divisor) < 0) {
-                /* sign of remainder is different from sign of divisor */
-                rem = -rem;
-            }
-            if ((dividend ^ divisor) < 0) {
-                /* different signs, so division would have returned a
-                 * negative number.
-                 * C rounds toward zero, this code will simulate
-                 * rounding towards negative infinity.
-                 */
-                rem = divisor - rem;
-            }
-        }
-        RETURN ( __mkSmallInteger(rem) );
+	&& (divisor = __intVal(aNumber)) != 0) {
+	/*
+	 * Note that the sign of something modulo a negative number is undefined
+	 * in C!
+	 */
+	dividend = __intVal(self);
+	rem = dividend % divisor;
+	if (rem) {
+	    if ((rem ^ divisor) < 0) {
+		/* sign of remainder is different from sign of divisor */
+		rem = -rem;
+	    }
+	    if ((dividend ^ divisor) < 0) {
+		/* different signs, so division would have returned a
+		 * negative number.
+		 * C rounds toward zero, this code will simulate
+		 * rounding towards negative infinity.
+		 */
+		rem = divisor - rem;
+	    }
+	}
+	RETURN ( __mkSmallInteger(rem) );
     }
+#endif /* not JAVA */
 %}.
     (aNumber = 0) ifTrue:[
-        ^ ZeroDivide raiseRequestWith:thisContext.
+	^ ZeroDivide raiseRequestWith:thisContext.
     ].
     ^ aNumber moduloFromInteger:self
 
@@ -742,7 +781,9 @@
      reimplemented here for speed"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.abs());
+#else
     INT val = __intVal(self);
 
     if (val >= 0) {
@@ -753,6 +794,7 @@
     }
     /* only reached for minVal */
     RETURN( __MKLARGEINT(-_MIN_INT));
+#endif
 %}.
     ^ super abs
 !
@@ -762,7 +804,9 @@
      reimplemented here for speed"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.negated());
+#else
     INT val = __intVal(self);
 
     if (val != _MIN_INT) {
@@ -770,6 +814,7 @@
     }
     /* only reached for minVal */
     RETURN (__MKLARGEINT( -_MIN_INT));
+#endif
 %}.
     ^ 0 - self
 "/    "only reached for minVal"
@@ -788,6 +833,9 @@
      in contrast: '9 quo: 4 = 2' and '-9 quo: 4 = -2'"
 
 %{  /* NOCONTEXT */
+#ifdef __JAVA__
+    return context._RETURN( self.quotient(aNumber));
+#else
     INT val;
 
     if (__isSmallInteger(aNumber)) {
@@ -811,6 +859,7 @@
 	    }
 	}
     }
+#endif /* not JAVA */
 %}.
     (aNumber = 0) ifTrue:[
 	^ ZeroDivide raiseRequestWith:thisContext.
@@ -832,11 +881,14 @@
     "return the bitwise-and of the receiver and the argument, anInteger"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.bitAnd(anInteger));
+#else
     /* anding the tags doesn't change it */
     if (__isSmallInteger(anInteger)) {
 	RETURN ( ((OBJ) ((INT)self & (INT)anInteger)) );
     }
+#endif /* not JAVA */
 %}.
     anInteger class == LargeInteger ifTrue:[
 	^ anInteger bitAnd:self
@@ -849,25 +901,28 @@
 bitAt:anIntegerIndex
     "return the value of the index's bit (index starts at 1) as 0 or 1.
      Notice: the result of bitAt: on negative receivers is not
-             defined in the language standard (since the implementation
-             is free to choose any internal representation for integers)"
+	     defined in the language standard (since the implementation
+	     is free to choose any internal representation for integers)"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.bitAt(anIntegerIndex));
+#else
     if (__isSmallInteger(anIntegerIndex)) {
-        INT idx = __smallIntegerVal(anIntegerIndex);
-        if (idx > 0) {
-            if (idx > N_INT_BITS) {
-                RETURN(__mkSmallInteger(0));
-            }
-            RETURN((__smallIntegerVal(self) & (1 << (idx-1))) ? __mkSmallInteger(1) : __mkSmallInteger(0));
-        }
+	INT idx = __smallIntegerVal(anIntegerIndex);
+	if (idx > 0) {
+	    if (idx > N_INT_BITS) {
+		RETURN(__mkSmallInteger(0));
+	    }
+	    RETURN((__smallIntegerVal(self) & (1 << (idx-1))) ? __mkSmallInteger(1) : __mkSmallInteger(0));
+	}
     }
+#endif /* not JAVA */
 %}.
 
     ^ SubscriptOutOfBoundsError
-            raiseRequestWith:anIntegerIndex
-            errorString:'index out of bounds'
+	    raiseRequestWith:anIntegerIndex
+	    errorString:'index out of bounds'
 
     "
      16r00000001 bitAt:0
@@ -887,9 +942,9 @@
     |mask|
 
     anIntegerIndex <= 0 ifTrue:[
-        ^ SubscriptOutOfBoundsSignal
-                raiseRequestWith:anIntegerIndex
-                errorString:'index out of bounds'
+	^ SubscriptOutOfBoundsSignal
+		raiseRequestWith:anIntegerIndex
+		errorString:'index out of bounds'
     ].
     (anIntegerIndex > SmallInteger maxBits) ifTrue:[^ 0].
     mask := 1 bitShift:(anIntegerIndex - 1).
@@ -903,11 +958,14 @@
      returning the receiver with bits of the argument cleared."
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.bitClear(anInteger));
+#else
     /* anding the tags doesn't change it */
     if (__isSmallInteger(anInteger)) {
 	RETURN ( ((OBJ) (((INT)self & ~(INT)anInteger) | TAG_INT)) );
     }
+#endif /* not JAVA */
 %}.
     ^ self retry:#bitClear: coercing:anInteger
 
@@ -921,6 +979,7 @@
     "return the number of 1-bits in the receiver"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
     unsigned int _cnt;
     unsigned INT _self = __intVal(self);
 
@@ -931,8 +990,8 @@
 
     _cnt = 0;
     while (_self) {
-        _cnt++;
-        _self = _self & (_self - 1);
+	_cnt++;
+	_self = _self & (_self - 1);
     }
 # else
 #  ifdef ALGORITHM_2
@@ -942,8 +1001,8 @@
 
     _cnt = 0;
     while (_self) {
-        _cnt += table[ _self & 0x0F ];
-        _self >>= 4;
+	_cnt += table[ _self & 0x0F ];
+	_self >>= 4;
     }
 #  else
 #   ifdef ALGORIHTM_3
@@ -975,30 +1034,32 @@
 # endif
 
     RETURN ( __MKSMALLINT(_cnt));
-%}
+#endif /* not JAVA */
+%}.
+    ^ super bitCount.
 
     "
 
      1 to:1000000 do:[:n |
-        self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1))
+	self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1))
      ].
 
      #(
-        16r00010000 16r00100000 16r01000000 16r10000000
-        16r00020000 16r00200000 16r02000000 16r20000000
-        16r00040000 16r00400000 16r04000000 16r40000000
-        16r00080000 16r00800000 16r08000000 16r80000000
-
-        16rFFFFFFFF 16r7FFFFFFF 16r3FFFFFFF 16r1FFFFFFF
-        16rEEEEEEEE 16r7EEEEEEE 16r3EEEEEEE 16r1EEEEEEE
-        16rDDDDDDDD 16r7DDDDDDD 16r3DDDDDDD 16r1DDDDDDD
-        16rCCCCCCCC 16r7CCCCCCC 16r3CCCCCCC 16r1CCCCCCC
+	16r00010000 16r00100000 16r01000000 16r10000000
+	16r00020000 16r00200000 16r02000000 16r20000000
+	16r00040000 16r00400000 16r04000000 16r40000000
+	16r00080000 16r00800000 16r08000000 16r80000000
+
+	16rFFFFFFFF 16r7FFFFFFF 16r3FFFFFFF 16r1FFFFFFF
+	16rEEEEEEEE 16r7EEEEEEE 16r3EEEEEEE 16r1EEEEEEE
+	16rDDDDDDDD 16r7DDDDDDD 16r3DDDDDDD 16r1DDDDDDD
+	16rCCCCCCCC 16r7CCCCCCC 16r3CCCCCCC 16r1CCCCCCC
      ) do:[:n |
-        self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1))
+	self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1))
      ]
 
      1 to:10000000 do:[:n |
-        (n bitCount)
+	(n bitCount)
      ]
     "
 
@@ -1009,22 +1070,27 @@
     "return the value of the receiver with all bits inverted"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+#else
     /* invert anything except tag bits */
     RETURN ( ((OBJ) ((INT)self ^ ~TAG_MASK)) );
+#endif
 %}.
-    ^ self primitiveFailed
+    ^ super bitInvert
 !
 
 bitOr:anInteger
     "return the bitwise-or of the receiver and the argument, anInteger"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.bitOr( anInteger ));
+#else
     /* oring the tags doesn't change it */
     if (__isSmallInteger(anInteger)) {
 	RETURN ( ((OBJ) ((INT)self | (INT)anInteger)) );
     }
+#endif
 %}.
     ^ self retry:#bitOr: coercing:anInteger
 
@@ -1040,76 +1106,79 @@
     "return the value of the receiver shifted by shiftCount bits;
      leftShift if shiftCount > 0; rightShift otherwise.
      Notice: the result of bitShift: on negative receivers is not
-             defined in the language standard (since the implementation
-             is free to choose any internal representation for integers).
-             However, ST/X preserves the sign."
+	     defined in the language standard (since the implementation
+	     is free to choose any internal representation for integers).
+	     However, ST/X preserves the sign."
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.bitShift( shiftCount ));
+#else
     INT bits, count;
 
     if (__isSmallInteger(shiftCount)) {
-        bits = __intVal(self);
-        if (bits == 0) {
-            RETURN (self);
-        }
-
-        count = __intVal(shiftCount);
-
-        if (count > 0) {
-            /*
-             * a left shift
-             */
-#if defined(USE_LONGLONG_FOR_SHIFT)
-            if (count <= N_INT_BITS) {
-                unsigned LONGLONG result;
-
-                result = (unsigned LONGLONG)bits;
-                result <<= count;
-                if (result <= _MAX_INT) {
-                    RETURN ( __mkSmallInteger(result) );
-                }
-                {
-                    RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
-                }
-            }
-#else
-            /*
-             * check for overflow
-             */
-            if (count < (N_INT_BITS-1)) {
-                if (! (bits >> (N_INT_BITS - 1 - count))) {
-                    RETURN ( __mkSmallInteger(bits << count) );
-                }
-                /*
-                 * so, there is an overflow ...
-                 * handle it as largeInteger
-                 */
-                /* FALL THROUGH */
-            }
-#endif
-        } else {
-            if (count == 0) {
-                RETURN (self);
-            }
-
-            /*
-             * right shifts cannot overflow
-             *
-             * some machines ignore shifts bigger than
-             * the number of bits in an int ...
-             */
-            count = -count;
-            if (count > (N_INT_BITS-1)) {
-                RETURN (__mkSmallInteger(0));
-            }
-
-            RETURN ( __mkSmallInteger(bits >> count) );
-        }
+	bits = __intVal(self);
+	if (bits == 0) {
+	    RETURN (self);
+	}
+
+	count = __intVal(shiftCount);
+
+	if (count > 0) {
+	    /*
+	     * a left shift
+	     */
+# if defined(USE_LONGLONG_FOR_SHIFT)
+	    if (count <= N_INT_BITS) {
+		unsigned LONGLONG result;
+
+		result = (unsigned LONGLONG)bits;
+		result <<= count;
+		if (result <= _MAX_INT) {
+		    RETURN ( __mkSmallInteger(result) );
+		}
+		{
+		    RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
+		}
+	    }
+# else
+	    /*
+	     * check for overflow
+	     */
+	    if (count < (N_INT_BITS-1)) {
+		if (! (bits >> (N_INT_BITS - 1 - count))) {
+		    RETURN ( __mkSmallInteger(bits << count) );
+		}
+		/*
+		 * so, there is an overflow ...
+		 * handle it as largeInteger
+		 */
+		/* FALL THROUGH */
+	    }
+# endif
+	} else {
+	    if (count == 0) {
+		RETURN (self);
+	    }
+
+	    /*
+	     * right shifts cannot overflow
+	     *
+	     * some machines ignore shifts bigger than
+	     * the number of bits in an int ...
+	     */
+	    count = -count;
+	    if (count > (N_INT_BITS-1)) {
+		RETURN (__mkSmallInteger(0));
+	    }
+
+	    RETURN ( __mkSmallInteger(bits >> count) );
+	}
     }
+#endif /* not JAVA */
 %}.
     (shiftCount isMemberOf:SmallInteger) ifTrue:[
-        ^ (LargeInteger value:self) bitShift:shiftCount
+	^ (LargeInteger value:self) bitShift:shiftCount
     ].
     ^ self bitShift:shiftCount asInteger   "/ is this a good idea ?
 !
@@ -1120,11 +1189,17 @@
      is non-0, false otherwise."
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN(
+	    ( self.bitAnd( aMask ) == STInteger._0 )
+	    ? STObject.False : STObject.True );
+    /* NOTREACHED */
+#else
     /* and all bits except tag */
     if (__isSmallInteger(aMask)) {
 	RETURN ( ((INT)self & ((INT)aMask & ~TAG_MASK)) ? true : false );
     }
+#endif /* not JAVA */
 %}.
     aMask class == LargeInteger ifTrue:[
 	^ (aMask bitAnd:self) ~~ 0
@@ -1146,11 +1221,14 @@
     "return the bitwise-exclusive-or of the receiver and the argument, anInteger"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.bitXor( anInteger ));
+#else
     /* xoring the tags turns it off - or it in again */
     if (__isSmallInteger(anInteger)) {
 	RETURN ( (OBJ)( ((INT)self ^ (INT)anInteger) | TAG_INT) );
     }
+#endif /* not JAVA */
 %}.
     ^ self retry:#bitXor: coercing:anInteger
 !
@@ -1162,24 +1240,26 @@
      but a new number is returned. Should be named #withBitCleared:"
 
 %{  /* NOCONTEXT */
-
-    if (__isSmallInteger(anInteger)) {
-        int index = __intVal(anInteger);
-
-        if (index > 0) {
-#if __POINTER_SIZE__ == 8
-            if (index <= 62)
+#ifdef __JAVA__
 #else
-            if (index <= 30)
-#endif
-            {
-                INT mask = __MASKSMALLINT(1 << (index-1));
-
-                RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) );
-            }
-            RETURN (self);  /* nothing to do ... */
-        }
+    if (__isSmallInteger(anInteger)) {
+	int index = __intVal(anInteger);
+
+	if (index > 0) {
+# if __POINTER_SIZE__ == 8
+	    if (index <= 62)
+# else
+	    if (index <= 30)
+# endif
+	    {
+		INT mask = __MASKSMALLINT(1 << (index-1));
+
+		RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) );
+	    }
+	    RETURN (self);  /* nothing to do ... */
+	}
     }
+#endif /* not JAVA */
 %}.
     ^ super clearBit:anInteger
 
@@ -1207,7 +1287,36 @@
      Returns 0 if no bit is set."
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    {
+	long bits = self.longValue();
+	int bitNr = 0;
+
+	if (bits != 0) {
+	    if ((bits & 0xFFFFFFFF00000000L) != 0) {
+		bitNr += 32; bits >>= 32;
+	    }
+	    if ((bits & 0xFFFF0000L) != 0) {
+		bitNr += 16; bits >>= 16;
+	    }
+	    if ((bits & 0xFF00) != 0) {
+		bitNr += 8; bits >>= 8;
+	    }
+	    if ((bits & 0xF0) != 0) {
+		bitNr += 4; bits >>= 4;
+	    }
+	    if ((bits & 0xC) != 0) {
+		bitNr += 2; bits >>= 2;
+	    }
+	    if ((bits & 0x2) != 0) {
+		bitNr += 1; bits >>= 1;
+	    }
+	    bitNr += 1;
+	}
+	return context._RETURN( STInteger._new(bitNr) );
+    }
+    /* NOTREACHED */
+#else
     unsigned INT bits;
     int index;
 
@@ -1216,41 +1325,44 @@
 	RETURN ( __mkSmallInteger(0) );
     }
 
-#ifdef __BSR
+# ifdef __BSR
     /*
      * so much for CISC CPUS:
      * the following code is not faster on a PIII-400
      * (but saves a few code-bytes, though)
      */
     index = __BSR(bits);
-#else
+# else
 
     index = 0;
 
-# if __POINTER_SIZE__ == 8
+#  if __POINTER_SIZE__ == 8
     if (bits & 0xFFFFFFFF00000000L) {
-	index += 32; bits = bits >> 32;
+	index += 32; bits >>= 32;
     }
-# endif
+#  endif
     if (bits & 0xFFFF0000L) {
-	index += 16; bits = bits >> 16;
+	index += 16; bits >>= 16;
     }
     if (bits & 0xFF00) {
-	index += 8; bits = bits >> 8;
+	index += 8; bits >>= 8;
     }
     if (bits & 0xF0) {
-	index += 4; bits = bits >> 4;
+	index += 4; bits >>= 4;
     }
     if (bits & 0xC) {
-	index += 2; bits = bits >> 2;
+	index += 2; bits >>= 2;
     }
     if (bits & 0x2) {
-	index += 1; bits = bits >> 1;
+	index += 1; bits >>= 1;
     }
-#endif /* no BSR instruction */
+# endif /* no BSR instruction */
 
     RETURN ( __mkSmallInteger(index+1) );
-%}
+#endif /* not JAVA */
+%}.
+    ^ super highBit
+
     "
      2r0 highBit
      2r1 highBit
@@ -1311,23 +1423,25 @@
      but a new number is returned. Should be named #withBitInverted:"
 
 %{  /* NOCONTEXT */
-
-    if (__isSmallInteger(anInteger)) {
-        int index = __intVal(anInteger);
-
-        if (index > 0) {
-#if __POINTER_SIZE__ == 8
-            if (index <= 62)
+#ifdef __JAVA__
 #else
-            if (index <= 30)
-#endif
-            {
-                INT mask = __MASKSMALLINT(1 << (index-1));
-
-                RETURN ( ((OBJ) ((INT)self ^ (INT)mask)) );
-            }
-        }
+    if (__isSmallInteger(anInteger)) {
+	int index = __intVal(anInteger);
+
+	if (index > 0) {
+# if __POINTER_SIZE__ == 8
+	    if (index <= 62)
+# else
+	    if (index <= 30)
+# endif
+	    {
+		INT mask = __MASKSMALLINT(1 << (index-1));
+
+		RETURN ( ((OBJ) ((INT)self ^ (INT)mask)) );
+	    }
+	}
     }
+#endif /* not JAVA */
 %}.
     ^ super invertBit:anInteger
 
@@ -1351,7 +1465,8 @@
      Returns 0 if no bit is set."
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+#else
     unsigned INT bits;
     int index;
 
@@ -1360,7 +1475,7 @@
 	RETURN ( __mkSmallInteger(0) );
     }
 
-#ifdef __BSF
+# ifdef __BSF
     /*
      * so much for CISC CPUS:
      * the following code is only marginally faster on a PIII-400
@@ -1369,15 +1484,15 @@
      */
     index = __BSF(bits);
     RETURN ( __mkSmallInteger(index + 1) );
-#else
+# else
 
     index = 1;
 
-# if __POINTER_SIZE__ == 8
+#  if __POINTER_SIZE__ == 8
     if ((bits<<32) == 0) {
 	index += 32; bits >>= 32;
     }
-# endif
+#  endif
 
     if ((bits & 0xFFFF)==0) {
 	index += 16; bits >>= 16;
@@ -1394,10 +1509,12 @@
     if ((bits & 0x1)==0) {
 	index += 1;
     }
-#endif
+# endif
 
     RETURN ( __mkSmallInteger(index) );
-%}
+#endif /* not JAVA */
+%}.
+    ^ super lowBit
 
     "
      0 lowBit
@@ -1443,83 +1560,85 @@
     "return the value of the receiver shifted by shiftCount bits;
      right shift if shiftCount > 0; left shift  otherwise.
      Notice: the result of bitShift: on negative receivers is not
-             defined in the language standard (since the implementation
-             is free to choose any internal representation for integers).
-             However, ST/X preserves the sign."
+	     defined in the language standard (since the implementation
+	     is free to choose any internal representation for integers).
+	     However, ST/X preserves the sign."
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+#else
     INT bits, count;
 
     if (__isSmallInteger(shiftCount)) {
-        bits = __intVal(self);
-        if (bits == 0) {
-            RETURN (self);
-        }
-
-        count = __intVal(shiftCount);
-
-        if (count < 0) {
-            /*
-             * a left shift
-             */
-            count = -count;
-#if defined(USE_LONGLONG_FOR_SHIFT)
-            if (count <= N_INT_BITS) {
-                unsigned LONGLONG result;
-
-                result = (unsigned LONGLONG)bits;
-                result <<= count;
-                if (result <= _MAX_INT) {
-                    RETURN ( __mkSmallInteger(result) );
-                }
-                {
-                    RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
-                }
-            }
-#else
-            /*
-             * check for overflow
-             */
-            if (count < (N_INT_BITS-1)) {
-                if (! (bits >> (N_INT_BITS - 1 - count))) {
-                    RETURN ( __mkSmallInteger(bits << count) );
-                }
-                /*
-                 * so, there is an overflow ...
-                 * handle it as largeInteger
-                 */
-                /* FALL THROUGH */
-            }
-#endif
-        } else {
-            if (count == 0) {
-                RETURN (self);
-            }
-
-            /*
-             * right shifts cannot overflow
-             *
-             * some machines ignore shifts bigger than
-             * the number of bits in an int ...
-             */
-            if (count > (N_INT_BITS-1)) {
-                RETURN (__mkSmallInteger(0));
-            }
-
-            RETURN ( __mkSmallInteger(bits >> count) );
-        }
+	bits = __intVal(self);
+	if (bits == 0) {
+	    RETURN (self);
+	}
+
+	count = __intVal(shiftCount);
+
+	if (count < 0) {
+	    /*
+	     * a left shift
+	     */
+	    count = -count;
+# if defined(USE_LONGLONG_FOR_SHIFT)
+	    if (count <= N_INT_BITS) {
+		unsigned LONGLONG result;
+
+		result = (unsigned LONGLONG)bits;
+		result <<= count;
+		if (result <= _MAX_INT) {
+		    RETURN ( __mkSmallInteger(result) );
+		}
+		{
+		    RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
+		}
+	    }
+# else
+	    /*
+	     * check for overflow
+	     */
+	    if (count < (N_INT_BITS-1)) {
+		if (! (bits >> (N_INT_BITS - 1 - count))) {
+		    RETURN ( __mkSmallInteger(bits << count) );
+		}
+		/*
+		 * so, there is an overflow ...
+		 * handle it as largeInteger
+		 */
+		/* FALL THROUGH */
+	    }
+# endif
+	} else {
+	    if (count == 0) {
+		RETURN (self);
+	    }
+
+	    /*
+	     * right shifts cannot overflow
+	     *
+	     * some machines ignore shifts bigger than
+	     * the number of bits in an int ...
+	     */
+	    if (count > (N_INT_BITS-1)) {
+		RETURN (__mkSmallInteger(0));
+	    }
+
+	    RETURN ( __mkSmallInteger(bits >> count) );
+	}
     }
+#endif /* not JAVA */
 %}.
     (shiftCount isMemberOf:SmallInteger) ifTrue:[
-        ^ (LargeInteger value:self) rightShift:shiftCount
+	^ (LargeInteger value:self) rightShift:shiftCount
     ].
     ^ self rightShift:shiftCount asInteger   "/ is this a good idea ?
 
 
     "
-        16 rightShift:2
-         4 rightShift:-2
+	16 rightShift:2
+	 4 rightShift:-2
     "
 !
 
@@ -1530,23 +1649,25 @@
      but a new number is returned. Should be named #withBitSet:"
 
 %{  /* NOCONTEXT */
-
-    if (__isSmallInteger(anInteger)) {
-        int index = __intVal(anInteger);
-
-        if (index > 0) {
-#if __POINTER_SIZE__ == 8
-            if (index <= 62)
+#ifdef __JAVA__
 #else
-            if (index <= 30)
-#endif
-            {
-                INT mask = __MASKSMALLINT(1 << (index-1));
-
-                RETURN ( ((OBJ) ((INT)self | (INT)mask)) );
-            }
-        }
+    if (__isSmallInteger(anInteger)) {
+	int index = __intVal(anInteger);
+
+	if (index > 0) {
+# if __POINTER_SIZE__ == 8
+	    if (index <= 62)
+# else
+	    if (index <= 30)
+# endif
+	    {
+		INT mask = __MASKSMALLINT(1 << (index-1));
+
+		RETURN ( ((OBJ) ((INT)self | (INT)mask)) );
+	    }
+	}
     }
+#endif /* not JAVA */
 %}.
     ^ super setBit:anInteger
 
@@ -1565,19 +1686,19 @@
 
 !SmallInteger methodsFor:'byte access'!
 
-byteSwapped 
+byteSwapped
     "lsb -> msb;
      i.e. a.b.c.d -> d.c.b.a"
 
     SmallInteger maxBytes == 8 ifTrue:[
-        ^ self byteSwapped64
+	^ self byteSwapped64
     ] ifFalse:[
-        ^ self byteSwapped32
+	^ self byteSwapped32
     ].
 
     "
-     16r11223344 byteSwapped hexPrintString  
-     16r44332211 byteSwapped hexPrintString   
+     16r11223344 byteSwapped hexPrintString
+     16r44332211 byteSwapped hexPrintString
     "
 
     "Created: / 09-01-2012 / 23:01:33 / cg"
@@ -1589,17 +1710,20 @@
      i.e. a.b -> b.a"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
     unsigned INT v = __intVal(self);
     unsigned INT swapped;
 
     swapped = ((v>>8)&0xFF) | ((v & 0xFF)<<8);
     RETURN (__mkSmallInteger(swapped));
+#endif
 %}.
+    ^ super byteSwapped16
 
     "
-     16r1122 byteSwapped16 hexPrintString   
-     16r2211 byteSwapped16 hexPrintString   
-     16r332211 byteSwapped16 hexPrintString   
+     16r1122 byteSwapped16 hexPrintString
+     16r2211 byteSwapped16 hexPrintString
+     16r332211 byteSwapped16 hexPrintString
     "
 !
 
@@ -1609,68 +1733,71 @@
      i.e. a.b.c.d -> d.c.b.a"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
     unsigned INT v = __intVal(self);
     unsigned INT swapped;
 
-#undef HAVE_BSWAP
-#if __POINTER_SIZE__ == 4
-
-# if defined(USE_BSWAP) && defined(__BORLANDC__)
+# undef HAVE_BSWAP
+# if __POINTER_SIZE__ == 4
+
+#  if defined(USE_BSWAP) && defined(__BORLANDC__)
 #   define HAVE_BSWAP
 
     _asm {
-        mov eax, v
-        bswap eax
-        mov swapped, eax
+	mov eax, v
+	bswap eax
+	mov swapped, eax
     };
-# endif
-# if defined(USE_BSWAP) && defined(__VISUALC__)
+#  endif
+#  if defined(USE_BSWAP) && defined(__VISUALC__)
 #   define HAVE_BSWAP
 
     _asm {
-        mov eax, v
-        xchg al, ah
-        rol eax, 16
-        xchg al, ah
-        mov swapped, eax
+	mov eax, v
+	xchg al, ah
+	rol eax, 16
+	xchg al, ah
+	mov swapped, eax
     };
-# endif
-# if defined(USE_BSWAP) && defined(__GNUC__)
+#  endif
+#  if defined(USE_BSWAP) && defined(__GNUC__)
 #   define HAVE_BSWAP
 
     asm("movl %1, %%eax \n\
-         bswap %%eax    \n\
-         movl %%eax, %0 \n\
-        "
-        : "=rm"  (swapped)
-        : "rm"   (v));
-# endif
-#endif /* __POINTER_SIZE__ == 4 */
-
-#if __POINTER_SIZE__ == 8
+	 bswap %%eax    \n\
+	 movl %%eax, %0 \n\
+	"
+	: "=rm"  (swapped)
+	: "rm"   (v));
+#  endif
+# endif /* __POINTER_SIZE__ == 4 */
+
+# if __POINTER_SIZE__ == 8
     v &= 0xFFFFFFFF;
 
-# if defined(__x86_64__) && defined(__GNUC__)
+#  if defined(__x86_64__) && defined(__GNUC__)
 #   define HAVE_BSWAP
     asm("movq %1, %%rax \n\
-         bswap %%eax    \n\
-         movq %%rax, %0 \n\
-        "
-        : "=rm"  (swapped)
-        : "rm"   (v));
+	 bswap %%eax    \n\
+	 movq %%rax, %0 \n\
+	"
+	: "=rm"  (swapped)
+	: "rm"   (v));
+#  endif
 # endif
-#endif
-
-#ifndef HAVE_BSWAP
+
+# ifndef HAVE_BSWAP
     swapped = ((v>>24) | ((v>>8)&0xFF00) | ((v & 0xFF00)<<8) | ((v & 0xFF)<<24));
-#endif
+# endif
 
     RETURN (__MKUINT(swapped));
+#endif /* not JAVA */
 %}.
+    ^ super byteSwapped32
 
     "
-     16r11223344 byteSwapped32 hexPrintString  
-     16r44332211 byteSwapped32 hexPrintString   
+     16r11223344 byteSwapped32 hexPrintString
+     16r44332211 byteSwapped32 hexPrintString
     "
 
     "Created: / 09-01-2012 / 23:01:33 / cg"
@@ -1682,31 +1809,34 @@
      i.e. a.b.c.d.e.f.g.h -> h.g.f.e.d.c.b.a"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
     unsigned INT v = __intVal(self);
     unsigned INT swapped;
 
-#if __POINTER_SIZE__ == 4
-    //   xxxxxxxx 00000000 00000000 00000000 -> 00000000 00000000 00000000 xxxxxxxx  
+# if __POINTER_SIZE__ == 4
+    //   xxxxxxxx 00000000 00000000 00000000 -> 00000000 00000000 00000000 xxxxxxxx
     //            xxxxxxxx                                        xxxxxxxx
     //                     xxxxxxxx                      xxxxxxxx
     //                              xxxxxxxx    xxxxxxxx
     swapped = (v>>24) | ((v>>8)&0xFF00) | ((v & 0xFF00)<<8) | ((v & 0xFF)<<24);
     RETURN(__MKLARGEINT64(1, 0, swapped));
-#else
-    //   xxxxxxxx 00000000 00000000 00000000 -> 00000000 00000000 00000000 xxxxxxxx  
+# else
+    //   xxxxxxxx 00000000 00000000 00000000 -> 00000000 00000000 00000000 xxxxxxxx
     //            xxxxxxxx                                        xxxxxxxx
     //                     xxxxxxxx                      xxxxxxxx
     //                              xxxxxxxx    xxxxxxxx
     swapped =  (v>>56) | ((v>>40)&0xFF00) | ((v>>24) & 0xFF0000) | ((v>>8) & 0xFF000000)
-                | ((v & 0xFF000000)<<8) | ((v & 0x00FF0000)<<24) | ((v & 0x0000FF00)<<40)
-                | ((v & 0xFF)<<56);
+		| ((v & 0xFF000000)<<8) | ((v & 0x00FF0000)<<24) | ((v & 0x0000FF00)<<40)
+		| ((v & 0xFF)<<56);
+# endif
+    RETURN(__MKUINT( swapped ));
 #endif
-    RETURN(__MKUINT( swapped ));
 %}.
+    ^ super byteSwapped64
 
     "
-     16r11223344 byteSwapped64 hexPrintString  
-     16r44332211 byteSwapped64 hexPrintString   
+     16r11223344 byteSwapped64 hexPrintString
+     16r44332211 byteSwapped64 hexPrintString
     "
 
     "Created: / 09-01-2012 / 23:01:33 / cg"
@@ -1716,7 +1846,15 @@
     "return 8 bits of value, starting at byte index"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    int idx = index.intValue() - 1;
+
+    if (idx <= 7) {
+	int byteVal = (int)((self.longValue() >> (idx * 8)) & 0xFF);
+
+	return context._RETURN( STInteger._new(byteVal) );
+    }
+#else
     REGISTER INT val;
     INT idx;
 
@@ -1736,7 +1874,7 @@
 	    case 4:
 		val = (val >> 24);
 		break;
-#if __POINTER_SIZE__ == 8
+# if __POINTER_SIZE__ == 8
 	    case 5:
 		val = (val >> 32);
 		break;
@@ -1749,7 +1887,7 @@
 	    case 8:
 		val = (val >> 56);
 		break;
-#endif
+# endif
 	    default:
 		if (idx < 1)
 		    goto bad;   /* sorry */
@@ -1758,6 +1896,7 @@
 	RETURN ( __mkSmallInteger( val & 0xFF) );
     }
   bad: ;
+#endif /* not JAVA */
 %}.
     index > 0 ifFalse:[
 	"
@@ -1782,7 +1921,7 @@
      for negative ones, the actual bit representation is returned."
 
 %{  /* NOCONTEXT */
-
+#ifndef __JAVA__
     REGISTER INT val;
     INT idx;
 
@@ -1800,7 +1939,7 @@
 	    case 4:
 		val = (val >> 24);
 		break;
-#if __POINTER_SIZE__ == 8
+# if __POINTER_SIZE__ == 8
 	    case 5:
 		val = (val >> 32);
 		break;
@@ -1813,7 +1952,7 @@
 	    case 8:
 		val = (val >> 56);
 		break;
-#endif
+# endif
 	    default:
 		if (idx < 1)
 		    goto bad;   /* sorry */
@@ -1825,6 +1964,7 @@
 	RETURN ( __mkSmallInteger( val & 0xFF) );
     }
   bad: ;
+#endif /* not JAVA */
 %}.
     index > 0 ifFalse:[
 	"
@@ -1862,83 +2002,83 @@
      overhead of producing any intermediate byte-arrays (and the scanning)
     "
     self == 0 ifTrue: [
-        ^ ByteArray with:0.
+	^ ByteArray with:0.
     ].
 
     self < 0 ifTrue: [
-        absValue := self negated
+	absValue := self negated
     ] ifFalse: [
-        absValue := self.
+	absValue := self.
     ].
 
     b1 := absValue bitAnd:16rFF.
     absValue := absValue bitShift:-8.
     absValue == 0 ifTrue:[
-        digitByteArray := ByteArray with:b1
+	digitByteArray := ByteArray with:b1
     ] ifFalse:[
-        b2 := absValue bitAnd:16rFF.
-        absValue := absValue bitShift:-8.
-        absValue == 0 ifTrue:[
-            digitByteArray := ByteArray with:b1 with:b2
-        ] ifFalse:[
-            b3 := absValue bitAnd:16rFF.
-            absValue := absValue bitShift:-8.
-            absValue == 0 ifTrue:[
-                digitByteArray := ByteArray with:b1 with:b2 with:b3
-            ] ifFalse:[
-                b4 := absValue bitAnd:16rFF.
-                absValue := absValue bitShift:-8.
-                absValue == 0 ifTrue:[
-                    digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4
-                ] ifFalse:[
-                    b5 := absValue bitAnd:16rFF.
-                    absValue := absValue bitShift:-8.
-                    absValue == 0 ifTrue:[
-                        digitByteArray := ByteArray new:5.
-                        digitByteArray at:1 put:b1.
-                        digitByteArray at:2 put:b2.
-                        digitByteArray at:3 put:b3.
-                        digitByteArray at:4 put:b4.
-                        digitByteArray at:5 put:b5.
-                    ] ifFalse:[
-                        b6 := absValue bitAnd:16rFF.
-                        absValue := absValue bitShift:-8.
-                        absValue == 0 ifTrue:[
-                            digitByteArray := ByteArray new:6.
-                            digitByteArray at:1 put:b1.
-                            digitByteArray at:2 put:b2.
-                            digitByteArray at:3 put:b3.
-                            digitByteArray at:4 put:b4.
-                            digitByteArray at:5 put:b5.
-                            digitByteArray at:6 put:b6.
-                        ] ifFalse:[
-                            b7 := absValue bitAnd:16rFF.
-                            absValue := absValue bitShift:-8.
-                            absValue == 0 ifTrue:[
-                                digitByteArray := ByteArray new:7.
-                                digitByteArray at:1 put:b1.
-                                digitByteArray at:2 put:b2.
-                                digitByteArray at:3 put:b3.
-                                digitByteArray at:4 put:b4.
-                                digitByteArray at:5 put:b5.
-                                digitByteArray at:6 put:b6.
-                                digitByteArray at:7 put:b7.
-                            ] ifFalse:[
-                                digitByteArray := ByteArray new:8.
-                                digitByteArray at:1 put:b1.
-                                digitByteArray at:2 put:b2.
-                                digitByteArray at:3 put:b3.
-                                digitByteArray at:4 put:b4.
-                                digitByteArray at:5 put:b5.
-                                digitByteArray at:6 put:b6.
-                                digitByteArray at:7 put:b7.
-                                digitByteArray at:8 put:absValue.
-                            ]
-                        ]
-                    ]
-                ]
-            ]
-        ]
+	b2 := absValue bitAnd:16rFF.
+	absValue := absValue bitShift:-8.
+	absValue == 0 ifTrue:[
+	    digitByteArray := ByteArray with:b1 with:b2
+	] ifFalse:[
+	    b3 := absValue bitAnd:16rFF.
+	    absValue := absValue bitShift:-8.
+	    absValue == 0 ifTrue:[
+		digitByteArray := ByteArray with:b1 with:b2 with:b3
+	    ] ifFalse:[
+		b4 := absValue bitAnd:16rFF.
+		absValue := absValue bitShift:-8.
+		absValue == 0 ifTrue:[
+		    digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4
+		] ifFalse:[
+		    b5 := absValue bitAnd:16rFF.
+		    absValue := absValue bitShift:-8.
+		    absValue == 0 ifTrue:[
+			digitByteArray := ByteArray new:5.
+			digitByteArray at:1 put:b1.
+			digitByteArray at:2 put:b2.
+			digitByteArray at:3 put:b3.
+			digitByteArray at:4 put:b4.
+			digitByteArray at:5 put:b5.
+		    ] ifFalse:[
+			b6 := absValue bitAnd:16rFF.
+			absValue := absValue bitShift:-8.
+			absValue == 0 ifTrue:[
+			    digitByteArray := ByteArray new:6.
+			    digitByteArray at:1 put:b1.
+			    digitByteArray at:2 put:b2.
+			    digitByteArray at:3 put:b3.
+			    digitByteArray at:4 put:b4.
+			    digitByteArray at:5 put:b5.
+			    digitByteArray at:6 put:b6.
+			] ifFalse:[
+			    b7 := absValue bitAnd:16rFF.
+			    absValue := absValue bitShift:-8.
+			    absValue == 0 ifTrue:[
+				digitByteArray := ByteArray new:7.
+				digitByteArray at:1 put:b1.
+				digitByteArray at:2 put:b2.
+				digitByteArray at:3 put:b3.
+				digitByteArray at:4 put:b4.
+				digitByteArray at:5 put:b5.
+				digitByteArray at:6 put:b6.
+				digitByteArray at:7 put:b7.
+			    ] ifFalse:[
+				digitByteArray := ByteArray new:8.
+				digitByteArray at:1 put:b1.
+				digitByteArray at:2 put:b2.
+				digitByteArray at:3 put:b3.
+				digitByteArray at:4 put:b4.
+				digitByteArray at:5 put:b5.
+				digitByteArray at:6 put:b6.
+				digitByteArray at:7 put:b7.
+				digitByteArray at:8 put:absValue.
+			    ]
+			]
+		    ]
+		]
+	    ]
+	]
     ].
 
     ^ digitByteArray
@@ -1970,83 +2110,83 @@
      overhead of producing any intermediate byte-arrays (and the scanning)
     "
     self == 0 ifTrue: [
-        ^ ByteArray with:0.
+	^ ByteArray with:0.
     ].
 
     self < 0 ifTrue: [
-        absValue := self negated
+	absValue := self negated
     ] ifFalse: [
-        absValue := self.
+	absValue := self.
     ].
 
     b1 := absValue bitAnd:16rFF.
     absValue := absValue bitShift:-8.
     absValue == 0 ifTrue:[
-        digitByteArray := ByteArray with:b1
+	digitByteArray := ByteArray with:b1
     ] ifFalse:[
-        b2 := absValue bitAnd:16rFF.
-        absValue := absValue bitShift:-8.
-        absValue == 0 ifTrue:[
-            digitByteArray := ByteArray with:b2 with:b1
-        ] ifFalse:[
-            b3 := absValue bitAnd:16rFF.
-            absValue := absValue bitShift:-8.
-            absValue == 0 ifTrue:[
-                digitByteArray := ByteArray with:b3 with:b2 with:b1
-            ] ifFalse:[
-                b4 := absValue bitAnd:16rFF.
-                absValue := absValue bitShift:-8.
-                absValue == 0 ifTrue:[
-                    digitByteArray := ByteArray with:b4 with:b3 with:b2 with:b1
-                ] ifFalse:[
-                    b5 := absValue bitAnd:16rFF.
-                    absValue := absValue bitShift:-8.
-                    absValue == 0 ifTrue:[
-                        digitByteArray := ByteArray new:5.
-                        digitByteArray at:1 put:b5.
-                        digitByteArray at:2 put:b4.
-                        digitByteArray at:3 put:b3.
-                        digitByteArray at:4 put:b2.
-                        digitByteArray at:5 put:b1.
-                    ] ifFalse:[
-                        b6 := absValue bitAnd:16rFF.
-                        absValue := absValue bitShift:-8.
-                        absValue == 0 ifTrue:[
-                            digitByteArray := ByteArray new:6.
-                            digitByteArray at:1 put:b6.
-                            digitByteArray at:2 put:b5.
-                            digitByteArray at:3 put:b4.
-                            digitByteArray at:4 put:b3.
-                            digitByteArray at:5 put:b2.
-                            digitByteArray at:6 put:b1.
-                        ] ifFalse:[
-                            b7 := absValue bitAnd:16rFF.
-                            absValue := absValue bitShift:-8.
-                            absValue == 0 ifTrue:[
-                                digitByteArray := ByteArray new:7.
-                                digitByteArray at:1 put:b7.
-                                digitByteArray at:2 put:b6.
-                                digitByteArray at:3 put:b5.
-                                digitByteArray at:4 put:b4.
-                                digitByteArray at:5 put:b3.
-                                digitByteArray at:6 put:b2.
-                                digitByteArray at:7 put:b1.
-                            ] ifFalse:[
-                                digitByteArray := ByteArray new:8.
-                                digitByteArray at:1 put:absValue.
-                                digitByteArray at:2 put:b7.
-                                digitByteArray at:3 put:b6.
-                                digitByteArray at:4 put:b5.
-                                digitByteArray at:5 put:b4.
-                                digitByteArray at:6 put:b3.
-                                digitByteArray at:7 put:b2.
-                                digitByteArray at:8 put:b1.
-                            ]
-                        ]
-                    ]
-                ]
-            ]
-        ]
+	b2 := absValue bitAnd:16rFF.
+	absValue := absValue bitShift:-8.
+	absValue == 0 ifTrue:[
+	    digitByteArray := ByteArray with:b2 with:b1
+	] ifFalse:[
+	    b3 := absValue bitAnd:16rFF.
+	    absValue := absValue bitShift:-8.
+	    absValue == 0 ifTrue:[
+		digitByteArray := ByteArray with:b3 with:b2 with:b1
+	    ] ifFalse:[
+		b4 := absValue bitAnd:16rFF.
+		absValue := absValue bitShift:-8.
+		absValue == 0 ifTrue:[
+		    digitByteArray := ByteArray with:b4 with:b3 with:b2 with:b1
+		] ifFalse:[
+		    b5 := absValue bitAnd:16rFF.
+		    absValue := absValue bitShift:-8.
+		    absValue == 0 ifTrue:[
+			digitByteArray := ByteArray new:5.
+			digitByteArray at:1 put:b5.
+			digitByteArray at:2 put:b4.
+			digitByteArray at:3 put:b3.
+			digitByteArray at:4 put:b2.
+			digitByteArray at:5 put:b1.
+		    ] ifFalse:[
+			b6 := absValue bitAnd:16rFF.
+			absValue := absValue bitShift:-8.
+			absValue == 0 ifTrue:[
+			    digitByteArray := ByteArray new:6.
+			    digitByteArray at:1 put:b6.
+			    digitByteArray at:2 put:b5.
+			    digitByteArray at:3 put:b4.
+			    digitByteArray at:4 put:b3.
+			    digitByteArray at:5 put:b2.
+			    digitByteArray at:6 put:b1.
+			] ifFalse:[
+			    b7 := absValue bitAnd:16rFF.
+			    absValue := absValue bitShift:-8.
+			    absValue == 0 ifTrue:[
+				digitByteArray := ByteArray new:7.
+				digitByteArray at:1 put:b7.
+				digitByteArray at:2 put:b6.
+				digitByteArray at:3 put:b5.
+				digitByteArray at:4 put:b4.
+				digitByteArray at:5 put:b3.
+				digitByteArray at:6 put:b2.
+				digitByteArray at:7 put:b1.
+			    ] ifFalse:[
+				digitByteArray := ByteArray new:8.
+				digitByteArray at:1 put:absValue.
+				digitByteArray at:2 put:b7.
+				digitByteArray at:3 put:b6.
+				digitByteArray at:4 put:b5.
+				digitByteArray at:5 put:b4.
+				digitByteArray at:6 put:b3.
+				digitByteArray at:7 put:b2.
+				digitByteArray at:8 put:b1.
+			    ]
+			]
+		    ]
+		]
+	    ]
+	]
     ].
 
     ^ digitByteArray
@@ -2064,13 +2204,13 @@
      is returned."
 
 %{  /* NOCONTEXT */
-
+#ifndef __JAVA__
     INT val = __intVal(self);
 
     if (val < 0) {
 	val = -val;
     }
-#if __POINTER_SIZE__ == 8
+# if __POINTER_SIZE__ == 8
     if (val & 0xFFFFFFFF00000000L) {
 	if (val & 0xFFFF000000000000L) {
 	    if (val & 0xFF00000000000000L) {
@@ -2086,7 +2226,7 @@
 	    }
 	}
     }
-#endif
+# endif
 
     if (val & 0xFFFF0000) {
 	if (val & 0xFF000000) {
@@ -2101,7 +2241,7 @@
 	    RETURN ( __mkSmallInteger(1));
 	}
     }
-
+#endif
 %}.
     ^ self abs highBit - 1 // 8 + 1
 
@@ -2129,35 +2269,36 @@
      This case is handled in the superclass."
 
 %{  /* NOCONTEXT */
-
+#ifndef __JAVA__
     unsigned INT v = __intVal(self);
 
     if ((INT)v >= 0) {
-        unsigned INT swapped;
-
-#if __POINTER_SIZE__ == 8
-        swapped = ((v >> 8) & 0x00FF00FF00FF00FF) | ((v & 0x00FF00FF00FF00FF) << 8);
-#else
-        swapped = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8);
-#endif /* __POINTER_SIZE__ */
-
-        //if (__ISVALIDINTEGER(swapped)) {   // sorry, but this does not work here if (INT)swapped would be negative
-        if (swapped <= _MAX_INT) {
-            RETURN ( __mkSmallInteger(swapped) );
-        }
-        RETURN (__MKUINT(swapped));
+	unsigned INT swapped;
+
+# if __POINTER_SIZE__ == 8
+	swapped = ((v >> 8) & 0x00FF00FF00FF00FF) | ((v & 0x00FF00FF00FF00FF) << 8);
+# else
+	swapped = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8);
+# endif /* __POINTER_SIZE__ */
+
+	//if (__ISVALIDINTEGER(swapped)) {   // sorry, but this does not work here if (INT)swapped would be negative
+	if (swapped <= _MAX_INT) {
+	    RETURN ( __mkSmallInteger(swapped) );
+	}
+	RETURN (__MKUINT(swapped));
     }
+#endif
 %}.
     ^ super swapBytes
 
     "
-     -1 swapBytes hexPrintString   
-     16r11223344 swapBytes hexPrintString   
-     16r44332211 swapBytes hexPrintString 
+     -1 swapBytes hexPrintString
+     16r11223344 swapBytes hexPrintString
+     16r44332211 swapBytes hexPrintString
      self maxVal swapBytes hexPrintString
      self maxVal swapBytes swapBytes hexPrintString
-     16r1122334455667788 swapBytes hexPrintString   
-     16r11223344556677889900 swapBytes hexPrintString   
+     16r1122334455667788 swapBytes hexPrintString
+     16r11223344556677889900 swapBytes hexPrintString
     "
 
     "Created: / 09-01-2012 / 23:01:33 / cg"
@@ -2205,12 +2346,15 @@
      Redefined for performance (machine can do it faster)"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( STDouble._new((double)(self.longValue())) );
+#else
     OBJ newFloat;
     double dVal = (double)__intVal(self);
 
     __qMKFLOAT(newFloat, dVal);
     RETURN ( newFloat );
+#endif
 %}.
     ^ self primitiveFailed
 !
@@ -2226,13 +2370,16 @@
      Redefined for performance (machine can do it faster)"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( STFloat._new((float)(self.longValue())) );
+#else
     OBJ dummy = @global(ShortFloat);
     OBJ newFloat;
     float fVal = (float)__intVal(self);
 
     __qMKSFLOAT(newFloat, fVal);
     RETURN ( newFloat );
+#endif
 %}.
     ^ self primitiveFailed
 !
@@ -2261,6 +2408,7 @@
      May be useful for communication interfaces"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
     INT i = __intVal(self);
 
     if (i & 0x800000) {
@@ -2270,6 +2418,7 @@
     }
 
     RETURN (__mkSmallInteger(i));
+#endif
 %}.
     ^ self primitiveFailed
 
@@ -2285,6 +2434,7 @@
      May be useful for communication interfaces"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
     INT i = __intVal(self);
 
     if (i & 0x80) {
@@ -2294,6 +2444,7 @@
     }
 
     RETURN (__mkSmallInteger(i));
+#endif
 %}.
     ^ self primitiveFailed
 
@@ -2309,15 +2460,17 @@
      May be useful for communication interfaces"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
     INT i = __intVal(self);
 
     if (i & 0x80000000) {
-        i = i | ~0xFFFFFFFFL;
+	i = i | ~0xFFFFFFFFL;
     } else {
-        i = i & 0x7FFFFFFF;
+	i = i & 0x7FFFFFFF;
     }
 
     RETURN (__mkSmallInteger(i));
+#endif
 %}.
     ^ self primitiveFailed
 
@@ -2333,6 +2486,7 @@
      May be useful for communication interfaces"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
     INT i = __intVal(self);
 
     if (i & 0x8000) {
@@ -2342,6 +2496,7 @@
     }
 
     RETURN (__mkSmallInteger(i));
+#endif
 %}.
     ^ self primitiveFailed
 
@@ -2358,18 +2513,21 @@
     "return true, if the argument is greater than the receiver"
 
 %{  /* NOCONTEXT */
-
+#ifdef __JAVA__
+    return context._RETURN( self.ltP( aNumber ));
+#else
     if (__isSmallInteger(aNumber)) {
-#ifdef POSITIVE_ADDRESSES
+# ifdef POSITIVE_ADDRESSES
 	RETURN ( (__intVal(self) < __intVal(aNumber)) ? true : false );
-#else
+# else
 	/* tag bit does not change ordering */
 	RETURN ( ((INT)self < (INT)aNumber) ? true : false );
-#endif
+# endif
     }
     if (__isFloatLike(aNumber)) {
 	RETURN ( ((double)__intVal(self) < __floatVal(aNumber)) ? true : false );
     }
+#endif
 %}.
     ^ aNumber lessFromInteger:self
     "^ self retry:#< coercing:aNumber"
@@ -2379,18 +2537,22 @@
     "return true, if the argument is greater or equal"
 
 %{  /* NOCONTEXT */
+#ifdef __JAVA__
+    return context._RETURN( self.leP( aNumber ));
+#else
 
     if (__isSmallInteger(aNumber)) {
-#ifdef POSITIVE_ADDRESSES
+# ifdef POSITIVE_ADDRESSES
 	RETURN ( (__intVal(self) <= __intVal(aNumber)) ? true : false );
-#else
+# else
 	/* tag bit does not change ordering */
 	RETURN ( ((INT)self <= (INT)aNumber) ? true : false );
-#endif
+# endif
     }
     if (__isFloatLike(aNumber)) {
 	RETURN ( ((double)__intVal(self) <= __floatVal(aNumber)) ? true : false );
     }
+#endif
 %}.
     ^ (self > aNumber) not
 
@@ -2402,6 +2564,9 @@
      as the receiver, false otherwise"
 
 %{  /* NOCONTEXT */
+#ifdef __JAVA__
+    return context._RETURN( self.eqP( aNumber ));
+#else
 
     if (aNumber == self) {
 	RETURN ( true );
@@ -2417,6 +2582,7 @@
     if (__qIsShortFloat(aNumber)) {
 	RETURN ( ((double)__intVal(self) == __shortFloatVal(aNumber)) ? true : false );
     }
+#endif
 %}.
     ^ aNumber equalFromInteger:self
 !
@@ -2425,18 +2591,22 @@
     "return true, if the argument is less than the receiver"
 
 %{  /* NOCONTEXT */
+#ifdef __JAVA__
+    return context._RETURN( self.gtP( aNumber ));
+#else
 
     if (__isSmallInteger(aNumber)) {
-#ifdef POSITIVE_ADDRESSES
+# ifdef POSITIVE_ADDRESSES
 	RETURN ( (__intVal(self) > __intVal(aNumber)) ? true : false );
-#else
+# else
 	/* tag bit does not change ordering */
 	RETURN ( ((INT)self > (INT)aNumber) ? true : false );
-#endif
+# endif
     }
     if (__isFloatLike(aNumber)) {
 	RETURN ( ((double)__intVal(self) > __floatVal(aNumber)) ? true : false );
     }
+#endif
 %}.
     ^ (aNumber < self)
 
@@ -2447,18 +2617,22 @@
     "return true, if the argument is less or equal"
 
 %{  /* NOCONTEXT */
+#ifdef __JAVA__
+    return context._RETURN( self.geP( aNumber ));
+#else
 
     if (__isSmallInteger(aNumber)) {
-#ifdef POSITIVE_ADDRESSES
+# ifdef POSITIVE_ADDRESSES
 	RETURN ( (__intVal(self) >= __intVal(aNumber)) ? true : false );
-#else
+# else
 	/* tag bit does not change ordering */
 	RETURN ( ((INT)self >= (INT)aNumber) ? true : false );
-#endif
+# endif
     }
     if (__isFloatLike(aNumber)) {
 	RETURN ( ((double)__intVal(self) >= __floatVal(aNumber)) ? true : false );
     }
+#endif
 %}.
     ^ (self < aNumber) not
 
@@ -2478,15 +2652,15 @@
     |low|
 
     low := self bitAnd: 16r3FFF.
-    ^ (9741 * low 
+    ^ (9741 * low
       + ((9741 * (self bitShift: -14) + (101 * low) bitAnd: 16383) * 16384))
-        bitAnd: 16r0FFFFFFF
+	bitAnd: 16r0FFFFFFF
 
     "
-     1 hashMultiply    
-     2 hashMultiply    
-     3 hashMultiply    
-     100 hashMultiply  
+     1 hashMultiply
+     2 hashMultiply
+     3 hashMultiply
+     100 hashMultiply
     "
 !
 
@@ -2503,14 +2677,15 @@
     "return the receiver or the argument, whichever is greater"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
 
     if (__isSmallInteger(aNumber)) {
-#if TAG_INT == 1
+# if TAG_INT == 1
 	/* tag bit does not change ordering */
 	if ((INT)(self) > (INT)(aNumber))
-#else
+# else
 	if (__intVal(self) > __intVal(aNumber))
-#endif
+# endif
 	{
 	    RETURN ( self );
 	}
@@ -2522,6 +2697,7 @@
 	}
 	RETURN ( aNumber );
     }
+#endif
 %}.
     "/ fallback for non-smallInteger argument
 
@@ -2533,14 +2709,15 @@
     "return the receiver or the argument, whichever is smaller"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
 
     if (__isSmallInteger(aNumber)) {
-#if TAG_INT == 1
+# if TAG_INT == 1
 	/* tag bit does not change ordering */
 	if ((INT)(self) < (INT)(aNumber))
-#else
+# else
 	if (__intVal(self) < __intVal(aNumber))
-#endif
+# endif
 	{
 	    RETURN ( self );
 	}
@@ -2552,6 +2729,7 @@
 	}
 	RETURN ( aNumber );
     }
+#endif
 %}.
     "/ fallback for non-smallInteger argument
 
@@ -2563,6 +2741,10 @@
     "return true, if the arguments value is not equal to mine"
 
 %{  /* NOCONTEXT */
+#ifdef __JAVA__
+    return context._RETURN( (self.eqP( aNumber ) == STObject.True) ? STObject.False : STObject.True);
+    /* NOTREACHED */
+#else
 
     if (aNumber == self) {
 	RETURN ( false );
@@ -2578,6 +2760,7 @@
     if (__qIsShortFloat(aNumber)) {
 	RETURN ( ((double)__intVal(self) != __shortFloatVal(aNumber)) ? true : false );
     }
+#endif
 %}.
     ^ (self = aNumber) not
 ! !
@@ -2620,6 +2803,7 @@
      Reimplemented as primitive for speed"
 
 %{
+#ifndef __JAVA__
     REGISTER INT tmp;
     static struct inlineCache blockVal = __ILC0(0);
 
@@ -2635,16 +2819,16 @@
 		 * (the most common case)
 		 */
 		if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
-#ifdef PARANOIA
+# ifdef PARANOIA
 		 && (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
-#endif
+# endif
 		) {
 
-#ifdef NEW_BLOCK_CALL
+# ifdef NEW_BLOCK_CALL
 
 #                   define BLOCK_ARG  aBlock
 
-#else
+# else
 
 #                   define BLOCK_ARG  rHome
 		    REGISTER OBJ rHome;
@@ -2654,9 +2838,9 @@
 		     */
 		    rHome = __BlockInstPtr(aBlock)->b_home;
 		    if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE))
-#endif
+# endif
 		    {
-#ifdef __UNROLL_LOOPS__
+# ifdef __UNROLL_LOOPS__
 
 			/*
 			 * you are not supposed to program like this - I know what I do
@@ -2688,7 +2872,7 @@
 			    (*codeVal)(BLOCK_ARG);
 			    tmp -= 8;
 			}
-#endif /* __UNROLL_LOOPS__ */
+# endif /* __UNROLL_LOOPS__ */
 			do {
 			    if (InterruptPending != nil) goto interruptedX;
 	continueX:
@@ -2697,7 +2881,7 @@
 
 			RETURN (self);
 			if (0) {
-#ifdef __UNROLL_LOOPS__
+# ifdef __UNROLL_LOOPS__
 			    interrupted0:
 						__interruptL(@line); goto continue0;
 			    interrupted1:
@@ -2714,7 +2898,7 @@
 						__interruptL(@line); goto continue6;
 			    interrupted7:
 						__interruptL(@line); goto continue7;
-#endif /* __UNROLL_LOOPS__ */
+# endif /* __UNROLL_LOOPS__ */
 			    interruptedX:
 						__interruptL(@line); goto continueX;
 			}
@@ -2724,13 +2908,13 @@
 
 #           undef BLOCK_ARG
 
-#ifdef NEW_BLOCK_CALL
+# ifdef NEW_BLOCK_CALL
 #           define BLOCK_ARG  aBlock
 #           define IBLOCK_ARG nil
-#else
+# else
 #           define BLOCK_ARG  (__BlockInstPtr(aBlock)->b_home)
 #           define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
-#endif
+# endif
 
 	    /*
 	     * sorry - must check for the blocks code within the loops;
@@ -2785,6 +2969,7 @@
 	} while(--tmp);
 	RETURN (self);
     }
+#endif
 %}.
     ^ super timesRepeat:aBlock
 
@@ -2801,6 +2986,7 @@
     "reimplemented as primitive for speed"
 
 %{
+#ifndef __JAVA__
     REGISTER INT tmp, step;
     REGISTER INT final;
     static struct inlineCache blockVal = __ILC1(0);
@@ -2820,23 +3006,23 @@
 		 * home on the stack (the most common case)
 		 */
 		if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
-#ifdef PARANOIA
+# ifdef PARANOIA
 		 && (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
-#endif
+# endif
 		) {
 
-#ifdef NEW_BLOCK_CALL
+# ifdef NEW_BLOCK_CALL
 
 #                   define BLOCK_ARG  aBlock
 
-#else
+# else
 
 #                   define BLOCK_ARG  rHome
 		    REGISTER OBJ rHome;
 		    rHome = __BlockInstPtr(aBlock)->b_home;
 		    if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE))
 
-#endif
+# endif
 		    {
 			if (step < 0) {
 			    if (step == -1) {
@@ -2879,13 +3065,13 @@
 
 #           undef BLOCK_ARG
 
-#ifdef NEW_BLOCK_CALL
+# ifdef NEW_BLOCK_CALL
 #           define BLOCK_ARG  aBlock
 #           define IBLOCK_ARG nil
-#else
+# else
 #           define BLOCK_ARG  (__BlockInstPtr(aBlock)->b_home)
 #           define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
-#endif
+# endif
 
 	    if (step < 0) {
 		while (tmp >= final) {
@@ -2905,16 +3091,16 @@
 			     * arg is a compiled block with bytecode -
 			     * directly call interpreter without going through Block>>value
 			     */
-#ifdef PASS_ARG_POINTER
+# ifdef PASS_ARG_POINTER
 			    {
 				OBJ idx;
 
 				idx = __mkSmallInteger(tmp);
 				__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
 			    }
-#else
+# else
 			    __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
-#endif
+# endif
 
 			} else {
 			    /*
@@ -2943,16 +3129,16 @@
 			     * arg is a compiled block with bytecode -
 			     * directly call interpreter without going through Block>>value
 			     */
-#ifdef PASS_ARG_POINTER
+# ifdef PASS_ARG_POINTER
 			    {
 				OBJ idx;
 
 				idx = __mkSmallInteger(tmp);
 				__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
 			    }
-#else
+# else
 			    __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
-#endif
+# endif
 
 			} else {
 			    /*
@@ -2996,6 +3182,7 @@
 	}
 	RETURN ( self );
     }
+#endif
 %}.
     "/
     "/ arrive here if stop is not a smallInteger
@@ -3014,6 +3201,7 @@
      Reimplemented as primitive for speed"
 
 %{
+#ifndef __JAVA__
     REGISTER INT tmp;
     INT final;
     static struct inlineCache blockVal = __ILC1(0);
@@ -3033,27 +3221,27 @@
 
 		if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
 
-#ifdef NEW_BLOCK_CALL
+# ifdef NEW_BLOCK_CALL
 
 #                   define BLOCK_ARG  aBlock
 
-#else
+# else
 
 #                   define BLOCK_ARG  rHome
 		    REGISTER OBJ rHome;
 		    rHome = __BlockInstPtr(aBlock)->b_home;
 		    if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE))
-#endif
+# endif
 		    {
 
-#ifdef PARANOIA
+# ifdef PARANOIA
 			if (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
-#endif
+# endif
 			{
 			    /*
 			     * static compiled blocks ...
 			     */
-#ifdef __UNROLL_LOOPS__
+# ifdef __UNROLL_LOOPS__
 			    /*
 			     * The following code is designed to run as fast as possible;
 			     *  - taken branches only if interrupts are pending
@@ -3062,95 +3250,95 @@
 			     *
 			     * you are not supposed to program like this - I know what I do
 			     */
-# if TAG_INT==1
+#  if TAG_INT==1
 			    INT t8 = (INT)(__mkSmallInteger(tmp+8));
 			    tmp = (INT)(__mkSmallInteger(tmp));
 			    final = (INT)(__mkSmallInteger(final));
-# else
+#  else
 			    INT t8 = tmp+8;
-# endif
+#  endif
 
 			    for (;;) {
 
 				while (t8 <= final) {
-# if TAG_INT==1
+#  if TAG_INT==1
 				    t8 += (INT)(__MASKSMALLINT(8));
-# else
+#  else
 				    t8 += 8;
-# endif
+#  endif
 				    if (InterruptPending != nil) goto interrupted0;
 	continue0:
-# if TAG_INT==1
+#  if TAG_INT==1
 				    (*codeVal)(BLOCK_ARG, tmp);
-# else
+#  else
 				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
-# endif
+#  endif
 				    if (InterruptPending != nil) goto interrupted1;
 	continue1:
-# if TAG_INT==1
+#  if TAG_INT==1
 				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(1)) );
-# else
+#  else
 				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+1));
-# endif
+#  endif
 				    if (InterruptPending != nil) goto interrupted2;
 	continue2:
-# if TAG_INT==1
+#  if TAG_INT==1
 				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(2)) );
-# else
+#  else
 				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+2));
-# endif
+#  endif
 				    if (InterruptPending != nil) goto interrupted3;
 	continue3:
-# if TAG_INT==1
+#  if TAG_INT==1
 				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(3)) );
-# else
+#  else
 				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+3));
-# endif
+#  endif
 				    if (InterruptPending != nil) goto interrupted4;
 	continue4:
-# if TAG_INT==1
+#  if TAG_INT==1
 				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(4)) );
-# else
+#  else
 				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+4));
-# endif
+#  endif
 				    if (InterruptPending != nil) goto interrupted5;
 	continue5:
-# if TAG_INT==1
+#  if TAG_INT==1
 				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(5)) );
-# else
+#  else
 				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+5));
-# endif
+#  endif
 				    if (InterruptPending != nil) goto interrupted6;
 	continue6:
-# if TAG_INT==1
+#  if TAG_INT==1
 				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(6)) );
-# else
+#  else
 				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+6));
-# endif
+#  endif
 				    if (InterruptPending != nil) goto interrupted7;
 	continue7:
-# if TAG_INT==1
+#  if TAG_INT==1
 				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(7)) );
-# else
+#  else
 				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+7));
-# endif
-
-# if TAG_INT==1
+#  endif
+
+#  if TAG_INT==1
 				    tmp += (INT)(__MASKSMALLINT(8));
-# else
+#  else
 				    tmp += 8;
-# endif
+#  endif
 				}
 				while (tmp <= final) {
 				    if (InterruptPending != nil) goto interruptedX;
 	continueX:
-# if TAG_INT==1
+#  if TAG_INT==1
 				    (*codeVal)(BLOCK_ARG, tmp);
 				    tmp += (INT)(__MASKSMALLINT(1));
-# else
+#  else
 				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
 				    tmp++;
-# endif
+#  endif
 				}
 				RETURN (self);
 
@@ -3180,14 +3368,14 @@
 						    __interruptL(@line); goto continueX;
 				}
 			    }
-#else
+# else
 			    while (tmp <= final) {
 				if (InterruptPending != nil) __interruptL(@line);
 				(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
 				tmp ++;
 			    }
 			    RETURN (self);
-#endif /* __UNROLL_LOOPS__ */
+# endif /* __UNROLL_LOOPS__ */
 			}
 
 			/*
@@ -3210,13 +3398,13 @@
 
 #           undef BLOCK_ARG
 
-#ifdef NEW_BLOCK_CALL
+# ifdef NEW_BLOCK_CALL
 #           define BLOCK_ARG  aBlock
 #           define IBLOCK_ARG nil
-#else
+# else
 #           define BLOCK_ARG  (__BlockInstPtr(aBlock)->b_home)
 #           define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
-#endif
+# endif
 
 	    /*
 	     * sorry - must check for the blocks code within the loops;
@@ -3246,16 +3434,16 @@
 			 * arg is a compiled block with bytecode -
 			 * directly call interpreter without going through Block>>value
 			 */
-#ifdef PASS_ARG_POINTER
+# ifdef PASS_ARG_POINTER
 			{
 			    OBJ idx;
 
 			    idx = __mkSmallInteger(tmp);
 			    __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
 			}
-#else
+# else
 			__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
-#endif
+# endif
 
 		    } else {
 			/*
@@ -3287,6 +3475,7 @@
 	}
 	RETURN ( self );
     }
+#endif /* not JAVA */
 %}.
 
     "/
@@ -3360,32 +3549,34 @@
 !
 
 divMod:aNumber
-    "return an array filled with 
-        (self // aNumber) and (self \\ aNumber).
+    "return an array filled with
+	(self // aNumber) and (self \\ aNumber).
      The returned remainder has the same sign as aNumber.
      The following is always true:
-        (receiver // something) * something + (receiver \\ something) = receiver
+	(receiver // something) * something + (receiver \\ something) = receiver
 
      Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
-     Especially surprising:     
-        -1 \\ 10 -> 9  (because -(1/10) is truncated towards next smaller integer, which is -1,
-                        and -1 multiplied by 10 gives -10, so we have to add 9 to get the original -1).
-        -10 \\ 3 -> 2 (because -(10/3) is truncated towards next smaller integer, which is -4,
-                        and -4 * 4 gives -12, so we need to add 2 to get the original -10.
+     Especially surprising:
+	-1 \\ 10 -> 9  (because -(1/10) is truncated towards next smaller integer, which is -1,
+			and -1 multiplied by 10 gives -10, so we have to add 9 to get the original -1).
+	-10 \\ 3 -> 2 (because -(10/3) is truncated towards next smaller integer, which is -4,
+			and -4 * 4 gives -12, so we need to add 2 to get the original -10.
 
      This is redefined here for more performance"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
     INT val, div, mod, mySelf;
 
     if (__isSmallInteger(aNumber)
      && ((val = __intVal(aNumber)) > 0)
      && ((mySelf = __intVal(self)) >= 0)) {
-        div = mySelf / val;
-        mod = mySelf % val;
-
-        RETURN (__ARRAY_WITH2( __mkSmallInteger(div), __mkSmallInteger(mod)));
+	div = mySelf / val;
+	mod = mySelf % val;
+
+	RETURN (__ARRAY_WITH2( __mkSmallInteger(div), __mkSmallInteger(mod)));
     }
+#endif
 %}.
     ^ super divMod:aNumber
 
@@ -3407,14 +3598,14 @@
 
      10 divMod:3       -> #(3 1)   because 3*3 + 1 = 10
      10 divMod:-3      -> #(-4 -2) because -4*-3 + (-2) = 10
-     -10 divMod:3      -> #(-4 2)  because -4*3 + 2 = -10   
+     -10 divMod:3      -> #(-4 2)  because -4*3 + 2 = -10
      -10 divMod:-3     -> #(3 -1)  because -3*3 + (-1) = -10
 
      1000000000000000000000 divMod:3   -> #(333333333333333333333 1)
      1000000000000000000000 divMod:-3  -> #(-333333333333333333334 -2)
      -1000000000000000000000 divMod:3  -> #(-333333333333333333334 2)
      -1000000000000000000000 divMod:-3 -> #(333333333333333333333 -1)
-     100 factorial divMod:103    
+     100 factorial divMod:103
     "
 !
 
@@ -3425,7 +3616,7 @@
      some code. (thanx to MessageTally)"
 
 %{  /* NOCONTEXT */
-
+#ifndef __JAVA__
     if (__isSmallInteger(anInteger)) {
 	INT orgArg, ttt, selfInt, orgSelfInt, temp;
 
@@ -3452,8 +3643,8 @@
 	    RETURN ( __mkSmallInteger(selfInt) );
 	}
     }
-%}
-.
+#endif
+%}.
     ^ super gcd:anInteger
 !
 
@@ -3474,49 +3665,49 @@
      (i.e. without log)."
 
     self > 0 ifTrue:[
-        self < 10000 ifTrue:[
-            self < 10 ifTrue:[^ 0].
-            self < 100 ifTrue:[^ 1].
-            self < 1000 ifTrue:[^ 2].
-            ^ 3
-        ].
-        self < 100000000 ifTrue:[
-            self < 100000 ifTrue:[^ 4].
-            self < 1000000 ifTrue:[^ 5].
-            self < 10000000 ifTrue:[^ 6].
-            ^ 7
-        ].
-        self < 1000000000 ifTrue:[^ 8].
-        SmallInteger maxBytes == 4 ifTrue:[
-            "/ on a 32 bit machine, SmallInt cannot be larger
-            ^ 9
-        ].
-
-        "/ 64 bit machine
-        self < 100000000000000 ifTrue:[
-            self < 10000000000 ifTrue:[^ 9].
-            self < 100000000000 ifTrue:[^ 10].
-            self < 1000000000000 ifTrue:[^ 11].
-            self < 10000000000000 ifTrue:[^ 12].
-            ^ 13
-        ].   
-        self < 1000000000000000 ifTrue:[^ 14].
-        self < 10000000000000000 ifTrue:[^ 15].
-        self < 100000000000000000 ifTrue:[^ 16].
-        self < 1000000000000000000 ifTrue:[^ 17].
-        ^ 18.
+	self < 10000 ifTrue:[
+	    self < 10 ifTrue:[^ 0].
+	    self < 100 ifTrue:[^ 1].
+	    self < 1000 ifTrue:[^ 2].
+	    ^ 3
+	].
+	self < 100000000 ifTrue:[
+	    self < 100000 ifTrue:[^ 4].
+	    self < 1000000 ifTrue:[^ 5].
+	    self < 10000000 ifTrue:[^ 6].
+	    ^ 7
+	].
+	self < 1000000000 ifTrue:[^ 8].
+	SmallInteger maxBytes == 4 ifTrue:[
+	    "/ on a 32 bit machine, SmallInt cannot be larger
+	    ^ 9
+	].
+
+	"/ 64 bit machine
+	self < 100000000000000 ifTrue:[
+	    self < 10000000000 ifTrue:[^ 9].
+	    self < 100000000000 ifTrue:[^ 10].
+	    self < 1000000000000 ifTrue:[^ 11].
+	    self < 10000000000000 ifTrue:[^ 12].
+	    ^ 13
+	].
+	self < 1000000000000000 ifTrue:[^ 14].
+	self < 10000000000000000 ifTrue:[^ 15].
+	self < 100000000000000000 ifTrue:[^ 16].
+	self < 1000000000000000000 ifTrue:[^ 17].
+	^ 18.
     ].
 
     ^ self class
-        raise:#domainErrorSignal
-        receiver:self
-        selector:#intlog10
-        arguments:#()
-        errorString:'logarithm of negative integer'
+	raise:#domainErrorSignal
+	receiver:self
+	selector:#intlog10
+	arguments:#()
+	errorString:'logarithm of negative integer'
 
     "
-      99 intlog10 
-      100 intlog10  
+      99 intlog10
+      100 intlog10
       101 intlog10
       (101 log:10) floor
       120 intlog10
@@ -3534,74 +3725,76 @@
      or control systems, which represent numbers this way..."
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
     int i;
-    INT _10000000s = 0, _1000000s = 0; 
+    INT _10000000s = 0, _1000000s = 0;
     INT _100000s = 0, _10000s = 0, _1000s = 0;
     INT _100s = 0, _10s = 0, _1s = 0;
     INT b = __intVal(self);
     unsigned INT rslt;
 
     if (b <= 99999999) {
-        if (b <= 255) {
-            // the most common case: convert bytes
-            for (i=7; i>=0; i--) {
-                if (_100s >= 5)       _100s += 3; 
-                if (_10s >= 5)        _10s += 3;
-                if (_1s >= 5)         _1s += 3;
-
-                _100s    =    (_100s<<1)       | (_10s >> 3 & 1);       _100s &= 0xF;  
-                _10s     =    (_10s<<1)        | (_1s >> 3 & 1);        _10s &= 0xF; 
-                _1s      =    (_1s<<1)         | (b >> 7 & 1);          _1s &= 0xF; 
-                b <<= 1;      
-            }
-            rslt = (_100s<<8) | (_10s<<4) | _1s;
-            RETURN (__MKSMALLINT( rslt) );
-        }
-
-        for (i=26; i>=0; i--) {
-            if (_10000000s >= 5)  _10000000s += 3; 
-            if (_1000000s >= 5)   _1000000s += 3; 
-            if (_100000s >= 5)    _100000s += 3; 
-            if (_10000s >= 5)     _10000s += 3; 
-            if (_1000s >= 5)      _1000s += 3; 
-            if (_100s >= 5)       _100s += 3; 
-            if (_10s >= 5)        _10s += 3;
-            if (_1s >= 5)         _1s += 3;
-
-            _10000000s =  (_10000000s<<1)  | (_1000000s >> 3 & 1);  _10000000s &= 0xF;  
-            _1000000s =   (_1000000s<<1)   | (_100000s >> 3 & 1);   _1000000s &= 0xF;  
-            _100000s =    (_100000s<<1)    | (_10000s >> 3 & 1);    _100000s &= 0xF;  
-            _10000s  =    (_10000s<<1)     | (_1000s >> 3 & 1);     _10000s &= 0xF;  
-            _1000s   =    (_1000s<<1)      | (_100s >> 3 & 1);      _1000s &= 0xF;  
-            _100s    =    (_100s<<1)       | (_10s >> 3 & 1);       _100s &= 0xF;  
-            _10s     =    (_10s<<1)        | (_1s >> 3 & 1);        _10s &= 0xF; 
-            _1s      =    (_1s<<1)         | (b >> 26 & 1);         _1s &= 0xF; 
-            b <<= 1;      
-        }
-
-        rslt = (_10000000s<<28)
-               | (_1000000s<<24) | (_100000s<<20) | (_10000s<<16) 
-               | (_1000s<<12) | (_100s<<8) | (_10s<<4) | _1s;
-        RETURN (__MKUINT( rslt) );
+	if (b <= 255) {
+	    // the most common case: convert bytes
+	    for (i=7; i>=0; i--) {
+		if (_100s >= 5)       _100s += 3;
+		if (_10s >= 5)        _10s += 3;
+		if (_1s >= 5)         _1s += 3;
+
+		_100s    =    (_100s<<1)       | (_10s >> 3 & 1);       _100s &= 0xF;
+		_10s     =    (_10s<<1)        | (_1s >> 3 & 1);        _10s &= 0xF;
+		_1s      =    (_1s<<1)         | (b >> 7 & 1);          _1s &= 0xF;
+		b <<= 1;
+	    }
+	    rslt = (_100s<<8) | (_10s<<4) | _1s;
+	    RETURN (__MKSMALLINT( rslt) );
+	}
+
+	for (i=26; i>=0; i--) {
+	    if (_10000000s >= 5)  _10000000s += 3;
+	    if (_1000000s >= 5)   _1000000s += 3;
+	    if (_100000s >= 5)    _100000s += 3;
+	    if (_10000s >= 5)     _10000s += 3;
+	    if (_1000s >= 5)      _1000s += 3;
+	    if (_100s >= 5)       _100s += 3;
+	    if (_10s >= 5)        _10s += 3;
+	    if (_1s >= 5)         _1s += 3;
+
+	    _10000000s =  (_10000000s<<1)  | (_1000000s >> 3 & 1);  _10000000s &= 0xF;
+	    _1000000s =   (_1000000s<<1)   | (_100000s >> 3 & 1);   _1000000s &= 0xF;
+	    _100000s =    (_100000s<<1)    | (_10000s >> 3 & 1);    _100000s &= 0xF;
+	    _10000s  =    (_10000s<<1)     | (_1000s >> 3 & 1);     _10000s &= 0xF;
+	    _1000s   =    (_1000s<<1)      | (_100s >> 3 & 1);      _1000s &= 0xF;
+	    _100s    =    (_100s<<1)       | (_10s >> 3 & 1);       _100s &= 0xF;
+	    _10s     =    (_10s<<1)        | (_1s >> 3 & 1);        _10s &= 0xF;
+	    _1s      =    (_1s<<1)         | (b >> 26 & 1);         _1s &= 0xF;
+	    b <<= 1;
+	}
+
+	rslt = (_10000000s<<28)
+	       | (_1000000s<<24) | (_100000s<<20) | (_10000s<<16)
+	       | (_1000s<<12) | (_100s<<8) | (_10s<<4) | _1s;
+	RETURN (__MKUINT( rslt) );
     }
+#endif
 %}.
     ^ super asBCD.
 
     "
-      99999999 asBCD hexPrintString     
-      12812345 asBCD hexPrintString     
-      128123 asBCD hexPrintString   
-      128901 asBCD hexPrintString   
-      12890 asBCD hexPrintString    
-      1289 asBCD hexPrintString    
-      999 asBCD hexPrintString 
-      256 asBCD hexPrintString  
-      255 asBCD hexPrintString  
-      128 asBCD hexPrintString 
-      162 asBCD hexPrintString 
-
-      999999999 asBCD hexPrintString     
-      128123456 asBCD hexPrintString     
+      99999999 asBCD hexPrintString
+      12812345 asBCD hexPrintString
+      128123 asBCD hexPrintString
+      128901 asBCD hexPrintString
+      12890 asBCD hexPrintString
+      1289 asBCD hexPrintString
+      999 asBCD hexPrintString
+      256 asBCD hexPrintString
+      255 asBCD hexPrintString
+      128 asBCD hexPrintString
+      162 asBCD hexPrintString
+
+      999999999 asBCD hexPrintString
+      128123456 asBCD hexPrintString
 
     "
 !
@@ -3640,6 +3833,9 @@
      upon the printOn: method."
 
 %{  /* NOCONTEXT */
+#ifdef __JAVA__
+    return context._RETURN( new STString( java.lang.Long.toString(self.longValue()) ));
+#else
     char buffer[30];    /* enough for 64 bit machines */
     char *cp;
     OBJ newString = nil;
@@ -3648,18 +3844,18 @@
     int len;
 
     if (self == __MKSMALLINT(0)) {
-        RETURN (@global(ZeroString));
+	RETURN (@global(ZeroString));
 //        RETURN (__MKSTRING_L("0", 1));
     }
     myValue = __intVal(self);
-#ifdef SLOW_CODE
+# ifdef SLOW_CODE
     /*
      * this takes twice as long as the code below ...
      * (printf is soooo slow)
      */
 
     /*
-     * PROTECT_REGISTERS: 
+     * PROTECT_REGISTERS:
      * actually only needed on sparc: since thisContext is
      * in a global register, which gets destroyed by printf,
      * manually save it here - very stupid ...
@@ -3669,28 +3865,29 @@
     __END_PROTECT_REGISTERS__
 
     if (len >= 0 && len <= sizeof(buffer)) {
-        newString = __MKSTRING_L(buffer, len);
+	newString = __MKSTRING_L(buffer, len);
     }
-#else
+# else
     if (myValue < 0) {
-        negative = 1;
-        myValue = -myValue;
+	negative = 1;
+	myValue = -myValue;
     }
     cp = buffer + sizeof(buffer) - 1;
     *cp-- = '\0';
     while (myValue != 0) {
-        *cp = '0' + (myValue % 10);
-        myValue = myValue / 10;
-        cp--;
+	*cp = '0' + (myValue % 10);
+	myValue = myValue / 10;
+	cp--;
     }
     if (negative) {
-        *cp-- = '-';
+	*cp-- = '-';
     }
     newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp));
-#endif
+# endif
     if (newString != nil) {
-        RETURN (newString);
+	RETURN (newString);
     }
+#endif /* not JAVA */
 %}.
     "/ only arrive here,
     "/  when having memory problems (i.e. no space for string) ...
@@ -3706,7 +3903,7 @@
     Time millisecondsToRun:[ 1000000 timesRepeat:[ 1234 printString ]]         130 140 130 130 130
     Time millisecondsToRun:[ 1000000 timesRepeat:[ 12 printString ]]           130 120 120 120 110
     Time millisecondsToRun:[ 1000000 timesRepeat:[ 5 printString ]]            110 110 100 110 90
-    Time millisecondsToRun:[ 1000000 timesRepeat:[ 0 printString ]]             60 
+    Time millisecondsToRun:[ 1000000 timesRepeat:[ 0 printString ]]             60
     "
 !
 
@@ -3716,6 +3913,7 @@
     |s|
 
 %{
+#ifndef __JAVA__
     char buffer[64+3];  /* for 64bit machines, base 2, plus sign, plus 0-byte */
     char *cp;
     OBJ newString;
@@ -3724,76 +3922,77 @@
     INT __base;
 
     if (__isSmallInteger(base)) {
-        if (self == __MKSMALLINT(0)) {
-            RETURN (__MKSTRING_L("0", 1));
-        }
-        myValue = __intVal(self);
-        __base = __intVal(base);
-
-#ifdef SLOW_CODE
-        /* disabled, because printf is slower than the code below */
-
-        switch (__base) {
-            case 10:
-                format = "%"_ld_"";
-                break;
-            case 16:
-                format = "%"_lx_"";
-                break;
-            case 8:
-                format = "%"_lo_"";
-                break;
-        }
-
-        if (format) {
-            /*
-             * actually only needed on sparc: since thisContext is
-             * in a global register, which gets destroyed by printf,
-             * manually save it here - very stupid ...
-             */
-            __BEGIN_PROTECT_REGISTERS__
-
-            len = snprintf(buffer, sizeof(buffer), format, (long)myValue);
-
-            __END_PROTECT_REGISTERS__
-
-            if (len > 0 && len <= sizeof(buffer)) {
-                newString = __MKSTRING_L(buffer, len);
-                if (newString != nil) {
-                    RETURN (newString);
-                }
-            }
-        }
-#else
-        if ((__base <= 36) && (__base > 1)) {
-            if (myValue < 0) {
-                negative = 1;
-                myValue = -myValue;
-            }
-            cp = buffer + sizeof(buffer) - 1;
-            *cp-- = '\0';
-            while (myValue != 0) {
-                int digit;
-
-                digit = myValue % __base;
-                if (digit <= 9) {
-                    *cp = '0' + digit;
-                } else {
-                    *cp = 'A' + digit - 10;
-                }
-                myValue = myValue / __base;
-                cp--;
-            }
-            if (negative) {
-                *cp-- = '-';
-            }
-            newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp));
-            if (newString != nil) {
-                RETURN (newString);
-            }
-        }
-#endif
+	if (self == __MKSMALLINT(0)) {
+	    RETURN (__MKSTRING_L("0", 1));
+	}
+	myValue = __intVal(self);
+	__base = __intVal(base);
+
+# ifdef SLOW_CODE
+	/* disabled, because printf is slower than the code below */
+
+	switch (__base) {
+	    case 10:
+		format = "%"_ld_"";
+		break;
+	    case 16:
+		format = "%"_lx_"";
+		break;
+	    case 8:
+		format = "%"_lo_"";
+		break;
+	}
+
+	if (format) {
+	    /*
+	     * actually only needed on sparc: since thisContext is
+	     * in a global register, which gets destroyed by printf,
+	     * manually save it here - very stupid ...
+	     */
+	    __BEGIN_PROTECT_REGISTERS__
+
+	    len = snprintf(buffer, sizeof(buffer), format, (long)myValue);
+
+	    __END_PROTECT_REGISTERS__
+
+	    if (len > 0 && len <= sizeof(buffer)) {
+		newString = __MKSTRING_L(buffer, len);
+		if (newString != nil) {
+		    RETURN (newString);
+		}
+	    }
+	}
+# else
+	if ((__base <= 36) && (__base > 1)) {
+	    if (myValue < 0) {
+		negative = 1;
+		myValue = -myValue;
+	    }
+	    cp = buffer + sizeof(buffer) - 1;
+	    *cp-- = '\0';
+	    while (myValue != 0) {
+		int digit;
+
+		digit = myValue % __base;
+		if (digit <= 9) {
+		    *cp = '0' + digit;
+		} else {
+		    *cp = 'A' + digit - 10;
+		}
+		myValue = myValue / __base;
+		cp--;
+	    }
+	    if (negative) {
+		*cp-- = '-';
+	    }
+	    newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp));
+	    if (newString != nil) {
+		RETURN (newString);
+	    }
+	}
+# endif
     }
+#endif /* not JAVA */
 %}.
     "/ arrive here, for bad base,
     "/ or when having memory problems (i.e. no space for string) ...
@@ -3844,39 +4043,41 @@
      Please use the printf: method, which is safe as it is completely implemented in Smalltalk."
 
 %{  /* STACK: 400 */
+#ifndef __JAVA__
     char buffer[256];
     OBJ s;
     int len;
 
     if (__isStringLike(formatString)) {
-        /*
-         * actually only needed on sparc: since thisContext is
-         * in a global register, which gets destroyed by printf,
-         * manually save it here - very stupid ...
-         */
-        __BEGIN_PROTECT_REGISTERS__
-
-        len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __intVal(self));
-
-        __END_PROTECT_REGISTERS__
-
-        if (len < 0) goto fail;
-
-        s = __MKSTRING_L(buffer, len);
-        if (s != nil) {
-            RETURN (s);
-        }
+	/*
+	 * actually only needed on sparc: since thisContext is
+	 * in a global register, which gets destroyed by printf,
+	 * manually save it here - very stupid ...
+	 */
+	__BEGIN_PROTECT_REGISTERS__
+
+	len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __intVal(self));
+
+	__END_PROTECT_REGISTERS__
+
+	if (len < 0) goto fail;
+
+	s = __MKSTRING_L(buffer, len);
+	if (s != nil) {
+	    RETURN (s);
+	}
     }
 fail: ;
+#endif /* not JAVA */
 %}.
     self primitiveFailed
 
     "
-        123 printfPrintString:'%%d -> %d'
-        123 printfPrintString:'%%6d -> %6d'   
-        123 printfPrintString:'%%x -> %x'     
-        123 printfPrintString:'%%4x -> %4x'   
-        123 printfPrintString:'%%04x -> %04x' 
+	123 printfPrintString:'%%d -> %d'
+	123 printfPrintString:'%%6d -> %6d'
+	123 printfPrintString:'%%x -> %x'
+	123 printfPrintString:'%%4x -> %4x'
+	123 printfPrintString:'%%04x -> %04x'
     "
 ! !
 
@@ -3913,13 +4114,15 @@
      This is of course not always correct, but allows for C/Java behavior to be emulated."
 
 %{  /* NOCONTEXT */
+#ifndef _JAVA__
     INT sum;
 
     sum =  __unsignedLongIntVal(self) + __unsignedLongIntVal(aNumber);
-#if __POINTER_SIZE__ == 8
+# if __POINTER_SIZE__ == 8
     sum &= 0xFFFFFFFFL;
-#endif
+# endif
     RETURN ( __MKUINT(sum));
+#endif /* not JAVA */
 %}.
     self primitiveFailed
 
@@ -3938,6 +4141,7 @@
      and can therefore speed things up by not going through LargeIntegers."
 
 %{  /* NOCONTEXT */
+#ifndef _JAVA__
 
     if (__isSmallInteger(aNumber)) {
 	INT sum;
@@ -3949,6 +4153,7 @@
 	}
 	RETURN ( __mkSmallInteger(sum));
     }
+#endif
 %}.
     self primitiveFailed
 
@@ -3970,6 +4175,7 @@
      and can therefore speed things up by not going through LargeIntegers."
 
 %{  /* NOCONTEXT */
+#ifndef _JAVA__
 
     if (__isSmallInteger(aNumber)) {
 	INT diff;
@@ -3981,6 +4187,7 @@
 	}
 	RETURN ( __mkSmallInteger(diff));
     }
+#endif
 %}.
     self primitiveFailed
 
@@ -4002,6 +4209,7 @@
      and can therefore speed things up by not going through LargeIntegers."
 
 %{  /* NOCONTEXT */
+#ifndef _JAVA__
 
     INT myValue, otherValue;
     unsigned INT productLow, productHi;
@@ -4019,25 +4227,25 @@
      * (took me a while to find this out :-(
      * (try 10000 * 10000)
      */
-#if defined(__sparc__) && defined(__GNUC__) && (__GNUC__ >= 2)
-# define USE_LONGLONG_FOR_MUL
-#endif
-
-#if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 2)
-# define USE_LONGLONG_FOR_MUL
-#endif
+# if defined(__sparc__) && defined(__GNUC__) && (__GNUC__ >= 2)
+#  define USE_LONGLONG_FOR_MUL
+# endif
+
+# if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 2)
+#  define USE_LONGLONG_FOR_MUL
+# endif
 
     if (__isSmallInteger(aNumber)) {
 	myValue = __intVal(self);
 	otherValue = __intVal(aNumber);
 
-#if defined(USE_LONGLONG_FOR_MUL)
+# if defined(USE_LONGLONG_FOR_MUL)
 	{
-# if defined(__alpha__) && !defined(__alpha64__)
-#  define LONGLONG      INT64
-# else
-#  define LONGLONG      long long
-# endif
+#  if defined(__alpha__) && !defined(__alpha64__)
+#   define LONGLONG      INT64
+#  else
+#   define LONGLONG      long long
+#  endif
 	    LONGLONG product;
 
 	    product = (LONGLONG)myValue * (LONGLONG)otherValue;
@@ -4046,7 +4254,7 @@
 	    }
 	    RETURN ( __mkSmallInteger((INT)(product & _MAX_INT)));
 	}
-#else /* no long-long */
+# else /* no long-long */
 	negative = 1;
 	if (myValue < 0) {
 	    negative = -1;
@@ -4057,21 +4265,21 @@
 	    otherValue = -otherValue;
 	}
 
-# if defined(__GNUC__) && defined(__mc68k__)
+#  if defined(__GNUC__) && defined(__mc68k__)
 	asm ("mulu%.l %3,%1:%0"
 		: "=d"  ((unsigned long)(productLow)),
 		  "=d"  ((unsigned long)(productHi))
 		: "%0"  ((unsigned long)(myValue)),
 		  "dmi" ((unsigned long)(otherValue)));
-# else
-#  if defined (__GNUC__) && defined(__i386__)
+#  else
+#   if defined (__GNUC__) && defined(__i386__)
 	asm ("mull %3"
 		: "=a"  ((unsigned long)(productLow)),
 		  "=d"  ((unsigned long)(productHi))
 		: "%0"  ((unsigned long)(myValue)),
 		  "rm"  ((unsigned long)(otherValue)));
-#  else
-#   if defined(WIN32) && defined(__BORLANDC__)
+#   else
+#    if defined(WIN32) && defined(__BORLANDC__)
 	asm {
 	    mov   eax, myValue
 	    mov   edx, otherValue
@@ -4079,7 +4287,7 @@
 	    mov   productLow, eax
 	    mov   productHi, edx
 	}
-#   else /* generic */
+#    else /* generic */
 	{
 	    unsigned INT pHH, pHL, pLH, pLL;
 	    unsigned INT low1, low2, hi1, hi2;
@@ -4092,19 +4300,19 @@
 	     * (or at least 32*32 with Overflow check)
 	     * - need more assembler (inline) functions here
 	     */
-#    if __POINTER_SIZE__ == 8
+#     if __POINTER_SIZE__ == 8
 	    low1 = low32Bits((unsigned INT)myValue);
 	    hi1 = hi32Bits((unsigned INT)myValue);
 	    low2 = low32Bits((unsigned INT)otherValue);
 	    hi2 = hi32Bits((unsigned INT)otherValue);
-#     define LLMASK 0xC000000000000000L
-#    else
+#      define LLMASK 0xC000000000000000L
+#     else
 	    low1 = low16Bits((unsigned INT)myValue);
 	    hi1 = hi16Bits((unsigned INT)myValue);
 	    low2 = low16Bits((unsigned INT)otherValue);
 	    hi2 = hi16Bits((unsigned INT)otherValue);
-#     define LLMASK 0xC0000000
-#    endif
+#      define LLMASK 0xC0000000
+#     endif
 
 	    pLH = low1 * hi2;
 	    pHL = hi1 * low2;
@@ -4131,26 +4339,27 @@
 	     *   pLL                   |--------|--------|
 	     */
 
-#    if __POINTER_SIZE__ == 8
+#     if __POINTER_SIZE__ == 8
 	    t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL);
 	    productLow = (t << 32) + low32Bits(pLL);
 	    productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH);
-#    else
+#     else
 	    t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL);
 	    productLow = (t << 16) + low16Bits(pLL);
 	    productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH);
-#    endif
+#     endif
 	}
-#   endif /* ! WIN32 */
-#  endif /* ! (__GNUC__ && __i386__) */
-# endif /* ! (__GNUC__ && __mc68k__) */
+#    endif /* ! WIN32 */
+#   endif /* ! (__GNUC__ && __i386__) */
+#  endif /* ! (__GNUC__ && __mc68k__) */
 
 	if (negative < 0) {
 	    RETURN ( __mkSmallInteger(-(INT)(productLow & _MAX_INT)));
 	}
 	RETURN ( __mkSmallInteger((INT)(productLow & _MAX_INT)));
-#endif /* ! USE_LONGLONG */
+# endif /* ! USE_LONGLONG */
     }
+#endif /* not JAVA */
 %}.
 
     self primitiveFailed
@@ -4171,14 +4380,16 @@
      (changes the sign)"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
     unsigned INT v;
 
     v = __intVal(self);
     v = ~v;
-#if __POINTER_SIZE__ == 8
+# if __POINTER_SIZE__ == 8
     v &= 0xFFFFFFFFL;
+# endif
+    RETURN ( __MKUINT(v) );
 #endif
-    RETURN ( __MKUINT(v) );
 %}.
     ^ self primitiveFailed
 
@@ -4196,6 +4407,7 @@
      Useful for crypt algorithms, or to emulate C/Java semantics."
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
 
     unsigned INT bits;
     int count;
@@ -4210,11 +4422,12 @@
 	} else {
 	    bits = (bits >> (-count)) | (bits << (32-(-count)));
 	}
-#if __POINTER_SIZE__ == 8
+# if __POINTER_SIZE__ == 8
 	bits &= 0xFFFFFFFFL;
-#endif
+# endif
 	RETURN (__MKUINT(bits));
     }
+#endif
 %}.
     ^ self primitiveFailed
 
@@ -4241,6 +4454,7 @@
      or to emulate C/Java semantics."
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
 
     INT bits, count;
 
@@ -4256,11 +4470,12 @@
 	} else {
 	    bits = bits >> (-count);
 	}
-#if __POINTER_SIZE__ == 8
+# if __POINTER_SIZE__ == 8
 	bits &= 0xFFFFFFFFL;
-#endif
+# endif
 	RETURN (__MKINT(bits));
     }
+#endif
 %}.
     ^ self primitiveFailed
 
@@ -4280,13 +4495,15 @@
      This is of course not always correct, but allows for C/Java behavior to be emulated."
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
     INT rslt;
 
     rslt =  __unsignedLongIntVal(self) ^ __unsignedLongIntVal(aNumber);
-#if __POINTER_SIZE__ == 8
+# if __POINTER_SIZE__ == 8
     rslt &= 0xFFFFFFFFL;
+# endif
+    RETURN ( __MKUINT(rslt));
 #endif
-    RETURN ( __MKUINT(rslt));
 %}.
     self primitiveFailed
 
@@ -4304,6 +4521,7 @@
      or to emulate C/Java semantics."
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
 
     unsigned INT bits;
     INT count;
@@ -4320,11 +4538,12 @@
 	} else {
 	    bits = bits >> (-count);
 	}
-#if __POINTER_SIZE__ == 8
+# if __POINTER_SIZE__ == 8
 	bits &= 0xFFFFFFFFL;
-#endif
+# endif
 	RETURN (__MKUINT(bits));
     }
+#endif
 %}.
     ^ self primitiveFailed
 
@@ -4348,30 +4567,32 @@
      - reimplemented here for speed"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
 
     if (__bothSmallInteger(min, max)) {
-#if TAG_INT == 1
-        // tag bit does not change the magnitude order
-        if ((INT)self < (INT)(min)) {
-             RETURN ( false );
-        }
-        if ((INT)self > (INT)(max)) {
-             RETURN ( false );
-        }
-        RETURN ( true );
-#else
-        REGISTER INT selfVal;
-
-        selfVal = __intVal(self);
-        if (selfVal < __intVal(min)) {
-             RETURN ( false );
-        }
-        if (selfVal > __intVal(max)) {
-             RETURN ( false );
-        }
-        RETURN ( true );
+# if TAG_INT == 1
+	// tag bit does not change the magnitude order
+	if ((INT)self < (INT)(min)) {
+	     RETURN ( false );
+	}
+	if ((INT)self > (INT)(max)) {
+	     RETURN ( false );
+	}
+	RETURN ( true );
+# else
+	REGISTER INT selfVal;
+
+	selfVal = __intVal(self);
+	if (selfVal < __intVal(min)) {
+	     RETURN ( false );
+	}
+	if (selfVal > __intVal(max)) {
+	     RETURN ( false );
+	}
+	RETURN ( true );
+# endif
+    }
 #endif
-    }
 %}.
     (self < min) ifTrue:[^ false].
     (self > max) ifTrue:[^ false].
@@ -4382,8 +4603,9 @@
     "return true, if the receiver is even"
 
 %{  /* NOCONTEXT */
-
+#ifndef __JAVA__
     RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? false : true );
+#endif
 %}.
     ^ super even
 !
@@ -4417,12 +4639,16 @@
      reimplemented here for speed"
 
 %{  /* NOCONTEXT */
-
-#if TAG_INT == 1
+#ifdef __JAVA__
+    return context._RETURN( self.ltP(0) );
+    /* NOTREACHED */
+#else
+# if TAG_INT == 1
     /* tag bit does not change sign */
     RETURN ( ((INT)(self) < 0) ? true : false );
-#else
+# else
     RETURN ( (__intVal(self) < 0) ? true : false );
+# endif
 #endif
 %}.
     ^ self < 0
@@ -4433,6 +4659,7 @@
      Useful for padding."
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
     INT x;
 
     x = __intVal(self) - 1;
@@ -4441,11 +4668,14 @@
     x |= (x >> 4);
     x |= (x >> 8);
     x |= (x >> 16);
-#if __POINTER_SIZE__ == 8
+# if __POINTER_SIZE__ == 8
     x |= (x >> 32);
+# endif
+    RETURN (__MKINT(x + 1));
 #endif
-    RETURN (__MKINT(x + 1));
-%}
+%}.
+    ^ super nextPowerOf2
+
     "
      1 nextPowerOf2
      2 nextPowerOf2
@@ -4457,9 +4687,9 @@
      8 nextPowerOf2
 
      22 nextPowerOf2
-     10 factorial nextPowerOf2 
-     20 factorial nextPowerOf2 
-     100 factorial nextPowerOf2 
+     10 factorial nextPowerOf2
+     20 factorial nextPowerOf2
+     100 factorial nextPowerOf2
     "
 !
 
@@ -4467,8 +4697,9 @@
     "return true, if the receiver is odd"
 
 %{  /* NOCONTEXT */
-
+#ifndef __JAVA__
     RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? true : false );
+#endif
 %}.
     ^ super odd
 
@@ -4480,9 +4711,10 @@
      Undefined for negative values (smalltalk does not require the machine to use 2's complement)"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
 
     // tricky, but very fast (google for it, to understand)
-#if __POINTER_SIZE__ == 4
+# if __POINTER_SIZE__ == 4
     unsigned int v = __intVal(self);
 
     v ^= v >> 16;
@@ -4490,6 +4722,7 @@
     v ^= v >> 4;
     v &= 0xf;
     RETURN ( ( (0x6996 >> v) & 1 ) ? true : false );
+# endif
 #endif
 %}.
     ^ super parityOdd
@@ -4516,12 +4749,16 @@
      reimplemented here for speed"
 
 %{  /* NOCONTEXT */
-
-#if TAG_INT == 1
+#ifdef __JAVA__
+    return context._RETURN( (self.ltP(0) == STObject.True) ? STObject.False : STObject.True);
+#else
+
+# if TAG_INT == 1
     /* tag bit does not change sign */
     RETURN ( ((INT)(self) >= 0) ? true : false );
-#else
+# else
     RETURN ( (__intVal(self) >= 0) ? true : false );
+# endif
 #endif
 %}.
     ^ super positive
@@ -4533,6 +4770,7 @@
      reimplemented here for speed"
 
 %{  /* NOCONTEXT */
+#ifndef __JAVA__
 
     INT val = __intVal(self);
 
@@ -4543,6 +4781,7 @@
 	RETURN ( __mkSmallInteger(1) );
     }
     RETURN ( __mkSmallInteger(0) );
+#endif
 %}.
     ^ super sign
 !
@@ -4552,31 +4791,33 @@
      reimplemented here for speed"
 
 %{  /* NOCONTEXT */
-
-#if TAG_INT == 1
+#ifndef __JAVA__
+
+# if TAG_INT == 1
     /* tag bit does not change sign */
     RETURN ( ((INT)(self) > (INT)(__mkSmallInteger(0))) ? true : false );
-#else
+# else
     RETURN ( (__intVal(self) > 0) ? true : false );
+# endif
 #endif
 %}.
     ^ super strictlyPositive
 
     "
-     0 strictlyPositive  
-     1 strictlyPositive   
-     -1 strictlyPositive  
+     0 strictlyPositive
+     1 strictlyPositive
+     -1 strictlyPositive
     "
 ! !
 
 !SmallInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.227 2015-03-26 16:23:23 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.231 2015-04-19 22:55:08 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.227 2015-03-26 16:23:23 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.231 2015-04-19 22:55:08 cg Exp $'
 ! !