File: theme-d-param-cache.scm

package info (click to toggle)
theme-d 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 12,784 kB
  • sloc: lisp: 47,684; sh: 4,200; makefile: 455; ansic: 319
file content (174 lines) | stat: -rw-r--r-- 5,331 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
;; Copyright (C) 2008-2013 Tommi Höynälänmaa
;; Distributed under GNU General Public License version 3,
;; see file doc/GPL-3.



;; *** Parametrized class instance cache ***


(import (rnrs exceptions)
	(srfi srfi-1)
	(th-scheme-utilities stdutils)
	(th-scheme-utilities hrecord))


;; (define gl-ctr7 0)
(define gl-flag8? #f)


(define equal-reprs-fwd? '())


(define-hrecord-type <param-cache> ()
  cache)


(define is-param-cache? (get-hrecord-type-predicate <param-cache>))


(define (param-cache-init) '())


;;(define (param-classes-equal? t1 t2)
;;  (address=? (hfield-ref t1 'address) (hfield-ref t2 'address)))


(define (param-classes-equal? t1 t2)
  ;; Probably eq? would work, too.
  (eqv? t1 t2))


(define (param-cache-fetch-param-class param-cache param-class)
  (assert (is-param-cache? param-cache))
  (assert (is-target-object? param-class))
  (let ((result
	 (assoc param-class (hfield-ref param-cache 'cache)
		param-classes-equal?)))
    result))


(define (type-params-equal? tp1 tp2)
  (and (= (length tp1) (length tp2))
       (and-map? eqv? tp1 tp2)))


(define (param-cache-fetch param-cache param-class type-params)
  (assert (is-param-cache? param-cache))
  (assert (is-target-object? param-class))
  (assert (list? type-params))
  (assert (and-map? is-target-object? type-params))
  (let ((class-bindings (param-cache-fetch-param-class param-cache
						       param-class)))
    (let* ((eq-pred? (lambda (tp1 tp2)
		       (type-params-equal? tp1 tp2)))
	   (result
	    (if (not (eqv? class-bindings #f))
		(assoc type-params (cdr class-bindings) eq-pred?)
		#f)))
      result)))


(define (param-cache-fetch2 param-cache binder param-class type-params)
  (assert (is-param-cache? param-cache))
  (assert (is-target-object? param-class))
  (assert (list? type-params))
  (assert (and-map? is-target-object? type-params))
  (let ((class-bindings (param-cache-fetch-param-class param-cache
						       param-class)))
    (let* ((eq-pred? (lambda (tp1 tp2)
		       (equal-reprs1? binder tp1 tp2)))
	   (result
	    (if (not (eqv? class-bindings #f))
		(assoc type-params (cdr class-bindings) eq-pred?)
		#f)))
      result)))


(define (param-cache-add-binding! param-cache param-class
				  type-params new-instance)
  (assert (is-param-cache? param-cache))
  (assert (is-target-object? param-class))
  (assert (list? type-params))
  (assert (and-map? is-target-object? type-params))
  (assert (is-target-object? new-instance))
  (let ((class-bindings (param-cache-fetch-param-class param-cache
						       param-class)))
    (if (not (eqv? class-bindings #f))
	(set-cdr! class-bindings
		  (cons (cons type-params new-instance) 
			(cdr class-bindings)))
	(hfield-set! param-cache 'cache
		     (append
		      (list (cons param-class
				  (list (cons type-params new-instance))))
		      (hfield-ref param-cache 'cache))))))


;; Voitanee käyttää eq?.
(define (param-cache-bind-declared! param-cache param-class type-params
				    new-instance)
  (assert (is-param-cache? param-cache))
  (assert (is-target-object? param-class))
  (assert (list? type-params))
  (assert (and-map? is-target-object type-params))
  (assert (is-target-object? new-instance))
  (let ((class-bindings (param-cache-fetch-param-class
			 param-cache param-class)))
    (if (not (eqv? class-bindings #f))
	(let* ((eq-pred? (lambda (tp1 tp2)
			   (type-params-equal? tp1 tp2)))
	       (binding (assoc type-params (cdr class-bindings)
			       eq-pred?)))
	  (if (not (eqv? binding #f))
	      (begin
		;; Vanha (cdr binding) voi aiheuttaa ongelmia.
		;; Vanhoissa versioissa asetettiin sen fw-val-kenttä.
		(set-cdr! binding new-instance))
	      (raise 'variable-not-found-1)))
	(raise 'variable-not-found-2))))


(define (param-cache-bind-declared2! param-cache param-class type-params
				     new-instance)
  (assert (is-param-cache? param-cache))
  (assert (is-target-object? param-class))
  (assert (list? type-params))
  (assert (and-map? is-target-object? type-params))
  (assert (is-target-object? new-instance))
  (let ((class-bindings (param-cache-fetch-param-class
			 param-cache param-class)))
    (if (not (eqv? class-bindings #f))
	(let* ((eq-pred? (lambda (tp1 tp2)
			   (type-params-equal? tp1 tp2)))
	       (binding (assoc type-params (cdr class-bindings)
			       eq-pred?)))
	  (if (not (eqv? binding #f))
	      (begin
		(assert (is-target-object? (cdr binding)))
		(set-object! (cdr binding) new-instance))
	      (raise 'variable-not-found-3)))
	(raise 'variable-not-found-4))))


(define (param-cache-bind-declared3! param-cache binder param-class type-params
				     new-instance)
  (assert (is-param-cache? param-cache))
  (assert (is-target-object? param-class))
  (assert (list? type-params))
  (assert (and-map? is-target-object? type-params))
  (assert (is-target-object? new-instance))
  (let ((class-bindings (param-cache-fetch-param-class
			 param-cache param-class)))
    (if (not (eqv? class-bindings #f))
	(let* ((eq-pred? (lambda (tp1 tp2)
			   (equal-reprs1? binder tp1 tp2)))
	       (binding (assoc type-params (cdr class-bindings)
			       eq-pred?)))
	  (if (not (eqv? binding #f))
	      (begin
		(assert (is-target-object? (cdr binding)))
		(set-object! (cdr binding) new-instance))
	      (raise 'variable-not-found-3)))
	(raise 'variable-not-found-4))))