~dieggsy/srfi-143

20f1422d8de58a3157411b9ad33e0ce1915607ff — dieggsy 3 years ago 57d2c7a 0.4
Use fixnum operations internally
4 files changed, 10 insertions(+), 8 deletions(-)

M srfi-143-impl.scm
M srfi-143.egg
M srfi-143.release-info
M srfi-143.svnwiki
M srfi-143-impl.scm => srfi-143-impl.scm +7 -7
@@ 48,13 48,13 @@

(define (fxarithmetic-shift i count)
  (if (negative? count)
      (fxarithmetic-shift-right i (- count))
      (fxarithmetic-shift-right i (chicken:fx- count))
      (fxarithmetic-shift-left i count)))

;;; Bitwise functions cloned from SRFI 151, fixnum version

;; Helper function
(define (mask start end) (fxnot (fxarithmetic-shift-left -1 (- end start))))
(define (mask start end) (fxnot (fxarithmetic-shift-left -1 (chicken:fx- end start))))

(define (fxif mask n0 n1)
  (fxior (fxand mask n0)


@@ 68,19 68,19 @@
      (fxior to (fxarithmetic-shift-left 1 index))
      (fxand to (fxnot (fxarithmetic-shift-left 1 index)))))

(define (fxfirst-set-bit i) (- (fxbit-count (fxxor i (- i 1))) 1))
(define (fxfirst-set-bit i) (chicken:fx- (fxbit-count (fxxor i (chicken:fx- i 1))) 1))

(define (fxbit-field n start end)
  (fxand (mask start end) (fxarithmetic-shift n (- start))))
  (fxand (mask start end) (fxarithmetic-shift n (chicken:fx- start))))

(define (fxbit-field-rotate n count start end)
  (define width (chicken:fx- end start))
  (set! count (modulo count width))
  (let ((mask (fxnot (fxarithmetic-shift -1 width))))
    (define zn (fxand mask (fxarithmetic-shift n (- start))))
    (define zn (fxand mask (fxarithmetic-shift n (chicken:fx- start))))
    (fxior (fxarithmetic-shift
            (fxior (fxand mask (fxarithmetic-shift zn count))
                   (fxarithmetic-shift zn (- count width)))
                   (fxarithmetic-shift zn (chicken:fx- count width)))
            start)
           (fxand (fxnot (fxarithmetic-shift mask start)) n))))



@@ 91,7 91,7 @@
      ((fxnegative? k) (if (fxnegative? n) (fxnot rvs) rvs))))

(define (fxbit-field-reverse n start end)
  (define width (- end start))
  (define width (chicken:fx- end start))
  (let ((mask (fxnot (fxarithmetic-shift-left -1 width))))
    (define zn (fxand mask (fxarithmetic-shift-right n start)))
    (fxior (fxarithmetic-shift-left (fxreverse width zn) start)

M srfi-143.egg => srfi-143.egg +1 -1
@@ 3,7 3,7 @@
((author "John Cowan")
 (maintainer "Sergey Goldgaber")
 (synopsis "SRFI 143: Fixnums")
 (version "0.3")
 (version "0.4")
 (category math)
 (test-dependencies test)
 (license "MIT")

M srfi-143.release-info => srfi-143.release-info +1 -0
@@ 1,6 1,7 @@
(repo git "https://code.dieggsy.com/{egg-name}")

(uri targz "https://code.dieggsy.com/{egg-name}/snapshot/{egg-name}-{egg-release}.tar.gz")
(release "0.4")
(release "0.3")
(release "0.2")
(release "0.1")

M srfi-143.svnwiki => srfi-143.svnwiki +1 -0
@@ 352,6 352,7 @@ Jaffer, Taylor Campbell, and the R6RS editors.

=== Version history

* 0.4 - Implement variadic arithmetic operators, use fixnum operations internally
* 0.3 - Reorganize and reduce files
* 0.2 - Use built-in CHICKEN procedures for fxlen and fxbit-set?, remove some unused files
* 0.1 - Ported to Chicken Scheme 5