/usr/share/scheme48-1.9/big/dump.scm is in scheme48 1.9-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | ; Part of Scheme 48 1.9. See file COPYING for notices and license.
; Authors: Richard Kelsey, Jonathan Rees, Mike Sperber
; Dump and restore
; Unix has special meanings for
; ETX, FS, DEL, ETB, NAK, DC2, EOT, EM (or SUB?), DC3, DC1, SI, SYN,
; 3 28 127 23 21 18 4 25 26 19 17 15 22
; so avoid using them.
(define type/null #\n)
(define type/true #\t)
(define type/false #\f)
(define type/unspecific #\u)
(define type/pair #\p) ;obj1 obj2
(define type/string #\s) ;length chars
(define type/number #\i) ;#chars rep
(define type/symbol #\y) ;length chars
(define type/char #\c) ;char
(define type/vector #\v) ;length objects
(define type/template #\a) ;length objects
(define type/code-vector #\k) ;length bytes (each byte is 2 hex digits?)
(define type/location #\l) ;uid
(define type/closure #\q) ;template-info
(define type/ellipsis #\e)
(define type/random #\r)
; Recursive entry
(define (dump obj write-char depth)
(cond ((null? obj) (dump-type type/null write-char))
((eq? obj #t) (dump-type type/true write-char))
((eq? obj #f) (dump-type type/false write-char))
((pair? obj) (dump-pair obj write-char depth))
;; Template case needs to precede vector case
((template? obj) (dump-template obj write-char depth))
((vector? obj) (dump-vector obj write-char depth))
((symbol? obj) (dump-symbol obj write-char))
((number? obj) (dump-number obj write-char))
((string? obj) (dump-string obj write-char))
((char? obj) (dump-char-literal obj write-char))
((code-vector? obj) (dump-code-vector obj write-char))
((location? obj) (dump-location obj write-char))
((unspecific? obj) (dump-type type/unspecific write-char))
((closure? obj) (dump-closure obj write-char))
(else (dump-random obj write-char depth))))
(define (restore read-char)
(let ((type (restore-type read-char)))
((vector-ref restorers (char->ascii type)) type read-char)))
(define restorers
(make-vector 256 (lambda (type read-char)
;; Invalid type
(assertion-violation 'restore "invalid type code" type))))
(define (define-restorer! type proc)
(vector-set! restorers (char->ascii type) proc))
; Particular dumpers & restorers
(define-restorer! type/null (lambda (c read-char) '()))
(define-restorer! type/false (lambda (c read-char) #f))
(define-restorer! type/true (lambda (c read-char) #t))
(define-restorer! type/unspecific (lambda (c read-char) (if #f #f)))
; Pairs
(define (dump-pair obj write-char depth)
(if (= depth 0)
(dump-ellipsis obj write-char)
(let ((depth (- depth 1)))
(dump-type type/pair write-char)
(dump (car obj) write-char depth)
(dump (cdr obj) write-char depth))))
(define-restorer! type/pair
(lambda (c write-char)
c ;ignored
(let ((the-car (restore write-char)))
(cons the-car (restore write-char)))))
; Symbols
(define (dump-symbol obj write-char)
(dump-type type/symbol write-char)
(dump-a-string (symbol-case-converter (symbol->string obj)) write-char))
(define-restorer! type/symbol
(lambda (c read-char)
c ;ignored
(string->symbol (symbol-case-converter (restore-a-string read-char)))))
; Numbers
; <space> ... _ represent 0 ... 63,
; {<space> ... {_ represent 64 ... 127, -- { is ascii 123
; |<space> ... |_ represent 128 ... 191, -- | is ascii 124
; }<space> ... }_ represent 192 ... 256. -- } is ascii 125
(define (dump-number n write-char)
(if (not (communicable-number? n))
(assertion-violation 'dump-number "can't dump this number" n))
(if (and (integer? n)
(>= n 0)
(< n 256))
(dump-byte n write-char)
(begin (dump-type type/number write-char)
;; Note logarithmic recursion
(dump-a-string (number->string n comm-radix) write-char))))
(define (communicable-number? n) #t) ;this gets redefined in client
(define (dump-byte n write-char) ;Dump a number between 0 and 255
(if (< n 64)
(write-char (ascii->char (+ n ascii-space)))
(begin (write-char (ascii->char (+ (arithmetic-shift n -6)
122)))
(write-char (ascii->char (+ (bitwise-and n 63)
ascii-space))))))
(define ascii-space (char->ascii #\space)) ;32
(define (restore-small-integer c read-char)
(- (char->ascii c) ascii-space))
(do ((i (+ ascii-space 63) (- i 1)))
((< i ascii-space))
(define-restorer! (ascii->char i) restore-small-integer))
(define (restore-medium-integer c read-char)
(+ (arithmetic-shift (- (char->ascii c) 122) 6)
(- (char->ascii (read-char)) ascii-space)))
(do ((i 123 (+ i 1)))
((> i 125))
(define-restorer! (ascii->char i) restore-medium-integer))
(define (restore-number read-char)
(let ((c (read-char)))
(if (char=? c type/number)
(string->number (restore-a-string read-char) comm-radix)
(let ((n (char->ascii c)))
(if (> n 122)
(restore-medium-integer c read-char)
(- n ascii-space))))))
(define-restorer! type/number
(lambda (c read-char)
c ;ignored
(string->number (restore-a-string read-char) comm-radix)))
(define comm-radix 16)
; String literals
(define (dump-string obj write-char)
(dump-type type/string write-char)
(dump-a-string obj write-char))
(define-restorer! type/string
(lambda (c read-char)
c ;ignored
(restore-a-string read-char)))
; Characters
(define (dump-char-literal obj write-char)
(dump-type type/char write-char)
(dump-a-char obj write-char))
(define-restorer! type/char
(lambda (c read-char)
c ;ignored
(restore-a-char read-char)))
; Vectors
(define (dump-vector obj write-char depth)
(dump-vector-like obj write-char depth
type/vector vector-length vector-ref))
(define (dump-template obj write-char depth)
(dump-vector-like obj write-char depth
type/template template-length template-ref))
(define (dump-vector-like obj write-char depth type vector-length vector-ref)
(if (= depth 0)
(dump-ellipsis obj write-char)
(let ((depth (- depth 1))
(len (vector-length obj)))
(dump-type type write-char)
(dump-length len write-char)
(do ((i 0 (+ i 1)))
((= i len) 'done)
(dump (vector-ref obj i) write-char depth)))))
(define (restore-vector-like make-vector vector-set!)
(lambda (c read-char)
c ;ignored
(let* ((len (restore-length read-char))
(v (make-vector len #\?)))
(do ((i 0 (+ i 1)))
((= i len) v)
(vector-set! v i (restore read-char))))))
(define-restorer! type/vector
(restore-vector-like make-vector vector-set!))
(define-restorer! type/template
(restore-vector-like make-template template-set!))
; Code vectors
(define (dump-code-vector obj write-char)
(dump-type type/code-vector write-char)
(let ((len (code-vector-length obj)))
(dump-length len write-char)
(do ((i 0 (+ i 1)))
((= i len) 'done)
(dump-byte (code-vector-ref obj i) write-char))))
(define-restorer! type/code-vector
(lambda (c read-char)
c ;ignored
(let* ((len (restore-length read-char))
(cv (make-code-vector len 0)))
(do ((i 0 (+ i 1)))
((= i len) cv)
(code-vector-set! cv i
(restore-number read-char))))))
; Locations
(define (dump-location obj write-char)
(dump-type type/location write-char)
(dump-number (location->uid obj) write-char))
(define (location->uid obj)
(or ((fluid $dump-index) obj)
(location-id obj)))
(define-restorer! type/location
(lambda (c read-char)
c ;ignored
(uid->location (restore-number read-char))))
(define (uid->location uid)
(or ((fluid $restore-index) uid)
(table-ref uid->location-table uid)
(let ((loc (make-undefined-location uid)))
(note-location! loc)
loc)))
(define $restore-index (make-fluid (lambda (uid) #f)))
(define uid->location-table (make-table))
(define (note-location! den)
(table-set! uid->location-table
(location-id den)
den))
(define $dump-index (make-fluid (lambda (loc) #f)))
; For simulation purposes, it's better for location uid's not to
; conflict with any that might be in the base Scheme 48 system. (In the
; real server system there isn't any base Scheme 48 system, so there's
; no danger of conflict.)
; (define location-uid-origin 5000)
; Closure
(define (dump-closure obj write-char)
(dump-type type/closure write-char)
(let ((id (template-info (closure-template obj))))
(dump-number (if (integer? id) id 0) write-char)))
(define-restorer! type/closure
(lambda (c read-char)
c ;ignored
(make-random (list 'closure (restore-number read-char)))))
; Random
(define random-type (make-record-type 'random '(disclosure)))
(define make-random (record-constructor random-type '(disclosure)))
(define-record-discloser random-type
(let ((d (record-accessor random-type 'disclosure)))
(lambda (r) (cons "Remote" (d r)))))
(define (dump-random obj write-char depth)
(dump-type type/random write-char)
(dump (or (disclose obj) (list '?))
write-char
depth))
(define-restorer! type/random
(lambda (c read-char)
(make-random (restore read-char))))
; Ellipsis
(define (dump-ellipsis obj write-char)
(dump-type type/ellipsis write-char))
(define-restorer! type/ellipsis
(lambda (c read-char) (make-random (list (string->symbol "---")))))
; Auxiliaries:
; Strings (not necessarily preceded by type code)
(define (dump-a-string obj write-char)
(let ((len (string-length obj)))
(dump-length len write-char)
(do ((i 0 (+ i 1)))
((= i len) 'done)
(dump-a-char (string-ref obj i) write-char))))
(define (restore-a-string read-char)
(let* ((len (restore-length read-char))
(str (make-string len #\?)))
(do ((i 0 (+ i 1)))
((= i len) str)
(string-set! str i (restore-a-char read-char)))))
(define (dump-a-char c write-char)
(write-char c))
(define (restore-a-char read-char)
(read-char))
; Type characters
(define (dump-type c write-char)
(write-char c))
(define (restore-type read-char)
(read-char))
(define dump-length dump-number)
(define restore-length restore-number)
;(define char->ascii char->integer) -- defined in p-features.scm
;(define ascii->char integer->char) -- ditto
; Miscellaneous support
(define (unspecific? obj)
(eq? obj *unspecific*))
(define *unspecific* (if #f #f)) ;foo
;(define (integer->digit-char n)
; (ascii->char (+ n (if (< n 10) ascii-zero a-minus-ten))))
;
;(define (digit-char->integer c)
; (cond ((char-numeric? c)
; (- (char->ascii c) ascii-zero))
; ((char=? c #\#) 0)
; (else
; (- (char->ascii (char-downcase c)) a-minus-ten))))
;
;(define ascii-zero (char->ascii #\0))
;
;(define a-minus-ten (- (char->integer #\a) 10))
; These modified from s48/boot/transport.scm
(define (string-case-converter string)
(let ((new (make-string (string-length string) #\?)))
(do ((i 0 (+ i 1)))
((>= i (string-length new)) new)
(string-set! new i (invert-case (string-ref string i))))))
(define (invert-case c)
(cond ((char-upper-case? c) (char-downcase c))
((char-lower-case? c) (char-upcase c))
(else c)))
(define symbol-case-converter
(if (char=? (string-ref (symbol->string 't) 0) #\t)
(lambda (string) string)
string-case-converter))
; ASCII
; !"#$%&'()*+,-./0123456789:;<=>?
; @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
; `abcdefghijklmnopqrstuvwxyz{|}~
;(define (tst x)
; (let ((l '()))
; (dump x (lambda (c) (set! l (cons c l))) -1)
; (let ((l (reverse l)))
; (restore (lambda ()
; (let ((c (car l)))
; (set! l (cdr l))
; c))))))
;(define cwcc call-with-current-continuation)
;
;(define (tst x)
; (letrec ((write-cont (lambda (ignore)
; (dump x
; (lambda (c)
; (cwcc (lambda (k)
; (set! write-cont k)
; (read-cont c))))
; -1)))
; (read-cont #f))
; (restore (lambda ()
; (cwcc (lambda (k)
; (set! read-cont k)
; (write-cont 'ignore)))))))
|