home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / sicp / genenv.scm < prev    next >
Encoding:
Text File  |  1993-07-17  |  3.2 KB  |  101 lines

  1. #| -*-Scheme-*-
  2.  
  3. $Header: genenv.scm,v 1.2 90/11/14 14:57:50 GMT cph Exp $
  4.  
  5. Copyright (c) 1987, 1988, 1989, 1990 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. |#
  34.  
  35. ;;;; Environment hacking for 6.001
  36.  
  37. (declare (usual-integrations))
  38.  
  39. (define build-environment)
  40.  
  41. (define make-unassigned-object
  42.   microcode-object/unassigned)
  43.  
  44. (let ()
  45.   (define (get-values descriptors frame receiver)
  46.     (define (inner descriptors names values unref)
  47.       (define (do-next name-here name-there)
  48.     (if (or (not (symbol? name-there))
  49.         (lexical-unreferenceable? frame name-there))
  50.         (inner (cdr descriptors)
  51.            (cons name-here names)
  52.            (cons (make-unassigned-object)
  53.              values)
  54.            (if (not (symbol? name-there))
  55.                unref
  56.                (cons name-here unref)))
  57.         (inner (cdr descriptors)
  58.            (cons name-here names)
  59.            (cons (lexical-reference frame name-there)
  60.              values)
  61.            unref)))
  62.  
  63.       (if (null? descriptors)
  64.       (receiver (reverse! names)
  65.             (reverse! values)
  66.             (reverse! unref))
  67.       (let ((this (car descriptors)))
  68.         (cond ((not (pair? this))
  69.            (do-next this this))
  70.           ((null? (cdr this))
  71.            (do-next (car this) (car this)))
  72.           (else
  73.            (do-next (car this) (cdr this)))))))
  74.     (inner descriptors '() '() '()))
  75.  
  76.   (set! build-environment
  77.     (named-lambda (build-environment names source-frame
  78.                      #!optional parent-frame
  79.                      process receiver)
  80.       (get-values names source-frame
  81.         (lambda (names values unreferenceable)
  82.           (if (default-object? receiver)
  83.           unreferenceable
  84.           (receiver
  85.            (apply (scode-eval (make-lambda lambda-tag:make-environment
  86.                            names
  87.                            '()
  88.                            '()
  89.                            '()
  90.                            '()
  91.                            (make-the-environment))
  92.                       (if (default-object? parent-frame)
  93.                       source-frame
  94.                       parent-frame))
  95.               (map (if (default-object? process)
  96.                    unmap-reference-trap
  97.                    (lambda (x)
  98.                      (unmap-reference-trap (process x))))
  99.                    values))
  100.            unreferenceable))))))
  101.   42)