Skip to content

Commit

Permalink
Flush outputs in main functions (#1066)
Browse files Browse the repository at this point in the history
Fixes #1064
  • Loading branch information
fare authored Dec 4, 2023
1 parent 367f9a5 commit a90c668
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/gerbil/compiler/driver.ss
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,13 @@ namespace: gxc
(write `(define builtin-modules
(append (quote ,builtin-modules) libgerbil-builtin-modules)))
(write `(define (gerbil-main)
(gerbil-runtime-init! builtin-modules)
(apply ,mod-main (cdr (command-line)))))
(with-unwind-protect
(lambda ()
(gerbil-runtime-init! builtin-modules)
(apply ,mod-main (cdr (command-line))))
(lambda ()
(with-catch void (lambda () (force-output (current-output-port))))
(with-catch void (lambda () (force-output (current-error-port))))))))
(write '(gerbil-main))
(newline)))

Expand Down
21 changes: 12 additions & 9 deletions src/gerbil/main.ss
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,17 @@ package: gerbil

(def (main)
(init!)
(let* ((cmdline (command-line))
(program (car cmdline))
(program-name (path-strip-directory program))
(args (cdr cmdline)))
(if (string-prefix? "gx" program-name)
;; a gerbil tool
(tool-main program-name args)
;; our main -- process arguments and dispatch
(bach-main program-name args))))
(unwind-protect
(let* ((cmdline (command-line))
(program (car cmdline))
(program-name (path-strip-directory program))
(args (cdr cmdline)))
(if (string-prefix? "gx" program-name)
;; a gerbil tool
(tool-main program-name args)
;; our main -- process arguments and dispatch
(bach-main program-name args)))
(with-catch void (cut force-output (current-output-port)))
(with-catch void (cut force-output (current-error-port)))))

(##main-set! main)

0 comments on commit a90c668

Please sign in to comment.