{
long numerator = (arg_fixnum (1));
long denominator = (arg_fixnum (2));
- FIXNUM_RESULT
- ((denominator > 0)
- ? ((numerator < 0)
- ? (- ((- numerator) / denominator))
- : (numerator / denominator))
- : (denominator < 0)
- ? ((numerator < 0)
- ? ((- numerator) / (- denominator))
- : (- (numerator / (- denominator))))
- : (error_bad_range_arg (2), 0));
+ FIXNUM_RESULT (numerator == 0
+ ? (error_bad_range_arg (2), 0)
+ : FIXNUM_QUOTIENT (numerator, denominator));
}
}
{
long numerator = (arg_fixnum (1));
long denominator = (arg_fixnum (2));
- FIXNUM_RESULT
- ((denominator > 0)
- ? ((numerator < 0)
- ? (- ((- numerator) % denominator))
- : (numerator % denominator))
- : (denominator < 0)
- ? ((numerator < 0)
- ? (- ((- numerator) % (- denominator)))
- : (numerator % (- denominator)))
- : (error_bad_range_arg (2), 0));
+ FIXNUM_RESULT (numerator == 0
+ ? (error_bad_range_arg (2), 0)
+ : FIXNUM_REMAINDER (numerator, denominator));
}
}
long y = (arg_fixnum (2));
unsigned long z;
- if (y < 0)
- z = (((-y) > ((long) DATUM_LENGTH)) ? 0 : (x >> (-y)));
- else
- z = ((y > ((long) DATUM_LENGTH)) ? 0 : (x << y));
- LOGICAL_RESULT (z);
+ LOGICAL_RESULT (FIXNUM_LSH (x, y));
}
}
--- /dev/null
+/* -*-C-*-
+
+Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
+ 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+ 2006, 2007, 2008, 2009, 2010, 2011 Massachusetts Institute of
+ Technology
+
+This file is part of MIT/GNU Scheme.
+
+MIT/GNU Scheme is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+MIT/GNU Scheme is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with MIT/GNU Scheme; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
+USA.
+
+*/
+
+#ifndef SCM_FIXNUM_H_INCLUDED
+#define SCM_FIXNUM_H_INCLUDED 1
+
+#define MAX_BIT_SHIFT DATUM_LENGTH
+
+#define RIGHT_SHIFT_UNSIGNED(source, number) \
+ (((number) > MAX_BIT_SHIFT) \
+ ? 0 \
+ : ((((unsigned long) (source)) & DATUM_MASK) >> (number)))
+
+#define RIGHT_SHIFT(source, number) \
+ (((number) > MAX_BIT_SHIFT) \
+ ? 0 \
+ : ((source) >> (number)))
+
+#define LEFT_SHIFT(source, number) \
+ (((number) > MAX_BIT_SHIFT) \
+ ? 0 \
+ : ((source) << (number)))
+
+#define FIXNUM_LSH(source, number) \
+ (((number) >= 0) \
+ ? (LEFT_SHIFT (source, number)) \
+ : (RIGHT_SHIFT_UNSIGNED (source, (- (number)))))
+
+#define FIXNUM_REMAINDER(source1, source2) \
+ (((source2) > 0) \
+ ? (((source1) >= 0) \
+ ? ((source1) % (source2)) \
+ : (- ((- (source1)) % (source2)))) \
+ : (((source1) >= 0) \
+ ? ((source1) % (- (source2))) \
+ : (- ((- (source1)) % (- (source2))))))
+
+#define FIXNUM_QUOTIENT(source1, source2) \
+ (((source2) > 0) \
+ ? (((source1) >= 0) \
+ ? ((source1) / (source2)) \
+ : (- ((- (source1)) / (source2)))) \
+ : (((source1) >= 0) \
+ ? (- ((source1) / (- (source2)))) \
+ : ((- (source1)) / (- (source2)))))
+
+#endif /* !SCM_FIXNUM_H_INCLUDED */
#include "const.h"
#include "object.h"
#include "sdata.h"
+#include "fixnum.h"
#include "errors.h"
#include "stack.h"
#include "interp.h"
CACHE_VARIABLES (); \
JUMP (IICdest); \
} while (false)
-\f
-#define MAX_BIT_SHIFT DATUM_LENGTH
-
-#define RIGHT_SHIFT_UNSIGNED(source, number) \
- (((number) > MAX_BIT_SHIFT) \
- ? 0 \
- : ((((unsigned long) (source)) & DATUM_MASK) >> (number)))
-
-#define RIGHT_SHIFT(source, number) \
- (((number) > MAX_BIT_SHIFT) \
- ? 0 \
- : ((source) >> (number)))
-
-#define LEFT_SHIFT(source, number) \
- (((number) > MAX_BIT_SHIFT) \
- ? 0 \
- : ((source) << (number)))
-
-#define FIXNUM_LSH(source, number) \
- (((number) >= 0) \
- ? (LEFT_SHIFT (source, number)) \
- : (RIGHT_SHIFT_UNSIGNED (source, (- (number)))))
-
-#define FIXNUM_REMAINDER(source1, source2) \
- (((source2) > 0) \
- ? (((source1) >= 0) \
- ? ((source1) % (source2)) \
- : (- ((- (source1)) % (source2)))) \
- : (((source1) >= 0) \
- ? ((source1) % (- (source2))) \
- : (- ((- (source1)) % (- (source2))))))
-
-#define FIXNUM_QUOTIENT(source1, source2) \
- (((source2) > 0) \
- ? (((source1) >= 0) \
- ? ((source1) / (source2)) \
- : (- ((- (source1)) / (source2)))) \
- : (((source1) >= 0) \
- ? (- ((source1) / (- (source2)))) \
- : ((- (source1)) / (- (source2)))))
#define INTERRUPT_CHECK(code, entry_point) do \
{ \
/* Scheme Virtual Machine version 1 */
#include "scheme.h"
+#include "fixnum.h"
#include "svm1-defns.h"
#include "cmpintmd/svm1.h"
#define SIGNED_BINARY(op, a1, a2) \
(FROM_SIGNED ((TO_SIGNED (a1)) op (TO_SIGNED (a2))))
+#define SIGNED_BINFUNC(func, a1, a2) \
+ (FROM_SIGNED (func (TO_SIGNED (a1), TO_SIGNED (a2))))
+
#if 0
/* The above definition isn't guaranteed to work in ANSI C, but in
practice it usually does. Here's an alternative that should always
#define FDECR(x) ((x) - 1.0)
#define WABS(x) (SIGNED_UNARY (labs, (x)))
-#define OP_ADD(x, y) ((x) + (y))
-#define OP_SUBTRACT(x, y) ((x) - (y))
-#define OP_MULTIPLY(x, y) ((x) * (y))
-#define OP_DIVIDE(x, y) ((x) / (y))
-#define OP_REMAINDER(x, y) ((x) % (y))
+#define FOP_ADD(x, y) ((x) + (y))
+#define FOP_SUBTRACT(x, y) ((x) - (y))
+#define FOP_MULTIPLY(x, y) ((x) * (y))
+#define FOP_DIVIDE(x, y) ((x) / (y))
+
+#define OP_ADD(x, y) (SIGNED_BINARY (+, (x), (y)))
+#define OP_SUBTRACT(x, y) (SIGNED_BINARY (-, (x), (y)))
+#define OP_MULTIPLY(x, y) (SIGNED_BINARY (*, (x), (y)))
+#define OP_DIVIDE(x, y) (SIGNED_BINFUNC (FIXNUM_QUOTIENT, (x), (y)))
+#define OP_REMAINDER(x, y) (SIGNED_BINFUNC (FIXNUM_REMAINDER, (x), (y)))
#define OP_AND(x, y) ((x) & (y))
#define OP_ANDC(x, y) ((x) &~ (y))
#define OP_OR(x, y) ((x) | (y))
{
DECODE_SVM1_INST_LSH (target, source1, source2);
long n = (TO_SIGNED (WREG_REF (source2)));
- WREG_SET (target,
- ((n < 0)
- ? ((WREG_REF (source1)) >> (- n))
- : ((WREG_REF (source1)) << n)));
+ WREG_SET (target, FIXNUM_LSH((WREG_REF (source1)), n));
NEXT_PC;
}
NEXT_PC; \
}
-DEFINE_BINARY_FR (add_fr, ADD_FR, OP_ADD)
-DEFINE_BINARY_FR (subtract_fr, SUBTRACT_FR, OP_SUBTRACT)
-DEFINE_BINARY_FR (multiply_fr, MULTIPLY_FR, OP_MULTIPLY)
-DEFINE_BINARY_FR (divide, DIVIDE, OP_DIVIDE)
+DEFINE_BINARY_FR (add_fr, ADD_FR, FOP_ADD)
+DEFINE_BINARY_FR (subtract_fr, SUBTRACT_FR, FOP_SUBTRACT)
+DEFINE_BINARY_FR (multiply_fr, MULTIPLY_FR, FOP_MULTIPLY)
+DEFINE_BINARY_FR (divide, DIVIDE, FOP_DIVIDE)
DEFINE_BINARY_FR (atan2, ATAN2, atan2)
\f
/* Address decoders */