diff --git a/bytestructures/body/numeric.scm b/bytestructures/body/numeric.scm index 842575d..b9bb312 100644 --- a/bytestructures/body/numeric.scm +++ b/bytestructures/body/numeric.scm @@ -21,9 +21,25 @@ ;; native or specific endianness, as made possible by the bytevector referencing ;; and assigning procedures in the (rnrs bytevectors) module. +;; We use the strange cond-expand/runtime macro to make sure that certain checks +;; for CPU architecture and data model are done at library-load-time and not +;; compile time, since one might cross-compile the library. + ;;; Code: +(define base-environment + (environment '(scheme base))) + +(define-syntax cond-expand/runtime + (syntax-rules () + ((_ ( ) ...) + (let ((const (eval '(cond-expand ( ') ...) + base-environment))) + (cond + ((equal? const ') ) + ...))))) + (define i8align 1) (define i16align 2) @@ -31,14 +47,14 @@ (define i32align 4) (define i64align - (cond-expand + (cond-expand/runtime (i386 4) (else 8))) (define f32align 4) (define f64align - (cond-expand + (cond-expand/runtime (i386 4) (else 8))) @@ -259,22 +275,22 @@ (define short int16) (define unsigned-short uint16) -(define int (cond-expand +(define int (cond-expand/runtime (lp32 int16) (ilp64 int64) (else int32))) -(define unsigned-int (cond-expand +(define unsigned-int (cond-expand/runtime (lp32 uint16) (ilp64 uint64) (else uint32))) -(define long (cond-expand +(define long (cond-expand/runtime (ilp64 int64) (lp64 int64) (else int32))) -(define unsigned-long (cond-expand +(define unsigned-long (cond-expand/runtime (ilp64 uint64) (lp64 uint64) (else uint32))) @@ -282,7 +298,7 @@ (define long-long int64) (define unsigned-long-long uint64) -(define arch32bit? (cond-expand +(define arch32bit? (cond-expand/runtime (lp32 #t) (ilp32 #t) (else #f))) diff --git a/bytestructures/guile/numeric-all.scm b/bytestructures/guile/numeric-all.scm index 2531c48..1f927b7 100644 --- a/bytestructures/guile/numeric-all.scm +++ b/bytestructures/guile/numeric-all.scm @@ -1,5 +1,6 @@ (define-module (bytestructures guile numeric-all)) (import + (scheme eval) (bytestructures guile bytevectors) (bytestructures guile utils) (bytestructures guile base) diff --git a/bytestructures/r7/numeric-all.sld b/bytestructures/r7/numeric-all.sld index f35d836..e9c25f5 100644 --- a/bytestructures/r7/numeric-all.sld +++ b/bytestructures/r7/numeric-all.sld @@ -2,6 +2,7 @@ (import (scheme base) (scheme complex) + (scheme eval) (bytestructures r7 utils) (bytestructures r7 base) (bytestructures r7 bytevectors)