-D, --define-feature cmd line option

This commit is contained in:
ESL 2024-07-24 18:01:42 -04:00
parent de92c2ed52
commit 3c34a4cbae
2 changed files with 60 additions and 51 deletions

View file

@ -2571,16 +2571,17 @@
;-------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------
(define *skint-options* (define *skint-options*
'([verbose "-v" "--verbose" #f "Increase output verbosity"] '([verbose "-v" "--verbose" #f "Increase output verbosity"]
[quiet "-q" "--quiet" #f "Suppress nonessential messages"] [quiet "-q" "--quiet" #f "Suppress nonessential messages"]
[append-libdir "-A" "--append-libdir" "DIR" "Append a library search directory"] [append-libdir "-A" "--append-libdir" "DIR" "Append a library search directory"]
[prepend-libdir "-I" "--prepend-libdir" "DIR" "Prepend a library search directory"] [prepend-libdir "-I" "--prepend-libdir" "DIR" "Prepend a library search directory"]
[eval "-e" "--eval" "SEXP" "Evaluate and print an expression"] [define-feature "-D" "--define-feature" "NAME" "Add name to the list of features"]
[script "-s" "--script" "FILE" "Run file as a Scheme script"] [eval "-e" "--eval" "SEXP" "Evaluate and print an expression"]
[program "-p" "--program" "FILE" "Run file as a Scheme program"] [script "-s" "--script" "FILE" "Run file as a Scheme script"]
[program "-p" "--program" "FILE" "Run file as a Scheme program"]
;[benchmark #f "--benchmark" "FILE" "Run .sf benchmark file (internal)"] ;[benchmark #f "--benchmark" "FILE" "Run .sf benchmark file (internal)"]
[version "-V" "--version" #f "Display version info"] [version "-V" "--version" #f "Display version info"]
[help "-h" "--help" #f "Display this help"] [help "-h" "--help" #f "Display this help"]
)) ))
(define *skint-version* "0.3.9") (define *skint-version* "0.3.9")
@ -2591,6 +2592,8 @@
(let ([obj (read-from-string str)]) (let ([obj (read-from-string str)])
(for-each (lambda (val) (when print? (write val) (newline))) (for-each (lambda (val) (when print? (write val) (newline)))
(call-with-values (lambda () (eval obj)) list)))) (call-with-values (lambda () (eval obj)) list))))
(define (add-feature! f)
(features (set-cons (string->symbol f) (features))))
(define (print-version!) (define (print-version!)
(format #t "(version ~s)~%(scheme.id skint)~%" *skint-version*)) (format #t "(version ~s)~%(scheme.id skint)~%" *skint-version*))
(define (print-help!) (define (print-help!)
@ -2612,6 +2615,7 @@
[(quiet) (set! *quiet* #t) (loop restargs #t)] [(quiet) (set! *quiet* #t) (loop restargs #t)]
[(append-libdir *) (append-library-path! optarg) (loop restargs #t)] [(append-libdir *) (append-library-path! optarg) (loop restargs #t)]
[(prepend-libdir *) (prepend-library-path! optarg) (loop restargs #t)] [(prepend-libdir *) (prepend-library-path! optarg) (loop restargs #t)]
[(define-feature *) (add-feature! optarg) (loop restargs #t)]
[(eval *) (eval! optarg #t) (loop restargs #f)] [(eval *) (eval! optarg #t) (loop restargs #f)]
[(script *) (set! *quiet* #t) (exit (run-script optarg restargs))] [(script *) (set! *quiet* #t) (exit (run-script optarg restargs))]
[(program *) (set! *quiet* #t) (exit (run-program optarg restargs))] [(program *) (set! *quiet* #t) (exit (run-program optarg restargs))]

89
t.c
View file

@ -1625,53 +1625,58 @@ char *t_code[] = {
",@(y16:repl-environment),.8^,@(y14:repl-from-port)[04}_3}t]3", ",@(y16:repl-environment),.8^,@(y14:repl-from-port)[04}_3}t]3",
"C", 0, "C", 0,
"'(l9:l5:y7:verbose;s2:-v;s9:--verbose;f;s25:Increase output verbosity;" "'(l10:l5:y7:verbose;s2:-v;s9:--verbose;f;s25:Increase output verbosity"
";l5:y5:quiet;s2:-q;s7:--quiet;f;s30:Suppress nonessential messages;;l5" ";;l5:y5:quiet;s2:-q;s7:--quiet;f;s30:Suppress nonessential messages;;l"
":y13:append-libdir;s2:-A;s15:--append-libdir;s3:DIR;s33:Append a libra" "5:y13:append-libdir;s2:-A;s15:--append-libdir;s3:DIR;s33:Append a libr"
"ry search directory;;l5:y14:prepend-libdir;s2:-I;s16:--prepend-libdir;" "ary search directory;;l5:y14:prepend-libdir;s2:-I;s16:--prepend-libdir"
"s3:DIR;s34:Prepend a library search directory;;l5:y4:eval;s2:-e;s6:--e" ";s3:DIR;s34:Prepend a library search directory;;l5:y14:define-feature;"
"val;s4:SEXP;s32:Evaluate and print an expression;;l5:y6:script;s2:-s;s" "s2:-D;s16:--define-feature;s4:NAME;s32:Add name to the list of feature"
"8:--script;s4:FILE;s27:Run file as a Scheme script;;l5:y7:program;s2:-" "s;;l5:y4:eval;s2:-e;s6:--eval;s4:SEXP;s32:Evaluate and print an expres"
"p;s9:--program;s4:FILE;s28:Run file as a Scheme program;;l5:y7:version" "sion;;l5:y6:script;s2:-s;s8:--script;s4:FILE;s27:Run file as a Scheme "
";s2:-V;s9:--version;f;s20:Display version info;;l5:y4:help;s2:-h;s6:--" "script;;l5:y7:program;s2:-p;s9:--program;s4:FILE;s28:Run file as a Sch"
"help;f;s17:Display this help;;)@!(y15:*skint-options*)", "eme program;;l5:y7:version;s2:-V;s9:--version;f;s20:Display version in"
"fo;;l5:y4:help;s2:-h;s6:--help;f;s17:Display this help;;)@!(y15:*skint"
"-options*)",
"C", 0, "C", 0,
"'(s5:0.3.9)@!(y15:*skint-version*)", "'(s5:0.3.9)@!(y15:*skint-version*)",
"P", "skint-main", "P", "skint-main",
"%0,,,,#0#1#2#3&0{%2${.2,@(y16:read-from-string)[01},${@(y4:list),.3,&1" "%0,,,,,#0#1#2#3#4&0{%2${.2,@(y16:read-from-string)[01},${@(y4:list),.3"
"{%0:0,@(y4:eval)[01},@(y16:call-with-values)[02},.3,&1{%1:0?{Po,.1W5Po" ",&1{%0:0,@(y4:eval)[01},@(y16:call-with-values)[02},.3,&1{%1:0?{Po,.1W"
"W6]1}]1},@(y10:%25for-each1)[32}.!0&0{%0@(y15:*skint-version*),'(s33:(" "5PoW6]1}]1},@(y10:%25for-each1)[32}.!0&0{%1${${@(y8:features)[00},.3X5"
"version ~s)~%25(scheme.id skint)~%25),t,@(y6:format)[03}.!1&0{%0${@(y1" ",@(y8:set-cons)[02},@(y8:features)[11}.!1&0{%0@(y15:*skint-version*),'"
"5:*skint-version*),'(s30:SKINT Scheme Interpreter v~a~%25),t,@(y6:form" "(s33:(version ~s)~%25(scheme.id skint)~%25),t,@(y6:format)[03}.!2&0{%0"
"at)[03}${'(s42:usage: skint [OPTION]... [FILE] [ARG]...~%25),t,@(y6:fo" "${@(y15:*skint-version*),'(s30:SKINT Scheme Interpreter v~a~%25),t,@(y"
"rmat)[02}${'(s2:~%25),t,@(y6:format)[02}${'(s10:Options:~%25),t,@(y6:f" "6:format)[03}${'(s42:usage: skint [OPTION]... [FILE] [ARG]...~%25),t,@"
"ormat)[02}${Po,@(y15:*skint-options*),@(y26:print-command-line-options" "(y6:format)[02}${'(s2:~%25),t,@(y6:format)[02}${'(s10:Options:~%25),t,"
")[02}${'(s2:~%25),t,@(y6:format)[02}${'(s80:'--' ends options processi" "@(y6:format)[02}${Po,@(y15:*skint-options*),@(y26:print-command-line-o"
"ng. Standalone FILE argument is treated as a script.~%25),t,@(y6:forma" "ptions)[02}${'(s2:~%25),t,@(y6:format)[02}${'(s80:'--' ends options pr"
"t)[02}${'(s82:If no FILE is given, skint enters Read-Eval-Print loop (" "ocessing. Standalone FILE argument is treated as a script.~%25),t,@(y6"
"stdin>eval-print>stdout)~%25),t,@(y6:format)[02}'(s2:~%25),t,@(y6:form" ":format)[02}${'(s82:If no FILE is given, skint enters Read-Eval-Print "
"at)[02}.!2${@(y12:command-line)[00}.!3${t,.6^d,,#0.7,.1,.8,.8,&4{%2:0," "loop (stdin>eval-print>stdout)~%25),t,@(y6:format)[02}'(s2:~%25),t,@(y"
":1,:2,:3,.5,&5{%3.1?{.1,.1,l2}{.0,l1},${.2,'(l1:y7:verbose;),@(y11:sex" "6:format)[02}.!3${@(y12:command-line)[00}.!4${t,.7^d,,#0.8,.1,.9,.8,.("
"p-match?)[02}?{t@!(y9:*verbose*)t,.4,:2^[42}${.2,'(l1:y5:quiet;),@(y11" "i10),&5{%2:0,:1,:2,:3,:4,.6,&6{%3.1?{.1,.1,l2}{.0,l1},${.2,'(l1:y7:ver"
":sexp-match?)[02}?{t@!(y7:*quiet*)t,.4,:2^[42}${.2,'(l2:y13:append-lib" "bose;),@(y11:sexp-match?)[02}?{t@!(y9:*verbose*)t,.4,:2^[42}${.2,'(l1:"
"dir;y1:*;),@(y11:sexp-match?)[02}?{${.4,@(y20:append-library-path!)[01" "y5:quiet;),@(y11:sexp-match?)[02}?{t@!(y7:*quiet*)t,.4,:2^[42}${.2,'(l"
"}t,.4,:2^[42}${.2,'(l2:y14:prepend-libdir;y1:*;),@(y11:sexp-match?)[02" "2:y13:append-libdir;y1:*;),@(y11:sexp-match?)[02}?{${.4,@(y20:append-l"
"}?{${.4,@(y21:prepend-library-path!)[01}t,.4,:2^[42}${.2,'(l2:y4:eval;" "ibrary-path!)[01}t,.4,:2^[42}${.2,'(l2:y14:prepend-libdir;y1:*;),@(y11"
"y1:*;),@(y11:sexp-match?)[02}?{${t,.5,:4^[02}f,.4,:2^[42}${.2,'(l2:y6:" ":sexp-match?)[02}?{${.4,@(y21:prepend-library-path!)[01}t,.4,:2^[42}${"
"script;y1:*;),@(y11:sexp-match?)[02}?{t@!(y7:*quiet*)${.5,.5,@(y10:run" ".2,'(l2:y14:define-feature;y1:*;),@(y11:sexp-match?)[02}?{${.4,:5^[01}"
"-script)[02},@(y4:exit)[41}${.2,'(l2:y7:program;y1:*;),@(y11:sexp-matc" "t,.4,:2^[42}${.2,'(l2:y4:eval;y1:*;),@(y11:sexp-match?)[02}?{${t,.5,:4"
"h?)[02}?{t@!(y7:*quiet*)${.5,.5,@(y11:run-program)[02},@(y4:exit)[41}$" "^[02}f,.4,:2^[42}${.2,'(l2:y6:script;y1:*;),@(y11:sexp-match?)[02}?{t@"
"{.2,'(l2:y9:benchmark;y1:*;),@(y11:sexp-match?)[02}?{${.5,.5,@(y10:run" "!(y7:*quiet*)${.5,.5,@(y10:run-script)[02},@(y4:exit)[41}${.2,'(l2:y7:"
"-script)[02},@(y4:exit)[41}${.2,'(l1:y7:version;),@(y11:sexp-match?)[0" "program;y1:*;),@(y11:sexp-match?)[02}?{t@!(y7:*quiet*)${.5,.5,@(y11:ru"
"2}?{${:3^[00}f,n,:2^[42}${.2,'(l1:y4:help;),@(y11:sexp-match?)[02}?{${" "n-program)[02},@(y4:exit)[41}${.2,'(l2:y9:benchmark;y1:*;),@(y11:sexp-"
":1^[00}f,n,:2^[42}${.2,'(l1:f;),@(y11:sexp-match?)[02}?{.3p?{t@!(y7:*q" "match?)[02}?{${.5,.5,@(y10:run-script)[02},@(y4:exit)[41}${.2,'(l1:y7:"
"uiet*)${.5d,.6a,@(y10:run-script)[02},@(y4:exit)[41}:0~?{t,@(y4:exit)[" "version;),@(y11:sexp-match?)[02}?{${:3^[00}f,n,:2^[42}${.2,'(l1:y4:hel"
"41}f]4}]4},@(y15:*skint-options*),.2,@(y28:get-next-command-line-optio" "p;),@(y11:sexp-match?)[02}?{${:1^[00}f,n,:2^[42}${.2,'(l1:f;),@(y11:se"
"n)[23}.!0.0^_1[02}PiP09?{PoP09}{f}?{${@(y15:*skint-version*),'(s30:SKI" "xp-match?)[02}?{.3p?{t@!(y7:*quiet*)${.5d,.6a,@(y10:run-script)[02},@("
"NT Scheme Interpreter v~a~%25),t,@(y6:format)[03}${'(s35:Copyright (c)" "y4:exit)[41}:0~?{t,@(y4:exit)[41}f]4}]4},@(y15:*skint-options*),.2,@(y"
" 2024 False Schemers~%25),t,@(y6:format)[02}}t]4", "28:get-next-command-line-option)[23}.!0.0^_1[02}PiP09?{PoP09}{f}?{${@("
"y15:*skint-version*),'(s30:SKINT Scheme Interpreter v~a~%25),t,@(y6:fo"
"rmat)[03}${'(s35:Copyright (c) 2024 False Schemers~%25),t,@(y6:format)"
"[02}}t]5",
0, 0, 0 0, 0, 0
}; };