(pair? (cdr form))
(null? (cddr form))))
(cerror form "malformed parameter declaration"))
+ (if (string-find-next-char-in-set
+ (symbol-name (car form)) char-set:not-c-symbol)
+ (cerror form "invalid parameter name"))
(let ((name (car form))
(ctype (valid-ctype (cadr form) includes)))
(list name ctype)))
+(define char-set:not-c-symbol (char-set-invert
+ (char-set-union (char-set #\_)
+ char-set:alphanumeric)))
+
(define (valid-ctype form includes)
;; Returns a valid ctype expression, a copy of FORM. Modifies
;; INCLUDES with any internal struct/union/enum declarations.
((ctype/pointer? ctype)
`(,(ucode-primitive c-peek-pointer 3)
,alien-form ,offset ,(or value-form '(MAKE-ALIEN))))
- ((ctype/array? ctype)
+ ((or (ctype/array? ctype) (ctype/struct? ctype))
(if value-form
`(LET ((VALUE ,value-form))
- (COPY-ALIEN-ADDRESS! VALUE ,alien-form)
- (ALIEN-BYTE-INCREMENT! VALUE ,offset)
- VALUE)
+ (COPY-ALIEN-ADDRESS! VALUE ,alien-form)
+ (ALIEN-BYTE-INCREMENT! VALUE ,offset)
+ VALUE)
`(ALIEN-BYTE-INCREMENT ,alien-form ,offset)))
((or (ctype/enum? ctype) (eq? ctype 'ENUM))
`(,(ucode-primitive c-peek-uint 2) ,alien-form ,offset))
(define-integrable set-alien/ctype! set-%alien/ctype!)
+(declare (integrate-operator c-cast))
+(define (c-cast alien ctype)
+ (set-%alien/ctype! alien ctype)
+ alien)
+
(define (alien/address-string alien)
;; Returns a string of length 8, e.g. "081adc60".
(let ((high (%alien/high-bits alien)))
(let ((ctype (if (default-object? ctype) #f ctype)))
(%make-alien 0 0 ctype)))
-(define-integrable (alien/address alien)
+(declare (integrate-operator alien/address))
+(define (alien/address alien)
(+ (* (%alien/high-bits alien) #x10000)
(%alien/low-bits alien)))
-(define-integrable (copy-alien-address! alien source)
+(declare (integrate-operator copy-alien-address!))
+(define (copy-alien-address! alien source)
(if (not (eq? alien source))
(begin
(set-%alien/high-bits! alien (%alien/high-bits source))
(set-%alien/low-bits! alien (%alien/low-bits source)))))
-(define-integrable (alien-null? alien)
+(declare (integrate-operator alien-null?))
+(define (alien-null? alien)
(and (fix:zero? (%alien/high-bits alien))
(fix:zero? (%alien/low-bits alien))))
-(define-integrable (alien-null! alien)
+(declare (integrate-operator alien-null!))
+(define (alien-null! alien)
(set-%alien/high-bits! alien 0)
(set-%alien/low-bits! alien 0))
(define null-alien (make-alien '|void|))
-(define-integrable (alien=? alien1 alien2)
+(declare (integrate-operator alien=?))
+(define (alien=? alien1 alien2)
(and (fix:= (%alien/high-bits alien1) (%alien/high-bits alien2))
(fix:= (%alien/low-bits alien1) (%alien/low-bits alien2))))