diff --git a/srfi/143.sld b/srfi/143.sld index 7f8827c3..d94a216a 100644 --- a/srfi/143.sld +++ b/srfi/143.sld @@ -21,8 +21,9 @@ fxabs fxsquare fxsqrt -; TODO: -; fx+/carry fx-/carry fx*/carry + + ; TODO: requires SRFI 141 + ; fx+/carry fx-/carry fx*/carry fxnot fxand fxior fxxor fxarithmetic-shift @@ -58,10 +59,7 @@ (define (fx-width) 31) (define (fx-greatest) 1073741823) (define (fx-least) -1073741824) - (define-c fixnum? - "(void *data, int argc, closure _, object k, object obj)" - " return_closcall1(data, k, - obj_is_int(obj) ? boolean_t : boolean_f); ") + (define-syntax bin-num-op (er-macro-transformer (lambda (expr rename compare) @@ -79,6 +77,8 @@ " object result = obj_int2obj(obj_obj2int(i) " op-str " obj_obj2int(j)); return_closcall1(data, k, result); "))) `(define-c ,fnc ,args ,body))))) + + ;; TODO: should be able to support any number of arguments (define-syntax cmp-op (er-macro-transformer (lambda (expr rename compare) @@ -93,51 +93,61 @@ object result = (obj_obj2int(i) " op-str " obj_obj2int(j)) ? boolean_t : boolean_f; return_closcall1(data, k, result); "))) `(define-c ,fnc ,args ,body))))) - (begin - (bin-num-op fx+ "+") - (bin-num-op fx- "-") - (bin-num-op fx* "*") - (bin-num-op fxquotient "/" #t) - (bin-num-op fxremainder "%" #t) - (cmp-op fx=? "==") - (cmp-op fx? ">") - (cmp-op fx<=? "<=") - (cmp-op fx>=? ">=") - ) + + (bin-num-op fx+ "+") + (bin-num-op fx- "-") + (bin-num-op fx* "*") + (bin-num-op fxquotient "/" #t) + (bin-num-op fxremainder "%" #t) + (bin-num-op fxand "&") + (bin-num-op fxior "|") + (bin-num-op fxxor "^") + (bin-num-op fxarithmetic-shift-left "<<") + (bin-num-op fxarithmetic-shift-right ">>") + (cmp-op fx=? "==") + (cmp-op fx? ">") + (cmp-op fx<=? "<=") + (cmp-op fx>=? ">=") + + (define-c fixnum? + "(void *data, int argc, closure _, object k, object obj)" + " return_closcall1(data, k, + obj_is_int(obj) ? boolean_t : boolean_f); ") + (define-c fxzero? "(void* data, int argc, closure _, object k, object i)" " Cyc_check_fixnum(data, i); return_closcall1(data, k, obj_obj2int(i) == 0 ? boolean_t : boolean_f); ") + (define (fxpositive? i) (fx>? i 0)) (define (fxnegative? i) (fx? old new) old new)) first rest)) (define (fxmin first . rest) (foldl (lambda (old new) (if (fx>") (define-c fxbit-count "(void* data, int argc, closure _, object k, object i)" diff --git a/tests/srfi-143-tests.scm b/tests/srfi-143-tests.scm index 7e5f120c..669ed0c7 100644 --- a/tests/srfi-143-tests.scm +++ b/tests/srfi-143-tests.scm @@ -4,6 +4,9 @@ (test #t (fixnum? 32767)) (test #f (fixnum? 1.1)) + (test #t (fx=? 1 1)) + (test #f (fx=? 1 2)) + (test #f (fx=? 2 3)) ; (test #t (fx=? 1 1 1)) ; (test #f (fx=? 1 2 2)) ; (test #f (fx=? 1 1 2))