60 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Scheme
		
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Scheme
		
	
	
	
(c-declare "#include <stdint.h>")
 | 
						|
 | 
						|
;(c-declare "int size_of_int8() { return sizeof(int8_t);}")
 | 
						|
;(define size-of-int8 (c-lambda () int "__return(sizeof(int8_t));"))
 | 
						|
;(define int8-size ((c-lambda () int "__return(sizeof(int8_t));")))
 | 
						|
;(define int8-size (c-lambda () int "__return(1);"))
 | 
						|
 | 
						|
(define size-of-int8_t (c-lambda () int "___return(sizeof(int8_t));"))
 | 
						|
(define size-of-uint8_t (c-lambda () int "___return(sizeof(uint8_t));"))
 | 
						|
(define size-of-int16_t (c-lambda () int "___return(sizeof(int16_t));"))
 | 
						|
(define size-of-uint16_t (c-lambda () int "___return(sizeof(uint16_t));"))
 | 
						|
(define size-of-int32_t (c-lambda () int "___return(sizeof(int32_t));"))
 | 
						|
(define size-of-uint32_t (c-lambda () int "___return(sizeof(uint32_t));"))
 | 
						|
(define size-of-int64_t (c-lambda () int "___return(sizeof(int64_t));"))
 | 
						|
(define size-of-uint64_t (c-lambda () int "___return(sizeof(uint64_t));"))
 | 
						|
(define size-of-char (c-lambda () int "___return(sizeof(char));"))
 | 
						|
(define size-of-unsigned-char (c-lambda () int "___return(sizeof(unsigned char));"))
 | 
						|
(define size-of-short (c-lambda () int "___return(sizeof(short));"))
 | 
						|
(define size-of-unsigned-short (c-lambda () int "___return(sizeof(unsigned short));"))
 | 
						|
(define size-of-int (c-lambda () int "___return(sizeof(int));"))
 | 
						|
(define size-of-unsigned-int (c-lambda () int "___return(sizeof(unsigned int));"))
 | 
						|
(define size-of-long (c-lambda () int "___return(sizeof(long));"))
 | 
						|
(define size-of-unsigned-long (c-lambda () int "___return(sizeof(unsigned long));"))
 | 
						|
(define size-of-float (c-lambda () int "___return(sizeof(float));"))
 | 
						|
(define size-of-double (c-lambda () int "___return(sizeof(double));"))
 | 
						|
(define size-of-void* (c-lambda () int "___return(sizeof(void*));"))
 | 
						|
 | 
						|
 | 
						|
(define pffi-size-of
 | 
						|
  (lambda (type)
 | 
						|
    (cond ((eq? type 'int8) (size-of-int8_t))
 | 
						|
          ((eq? type 'uint8) (size-of-uint8_t))
 | 
						|
          ((eq? type 'int16) (size-of-int16_t))
 | 
						|
          ((eq? type 'uint16) (size-of-uint16_t))
 | 
						|
          ((eq? type 'int32) (size-of-int32_t))
 | 
						|
          ((eq? type 'uint32) (size-of-uint32_t))
 | 
						|
          ((eq? type 'int64) (size-of-int64_t))
 | 
						|
          ((eq? type 'uint64) (size-of-uint64_t))
 | 
						|
          ((eq? type 'char) (size-of-char))
 | 
						|
          ((eq? type 'unsigned-char) (size-of-char))
 | 
						|
          ((eq? type 'short) (size-of-short))
 | 
						|
          ((eq? type 'unsigned-short) (size-of-unsigned-short))
 | 
						|
          ((eq? type 'int) (size-of-int))
 | 
						|
          ((eq? type 'unsigned-int) (size-of-unsigned-int))
 | 
						|
          ((eq? type 'long) (size-of-long))
 | 
						|
          ((eq? type 'unsigned-long) (size-of-unsigned-long))
 | 
						|
          ((eq? type 'float) (size-of-float))
 | 
						|
          ((eq? type 'double) (size-of-double))
 | 
						|
          ((eq? type 'pointer) (size-of-void*))
 | 
						|
          (else (error "Can not get size of unknown type" type)))))
 | 
						|
 | 
						|
(define-macro (pffi-shared-object-load header)
 | 
						|
  `(c-declare ,(string-append "#include <" header ">")))
 | 
						|
 | 
						|
#;(define-syntax pffi-shared-object-load
 | 
						|
  (syntax-rules ()
 | 
						|
    ((_ headers)
 | 
						|
    (c-declare "#include <stdint.h>"))))
 | 
						|
 |