home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / runtime / sdata.scm < prev    next >
Text File  |  1999-01-02  |  3KB  |  97 lines

  1. #| -*-Scheme-*-
  2.  
  3. $Id: sdata.scm,v 14.3 1999/01/02 06:19:10 cph Exp $
  4.  
  5. Copyright (c) 1988-1999 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. |#
  21.  
  22. ;;;; Abstract Data Field
  23. ;;; package: (runtime scode-data)
  24.  
  25. (declare (usual-integrations))
  26.  
  27. (define (&typed-singleton-cons type element)
  28.   (system-pair-cons type (unmap-reference-trap element) '()))
  29.  
  30. (define (&singleton-element singleton)
  31.   (map-reference-trap (lambda () (system-pair-car singleton))))
  32.  
  33. (define (&singleton-set-element! singleton new-element)
  34.   (system-pair-set-car! singleton (unmap-reference-trap new-element)))
  35.  
  36. (define (&typed-pair-cons type car cdr)
  37.   (system-pair-cons type
  38.             (unmap-reference-trap car)
  39.             (unmap-reference-trap cdr)))
  40.  
  41. (define (&pair-car pair)
  42.   (map-reference-trap (lambda () (system-pair-car pair))))
  43.  
  44. (define (&pair-set-car! pair new-car)
  45.   (system-pair-set-car! pair (unmap-reference-trap new-car)))
  46.  
  47. (define (&pair-cdr pair)
  48.   (map-reference-trap (lambda () (system-pair-cdr pair))))
  49.  
  50. (define (&pair-set-cdr! pair new-cdr)
  51.   (system-pair-set-cdr! pair (unmap-reference-trap new-cdr)))
  52.  
  53. (define (&typed-triple-cons type first second third)
  54.   (object-new-type type
  55.            (hunk3-cons (unmap-reference-trap first)
  56.                    (unmap-reference-trap second)
  57.                    (unmap-reference-trap third))))
  58.  
  59. (define (&triple-first triple)
  60.   (map-reference-trap (lambda () (system-hunk3-cxr0 triple))))
  61.  
  62. (define (&triple-set-first! triple new-first)
  63.   (system-hunk3-set-cxr0! triple (unmap-reference-trap new-first)))
  64.  
  65. (define (&triple-second triple)
  66.   (map-reference-trap (lambda () (system-hunk3-cxr1 triple))))
  67.  
  68. (define (&triple-set-second! triple new-second)
  69.   (system-hunk3-set-cxr1! triple (unmap-reference-trap new-second)))
  70.  
  71. (define (&triple-third triple)
  72.   (map-reference-trap (lambda () (system-hunk3-cxr2 triple))))
  73.  
  74. (define (&triple-set-third! triple new-third)
  75.   (system-hunk3-set-cxr2! triple (unmap-reference-trap new-third)))
  76.  
  77. (define (&typed-vector-cons type elements)
  78.   (system-list->vector
  79.    type
  80.    (let loop ((elements elements))
  81.      (if (null? elements)
  82.      '()
  83.      (cons (unmap-reference-trap (car elements))
  84.            (loop (cdr elements)))))))
  85.  
  86. (define (&vector-length vector)
  87.   (system-vector-length vector))
  88.  
  89. (define (&vector-ref vector index)
  90.   (map-reference-trap (lambda () (system-vector-ref vector index))))
  91.  
  92. (define (&subvector->list vector start stop)
  93.   (let loop ((sublist (system-subvector->list vector start stop)))
  94.     (if (null? sublist)
  95.     '()
  96.     (cons (map-reference-trap (lambda () (car sublist)))
  97.           (loop (cdr sublist))))))