c-record.scm 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey
  3. (define-c-generator make-record #t
  4. (lambda (args)
  5. (bug "no eval method for MAKE-RECORD"))
  6. (lambda (call depth)
  7. (reconstruct-make-record call depth))
  8. (lambda (call port indent)
  9. (let ((type (node-type call)))
  10. (write-c-coercion type port)
  11. (format port "malloc(sizeof(")
  12. (display-c-type (pointer-type-to type) #f port)
  13. (format port ") * ")
  14. (c-value (call-arg call 0) port)
  15. (format port ")"))))
  16. (define (reconstruct-make-record call depth)
  17. (let* ((args (call-exp-args call))
  18. (arg-types (call-arg-types (cdr args) depth))
  19. (record-type (quote-exp-value (car args)))
  20. (type (record-type-type record-type))
  21. (maker-type (record-type-maker-type record-type)))
  22. (unify! maker-type (make-arrow-type arg-types type))
  23. type))
  24. (define-c-scheme-primop make-record
  25. 'allocate
  26. (lambda (call)
  27. (record-type-type (literal-value (node-ref call 0))))
  28. default-simplifier)
  29. (define-scheme-primop record-ref
  30. 'read
  31. (lambda (call)
  32. (record-slot-type (literal-value (node-ref call 0))))
  33. default-simplifier)
  34. (define-scheme-primop record-set!
  35. 'write
  36. (lambda (call) type/unit)
  37. default-simplifier)