turn (list kw val)))) (cond ((string=? arg "help") (show-optimization-help) (exit 0)) ((equal? arg "0") (return (optimizations-for-level 0))) ((equal? arg "1") (return (optimizations-for-level 1))) ((equal? arg "2") (return (optimizations-for-level 2))) ((equal? arg "3") (return (optimizations-for-level 3))) ((string-prefix? "no-" arg) (return-option (substring arg 3) #f)) (else (return-option arg #t))))) (option '(#\f "from") #t #f (lambda (opt name arg result) (if (assoc-ref result 'from) (fail "`--from' option cannot be specified more than once") (alist-cons 'from (string->symbol arg) result)))) (option '(#\t "to") #t #f (lambda (opt name arg result) (if (assoc-ref result 'to) (fail "`--to' option cannot be specified more than once") (alist-cons 'to (string->symbol arg) result)))) (option '(#\T "target") #t #f (lambda (opt name arg result) (if (assoc-ref result 'target) (fail "`--target' option cannot be specified more than once") (alist-cons 'target arg result)))))) (define (parse-args args) "Parse argument list @var{args} and return an alist with all the relevant options." (args-fold args %options (lambda (opt name arg result) (format (current-error-port) "~A: unrecognized option~%" name) (exit 1)) (lambda (file result) (let ((input-files (assoc-ref result 'input-files))) (alist-cons 'input-files (cons file input-files) result))) ;; default option values '((input-files) (load-path) (warnings unsupported-warning)))) (define (show-version) (format #t "compile (GNU Guile) ~A~%" (version)) (format #t "Copyright (C) 2020 Free Software Foundation, Inc. License LGPLv3+: GNU LGPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.~%")) (define (show-warning-help) (format #t "The available warning types are:~%~%") (for-each (lambda (wt) (format #t " ~22A ~A~%" (format #f "`~A'" (warning-type-name wt)) (warning-type-description wt))) %warning-types) (format #t "~%")) (define (show-optimization-help) (format #t "The available optimizations are:~%~%") (let lp ((options (available-optimizations))) (match options (() #t) ((kw val . options) (let ((name (string-trim-right (symbol->string (keyword->symbol kw)) #\?))) (format #t " -O~a~%" (if val name (string-append "no-" name))) (lp options))))) (format #t "~%") (format #t "To disable an optimization, prepend it with `no-', for example~%") (format #t "`-Ono-cse.'~%~%") (format #t "You may also specify optimization levels as `-O0', `-O1',~%") (format #t "`-O2', or `-O3'. Currently `-O0' turns off all optimizations,~%") (format #t "`-O1' turns on partial evaluation, and `-O2' and `-O3' turn on~%") (format #t "everything. The default is equivalent to `-O2'.") (format #t "~%"))