File: theme-d-constructors.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 (84 lines) | stat: -rw-r--r-- 1,830 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
;; Copyright (C) 2008-2013 Tommi Höynälänmaa
;; Distributed under GNU General Public License version 3,
;; see file doc/GPL-3.



;;; *** Constructors ***


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


(define (get-field-arg-types fields)
  (assert (list? fields))
  (let ((result '()))
    (do ((cur-lst fields (cdr cur-lst)))
	((null? cur-lst) result)
      (let ((cur-field (car cur-lst)))
	(if (not (tno-field-ref cur-field 'has-init-value?))
	    (begin
	      (dvar1-set! cur-field)
	      (let ((type (tno-field-ref cur-field 'type)))
		(set! result
		      (append result (list type))))))))))


(define (get-constructor-type binder r-class)
  (assert (is-binder? binder))
  (assert (is-target-object? r-class))
  (assert (is-t-instance? binder r-class tc-class))
  (let* ((all-fields (tno-field-ref r-class 'l-all-fields))
	 (field-types (get-field-arg-types all-fields))
	 (result
	  ;; Constructors always return.
	  (translate-simple-proc-class-expression
	   binder
	   field-types r-class #t #t #f #f)))
    result))


(define (get-empty-constructor to-class)
  (make-hrecord <expr-constructor>
		(make-tpti-general-proc
		 #t
		 (make-tt-uniform-list tc-object)
		 to-class
		 #t #t #f #f)
		#t
		#f
		'()

		#t
		#t
		#f
		'()

		to-class))


(define (make-constructor! binder to-class)
  (assert (is-binder? binder))
  (assert (is-target-object? to-class))
  (let ((type-constructor (get-constructor-type binder to-class)))
    ;; The result value of make-constructor! is not used.
    (tno-field-set! to-class 'type-constructor type-constructor)))


(set! make-constructor-fwd! make-constructor!)


(define (get-constructor-expr tc type-constructor)
  (make-hrecord <expr-constructor>
		type-constructor
		#t
		#t
		'()
		#t
		#t
		#f
		'()
		tc))