File: theme-d-fields.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 (203 lines) | stat: -rw-r--r-- 7,238 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
;; Copyright (C) 2008-2013 Tommi Höynälänmaa
;; Distributed under GNU General Public License version 3,
;; see file doc/GPL-3.


;; *** Field handling for the compiler ***


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


(define (check-field-read-access? field modname-cur modname-cl)
  (let ((read-access (tno-field-ref field 's-read-access)))
    (case read-access
      ((public) #t)
      ;; Toimiiko, jos modname-cl on nil?
      ((module) (or (null? modname-cl) (module-name=? modname-cur modname-cl)))
      ((hidden) #f))))


(define (do-translate-field-ref-appl compiler t-obj-expr t-field-name-value)
  (if (not (and (is-t-primitive-object? t-field-name-value)
		(symbol? (hfield-ref t-field-name-value 'obj-prim-contents))))
      (raise 'field-ref:invalid-field))
  (let* ((obj-type (get-entity-type t-obj-expr))
	 (binder (compiler-get-binder compiler)))
    (cond
     ;; ((is-t-param-class-instance? obj-type)
     ;;  (let* ((param-class (hfield-ref obj-type 'type))
     ;; 	     (field-name (hfield-ref t-field-name-value
     ;; 				     'obj-prim-contents))
     ;; 	     (modname-cl (tno-field-ref param-class 'module))
     ;; 	     (modname-cur (get-current-module-name compiler))
     ;; 	     (field (get-instance-field-spec obj-type field-name)))
     ;; 	  (if (eqv? field '())
     ;; 	      (raise 'nonexistent-field-1)
     ;; 	      (if (check-field-read-access? field modname-cur modname-cl)
     ;; 		  (translate-const-field-ref-param binder
     ;; 						   t-obj-expr field-name #f)
     ;; 		  (raise 'field-ref-access-violation)))))
     ((is-t-instance? binder obj-type tc-class)
      (let ((inside-param-def? (hfield-ref compiler 'inside-param-def?))
	    (type-dispatched? (hfield-ref t-obj-expr 'type-dispatched?)))
	(cond
	 ((and (not inside-param-def?) (not type-dispatched?))
	  (raise 'illegal-nondispatched-type))
	 ((not type-dispatched?)
	  (let* ((field-name (hfield-ref t-field-name-value
					 'obj-prim-contents))
		 (field (get-field-spec obj-type field-name)))
	    (assert (is-t-field? field))
	    (let ((tt-field (tno-field-ref field 'type)))
	      (assert (is-type? binder tt-field))
	      (make-hrecord
	       <field-ref-expr>
	       tt-field
	       #f
	       #f
	       '()
	       
	       (is-pure-entity? t-obj-expr)
	       #f
	       #t
	       '()
	       
	       ;; The existence of the field is checked statically.
	       (entity-always-returns? t-obj-expr)
	       (entity-never-returns? t-obj-expr)
	       #t
	       t-obj-expr
	       field-name))))
	 (else
	  (let* ((field-name (hfield-ref t-field-name-value
					 'obj-prim-contents))
		 (modname-cl (tno-field-ref obj-type 'module))
		 (modname-cur (get-current-module-name compiler))
		 (field (get-field-spec obj-type field-name)))
	    (if (eqv? field '())
		(raise (list 'field-ref:nonexistent-field
			     (cons 's-field-name field-name)))
		(if (check-field-read-access? field modname-cur modname-cl)
		    (translate-const-field-ref-fwd binder
						   t-obj-expr
						   field-name)
		    (raise 'field-ref-access-violation))))))))
     (else
      (dvar1-set! t-obj-expr)
      (raise 'field-ref:invalid-object-type)))))


(define (translate-field-ref-appl compiler proc arguments)
  (assert (hrecord-is-instance? compiler <compiler>))
  (assert (is-entity? proc))
  (if (and (list? arguments)
	   (= (length arguments) 2)
	   (and-map? is-entity? arguments))
      (begin
	(check-no-none-arguments (compiler-get-binder compiler)
				 arguments 'field-ref)
	(let ((obj (car arguments))
	      (sym-field-name (cadr arguments)))
	  (do-translate-field-ref-appl compiler obj sym-field-name)))
      (raise 'field-ref:invalid-args)))


;; Olion konstruoinnissa kenttien arvot kirjoitetaan
;; suoraan kohdekoodilla, joten proseduuria field-set!
;; ei silloin tarvita.
(define (check-field-write-access? field modname-cur modname-cl)
  (let ((write-access (tno-field-ref field 's-write-access)))
    (case write-access
      ((public) #t)
      ((module) (or (null? modname-cl) (module-name=? modname-cur modname-cl)))
      ((hidden) #f))))


(define (do-translate-field-set-appl compiler t-obj-expr t-field-name-value
				     t-value)
  (if (not (and (is-t-primitive-object? t-field-name-value)
		(symbol? (hfield-ref t-field-name-value 'obj-prim-contents))))
      (raise 'field-set!:invalid-field))
  (let ((obj-type (get-entity-type t-obj-expr))
	(binder (compiler-get-binder compiler)))
    (cond
     ((is-t-instance? binder obj-type tc-class)
      (let ((inside-param-def? (hfield-ref compiler 'inside-param-def?))
	    (type-dispatched? (hfield-ref t-obj-expr 'type-dispatched?)))
	(cond
	 ((and (not inside-param-def?) (not type-dispatched?))
	  (raise 'illegal-nondispatched-type))
	 ((not type-dispatched?)
	  (let ((field-name (hfield-ref t-field-name-value
					'obj-prim-contents)))
	    (make-hrecord
	     <field-set-expr>
	     tc-object
	     #f
	     #f
	     '()
	     
	     (and (is-pure-entity? t-obj-expr) (is-pure-entity? t-value))
	     #f
	     #t
	     '()

	     ;; The existence of the field is checked statically.
	     (and (entity-always-returns? t-obj-expr)
		  (entity-always-returns? t-value))
	     (or (entity-never-returns? t-obj-expr)
		 (entity-never-returns? t-value))
	     #t
	     t-obj-expr
	     field-name
	     t-value)))
	 (else
	  (let* ((field-name (hfield-ref t-field-name-value
					 'obj-prim-contents))
		 (modname-cl (tno-field-ref obj-type 'module))
		 (modname-cur (get-current-module-name compiler))
		 (field (get-field-spec obj-type field-name)))
	    (if (eqv? field '())
		(raise (list 'field-set!:nonexistent-field
			     (cons 's-field-name field-name)))
		(if (check-field-write-access?
		     field modname-cur modname-cl)
		    (translate-const-field-set-fwd binder t-obj-expr field-name
						   t-value #t
						   inside-param-def?)
		    (raise 'field-set-access-violation))))))))
     ;; ((is-t-param-class-instance? obj-type)
     ;;  (let* ((param-class (hfield-ref obj-type 'param-class))
     ;; 	     (field-name (hfield-ref t-field-name-value
     ;; 				       'contents))
     ;; 	     (modname-cl (tno-field-ref param-class 'module))
     ;; 	     (modname-cur (get-current-module-name compiler))
     ;; 	     (field (get-instance-field-spec param-class field-name)))
     ;; 	(if (check-field-write-access?
     ;; 	     field modname-cur modname-cl)
     ;; 	    (translate-const-field-set binder t-obj-expr field-name
     ;; 				       t-value #f)
     ;; 	    (raise 'field-set-access-violation))))
     (else (raise 'field-set:invalid-object-type)))))


(define (translate-field-set-appl compiler proc arguments)
  (assert (hrecord-is-instance? compiler <compiler>))
  (assert (is-entity? proc))
  (if (and (list? arguments)
	   (= (length arguments) 3)
	   (and-map? is-entity? arguments))
      (begin
	(check-no-none-arguments (compiler-get-binder compiler)
				 arguments 'field-set!)
	(let ((t-obj-expr (car arguments))
	      (t-field-expr (cadr arguments))
	      (t-value-expr (caddr arguments)))
	  (do-translate-field-set-appl compiler t-obj-expr t-field-expr
				       t-value-expr)))
      (raise 'field-set!:invalid-args)))