1999-09-14 09:32:05 -04:00
|
|
|
;;; Scsh start-up code.
|
|
|
|
;;; Copyright (c) 1995 by Olin Shivers.
|
|
|
|
|
|
|
|
;;; A scsh starter takes the command line args, parses them,
|
|
|
|
;;; initialises the scsh system, and either starts up a repl loop
|
|
|
|
;;; or executes the -s script.
|
|
|
|
|
|
|
|
(define (make-scsh-starter)
|
|
|
|
(let ((context (user-context)))
|
|
|
|
(lambda (args)
|
|
|
|
(parse-switches-and-execute args context))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Had to define these as the ones in s48's build.scm do not properly
|
|
|
|
;;; initialise ERROR-OUTPUT-PORT to stderr -- this is a bug in the vm's
|
|
|
|
;;; handoff to the very first Scheme form (it passes two ports -- not three).
|
|
|
|
;;; Until Kelsey fixes these, we hack it with these replacements, which
|
|
|
|
;;; invoke INIT-SCSH-HINDBRAIN, which re-initialises the I/O system to be
|
|
|
|
;;; what you wanted.
|
|
|
|
|
|
|
|
;;; WRITE-IMAGE calls the starter after installing a fatal top-level
|
|
|
|
;;; error handler. MAKE-SCSH-STARTER shadows it in the interactive case.
|
|
|
|
|
|
|
|
(define (really-dump-scsh-program start filename)
|
|
|
|
(let ((filename (translate filename)))
|
|
|
|
(display (string-append "Writing " filename) (command-output))
|
|
|
|
(newline (command-output))
|
2000-12-21 08:27:28 -05:00
|
|
|
;JMG: it is set to #f in the vm, so I omit it now
|
1999-09-22 20:43:13 -04:00
|
|
|
;;;(flush-the-symbol-table!) ;Gets restored at next use of string->symbol
|
1999-09-14 09:32:05 -04:00
|
|
|
(write-image filename
|
|
|
|
(scsh-stand-alone-resumer start)
|
|
|
|
"Scsh 0.6")
|
|
|
|
#t))
|
|
|
|
|
|
|
|
|
|
|
|
;;; This one relies on the scsh top-level command-line switch parser
|
|
|
|
;;; to decide whether to do the scsh-var inits quietly or with warnings.
|
|
|
|
|
|
|
|
(define (dump-scsh fname)
|
1999-09-29 18:45:47 -04:00
|
|
|
(really-dump-scsh-program (make-scsh-starter) fname))
|
1999-09-14 09:32:05 -04:00
|
|
|
|
|
|
|
;;; Init the scsh run-time's vars quietly before running the program.
|
|
|
|
;;; This is what we export to the user for his programs.
|
|
|
|
|
|
|
|
(define (dump-scsh-program start filename)
|
2001-11-27 13:11:38 -05:00
|
|
|
(let ((context (user-context)))
|
2002-05-16 10:34:58 -04:00
|
|
|
(really-dump-scsh-program (lambda (args)
|
|
|
|
(with-scsh-initialized
|
|
|
|
#f context args
|
|
|
|
(lambda ()
|
|
|
|
(start args))))
|
|
|
|
filename)))
|
1999-09-14 09:32:05 -04:00
|
|
|
|
|
|
|
(define (scsh-stand-alone-resumer start)
|
2002-05-03 09:42:36 -04:00
|
|
|
(usual-resumer ; sets up exceptions, interrupts,
|
|
|
|
; and current input & output
|
|
|
|
(lambda (args) ; VM gives us our args, but not our program.
|
1999-09-24 19:52:32 -04:00
|
|
|
(init-fdports!)
|
1999-09-14 09:32:05 -04:00
|
|
|
(call-with-current-continuation
|
2002-05-03 09:42:36 -04:00
|
|
|
(lambda (halt)
|
|
|
|
(set! %vm-prog-args (cons "scsh" args)) ; WRONG -- use image.
|
|
|
|
(set-command-line-args! %vm-prog-args)
|
|
|
|
(with-handler
|
|
|
|
(simple-condition-handler halt (current-error-port))
|
|
|
|
(lambda ()
|
|
|
|
(let ((dynamic-env (get-dynamic-env))
|
|
|
|
(*result* 4711))
|
|
|
|
(let ((runnable (make-thread-queue))
|
|
|
|
(thread (make-thread (lambda ()
|
|
|
|
(set! *result*
|
|
|
|
(start (command-line))))
|
|
|
|
dynamic-env
|
|
|
|
'scsh-initial-thread))
|
|
|
|
(thread-count (make-counter)))
|
|
|
|
|
|
|
|
(enqueue-thread! runnable thread)
|
|
|
|
(increment-counter! thread-count)
|
|
|
|
|
|
|
|
(run-threads
|
|
|
|
(round-robin-event-handler runnable 200 dynamic-env thread-count
|
|
|
|
(lambda args #f)
|
|
|
|
(lambda (thread token args) ; upcall handler
|
|
|
|
(propogate-upcall thread token args))
|
|
|
|
(lambda ()
|
|
|
|
(if (positive? (counter-value thread-count))
|
|
|
|
((structure-ref threads-internal wait))
|
|
|
|
#f))))
|
|
|
|
(if (integer? *result*) *result* 0)))))))))) ; work around bug.
|
1999-09-14 09:32:05 -04:00
|
|
|
|
|
|
|
(define %vm-prog-args #f)
|
1999-09-29 18:45:47 -04:00
|
|
|
|