racketcs: add support for -m flag

This commit is contained in:
Matthew Flatt 2018-10-09 15:07:31 -06:00
parent 238e2c7861
commit de753399b6
4 changed files with 26 additions and 3 deletions

View File

@ -41,6 +41,6 @@
(error "output did not match expected pattern: " (error "output did not match expected pattern: "
(get-output-bytes s)))) (get-output-bytes s))))
(check "tcp" "socket dup failed") (check "tcp" "socket dup failed|error during dup of file descriptor")
(check "stdio" "port dup failed")) (check "stdio" "port dup failed|error during dup of file descriptor"))

View File

@ -24,6 +24,10 @@
module-declared? module-declared?
module->language-info module->language-info
module-path-index-join module-path-index-join
identifier-binding
namespace-datum-introduce
datum->kernel-syntax
namespace-variable-value
version version
exit exit
compile-keep-source-locations! compile-keep-source-locations!
@ -279,6 +283,12 @@
(eval (read (open-input-string expr)))) (eval (read (open-input-string expr))))
loads)) loads))
(flags-loop rest-args (see saw 'non-config)))] (flags-loop rest-args (see saw 'non-config)))]
[("-m" "--main")
(set! loads
(cons
(lambda () (call-main))
loads))
(flags-loop (cdr args) (see saw 'non-config))]
[("-i" "--repl") [("-i" "--repl")
(set! repl? #t) (set! repl? #t)
(set! version? #t) (set! version? #t)
@ -363,6 +373,18 @@
;; Non-flag argument ;; Non-flag argument
(finish args saw)])]))))) (finish args saw)])])))))
(define (call-main)
(let ([m (namespace-datum-introduce 'main)])
(unless (identifier-binding m)
(namespace-variable-value 'main #f
(lambda ()
(error "main: not defined or required into the top-level environment"))))
(call-with-values (lambda () (eval (datum->kernel-syntax
(cons m (vector->list remaining-command-line-arguments)))))
(lambda results
(let ([p (|#%app| current-print)])
(for-each (lambda (v) (|#%app| p v)) results))))))
;; Set up GC logging ;; Set up GC logging
(define-values (struct:gc-info make-gc-info gc-info? gc-info-ref gc-info-set!) (define-values (struct:gc-info make-gc-info gc-info? gc-info-ref gc-info-set!)
(make-struct-type 'gc-info #f 10 0 #f null 'prefab #f '(0 1 2 3 4 5 6 7 8 9))) (make-struct-type 'gc-info #f 10 0 #f null 'prefab #f '(0 1 2 3 4 5 6 7 8 9)))

View File

@ -101,6 +101,7 @@
namespace-attach-module namespace-attach-module
namespace-attach-module-declaration namespace-attach-module-declaration
namespace-mapped-symbols namespace-mapped-symbols
namespace-variable-value
module-path-index? module-path-index?
module-path-index-join module-path-index-join

View File

@ -369,7 +369,7 @@
(define new-fd (rktio_dup rktio fd)) (define new-fd (rktio_dup rktio fd))
(when (rktio-error? new-fd) (when (rktio-error? new-fd)
(end-atomic) (end-atomic)
(raise-rktio-error 'place-channel-put new-fd "error during duping file descriptor")) (raise-rktio-error 'place-channel-put new-fd "error during dup of file descriptor"))
(define fd-dup (box (rktio_fd_detach rktio new-fd))) (define fd-dup (box (rktio_fd_detach rktio new-fd)))
(unsafe-add-global-finalizer fd-dup (lambda () (unsafe-add-global-finalizer fd-dup (lambda ()
(define fd (unbox fd-dup)) (define fd (unbox fd-dup))