scm-memory.scm 3.7 KB

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