boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

014-c-value-small.scm (1246B)


      1 ;; The fixed-width C integer carrier must be safe even on a 32-bit
      2 ;; scheme1 host, where an unsigned C int cannot always be a fixnum.
      3 (define (cv s) (cdr (%c-value-parse-decimal-bv s)))
      4 (define (dec=? v s) (bv= (%c-value-source-bv v) s))
      5 (define u32max (cv "4294967295"))
      6 (define u64max (cv "18446744073709551615"))
      7 
      8 (cond
      9   ((not (= (%c-value-trunc 1 4 #t) 1)) (sys-exit 1))
     10   ((not (dec=? u32max "4294967295")) (sys-exit 2))
     11   ((not (dec=? u64max "18446744073709551615")) (sys-exit 3))
     12   ((not (dec=? (%c-value-add u32max 1) "4294967296")) (sys-exit 4))
     13   ((not (= (%c-value-trunc (%c-value-add u32max 1) 4 #f) 0))
     14    (sys-exit 5))
     15   ((not (= (%c-value-add u64max 1) 0)) (sys-exit 6))
     16   ((not (dec=? (%c-value-mul (cv "4294967296") 3) "12884901888"))
     17    (sys-exit 7))
     18   ((not (dec=? (%c-value-shift 1 -63 #f) "9223372036854775808"))
     19    (sys-exit 8))
     20   ((not (= (%c-value-shift (cv "9223372036854775808") 63 #f) 1))
     21    (sys-exit 9))
     22   ((not (= (%c-value-shift (cv "9223372036854775808") 63 #t) -1))
     23    (sys-exit 10))
     24   (else
     25    (let ((qr (%c-value-udivmod (cv "123456789012345") (cv "12345"))))
     26      (cond
     27        ((not (dec=? (car qr) "10000549940")) (sys-exit 11))
     28        ((not (= (cdr qr) 3045)) (sys-exit 12))
     29        (else (sys-exit 0))))))