Skip to content

Commit

Permalink
Fix the numeric module for when we're cross-compiled.
Browse files Browse the repository at this point in the history
  • Loading branch information
TaylanUB committed Oct 17, 2020
1 parent 0b48642 commit 707eea3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
30 changes: 23 additions & 7 deletions bytestructures/body/numeric.scm
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,40 @@
;; 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 ()
((_ (<cond> <expr>) ...)
(let ((const (eval '(cond-expand (<cond> '<expr>) ...)
base-environment)))
(cond
((equal? const '<expr>) <expr>)
...)))))

(define i8align 1)

(define i16align 2)

(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)))

Expand Down Expand Up @@ -259,30 +275,30 @@
(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)))

(define long-long int64)
(define unsigned-long-long uint64)

(define arch32bit? (cond-expand
(define arch32bit? (cond-expand/runtime
(lp32 #t)
(ilp32 #t)
(else #f)))
Expand Down
1 change: 1 addition & 0 deletions bytestructures/guile/numeric-all.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(define-module (bytestructures guile numeric-all))
(import
(scheme eval)
(bytestructures guile bytevectors)
(bytestructures guile utils)
(bytestructures guile base)
Expand Down
1 change: 1 addition & 0 deletions bytestructures/r7/numeric-all.sld
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(import
(scheme base)
(scheme complex)
(scheme eval)
(bytestructures r7 utils)
(bytestructures r7 base)
(bytestructures r7 bytevectors)
Expand Down

0 comments on commit 707eea3

Please sign in to comment.