scm-memory.scm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey
  3. (define-primitive allocate-memory ((positive-integer? type/integer)) type/address)
  4. (define-primitive deallocate-memory ((address? type/address)) type/unit)
  5. (define-load-time-primitive (address? #f) address?)
  6. (define-primitive address+
  7. ((address? type/address)
  8. (integer? type/integer))
  9. type/address)
  10. (define-semi-primitive (address- address? integer?) address-
  11. (lambda (args node depth return?)
  12. (check-arg-type args 0 type/address depth node)
  13. (check-arg-type args 1 type/integer depth node)
  14. type/address)
  15. (lambda (x y) (address+ x (- 0 y))))
  16. (define-primitive address-difference
  17. ((address? type/address)
  18. (address? type/address))
  19. type/integer)
  20. (define-primitive address=
  21. ((address? type/address)
  22. (address? type/address))
  23. type/boolean)
  24. (define-primitive address<
  25. ((address? type/address)
  26. (address? type/address))
  27. type/boolean)
  28. (define-prescheme! 'null-address
  29. (let ((location (make-undefined-location 'null-address)))
  30. (set-contents! location (make-external-value "NULL" type/address))
  31. location)
  32. #f)
  33. (define-semi-primitive (null-address? address?) null-address?
  34. (lambda (args node depth return)
  35. (check-arg-type args 0 type/address depth node)
  36. type/boolean)
  37. (lambda (x) (address= x null-address)))
  38. (define (address-comparison-rule args node depth return?)
  39. (check-arg-type args 0 type/address depth node)
  40. (check-arg-type args 1 type/address depth node)
  41. type/boolean)
  42. (define-semi-primitive (address> address? address?) address>
  43. address-comparison-rule
  44. (lambda (x y) (address< y x)))
  45. (define-semi-primitive (address<= address? address?) address<=
  46. address-comparison-rule
  47. (lambda (x y) (not (address< y x))))
  48. (define-semi-primitive (address>= address? address?) address>=
  49. address-comparison-rule
  50. (lambda (x y) (not (address< x y))))
  51. (define-primitive address->integer
  52. ((address? type/address))
  53. type/integer)
  54. (define-primitive integer->address
  55. ((integer? type/integer))
  56. type/address)
  57. (define-primitive copy-memory!
  58. ((address? type/address)
  59. (address? type/address)
  60. (positive-integer? type/integer))
  61. type/unit)
  62. (define-primitive memory-equal?
  63. ((address? type/address)
  64. (address? type/address)
  65. (positive-integer? type/integer))
  66. type/boolean)
  67. (define-primitive unsigned-byte-ref
  68. ((address? type/address))
  69. type/integer
  70. byte-ref)
  71. (define-primitive unsigned-byte-set!
  72. ((address? type/address) (unsigned-byte? type/integer))
  73. type/unit
  74. byte-set!)
  75. (define-primitive word-ref ((address? type/address)) type/integer)
  76. (define-primitive word-set!
  77. ((address? type/address) (positive-integer? type/integer))
  78. type/unit)
  79. (define-primitive flonum-ref ((address? type/address)) type/float)
  80. (define-primitive flonum-set!
  81. ((address? type/address) (floatnum? type/float))
  82. type/unit)
  83. (define-primitive char-pointer->string
  84. ((address? type/address)
  85. (positive-integer? type/integer))
  86. type/string)
  87. (define-primitive char-pointer->nul-terminated-string
  88. ((address? type/address))
  89. type/string)
  90. (let ((read-block-return-type
  91. (make-tuple-type (list type/integer type/boolean type/status))))
  92. (define-primitive read-block
  93. ((input-port? type/input-port)
  94. (address? type/address)
  95. (positive-integer? type/integer))
  96. read-block-return-type))
  97. (define-primitive write-block
  98. ((output-port? type/output-port)
  99. (address? type/address)
  100. (positive-integer? type/integer))
  101. type/status)