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 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
|
;==============================================================================
; file: "_errors.scm"
; Copyright (C) 1994-1998 by Marc Feeley, All Rights Reserved.
(##include "header.scm")
;------------------------------------------------------------------------------
; Traps from the runtime system.
(define (##trap-list-lengths name . args)
(##runtime-error "Lists are not of equal length" name args))
(define (##trap-list-lengths* name . args)
(##runtime-error* "Lists are not of equal length" name args))
(define (##trap-list name . args)
(##runtime-error "LIST expected" name args))
(define (##trap-list* name . args)
(##runtime-error* "LIST expected" name args))
(define (##trap-open-file name . args)
(##runtime-error "Can't open file" name args))
(define (##trap-open-file* name . args)
(##runtime-error* "Can't open file" name args))
(define (##trap-open-pipe name . args)
(##runtime-error "Can't open pipe" name args))
(define (##trap-open-pipe* name . args)
(##runtime-error* "Can't open pipe" name args))
(define (##trap-load err-msg name . args)
(##runtime-error
(if err-msg
(##string-append "Can't load file (" err-msg ")")
"Can't load file")
name args))
(define (##trap-load* err-msg name . args)
(##runtime-error*
(if err-msg
(##string-append "Can't load file (" err-msg ")")
"Can't load file")
name args))
(define (##trap-check-pair name . args)
(##runtime-error "PAIR expected" name args))
(define (##trap-check-pair* name . args)
(##runtime-error* "PAIR expected" name args))
(define (##trap-check-will name . args)
(##runtime-error "WILL expected" name args))
(define (##trap-check-will* name . args)
(##runtime-error* "WILL expected" name args))
(define (##trap-check-char name . args)
(##runtime-error "CHARACTER expected" name args))
(define (##trap-check-char* name . args)
(##runtime-error* "CHARACTER expected" name args))
(define (##trap-check-symbol name . args)
(##runtime-error "SYMBOL expected" name args))
(define (##trap-check-symbol* name . args)
(##runtime-error* "SYMBOL expected" name args))
(define (##trap-check-keyword name . args)
(##runtime-error "KEYWORD expected" name args))
(define (##trap-check-keyword* name . args)
(##runtime-error* "KEYWORD expected" name args))
(define (##trap-check-string name . args)
(##runtime-error "STRING expected" name args))
(define (##trap-check-string* name . args)
(##runtime-error* "STRING expected" name args))
(define (##trap-check-vector name . args)
(##runtime-error "VECTOR expected" name args))
(define (##trap-check-vector* name . args)
(##runtime-error* "VECTOR expected" name args))
(define (##trap-check-u8vector name . args)
(##runtime-error "U8VECTOR expected" name args))
(define (##trap-check-u8vector* name . args)
(##runtime-error* "U8VECTOR expected" name args))
(define (##trap-check-u16vector name . args)
(##runtime-error "U16VECTOR expected" name args))
(define (##trap-check-u16vector* name . args)
(##runtime-error* "U16VECTOR expected" name args))
(define (##trap-check-u32vector name . args)
(##runtime-error "U32VECTOR expected" name args))
(define (##trap-check-u32vector* name . args)
(##runtime-error* "U32VECTOR expected" name args))
(define (##trap-check-f32vector name . args)
(##runtime-error "F32VECTOR expected" name args))
(define (##trap-check-f32vector* name . args)
(##runtime-error* "F32VECTOR expected" name args))
(define (##trap-check-f64vector name . args)
(##runtime-error "F64VECTOR expected" name args))
(define (##trap-check-f64vector* name . args)
(##runtime-error* "F64VECTOR expected" name args))
(define (##trap-check-procedure name . args)
(##runtime-error "PROCEDURE expected" name args))
(define (##trap-check-procedure* name . args)
(##runtime-error* "PROCEDURE expected" name args))
(define (##trap-check-interp-procedure* name . args)
(##runtime-error* "Interpreted PROCEDURE expected" name args))
(define (##trap-check-input-port name . args)
(##runtime-error "INPUT PORT expected" name args))
(define (##trap-check-input-port* name . args)
(##runtime-error* "INPUT PORT expected" name args))
(define (##trap-check-output-port name . args)
(##runtime-error "OUTPUT PORT expected" name args))
(define (##trap-check-output-port* name . args)
(##runtime-error* "OUTPUT PORT expected" name args))
(define (##trap-check-open-port name . args)
(##runtime-error "Open PORT expected" name args))
(define (##trap-check-open-port* name . args)
(##runtime-error* "Open PORT expected" name args))
(define (##trap-check-readtable name . args)
(##runtime-error "READTABLE expected" name args))
(define (##trap-check-readtable* name . args)
(##runtime-error* "READTABLE expected" name args))
(define (##trap-check-number name . args)
(##runtime-error "NUMBER expected" name args))
(define (##trap-check-number* name . args)
(##runtime-error* "NUMBER expected" name args))
(define (##trap-check-real name . args)
(##runtime-error "REAL expected" name args))
(define (##trap-check-real* name . args)
(##runtime-error* "REAL expected" name args))
(define (##trap-check-rational name . args)
(##runtime-error "RATIONAL expected" name args))
(define (##trap-check-integer name . args)
(##runtime-error "INTEGER expected" name args))
(define (##trap-check-integer* name . args)
(##runtime-error* "INTEGER expected" name args))
(define (##trap-check-exact-int name . args)
(##runtime-error "Exact INTEGER expected" name args))
(define (##trap-check-exact-int* name . args)
(##runtime-error* "Exact INTEGER expected" name args))
(define (##trap-check-inexact-real name . args)
(##runtime-error "Inexact REAL expected" name args))
(define (##trap-check-inexact-real* name . args)
(##runtime-error* "Inexact REAL expected" name args))
(define (##trap-check-range name . args)
(##runtime-error "Out of range" name args))
(define (##trap-check-range* name . args)
(##runtime-error* "Out of range" name args))
(define (##trap-divide-by-zero name . args)
(##runtime-error "Division by zero" name args))
(define (##trap-divide-by-zero* name . args)
(##runtime-error* "Division by zero" name args))
(define (##trim-absent lst)
(if (##pair? lst)
(if (##eq? (##car lst) (absent-obj))
'()
(begin
(let loop ((curr lst) (next (##cdr lst)))
(if (##pair? next)
(if (##eq? (##car next) (absent-obj))
(##set-cdr! curr '())
(loop next (##cdr next)))))
lst))
'()))
(define (##runtime-error err-msg name args)
(##signal '##signal.runtime-error err-msg name (##trim-absent args)))
(define (##runtime-error* err-msg name args)
(define (fix l)
(if (##pair? (##cdr l)) (##cons (##car l) (fix (##cdr l))) (##car l)))
(##signal '##signal.runtime-error err-msg name (##trim-absent (fix args))))
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(define (##default-signal-catcher s args)
(if (##unbound? ##stderr)
(##exit 1)
(cond ((##eq? s '##signal.io-error)
(##handle-simple-error
#f
#f
(##car args)
(##cdr args)
'()))
((##eq? s '##signal.read-error)
(##handle-simple-error
'read
(##make-locat (##port-name (##car args))
(##cadr args))
(##caddr args)
(##cdddr args)
'()))
((##eq? s '##signal.unbound-dynamic-var)
(##handle-simple-error
#f
#f
"Unbound dynamic variable:"
(##list (##car args))
'()))
((##eq? s '##signal.global-unbound)
(##handle-interpreter-error
(##car args)
(##cadr args)
"Unbound variable:"
(##list (##decomp (##car args)))
'()))
((##eq? s '##signal.global-unbound-operator)
(##handle-call-error
(##car args)
(##cadr args)
"Unbound global variable in operator position"
'()))
((##eq? s '##signal.global-non-procedure-operator)
(##handle-call-error
(##car args)
(##cadr args)
"Global variable in operator position is not a PROCEDURE"
'()))
((##eq? s '##signal.non-procedure-jump)
(##handle-call-error
(let ((x (##car args)))
(if (##self-eval? x) x (##list 'quote x)))
(##cadr args)
"Operator is not a PROCEDURE"
'()))
((##eq? s '##signal.non-procedure-operator)
(##handle-interpreter-error
(##car args)
(##cadr args)
"Operator is not a PROCEDURE"
'()
(##list (##decomp (##car args)))))
((##eq? s '##signal.non-procedure-send)
(##handle-interpreter-error
(##car args)
(##cadr args)
"PROCEDURE expected after '=>':"
'()
(##list (##decomp (##car args)))))
((##eq? s '##signal.wrong-nb-arg)
(##handle-call-error
(##car args)
(##trim-absent (##cadr args))
"Wrong number of arguments passed to procedure"
'()))
((##eq? s '##signal.unknown-keyword-arg)
(##handle-call-error
(##car args)
(##cadr args)
"Unknown keyword argument passed to procedure"
'()))
((##eq? s '##signal.keyword-expected)
(##handle-call-error
(##car args)
(##cadr args)
"Keyword argument expected"
'()))
((##eq? s '##signal.clam-conv-error)
(let ((arg-num (##fixnum.modulo (##car args) 128)))
(if (##fixnum.= arg-num 0)
(##handle-call-error
(##cadr args)
(##caddr args)
"'c-lambda' data representation conversion error on result"
'())
(##handle-call-error
(##cadr args)
(##caddr args)
"'c-lambda' data representation conversion error on argument"
(##list arg-num)))))
((##eq? s '##signal.cdef-conv-error)
(##handle-call-error;****************
(##cadr args)
'()
"'c-define' data representation conversion error on argument"
(##list (##fixnum.modulo (##car args) 128))))
((##eq? s '##signal.multiple-c-return)
(##handle-simple-error
#f
#f
"Attempt to return to a C function that has already returned"
'()
'()))
((##eq? s '##signal.apply-arg-limit)
(##handle-call-error
(##car args)
(##cadr args)
"Argument count to apply exceeds implementation limit"
'()))
((##eq? s '##signal.heap-overflow)
(##handle-simple-error
#f
#f
"Heap overflow"
'()
'()))
((##eq? s '##signal.stack-overflow)
(##handle-simple-error
#f
#f
"Stack overflow"
'()
'()))
((##eq? s '##signal.promise-already-determined)
(##handle-simple-error
#f
#f
"Promise already determined"
'()
'()))
((##eq? s '##signal.runtime-error)
(##handle-call-error
(##cadr args)
(##caddr args)
(##car args)
'()))
((##eq? s '##signal.global-env-overflow)
(##handle-simple-error
#f
#f
"Global variable table overflow"
'()
'()))
((##eq? s '##signal.syntax-error)
(let* ((src (##car args))
(locat (##source-locat src)))
(##handle-simple-error
#f
locat
(##cadr args)
(##cddr args)
(if locat '() (##list (##desourcify src))))))
(else
(##write-string "*** ERROR -- Signal not caught, " ##stderr)
(##write s ##stderr ##main-readtable #f)
(##write-string " " ##stderr)
(##write args ##stderr ##main-readtable #f)
(##newline ##stderr)
(##exit 1)))))
(define (##handle-simple-error proc locat err-msg err-infos pps)
(##sequentially (lambda ()
(##identify-error
"ERROR"
proc
locat
err-msg
err-infos
pps)
(##pop-repl))))
(define (##handle-interpreter-error $code rte err-msg err-infos pps)
(##call-with-current-continuation
(lambda (cont) (##sequentially (lambda ()
(##identify-error
"ERROR"
(##extract-container $code rte)
(##frame-locat (##continuation->first-frame cont))
err-msg
err-infos
pps)
(##debug-repl cont #t))))))
(define (##handle-call-error proc args err-msg err-infos)
(##call-with-current-continuation
(lambda (cont) (##sequentially (lambda ()
(define (add-quotes l)
(if (##pair? l)
(let ((x (##car l)))
(##cons (if (##self-eval? x) x (##list 'quote x))
(add-quotes (##cdr l))))
'()))
(##identify-error
"ERROR"
#f
(##frame-locat (##continuation->first-frame cont))
err-msg
err-infos
'())
(let ((out (##repl-out))
(rt (##repl-readtable)))
(let ((call (##cons (if (##procedure? proc)
(##procedure-name proc)
proc)
(add-quotes args)))
(width (##port-width out)))
(let ((str (##object->string call rt width (if-forces #t #f))))
(if (##fixnum.< (##string-length str) width)
(##write-string str out)
(begin
(##write-string "(" out)
(##write-string (##object->string
(##car call)
rt
(##fixnum.- width 1)
(if-forces #t #f))
out)
(##newline out)
(let loop ((l (##cdr call)))
(if (##pair? l)
(begin
(##write-string " " out)
(##write-string (##object->string
(##car l)
rt
(##fixnum.- width 2)
(if-forces #t #f))
out)
(##newline out)
(loop (##cdr l)))))
(##write-string ")" out)))
(##newline out)
(##debug-repl cont #t)))))))))
(define (##identify-error kind proc locat err-msg err-infos pps)
(let ((out (##repl-out))
(rt (##repl-readtable)))
(##write-string "*** " out)
(##write-string kind out)
(if (or proc locat)
(##write-string " IN " out))
(if proc
(##display (if (##procedure? proc)
(##procedure-name proc)
proc)
out
rt
#f))
(if locat
(begin
(if proc
(##write-string ", " out))
(##display-locat locat #t out rt)))
(if err-msg
(begin
(##write-string " -- " out)
(##display err-msg out rt #f)
(let loop1 ((l err-infos))
(if (##pair? l)
(begin
(##write-string " " out)
(##write (##car l) out rt #f)
(loop1 (##cdr l)))))))
(##newline out)
(let loop2 ((l pps))
(if (##pair? l)
(begin
(##pretty-print (##car l) out rt)
(loop2 (##cdr l)))))))
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(define (##signal sig . args)
(let ((signal-catcher
(##dynamic-ref '##signal-catcher ##default-signal-catcher)))
(signal-catcher sig args)))
(define (##catch-all signal-catcher thunk)
(##dynamic-let (##list (##cons '##signal-catcher signal-catcher)) thunk))
(define (##catch-signal sig signal-catcher thunk)
(let ((parent-signal-catcher
(##dynamic-ref '##signal-catcher ##default-signal-catcher)))
(##catch-all (lambda (s args)
(if (##eq? s sig)
(signal-catcher s args)
(parent-signal-catcher s args)))
thunk)))
(define (##cleanup-on-signal thunk1 thunk2)
(let ((parent-signal-catcher
(##dynamic-ref '##signal-catcher ##default-signal-catcher)))
(##catch-all (lambda (s args)
(thunk2)
(parent-signal-catcher s args))
thunk1)))
;------------------------------------------------------------------------------
; Exceptions raised by low level runtime system
(##declare (not interrupts-enabled))
(define (##exception.global-jump gv . args)
(let ((val (##global-var-ref gv)))
(force-vars (val)
(if (##procedure? val)
(##apply val args)
(if (##unbound? val)
(##signal '##signal.global-unbound-operator gv args)
(##signal '##signal.global-non-procedure-operator gv args))))))
(define (##exception.non-proc-jump proc . args)
(force-vars (proc)
(if (##procedure? proc)
(##apply proc args)
(##signal '##signal.non-procedure-jump proc args))))
(define (##exception.wrong-nb-arg proc . args)
(##signal '##signal.wrong-nb-arg proc args))
(define (##exception.unknown-keyword-arg proc . args)
(##signal '##signal.unknown-keyword-arg proc args))
(define (##exception.keyword-expected proc . args)
(##signal '##signal.keyword-expected proc args))
(define (##exception.clam-conv-error err-code proc . args)
(##signal '##signal.clam-conv-error err-code proc args))
(define (##exception.cdef-conv-error err-code proc)
(##signal '##signal.cdef-conv-error err-code proc))
(define (##exception.multiple-c-return)
(##signal '##signal.multiple-c-return))
(define (##exception.apply-arg-limit proc args)
(##signal '##signal.apply-arg-limit proc args))
(define (##exception.heap-overflow)
(##signal '##signal.heap-overflow))
(define (##exception.stack-overflow)
(##signal '##signal.stack-overflow))
(define (##exception.promise-already-determined)
(##signal '##signal.promise-already-determined))
;------------------------------------------------------------------------------
|