diff --git a/csug/foreign.stex b/csug/foreign.stex index 32bf43639..9be83750e 100644 --- a/csug/foreign.stex +++ b/csug/foreign.stex @@ -492,6 +492,12 @@ Transmission of fixnums is slightly faster than transmission of \scheme{#f} is converted to 0; all other objects are converted to 1. The argument is passed to C as an \scheme{int}. +\foreigntype{\scheme{stdbool}} +\index{\scheme{stdbool}}Any Scheme object may be passed as a boolean. +\scheme{#f} is converted to 0; all other objects are converted to 1. +The argument is passed to C as a \scheme{bool} defined by the the host +machine's \scheme{stdbool.h} include file. + \foreigntype{\scheme{char}} \index{\scheme{char}}Only Scheme characters with Unicode scalar values in the range 0 through 255 are valid \scheme{char} parameters. @@ -772,6 +778,12 @@ fixed-size type above, depending on the size of a C pointer. into a Scheme boolean. 0 is converted to \scheme{#f}; all other values are converted to \scheme{#t}. +\foreigntype{\scheme{stdbool}} +\index{\scheme{stdbool}}This type converts a C \scheme{bool} return value +into a Scheme boolean, where \scheme{bool} is from the host machine's \scheme{stdbool.h} +include file. +0 is converted to \scheme{#f}; all other values are converted to \scheme{#t}. + \foreigntype{\scheme{char}} \index{\scheme{char}}This type converts a C \scheme{unsigned char} return value into a Scheme character, as if via \scheme{integer->char}. @@ -1427,8 +1439,9 @@ Several additional machine-dependent types are recognized: \begin{itemize} \item \scheme{iptr}, \item \scheme{uptr}, -\item \scheme{fixnum}, and -\item \scheme{boolean}. +\item \scheme{fixnum}, +\item \scheme{boolean}, and +\item \scheme{stdbool}. \end{itemize} \scheme{uptr} is equivalent to \scheme{void*}; both are treated as @@ -1439,6 +1452,9 @@ to the fixnum range. \scheme{boolean} is treated as an \scheme{int}, with zero converted to the Scheme value \scheme{#f} and all other values converted to \scheme{#t}. +\scheme{stdbool} is treated as an \scheme{bool} from \scheme{stdbool.h}, with zero +converted to the Scheme value \scheme{#f} and all +other values converted to \scheme{#t}. Finally, several fixed-sized types are also supported: @@ -1482,7 +1498,7 @@ to be stored, one of those listed in the description of \scheme{foreign-ref} above. Scheme characters are converted to type \scheme{char} or \scheme{wchar_t} as if via \scheme{char->integer}. -For type \scheme{boolean}, Scheme \scheme{#f} is converted to the +For type \scheme{boolean} or \scheme{stdbool}, Scheme \scheme{#f} is converted to the \scheme{int} 0, and any other Scheme object is converted to 1. \var{address} must be an exact integer in the range $-2^{w-1}$ through diff --git a/mats/foreign.ms b/mats/foreign.ms index 48c03c622..783033ecb 100644 --- a/mats/foreign.ms +++ b/mats/foreign.ms @@ -933,6 +933,7 @@ (equal? (foreign-sizeof 'unsigned-long) (foreign-sizeof 'long)) (equal? (foreign-sizeof 'unsigned-long-long) (foreign-sizeof 'long-long)) (equal? (foreign-sizeof 'boolean) (foreign-sizeof 'int)) + (equal? (foreign-sizeof 'stdbool) (foreign-sizeof 'stdbool)) (equal? (foreign-sizeof 'fixnum) (foreign-sizeof 'iptr)) (equal? (foreign-sizeof 'scheme-object) (foreign-sizeof 'void*)) (equal? (foreign-sizeof 'ptr) (foreign-sizeof 'void*)) @@ -2594,6 +2595,19 @@ (and (eqv? (Srvtest_boolean Frvtest_boolean "abcdefg") #t) (eqv? (Srvtest_boolean Frvtest_boolean "gfedcba") #f))) + (let () + (define Frvtest_stdbool + (foreign-callable + (lambda (x) (equal? x "abCDEfg")) + (scheme-object) + stdbool)) + (define Srvtest_stdbool + (foreign-procedure "Srvtest_stdbool" + (scheme-object scheme-object) + stdbool)) + (and + (eqv? (Srvtest_stdbool Frvtest_stdbool "abCDEfg") #t) + (eqv? (Srvtest_stdbool Frvtest_stdbool "gfEDCba") #f))) (let () (define Frvtest_fixnum (foreign-callable diff --git a/mats/foreign3.c b/mats/foreign3.c index 60777ebec..0b7007a5b 100644 --- a/mats/foreign3.c +++ b/mats/foreign3.c @@ -31,6 +31,9 @@ #include "scheme.h" #endif +/* Standard in C99, but widely available in environments for earlier C dialects: */ +#include + EXPORT int chk_data(void) { static char c[10]="ABCDEFGH"; @@ -178,6 +181,10 @@ EXPORT char Srvtest_char(ptr code, ptr x1) { return (*((char (*)(ptr))Sforeign_callable_entry_point(code)))(x1); } +EXPORT bool Srvtest_stdbool(ptr code, ptr x1) { + return (*((bool (*)(ptr))Sforeign_callable_entry_point(code)))(x1); +} + #ifdef _WIN32 EXPORT int __stdcall sum_stdcall(int a, int b) { return a + b; diff --git a/mats/ftype.ms b/mats/ftype.ms index c3316450e..455328263 100644 --- a/mats/ftype.ms +++ b/mats/ftype.ms @@ -443,6 +443,7 @@ (uptr . ,(if (< (fixnum-width) 32) "uint32_t" "uint64_t")) (fixnum . ,(if (< (fixnum-width) 32) "int32_t" "int64_t")) (boolean . "int") + (stdbool . "int8_t") (integer-8 . "int8_t") (unsigned-8 . "uint8_t") (integer-16 . "int16_t") @@ -723,7 +724,8 @@ [a15 fixnum] [a16 iptr] [a17 uptr] - [a18 void*])) + [a18 void*] + [a19 stdbool])) (define a (make-ftype-pointer A (foreign-alloc (ftype-sizeof A)))) (free-after a (ftype-set! A (a1) a 3.5) @@ -744,6 +746,7 @@ (ftype-set! A (a16) a -30004) (ftype-set! A (a17) a #xabcdef07) (ftype-set! A (a18) a 25000) + (ftype-set! A (a19) a 'howdy) (list (ftype-ref A (a1) a) (ftype-ref A (a2) a) @@ -762,7 +765,8 @@ (ftype-ref A (a15) a) (ftype-ref A (a16) a) (ftype-ref A (a17) a) - (ftype-ref A (a18) a)))) + (ftype-ref A (a18) a) + (ftype-ref A (a19) a)))) `(3.5 -4.5 -30000 @@ -780,7 +784,8 @@ ,(most-positive-fixnum) -30004 #xabcdef07 - 25000)) + 25000 + #t)) (begin (define-ftype A @@ -4022,7 +4027,8 @@ [a15 fixnum] [a16 iptr] [a17 uptr] - [a18 void*]))) + [a18 void*] + [a19 stdbool]))) (define a (make-ftype-pointer A (foreign-alloc (ftype-sizeof A)))) (free-after a (ftype-set! A (a1) a 3.5) @@ -4043,6 +4049,7 @@ (ftype-set! A (a16) a -30004) (ftype-set! A (a17) a #xabcdef07) (ftype-set! A (a18) a 25000) + (ftype-set! A (a19) a 'howdy) (list (ftype-ref A (a1) a) (ftype-ref A (a2) a) @@ -4061,7 +4068,8 @@ (ftype-ref A (a15) a) (ftype-ref A (a16) a) (ftype-ref A (a17) a) - (ftype-ref A (a18) a)))) + (ftype-ref A (a18) a) + (ftype-ref A (a19) a)))) `(3.5 -4.5 -30000 @@ -4079,7 +4087,8 @@ ,(most-positive-fixnum) -30004 #xabcdef07 - 25000)) + 25000 + #t)) (equal? (let () (define-ftype A @@ -4102,7 +4111,8 @@ [a15 fixnum] [a16 iptr] [a17 uptr] - [a18 void*]))) + [a18 void*] + [a19 stdbool]))) (define a (make-ftype-pointer A (foreign-alloc (ftype-sizeof A)))) (free-after a (ftype-set! A (a1) a 3.5) @@ -4123,6 +4133,7 @@ (ftype-set! A (a16) a -30004) (ftype-set! A (a17) a #xabcdef07) (ftype-set! A (a18) a 25000) + (ftype-set! A (a19) a 'howdy) (list (ftype-ref A (a1) a) (ftype-ref A (a2) a) @@ -4141,7 +4152,8 @@ (ftype-ref A (a15) a) (ftype-ref A (a16) a) (ftype-ref A (a17) a) - (ftype-ref A (a18) a)))) + (ftype-ref A (a18) a) + (ftype-ref A (a19) a)))) `(3.5 -4.5 -30000 @@ -4159,7 +4171,8 @@ ,(most-positive-fixnum) -30004 #xabcdef07 - 25000)) + 25000 + #t)) (equal? (let () (define-ftype A @@ -4182,7 +4195,8 @@ [a15 fixnum] [a16 iptr] [a17 uptr] - [a18 void*]))) + [a18 void*] + [a19 stdbool]))) (define a (make-ftype-pointer A (foreign-alloc (ftype-sizeof A)))) (free-after a (ftype-set! A (a1) a 3.5) @@ -4203,6 +4217,7 @@ (ftype-set! A (a16) a -30004) (ftype-set! A (a17) a #xabcdef07) (ftype-set! A (a18) a 25000) + (ftype-set! A (a19) a 'howdy) (list (ftype-ref A (a1) a) (ftype-ref A (a2) a) @@ -4221,7 +4236,8 @@ (ftype-ref A (a15) a) (ftype-ref A (a16) a) (ftype-ref A (a17) a) - (ftype-ref A (a18) a)))) + (ftype-ref A (a18) a) + (ftype-ref A (a19) a)))) `(3.5 -4.5 -30000 @@ -4239,7 +4255,8 @@ ,(most-positive-fixnum) -30004 #xabcdef07 - 25000)) + 25000 + #t)) ; ---------------- (begin @@ -5667,7 +5684,8 @@ [a15 fixnum] [a16 iptr] [a17 uptr] - [a18 void*]))) + [a18 void*] + [a19 stdbool]))) #t) (equivalent-expansion? (parameterize ([optimize-level 3] [enable-cp0 #t] [#%$suppress-primitive-inlining #f]) @@ -5691,6 +5709,7 @@ (ftype-ref A (a16) x) (ftype-ref A (a17) x) (ftype-ref A (a18) x) + (ftype-ref A (a19) x) x))) '(lambda (x) x)) (equivalent-expansion? @@ -5715,6 +5734,7 @@ (ftype-&ref A (a16) x) (ftype-&ref A (a17) x) (ftype-&ref A (a18) x) + (ftype-&ref A (a19) x) x))) '(lambda (x) x)) (begin @@ -5738,7 +5758,8 @@ [a15 fixnum] [a16 iptr] [a17 uptr] - [a18 void*]))) + [a18 void*] + [a19 stdbool]))) #t) (equivalent-expansion? (parameterize ([optimize-level 3] [enable-cp0 #t] [#%$suppress-primitive-inlining #f]) @@ -5762,6 +5783,7 @@ (ftype-ref A (a16) x) (ftype-ref A (a17) x) (ftype-ref A (a18) x) + (ftype-ref A (a19) x) x))) '(lambda (x) x)) (equivalent-expansion? @@ -5786,6 +5808,7 @@ (ftype-&ref A (a16) x) (ftype-&ref A (a17) x) (ftype-&ref A (a18) x) + (ftype-&ref A (a19) x) x))) '(lambda (x) x)) (begin diff --git a/release_notes/release_notes.stex b/release_notes/release_notes.stex index fb674f762..7c6033102 100644 --- a/release_notes/release_notes.stex +++ b/release_notes/release_notes.stex @@ -124,6 +124,11 @@ iOS compilation target. Native-code support for iOS is currently limited to applications attached to a debugger as the platform does not allow executable code to be loaded at runtime. +\subsection{Standard boolean foreign type (10.1.0)} + +The \scheme{stdbool} foregin type corresponds to \scheme{bool} as +defined by the host machine's \scheme{stdbool.h} include file. + \subsection{Unicode 15.1 support (10.0.0)} The character sets, character classes, and word-breaking algorithms for character, string, diff --git a/s/cmacros.ss b/s/cmacros.ss index f0b0e928a..633cf8f9b 100644 --- a/s/cmacros.ss +++ b/s/cmacros.ss @@ -357,7 +357,7 @@ ;; --------------------------------------------------------------------- ;; Version and machine types: -(define-constant scheme-version #x0a010002) +(define-constant scheme-version #x0a010003) (define-syntax define-machine-types (lambda (x) @@ -419,7 +419,7 @@ rv64nb trv64nb la64le tla64le ) - +< (include "machine.def") (define-constant machine-type-name (cdr (assv (constant machine-type) (constant machine-type-alist)))) @@ -1209,7 +1209,8 @@ (fixnum (constant ptr-bytes) fixnum?) (char 1 $foreign-char?) (wchar (fxsrl (constant wchar-bits) 3) $foreign-wchar?) - (boolean (fxsrl (constant int-bits) 3) (lambda (x) #t))))) + (boolean (fxsrl (constant int-bits) 3) (lambda (x) #t)) + (stdbool (fxsrl (constant stdbool-bits) 3) (lambda (x) #t))))) ) (define-syntax record-datatype diff --git a/s/cp0.ss b/s/cp0.ss index dd2c629f8..91eef150a 100644 --- a/s/cp0.ss +++ b/s/cp0.ss @@ -3729,7 +3729,7 @@ (lambda (x) (syntax-case x () [(_ type bytes pred) - (if (memq (datum type) '(scheme-object boolean)) + (if (memq (datum type) '(scheme-object boolean stdbool)) #'($oops who "unexpected type ~s" 'type) #'(build-primcall 3 'pred (list (build-ref val-t))))]))) @@ -3752,7 +3752,7 @@ (lambda (fld t check*) (let* ([type (fld-type fld)] [real-type (filter-foreign-type type)]) - (if (memq real-type '(scheme-object boolean)) + (if (memq real-type '(scheme-object boolean stdbool)) check* (cons `(if ,(type->pred 'record-constructor real-type t) @@ -4007,7 +4007,7 @@ [rec-t (cp0-make-temp #t)] [val-t (cp0-make-temp #t)]) (let ([expr `(record-set! ,rtd ,type ,index (ref #f ,rec-t) (ref #f ,val-t))] - [pred (and (not (memq real-type '(scheme-object boolean))) + [pred (and (not (memq real-type '(scheme-object boolean stdbool))) (type->pred who real-type val-t))]) (cond [(fx= level 3) diff --git a/s/cpprim.ss b/s/cpprim.ss index 50cdfd5b6..040fa9984 100644 --- a/s/cpprim.ss +++ b/s/cpprim.ss @@ -5268,7 +5268,7 @@ [(quote ,d) (let ([type (filter-foreign-type d)]) (and (memq type (record-datatype list)) - (not (memq type '(char wchar boolean))) + (not (memq type '(char wchar boolean stdbool))) (build-object-ref #f type base offset)))] [else #f])]) (define-inline 2 $swap-object-ref @@ -5277,7 +5277,7 @@ [(quote ,d) (let ([type (filter-foreign-type d)]) (and (memq type (record-datatype list)) - (not (memq type '(char wchar boolean))) + (not (memq type '(char wchar boolean stdbool))) (build-object-ref #t type base offset)))] [else #f])]) (define-inline 3 foreign-ref @@ -5286,7 +5286,7 @@ [(quote ,d) (let ([type (filter-foreign-type d)]) (and (memq type (record-datatype list)) - (not (memq type '(char wchar boolean))) + (not (memq type '(char wchar boolean stdbool))) (bind #f (e-offset) (build-object-ref #f type (ptr->integer e-addr (constant ptr-bits)) @@ -5298,7 +5298,7 @@ [(quote ,d) (let ([type (filter-foreign-type d)]) (and (memq type (record-datatype list)) - (not (memq type '(char wchar boolean))) + (not (memq type '(char wchar boolean stdbool))) (bind #f (e-offset) (build-object-ref #t type (ptr->integer e-addr (constant ptr-bits)) @@ -5310,7 +5310,7 @@ [(quote ,d) (let ([type (filter-foreign-type d)]) (and (memq type (record-datatype list)) - (not (memq type '(char wchar boolean))) + (not (memq type '(char wchar boolean stdbool))) (or (>= (constant ptr-bits) (type->width type)) (eq? type 'double-float)) (build-object-set! type base offset value)))] [else #f])]) @@ -5320,7 +5320,7 @@ [(quote ,d) (let ([type (filter-foreign-type d)]) (and (memq type (record-datatype list)) - (not (memq type '(char wchar boolean))) + (not (memq type '(char wchar boolean stdbool))) (or (>= (constant ptr-bits) (type->width type)) (eq? type 'double-float)) (bind #f (e-offset e-value) (build-object-set! type @@ -5334,7 +5334,7 @@ [(quote ,d) (let ([type (filter-foreign-type d)]) (and (memq type (record-datatype list)) - (not (memq type '(char wchar boolean single-float))) + (not (memq type '(char wchar boolean stdbool single-float))) (>= (constant ptr-bits) (type->width type)) (bind #f (e-offset e-value) (build-swap-object-set! type @@ -5550,6 +5550,21 @@ ,(%constant sfalse) ,(%constant strue)))) + (define-fptr-ref-inline $fptr-ref-stdbool + (constant-case stdbool-bits [(8) 'unsigned-8]) + #f + (lambda (x) + `(if ,(%inline eq? ,x (immediate 0)) + ,(%constant sfalse) + ,(%constant strue)))) + (define-fptr-ref-inline $fptr-ref-swap-stdbool + (constant-case stdbool-bits [(8) 'unsigned-8]) + #t + (lambda (x) + `(if ,(%inline eq? ,x (immediate 0)) + ,(%constant sfalse) + ,(%constant strue)))) + (define-fptr-ref-inline $fptr-ref-fixnum 'fixnum #f) (define-fptr-ref-inline $fptr-ref-swap-fixnum 'fixnum #t)) (let () @@ -5653,6 +5668,17 @@ build-swap-object-set! (lambda (z) `(if ,z (immediate ,(fix 1)) (immediate ,(fix 0))))) + (define-fptr-set!-inline #f $fptr-set-stdbool! + (constant-case stdbool-bits + [(8) 'unsigned-8]) + build-object-set! + (lambda (z) `(if ,z (immediate ,(fix 1)) (immediate ,(fix 0))))) + (define-fptr-set!-inline #f $fptr-set-swap-stdbool! + (constant-case stdbool-bits + [(8) 'unsigned-8]) + build-swap-object-set! + (lambda (z) `(if ,z (immediate ,(fix 1)) (immediate ,(fix 0))))) + (define-fptr-set!-inline #f $fptr-set-fixnum! 'fixnum build-object-set!) (define-fptr-set!-inline #f $fptr-set-swap-fixnum! 'fixnum build-swap-object-set!)) (let () diff --git a/s/default.def b/s/default.def index 0a171e881..95cf72317 100644 --- a/s/default.def +++ b/s/default.def @@ -1,6 +1,7 @@ ;; types that are right for most platforms: (define-constant-default int-bits 32) (define-constant-default short-bits 16) +(define-constant-default stdbool-bits 8) (define-constant-default typedef-ptr "void *") (define-constant-default typedef-iptr "long") (define-constant-default typedef-uptr "unsigned long") diff --git a/s/ftype.ss b/s/ftype.ss index 674e68b6b..dbbc83192 100644 --- a/s/ftype.ss +++ b/s/ftype.ss @@ -72,7 +72,7 @@ built-in ftype names: char | wchar float | double void* | iptr | uptr - fixnum | boolean + fixnum | boolean | stdbool integer-8 | unsigned-8 integer-16 | unsigned-16 integer-24 | unsigned-24 @@ -326,7 +326,7 @@ ftype operators: (define base-types '(short unsigned-short int unsigned unsigned-int long unsigned-long long-long unsigned-long-long char wchar float - double void* iptr uptr fixnum boolean integer-8 unsigned-8 + double void* iptr uptr fixnum boolean stdbool integer-8 unsigned-8 integer-16 unsigned-16 integer-24 unsigned-24 integer-32 unsigned-32 integer-40 unsigned-40 integer-48 unsigned-48 integer-56 unsigned-56 integer-64 unsigned-64 single-float double-float wchar_t size_t ssize_t ptrdiff_t)) @@ -1683,6 +1683,13 @@ ftype operators: (lambda (fptr offset) (#3%$fptr-ref-swap-boolean fptr offset))) + (set! $fptr-ref-stdbool + (lambda (fptr offset) + (#3%$fptr-ref-stdbool fptr offset))) + (set! $fptr-ref-swap-stdbool + (lambda (fptr offset) + (#3%$fptr-ref-swap-stdbool fptr offset))) + (set! $fptr-ref-fixnum (lambda (fptr offset) (#3%$fptr-ref-fixnum fptr offset))) @@ -1919,6 +1926,13 @@ ftype operators: (lambda (info fptr offset val) (#3%$fptr-set-swap-boolean! info fptr offset val))) + (set! $fptr-set-stdbool! + (lambda (info fptr offset val) + (#3%$fptr-set-stdbool! info fptr offset val))) + (set! $fptr-set-swap-stdbool! + (lambda (info fptr offset val) + (#3%$fptr-set-swap-stdbool! info fptr offset val))) + (set! $fptr-set-fixnum! (lambda (info fptr offset val) (unless (fixnum? val) (invalid-value info val)) diff --git a/s/primdata.ss b/s/primdata.ss index ca44522a6..6fad5f278 100644 --- a/s/primdata.ss +++ b/s/primdata.ss @@ -2073,6 +2073,7 @@ ($fptr-ref-integer-64 [flags single-valued discard]) ($fptr-ref-integer-8 [flags single-valued discard]) ($fptr-ref-single-float [flags single-valued discard]) + ($fptr-ref-stdbool [flags single-valued discard]) ($fptr-ref-swap-boolean [flags single-valued discard]) ($fptr-ref-swap-double-float [flags single-valued discard]) ($fptr-ref-swap-fixnum [flags single-valued discard]) @@ -2084,6 +2085,7 @@ ($fptr-ref-swap-integer-56 [flags single-valued discard]) ($fptr-ref-swap-integer-64 [flags single-valued discard]) ($fptr-ref-swap-single-float [flags single-valued discard]) + ($fptr-ref-swap-stdbool [flags single-valued discard]) ($fptr-ref-swap-unsigned-16 [flags single-valued discard]) ($fptr-ref-swap-unsigned-24 [flags single-valued discard]) ($fptr-ref-swap-unsigned-32 [flags single-valued discard]) @@ -2146,6 +2148,7 @@ ($fptr-set-integer-64! [flags single-valued]) ($fptr-set-integer-8! [flags single-valued]) ($fptr-set-single-float! [flags single-valued]) + ($fptr-set-stdbool! [flags single-valued]) ($fptr-set-swap-boolean! [flags single-valued]) ($fptr-set-swap-double-float! [flags single-valued]) ($fptr-set-swap-fixnum! [flags single-valued]) @@ -2157,6 +2160,7 @@ ($fptr-set-swap-integer-56! [flags single-valued]) ($fptr-set-swap-integer-64! [flags single-valued]) ($fptr-set-swap-single-float! [flags single-valued]) + ($fptr-set-swap-stdbool! [flags single-valued]) ($fptr-set-swap-unsigned-16! [flags single-valued]) ($fptr-set-swap-unsigned-24! [flags single-valued]) ($fptr-set-swap-unsigned-32! [flags single-valued]) diff --git a/s/record.ss b/s/record.ss index 061af14d8..9224ff72f 100644 --- a/s/record.ss +++ b/s/record.ss @@ -197,7 +197,7 @@ (set-who! foreign-ref ; checks ty, addr, and offset, but inherently unsafe (lambda (ty addr offset) (define-syntax ref - (syntax-rules (scheme-object char wchar boolean + (syntax-rules (scheme-object char wchar boolean stdbool integer-24 unsigned-24 integer-40 unsigned-40 integer-48 unsigned-48 integer-56 unsigned-56 integer-64 unsigned-64) [(_ scheme-object bytes pred) ($oops who "cannot load scheme pointers from foreign memory")] @@ -210,6 +210,9 @@ (constant-case int-bits [(32) (not (eq? (#3%foreign-ref 'integer-32 addr offset) 0))] [(64) (not (eq? (#3%foreign-ref 'integer-64 addr offset) 0))])] + [(_ stdbool bytes pred) + (constant-case stdbool-bits + [(8) (not (eq? (#3%foreign-ref 'integer-8 addr offset) 0))])] [(_ integer-24 bytes pred) (eq? 'unknown (constant native-endianness)) (build-multi-int (#3%foreign-ref addr offset) integer 16 8 swap?)] @@ -256,7 +259,7 @@ (lambda (ty addr offset v) (define (value-err x t) ($oops who "invalid value ~s for foreign type ~s" x t)) (define-syntax set - (syntax-rules (scheme-object char wchar boolean + (syntax-rules (scheme-object char wchar boolean stdbool integer-24 unsigned-24 integer-40 unsigned-40 integer-48 unsigned-48 integer-56 unsigned-56 integer-64 unsigned-64 double-float single-float) [(_ scheme-object bytes pred) ($oops who "cannot store scheme pointers into foreign memory")] @@ -274,6 +277,9 @@ (constant-case int-bits [(32) (#3%foreign-set! 'integer-32 addr offset (if v 1 0))] [(64) (#3%foreign-set! 'integer-64 addr offset (if v 1 0))])] + [(_ stdbool bytes pred) + (constant-case stdbool-bits + [(8) (#3%foreign-set! 'integer-8 addr offset (if v 1 0))])] [(_ integer-24 bytes pred) (eq? 'unknown (constant native-endianness)) (begin @@ -364,7 +370,7 @@ (set-who! $object-ref ; not safe, just handles non-constant types (lambda (ty r offset) (define-syntax ref - (syntax-rules (char wchar boolean + (syntax-rules (char wchar boolean stdbool integer-24 unsigned-24 integer-40 unsigned-40 integer-48 unsigned-48 integer-56 unsigned-56 integer-64 unsigned-64) [(_ char bytes pred) (integer->char (#3%$object-ref 'unsigned-8 r offset))] @@ -376,6 +382,9 @@ (constant-case int-bits [(32) (not (eq? (#3%$object-ref 'integer-32 r offset) 0))] [(64) (not (eq? (#3%$object-ref 'integer-64 r offset) 0))])] + [(_ stdbool bytes pred) + (constant-case stdbool-bits + [(8) (not (eq? (#3%$object-ref 'integer-8 r offset) 0))])] [(_ integer-24 bytes pred) (eq? 'unknown (constant native-endianness)) (build-multi-int (#3%$object-ref r offset) integer 16 8 #f)] @@ -407,7 +416,7 @@ (set-who! $swap-object-ref ; not safe, just handles non-constant types (lambda (ty r offset) (define-syntax ref - (syntax-rules (char wchar boolean + (syntax-rules (char wchar boolean stdbool integer-24 unsigned-24 integer-40 unsigned-40 integer-48 unsigned-48 integer-56 unsigned-56 integer-64 unsigned-64) [(_ char bytes pred) (integer->char (#3%$swap-object-ref 'unsigned-8 r offset))] @@ -419,6 +428,9 @@ (constant-case int-bits [(32) (not (eq? (#3%$swap-object-ref 'integer-32 r offset) 0))] [(64) (not (eq? (#3%$swap-object-ref 'integer-64 r offset) 0))])] + [(_ stdbool bytes pred) + (constant-case stdbool-bits + [(8) (not (eq? (#3%$swap-object-ref 'integer-8 r offset) 0))])] [(_ integer-24 bytes pred) (eq? 'unknown (constant native-endianness)) (build-multi-int (#3%$swap-object-ref r offset) integer 16 8 #t)] @@ -450,7 +462,7 @@ (set-who! $object-set! ; not safe, just handles non-constant types (lambda (ty r offset v) (define-syntax set - (syntax-rules (char wchar boolean + (syntax-rules (char wchar boolean stdbool integer-24 unsigned-24 integer-40 unsigned-40 integer-48 unsigned-48 integer-56 unsigned-56 integer-64 unsigned-64) [(_ char bytes pred) @@ -463,6 +475,9 @@ (constant-case int-bits [(32) (#3%$object-set! 'integer-32 r offset (if v 1 0))] [(64) (#3%$object-set! 'integer-64 r offset (if v 1 0))])] + [(_ stdbool bytes pred) + (constant-case stdbool-bits + [(8) (#3%$object-set! 'integer-8 r offset (if v 1 0))])] [(_ integer-24 bytes pred) (eq? 'unknown (constant native-endianness)) (build-multi-int (#3%$object-set! r offset v) integer 16 8 #f)] diff --git a/s/syntax.ss b/s/syntax.ss index 197d1b10c..20e46a182 100644 --- a/s/syntax.ss +++ b/s/syntax.ss @@ -8872,7 +8872,7 @@ integer-8 unsigned-8 integer-16 unsigned-16 integer-24 unsigned-24 integer-32 unsigned-32 integer-40 unsigned-40 integer-48 unsigned-48 integer-56 unsigned-56 integer-64 unsigned-64 - boolean fixnum char wchar u8* u16* u32* utf-8 utf-16le utf-16be utf-16 + boolean stdbool fixnum char wchar u8* u16* u32* utf-8 utf-16le utf-16be utf-16 utf-32le utf-32be utf-32) type] [(void) (and void-okay? type)] [(ptr) 'scheme-object] @@ -8960,7 +8960,7 @@ a))] [else (case type - [(boolean void) '(lambda (id) #t)] + [(boolean stdbool void) '(lambda (id) #t)] [(char) '(lambda (id) (and (char? id) (fx<= (char->integer id) #xff)))] [(wchar) (constant-case wchar-bits @@ -9054,6 +9054,11 @@ (#,(constant-case int-bits [(32) #'integer-32] [(64) #'integer-64])))] + [(stdbool) + #`(() + ((if x 1 0)) + (#,(constant-case stdbool-bits + [(8) #'integer-8])))] [(char) #`(() (#,(if unsafe? @@ -9178,6 +9183,9 @@ #,(constant-case int-bits [(32) #'integer-32] [(64) #'integer-64]))] + [(stdbool) #`((lambda (x) (not (eq? x 0))) + #,(constant-case stdbool-bits + [(8) #'integer-8]))] [(char) #'((lambda (x) (#3%integer->char (#3%fxlogand x #xff))) unsigned-8)] [(wchar) #`(integer->char @@ -9274,6 +9282,12 @@ (#,(constant-case int-bits [(32) #'integer-32] [(64) #'integer-64]))))] + [(stdbool) + (with-syntax ([(x) (generate-temporaries #'(*))]) + #`((not (eq? x 0)) + (x) + (#,(constant-case stdbool-bits + [(8) #'integer-8]))))] [(char) (with-syntax ([(x) (generate-temporaries #'(*))]) #`((#3%integer->char (#3%fxlogand x #xff)) @@ -9375,6 +9389,10 @@ [(32) #'integer-32] [(64) #'integer-64]) [] [])] + [(stdbool) #`((lambda (x) (if x 1 0)) + #,(constant-case stdbool-bits + [(8) #'integer-8]) + [] [])] [(char) #`((lambda (x) #,(if unsafe?