File: shadow.scm

package info (click to toggle)
scsh 0.5.1-2
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 6,540 kB
  • ctags: 8,656
  • sloc: lisp: 39,346; ansic: 13,466; sh: 1,669; makefile: 624
file content (70 lines) | stat: -rw-r--r-- 2,201 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
; Copyright (c) 1993, 1994 Richard Kelsey and Jonathan Rees.  See file COPYING.


; Deal with shadowed variables.

; When a variable is shadowed by a variable, split the existing shared
; location into two replacement locations.

; name (structure-ref p name) (define name ...) within a single template
; will lose big.

;(define *replaced-locations* '()) ;alist of (old rep ((uid ...) . new))

(define (shadow-location! old p-uids new replacement)
  (if (location-defined? old)
      (set-contents! replacement (contents old)))
  (set-location-id! old
		    (vector replacement p-uids new))
  (set-location-defined?! old #f))  ;so that exceptions will be raised

(define maybe-replace-location
  (let ((memv memv))
    (lambda (loc p-uid)			;Package's unique id
      (let ((foo (location-id loc)))
	(if (vector? foo)
	    (maybe-replace-location
	     (if (memv p-uid (vector-ref foo 1))
		 (vector-ref foo 2)
		 (vector-ref foo 0))
	     p-uid)
	    loc)))))

; Exception handler:

(define (deal-with-replaced-variables succeed)
  (lambda (opcode args)
    (primitive-catch
     (lambda (cont)
       (let* ((loc (car args))
	      (tem (continuation-template cont))
	      (index (code-vector-ref (template-code tem)
				      (- (continuation-pc cont) 1))))
	 (if (eq? (template-ref tem index) loc)
	     (let* ((p-uid (do ((env (continuation-env cont)
				     (vector-ref env 0)))
			       ((not (vector? env)) env)))
		    (new (maybe-replace-location loc p-uid)))
	       (if (eq? new loc)
		   (signal-exception opcode args)
		   (begin (template-set! tem index new)
			  (signal 'note "Replaced location" loc new p-uid)
			  (if (location-defined? new)
			      (succeed new (cdr args))
			      (signal-exception opcode
						(cons new (cdr args)))))))
	     (error "lossage in deal-with-replaced-variables"
		    loc index)))))))

(let ((op/global (enum op global))
      (op/set-global! (enum op set-global!)))

  (define-exception-handler op/global
    (deal-with-replaced-variables
       (lambda (loc more-args)
	 (contents loc))))

  (define-exception-handler op/set-global!
    (deal-with-replaced-variables
       (lambda (loc more-args)
	 (set-contents! loc (car more-args))))))