vector.scm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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, Mike Sperber
  6. ;;;
  7. ;;; scheme48-1.9.2/ps-compiler/prescheme/primop/vector.scm
  8. (define-module (ps-compiler prescheme primop vector)
  9. #:use-module (ps-compiler node let-nodes)
  10. #:use-module (ps-compiler node node)
  11. #:use-module (ps-compiler node node-util)
  12. #:use-module (ps-compiler node variable)
  13. #:use-module (ps-compiler node primop)
  14. #:use-module (ps-compiler prescheme primop primop)
  15. #:use-module (ps-compiler prescheme record)
  16. #:use-module (ps-compiler prescheme type)
  17. #:use-module (ps-compiler simp call)
  18. #:use-module (ps-compiler simp pattern)
  19. #:use-module (ps-compiler simp simplify)
  20. #:use-module (ps-compiler util util))
  21. (define-polymorphic-scheme-primop make-vector allocate
  22. (lambda (call)
  23. (make-pointer-type (node-type (call-arg call 1)))))
  24. (define-polymorphic-scheme-primop vector-ref read
  25. (lambda (call)
  26. (pointer-type-to (node-type (call-arg call 0)))))
  27. (define-nonsimple-scheme-primop vector-set! write)
  28. (define-scheme-primop make-string allocate type/string)
  29. (define-scheme-primop string-length type/integer)
  30. (define-scheme-primop string-ref read type/char)
  31. (define-nonsimple-scheme-primop string-set! write)
  32. (define-polymorphic-scheme-primop make-record allocate
  33. (lambda (call)
  34. (literal-value (call-arg call 1))))
  35. (define-polymorphic-scheme-primop record-ref read
  36. (lambda (call)
  37. (record-field-type
  38. (get-record-type-field (literal-value (call-arg call 1))
  39. (literal-value (call-arg call 2))))))
  40. (define-nonsimple-scheme-primop record-set! write)
  41. (define (simplify-type-case-test call)
  42. (simplify-args call 0))
  43. ;; There should be no discovered calls to TYPE-CASE.
  44. (define (expand-type-case call)
  45. (bug "Trying to expand a call to TYPE-CASE (~D) ~S"
  46. (node-hash (node-parent (nontrivial-ancestor call)))
  47. call))
  48. ;; See simplify-if? in simplify/call.scm
  49. (define (simplify-type-case? call index value)
  50. #f)
  51. (define-scheme-cond-primop type-case
  52. simplify-type-case-test
  53. expand-test
  54. simplify-type-case?)
  55. (define-scheme-primop deallocate deallocate type/unit)
  56. (define-scheme-primop allocate-memory allocate type/address)
  57. (define-scheme-primop deallocate-memory deallocate type/unit)
  58. (define (simplify-address+ call)
  59. (simplify-args call 0)
  60. ((pattern-simplifier
  61. ((address+ a '0) a)
  62. ((address+ (address+ a x) y) (address+ a (+ x y))))
  63. call))
  64. (define-scheme-primop address+ #f type/address simplify-address+)
  65. (define-scheme-primop address-difference type/address)
  66. (define-scheme-primop address= type/boolean)
  67. (define-scheme-primop address< type/boolean)
  68. (define-scheme-primop address->integer type/integer)
  69. (define-scheme-primop integer->address type/address)
  70. (define-scheme-primop copy-memory! write type/unit)
  71. (define-scheme-primop memory-equal? type/boolean)
  72. (define-scheme-primop byte-ref read type/integer)
  73. (define-scheme-primop word-ref read type/integer)
  74. (define-scheme-primop flonum-ref read type/float)
  75. (define-nonsimple-scheme-primop byte-set! write)
  76. (define-nonsimple-scheme-primop word-set! write)
  77. (define-nonsimple-scheme-primop flonum-set! write)
  78. ;; We delete the length argument because we don't need it. This is allowable
  79. ;; because trivial calls can't have WRITE side effects.
  80. (define-scheme-primop char-pointer->string #f type/string
  81. (lambda (call)
  82. (if (= 2 (call-arg-count call))
  83. (remove-call-arg call 1))))
  84. (define-scheme-primop char-pointer->nul-terminated-string type/string)
  85. ;; (COMPUTED-GOTO <exit0> <exit1> ... <exitN> <dispatch-value>)
  86. ;; Remove an unecessary coercion on the dispatch-value, if possible.
  87. (define (simplify-computed-goto call)
  88. (simplify-args call 0)
  89. (let ((value (call-arg call (call-exits call))))
  90. (cond ((and (call-node? value)
  91. (eq? 'coerce (primop-id (call-primop value)))
  92. (< (call-exits call) 256)
  93. (eq? type/integer (literal-value (call-arg value 1))))
  94. (replace value (detach (call-arg value 0)))))))
  95. (define-nonsimple-scheme-primop computed-goto #f simplify-computed-goto)