;; -*- Mode: Irken -*- (include "lib/basis.scm") ;; (define (pointer-deref p) ;; (%%cexp ((ptr 'a) -> 'a) "*(%0)" p)) ;; (define (as-pint x) ;; (%%cexp ('a -> (ptr int)) "(int*)%0" x)) ;; how about something that can allocate a number of objects of a certain ;; size. For example, an array of 100 8-bit unsigned bytes? ;; we want to be able to allocate and use C structs without having to know ;; their exact layout. (cinclude "sys/socket.h") (define (make-sockaddr) (%callocate (struct sockaddr) 5)) (printn (make-sockaddr)) (let ((ui100 (%callocate uint8_t 100)) (ul10 (%callocate uint64_t 10))) (printn (%cget #f ui100 0)) (printn (%cget #f ul10 5)) (printn (%cset #f ul10 5 314159)) (printn (%cget #f ul10 5)) ) ;;(let ((ob #(1 2 3))) ;; (printn (%%cexp (-> int) "sizeof(struct sockaddr)")) ;; (printn (%%cexp (-> int) "sizeof(uint8_t[100])")) ;; (pointer-deref (as-pint ob)))