;;;; Fixnums
(define-primitives
- (fix:fixnum? fixnum? 1)
- (fixnum? fixnum? 1)
- (index-fixnum? index-fixnum? 1)
- (fix:zero? zero-fixnum? 1)
- (fix:negative? negative-fixnum? 1)
- (fix:positive? positive-fixnum? 1)
- (fix:= equal-fixnum? 2)
- (fix:< less-than-fixnum? 2)
- (fix:> greater-than-fixnum? 2)
- (fix:1+ one-plus-fixnum 1)
- (fix:-1+ minus-one-plus-fixnum 1)
- (fix:+ plus-fixnum 2)
- (fix:- minus-fixnum 2)
- (fix:* multiply-fixnum 2)
(fix:divide divide-fixnum 2)
- (fix:quotient fixnum-quotient 2)
- (fix:remainder fixnum-remainder 2)
(fix:gcd gcd-fixnum 2)
- (fix:andc fixnum-andc 2)
- (fix:and fixnum-and 2)
- (fix:or fixnum-or 2)
- (fix:xor fixnum-xor 2)
- (fix:not fixnum-not 1)
- (fix:lsh fixnum-lsh 2))
+ (fixnum? fixnum? 1)
+ (fx* multiply-fixnum 2)
+ (fx+ plus-fixnum 2)
+ (fx- minus-fixnum 2)
+ (fx<? less-than-fixnum? 2)
+ (fx=? equal-fixnum? 2)
+ (fx>? greater-than-fixnum? 2)
+ (fxand fixnum-and 2)
+ (fxandc fixnum-andc 2)
+ (fxarithmetic-shift fixnum-lsh 2)
+ (fxdecr minus-one-plus-fixnum 1)
+ (fxincr one-plus-fixnum 1)
+ (fxior fixnum-or 2)
+ (fxnegative? negative-fixnum? 1)
+ (fxnot fixnum-not 1)
+ (fxpositive? positive-fixnum? 1)
+ (fxquotient fixnum-quotient 2)
+ (fxremainder fixnum-remainder 2)
+ (fxxor fixnum-xor 2)
+ (fxzero? zero-fixnum? 1)
+ (non-negative-fixnum? index-fixnum? 1))
+
+(define (fx<=? n m) (not (fx>? n m)))
+(define (fx>=? n m) (not (fx<? n m)))
+(define (fxabs n) (if (fx<? n 0) (fx- 0 n) n))
+(define (fxarithmetic-shift-right n m) (fxarithmetic-shift n (fx- 0 m)))
+(define (fxmax n m) (if (fx>? n m) n m))
+(define (fxmin n m) (if (fx<? n m) n m))
+(define (fxneg n) (fx- 0 n))
+(define (fxsquare n) (fx* n n))
(define (positive-fixnum? object)
(and (fixnum? object)
- (fix:positive? object)))
+ (fxpositive? object)))
(define (negative-fixnum? object)
(and (fixnum? object)
- (fix:negative? object)))
-
-(define (non-negative-fixnum? object)
- (and (fixnum? object)
- (not (fix:negative? object))))
+ (fxnegative? object)))
(define (non-positive-fixnum? object)
(and (fixnum? object)
- (not (fix:positive? object))))
+ (not (fxpositive? object))))
\f
(define (guarantee-limited-index-fixnum object limit #!optional caller)
(guarantee index-fixnum? object caller)
(if (not (fix:< object limit))
(error:bad-range-argument object caller)))
-(define (fix:<= n m) (not (fix:> n m)))
-(define (fix:>= n m) (not (fix:< n m)))
-(define (fix:min n m) (if (fix:< n m) n m))
-(define (fix:max n m) (if (fix:> n m) n m))
-
-(define (fix:largest-value)
- (force largest-fixnum-promise))
-
-(define largest-fixnum-promise
- (delay
- (let loop ((n 1))
- (if (fix:fixnum? n)
- (loop (* n 2))
- (let ((n (- n 1)))
- (if (not (fix:fixnum? n))
- (error "Unable to compute largest fixnum:" n))
- n)))))
-
-(define (fix:smallest-value)
- (force smallest-fixnum-promise))
-
-(define smallest-fixnum-promise
- (delay
- (let loop ((n -1))
- (if (fix:fixnum? n)
- (loop (* n 2))
- (let ((n (quotient n 2)))
- (if (not (fix:fixnum? n))
- (error "Unable to compute smallest fixnum:" n))
- n)))))
+(define (fix:largest-value) fx-greatest)
+(define (fix:smallest-value) fx-least)
+
+(define fx-width)
+(define fx-greatest)
+(define fx-least)
+(add-boot-init!
+ (lambda ()
+ (let loop ((n 1) (w 1))
+ (if (fixnum? n)
+ (loop (int:* n 2) (int:+ w 1))
+ (let ((n (int:- n 1)))
+ (if (not (fixnum? n))
+ (error "Unable to compute largest fixnum:" n))
+ (set! fx-greatest n)
+ (set! fx-width w))))
+ (let loop ((n -1))
+ (if (fixnum? n)
+ (loop (int:* n 2))
+ (let ((n (int:quotient n 2)))
+ (if (not (fixnum? n))
+ (error "Unable to compute smallest fixnum:" n))
+ (set! fx-least n))))))
(define (fix:iota count #!optional start step)
(guarantee index-fixnum? count 'fix:iota)
(if (default-object? start)
0
(begin
- (guarantee fix:fixnum? start 'fix:iota)
+ (guarantee fixnum? start 'fix:iota)
start)))
(step
(if (default-object? step)
1
(begin
- (guarantee fix:fixnum? step 'fix:iota)
+ (guarantee fixnum? step 'fix:iota)
step))))
(let loop
((index (fix:- count 1))