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 / compiler / back / symtab.scm < prev    next >
Encoding:
Text File  |  1999-01-02  |  1.9 KB  |  62 lines

  1. #| -*-Scheme-*-
  2.  
  3. $Id: symtab.scm,v 1.47 1999/01/02 06:06:43 cph Exp $
  4.  
  5. Copyright (c) 1987-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. ;;;; Symbol Tables
  23. ;;; package: (compiler assembler)
  24.  
  25. (declare (usual-integrations))
  26.  
  27. (define make-symbol-table
  28.   (strong-hash-table/constructor eq-hash-mod eq? #t))
  29.  
  30. (define (symbol-table-define! table key value)
  31.   (let ((binding (hash-table/get table key #f)))
  32.     (if binding
  33.     (begin
  34.       (error "Redefining symbol:" key)
  35.       (set-binding-value! binding value))
  36.     (hash-table/put! table key (make-binding value)))))
  37.  
  38. (define (symbol-table-value table key)
  39.   (let ((binding (hash-table/get table key #f)))
  40.     (if (not binding)
  41.     (error "Undefined key:" key))
  42.     (let ((value (binding-value binding)))
  43.       (if (not value)
  44.       (error "Key has no value:" key))
  45.       value)))
  46.  
  47. (define (symbol-table->assq-list table)
  48.   (map (lambda (pair)
  49.      (cons (car pair) (binding-value (cdr pair))))
  50.        (symbol-table-bindings table)))
  51.  
  52. (define-integrable (symbol-table-bindings table)
  53.   (hash-table->alist table))
  54.  
  55. (define-integrable (make-binding initial-value)
  56.   (cons initial-value '()))
  57.  
  58. (define-integrable (binding-value binding)
  59.   (car binding))
  60.  
  61. (define (set-binding-value! binding value)
  62.   (set-car! binding value))