cffi.scm 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. (define-module (cffi)
  2. #:export (defcstruct define-foreign-type defctype
  3. with-foreign-pointer with-foreign-object
  4. foreign-enum-value defbitfield defcenum defcfun)
  5. #:use-module (system reader library)
  6. #:use-module (oop goops)
  7. #:use-module (rnrs base)
  8. #:use-module (hurd-cl-compat))
  9. ;; XXX use guile-reader for temporarily
  10. ;; changing the reader.
  11. (eval-when (expand)
  12. (use-modules (system base target)
  13. (srfi srfi-1))
  14. (define (clisp-features)
  15. `(,(case (target-endianness)
  16. (big 'big-endian)
  17. (little 'little-endian))
  18. ,(case (target-word-size)
  19. (16 '128-bit)
  20. (8 '64-bit)
  21. (4 '32-bit))
  22. guile))
  23. (define (has-features? features condition)
  24. (cond ((symbol? condition)
  25. (memq condition features))
  26. ((and (pair? condition)
  27. (eq? (car condition) 'and))
  28. (lset<= eq? (cdr condition) features))
  29. ((and (pair? condition)
  30. (eq? (car condition) 'or))
  31. (not (null? (lset-intersection eq? (cdr condition) features))))
  32. (#t (pk 'c condition)
  33. TODO)))
  34. (define (parse-path c port)
  35. (let ((path (read port)))
  36. (assert (string? path))
  37. path))
  38. ;; XXX features
  39. ;; XXX these cannot be used before a #\)
  40. (define (parse-unless c port)
  41. (let ((condition (read port))
  42. (code (read port)))
  43. (if (has-features? (clisp-features) condition)
  44. (read port)
  45. code)))
  46. (define (parse-when c port)
  47. (let ((condition (read port))
  48. (code (read port)))
  49. (if (has-features? (clisp-features) condition)
  50. code
  51. (read port))))
  52. (read-hash-extend #\p parse-path)
  53. (read-hash-extend #\- parse-unless)
  54. (read-hash-extend #\+ parse-when))
  55. (read-set! keywords 'prefix)
  56. (define-syntax-rule (include-from-paths x ...)
  57. (begin (include-from-path x)
  58. ...))
  59. (define-syntax-rule (in-package anything)
  60. (begin #f))
  61. (eval-when (expand load eval)
  62. (include-from-paths
  63. "cffi/src/utils.lisp"
  64. "cffi/src/early-types.lisp"))
  65. #;
  66. (include-from-paths
  67. "cffi/src/cffi-guile.lisp"
  68. ;; "cffi/src/package.lisp"
  69. "cffi/src/libraries.lisp"
  70. "cffi/src/types.lisp"
  71. "cffi/src/enum.lisp"
  72. "cffi/src/strings.lisp"
  73. "cffi/src/structures.lisp"
  74. "cffi/src/functions.lisp"
  75. "cffi/src/foreign-vars.lisp"
  76. "cffi/src/features.lisp")
  77. (eval-when (expand)
  78. (read-hash-extend #\p #f)
  79. (read-hash-extend #\- #f)
  80. (read-hash-extend #\+ #f))