top.scm (2795B)
1 ;;; top.scm - driver for command-line executable 2 3 4 (define (option? x) 5 (and (> (string-length x) 0) 6 (char=? #\- (string-ref x 0)))) 7 8 (define (usage code) 9 (let ((out (if (zero? code) (current-output-port) (current-error-port)))) 10 (display "usage: spock OPTION | FILENAME ...\n\n" out) 11 (display " -source show source forms\n" out) 12 (display " -expand show forms after macro-expansion\n" out) 13 (display " -canonicalized show forms after canonicalization\n" out) 14 (display " -optimized show forms after optimization\n" out) 15 (display " -cps show forms after CPS-conversion\n" out) 16 (display " -strict enable strict mode\n" out) 17 (display " -optimize enable optimizations\n" out) 18 (display " -block enable block-compilation\n" out) 19 (display " -library-path [DIR] add DIR to library path or show library path\n" out) 20 (display " -namespace VAR put globals into module\n" out) 21 (display " -xref show cross-reference\n" out) 22 (display " -runtime include runtime-system in generated code\n" out) 23 (display " -library compile runtime library\n" out) 24 (display " -seal wrap toplevel definitions into local scope\n" out) 25 (display " -debug enable debug mode\n" out) 26 (display " -verbose show diagnostic messages\n" out) 27 (display " -import FILENAME expand syntax in FILENAME\n" out) 28 (display " -debug-syntax show debug-output during expansion\n" out) 29 (display " -bind FILENAME generate bindings for specifications in FILENAME\n" out) 30 (display " -o FILENAME specify output-file\n" out) 31 (exit code))) 32 33 (define (run args) 34 (let ((opts '())) 35 (define (add . xs) 36 (set! opts (append opts xs))) 37 (define (option->symbol o) 38 (string->symbol (substring o 1 (string-length o)))) 39 (let loop ((args args)) 40 (match args 41 (() 42 (apply spock 'usage (lambda _ (usage 1)) 'fail fail opts)) 43 (((or "-h" "-help" "--help") . _) 44 (usage 0)) 45 (("-o" out . more) 46 (add 'output-file out) 47 (loop more)) 48 (("-library-path") 49 (print (car (spock 'library-path)))) 50 (((and o (or "-library-path" "-namespace" "-bind")) arg . more) 51 (add (option->symbol o) arg) 52 (loop more)) 53 (((and o (or "-source" "-expand" "-canonicalized" "-cps" "-strict" 54 "-block" "-xref" "-runtime" "-library" 55 "-seal" "-debug" "-debug-syntax" "-import" "-verbose" 56 "-optimize" "-optimized")) 57 . more) 58 (add (option->symbol o)) 59 (loop more)) 60 (((? option?) . _) 61 (usage 1)) 62 ((file . more) 63 (add file) 64 (loop more)))))) 65 66 (cond-expand 67 (spock 68 (define-entry-point (spock_main . args) 69 (run args))) 70 (else))