99 lines
3.9 KiB
Scheme
99 lines
3.9 KiB
Scheme
(define (primitives-init set-procedure get-procedure) #t)
|
|
|
|
(define internal-size-of-type
|
|
(lambda (type)
|
|
(cond ((eq? type 'i8) (size-of-type 'int8))
|
|
((eq? type 'u8) (size-of-type 'uint8))
|
|
((eq? type 'i16) (size-of-type 'int16))
|
|
((eq? type 'u16) (size-of-type 'uint16))
|
|
((eq? type 'i32) (size-of-type 'int32))
|
|
((eq? type 'u32) (size-of-type 'uint32))
|
|
((eq? type 'i64) (size-of-type 'int64))
|
|
((eq? type 'u64) (size-of-type 'uint64))
|
|
((eq? type 'char) (size-of-type 'char))
|
|
((eq? type 'uchar) (size-of-type 'char))
|
|
((eq? type 'short) (size-of-type 'short))
|
|
((eq? type 'ushort) (size-of-type 'unsigned-short))
|
|
((eq? type 'int) (size-of-type 'int))
|
|
((eq? type 'uint) (size-of-type 'unsigned-int))
|
|
((eq? type 'long) (size-of-type 'long))
|
|
((eq? type 'ulong) (size-of-type 'unsigned-long))
|
|
((eq? type 'float) (size-of-type 'float))
|
|
((eq? type 'double) (size-of-type 'double))
|
|
((eq? type 'pointer) (size-of-type 'pointer)))))
|
|
|
|
(define internal-align-of-type
|
|
(lambda (type)
|
|
(cond ((eq? type 'i8) (align-of-type 'int8))
|
|
((eq? type 'u8) (align-of-type 'uint8))
|
|
((eq? type 'i16) (align-of-type 'int16))
|
|
((eq? type 'u16) (align-of-type 'uint16))
|
|
((eq? type 'i32) (align-of-type 'int32))
|
|
((eq? type 'u32) (align-of-type 'uint32))
|
|
((eq? type 'i64) (align-of-type 'int64))
|
|
((eq? type 'u64) (align-of-type 'uint64))
|
|
((eq? type 'char) (align-of-type 'char))
|
|
((eq? type 'uchar) (align-of-type 'char))
|
|
((eq? type 'short) (align-of-type 'short))
|
|
((eq? type 'ushort) (align-of-type 'unsigned-short))
|
|
((eq? type 'int) (align-of-type 'int))
|
|
((eq? type 'uint) (align-of-type 'unsigned-int))
|
|
((eq? type 'long) (align-of-type 'long))
|
|
((eq? type 'ulong) (align-of-type 'unsigned-long))
|
|
((eq? type 'float) (align-of-type 'float))
|
|
((eq? type 'double) (align-of-type 'double))
|
|
((eq? type 'pointer) (align-of-type 'pointer)))))
|
|
|
|
(define shared-object-load
|
|
(lambda (path options)
|
|
(if (null? options)
|
|
(open-shared-library path)
|
|
(open-shared-library path (cadr (assoc 'additional-versions options))))))
|
|
|
|
(define type->native-type
|
|
(lambda (type)
|
|
(cond ((equal? type 'i8) 'int8)
|
|
((equal? type 'u8) 'uint8)
|
|
((equal? type 'i16) 'int16)
|
|
((equal? type 'u16) 'uint16)
|
|
((equal? type 'i32) 'int32)
|
|
((equal? type 'u32) 'uint32)
|
|
((equal? type 'i64) 'int64)
|
|
((equal? type 'u64) 'uint64)
|
|
((equal? type 'char) 'char)
|
|
((equal? type 'uchar) 'char)
|
|
((equal? type 'short) 'short)
|
|
((equal? type 'ushort) 'unsigned-short)
|
|
((equal? type 'int) 'int)
|
|
((equal? type 'uint) 'unsigned-int)
|
|
((equal? type 'long) 'long)
|
|
((equal? type 'ulong) 'unsigned-long)
|
|
((equal? type 'float) 'float)
|
|
((equal? type 'double) 'double)
|
|
((equal? type 'pointer) 'pointer)
|
|
((equal? type 'void) 'pointer)
|
|
((equal? type 'callback) 'callback)
|
|
(else #f))))
|
|
|
|
(define-syntax define-c-procedure
|
|
(syntax-rules ()
|
|
((_ scheme-name shared-object c-name return-type argument-types)
|
|
(define scheme-name
|
|
(make-c-function shared-object
|
|
(type->native-type return-type)
|
|
c-name
|
|
(map type->native-type argument-types))))))
|
|
|
|
(define c-bytevector?
|
|
(lambda (object)
|
|
(pointer? object)))
|
|
|
|
(define c-bytevector-u8-set! pointer-set-c-uint8!)
|
|
(define c-bytevector-u8-ref pointer-ref-c-uint8)
|
|
(define c-bytevector-pointer-set! pointer-set-c-pointer!)
|
|
(define c-bytevector-pointer-ref pointer-ref-c-pointer)
|
|
(define make-c-null null-pointer)
|
|
(define c-null? null-pointer?)
|
|
|
|
|