vector.scm 3.4 KB

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