File: prt.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 (189 lines) | stat: -rw-r--r-- 5,225 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

;; Copyright (C) 2018 Tommi Höynälänmaa
;; Distributed under GNU Lesser General Public License version 3,
;; see file doc/LGPL-3.

(import (theme-d runtime runtime0))


(define obj->string-to-display-fwd '())


(define (list-contents-to-string lst visited)
  (let ((result
	 (if (null? lst)
	     ""
	     (string-append
	      (obj->string-to-display-fwd (car lst) visited)
	      (if (not-null? (cdr lst)) " " "")
	      (list-contents-to-string (cdr lst) visited)))))
    result))


(define (tvar->string-to-display tvar)
  (string-append
   "%"
   (number->string (vector-ref tvar i-tvar-object-number))))


(define (aplti->string-to-display aplti visited)
  (string-append
   "(*"
   (vector-ref (vector-ref aplti i-aplti-param-ltype) i-class-name)
   " "
   (list-contents-to-string (vector-ref aplti i-aplti-tvar-values)
			    visited)
   "*)"))


(define (apci->string-to-display apci visited)
  (string-append
   "(*"
   (vector-ref (vector-ref apci i-apci-param-class) i-class-name)
   " "
   (list-contents-to-string (vector-ref apci i-apci-tvar-values)
			    visited)
   "*)"))


(define (obj->string-to-display obj visited)
  (let ((new-visited (cons obj visited)))
    (cond
     ((null? obj) "[]")
     ((eqv? obj _b_<null>) "{}")
     ((memv obj visited) "/cycle/")
     ((is-tvar-object? obj)
      (tvar->string-to-display obj))
     ((list? obj)
      (string-append
       "["
       (list-contents-to-string obj new-visited)
       "]"))
     ((pair? obj)
      (string-append "["
		     (obj->string-to-display (car obj) new-visited)
		     " . "
		     (obj->string-to-display (cdr obj) new-visited)
		     "]"))
     ((is-tuple-type? obj)
      (string-append
       "{"
       (list-contents-to-string (tuple-type->list-reject-cycles obj)
				new-visited)
       "}"))
     ((is-pair-class? obj)
      (string-append
       "{"
       (obj->string-to-display (gen-car obj) new-visited)
       " . "
       (obj->string-to-display (gen-cdr obj) new-visited)
       "}"))
     ((is-simple-proc-class? obj)
      (string-append
       "(:simple-proc "
       (obj->string-to-display (vector-ref obj i-procedure-class-arg-list-type)
			       new-visited)
       " "
       (obj->string-to-display (vector-ref obj i-procedure-class-result-type)
			       new-visited)
       " "
       (if (vector-ref obj i-procedure-class-pure-proc) "pure" "nonpure")
       ")"))
     ((is-param-proc-class? obj)
      (let ((tvars (vector-ref obj i-ppc-tvars))
	    (inst-type (vector-ref obj i-ppc-inst-type)))
	(string-append
	 "(:param-proc ["
	 (list-contents-to-string tvars new-visited)
	 "] "
	 (obj->string-to-display
	  (vector-ref inst-type i-procedure-class-arg-list-type)
	  new-visited)
	 " "
	 (obj->string-to-display
	  (vector-ref inst-type i-procedure-class-result-type)
	  new-visited)
	 " "
	 (if (vector-ref inst-type i-procedure-class-pure-proc)
	     "pure" "nonpure")
	 ")")))
     ((is-abstract-proc-type? obj)
      (string-append
       "(:procedure "
       (obj->string-to-display (vector-ref obj i-procedure-class-arg-list-type)
			       new-visited)
       " "
       (obj->string-to-display (vector-ref obj i-procedure-class-result-type)
			       new-visited)
       " "
       (if (vector-ref obj i-procedure-class-pure-proc) "pure" "nonpure")
       ")"))
     ((is-type-list? obj)
      (string-append
       "(type-list "
       (list-contents-to-string (vector-ref obj i-type-list-subexprs)
				new-visited)
       ")"))
     ((is-splice-expression? obj)
      (string-append
       "(splice "
       (obj->string-to-display (vector-ref obj i-splice-component)
			       new-visited)
       ")"))
     ;; ((is-concrete-uniform-list? obj)
     ;;  (string-append
     ;;   "(:uniform-list "
     ;;   (obj->string-to-display (get-uniform-list-element-type obj))
     ;;  ")"))
     ((is-type-loop? obj)
      (string-append
       "(type-loop "
       (tvar->string-to-display (vector-ref obj i-type-loop-iter-var))
       " "
       (obj->string-to-display (vector-ref obj i-type-loop-subtype-list)
			       new-visited)
       " "
       (obj->string-to-display (vector-ref obj i-type-loop-iter-expr)
			       new-visited)
       ")"))
     ((is-class? obj)
      (vector-ref obj i-class-name))
     ((is-aplti? obj)
      (aplti->string-to-display obj new-visited))
     ((is-apci? obj)
      (apci->string-to-display obj new-visited))
     ((is-union? obj)
      (string-append
       "(:union "
       (list-contents-to-string (vector-ref obj i-union-member-types)
				new-visited)
       ")"))
     ((is-singleton? obj)
      (string-append
       "(<singleton> "
       (obj->string-to-display (vector-ref obj i-singleton-element)
			       new-visited)
       ")"))
     ((is-marker? obj)
      (string-append
       "(<marker> "
       (obj->string-to-display (vector-ref obj i-marker-object)
			       new-visited)
       ")"))
     ((eq? obj _b_none)
      "<none>")
     (else
      (let* ((cl (theme-class-of obj))
	     (class-name (vector-ref cl i-class-name)))
	(string-append "@" class-name))))))


(set! obj->string-to-display-fwd obj->string-to-display)


(define (prt obj)
  (display (obj->string-to-display obj '()))
  (newline))


(set! prt-fwd prt)