From fd8586e11373d5c46bd7ec058960a0d4c9595e60 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 29 Nov 2007 14:32:15 +0000 Subject: [PATCH] MzScheme's -e command-line flag prints results svn: r7860 --- doc/release-notes/mzscheme/MzScheme_4.txt | 6 ++ man/man1/mzscheme.1 | 97 +++-------------------- src/mzscheme/cmdline.inc | 4 +- src/mzscheme/src/eval.c | 30 ++++++- 4 files changed, 49 insertions(+), 88 deletions(-) diff --git a/doc/release-notes/mzscheme/MzScheme_4.txt b/doc/release-notes/mzscheme/MzScheme_4.txt index d1888ecaa5..3e99e5b9d9 100644 --- a/doc/release-notes/mzscheme/MzScheme_4.txt +++ b/doc/release-notes/mzscheme/MzScheme_4.txt @@ -187,6 +187,12 @@ the class system, the unit system, and the pretty printer. More precisely, the default module is `scheme/init', which is like `scheme', but it installs the pretty printer. +The initial top-level environment is completely empty. Command-line +flags like `-l' introduce bindings into the environment. Such bindings +are not yet introduced, however, during the evaluation of the module +body (for the module named by `-l'), which means that `eval' using the +default namespace will not work. + ====================================================================== Module Paths ====================================================================== diff --git a/man/man1/mzscheme.1 b/man/man1/mzscheme.1 index d999c6dfab..80ee5d3b26 100644 --- a/man/man1/mzscheme.1 +++ b/man/man1/mzscheme.1 @@ -1,5 +1,5 @@ .\" dummy line -.TH MZSCHEME 1 "February 2007" +.TH MZSCHEME 1 "November 2007" .UC 4 .SH NAME mzscheme \- The PLT Scheme implementation @@ -32,72 +32,24 @@ applications. .SH STARTUP FILE AND EXPRESSION OPTIONS .TP -.BI \-e \ expr\fR,\ \fP \-\^\-eval \ expr +.BI \-e \ exprs\fR,\ \fP \-\^\-eval \ exprs Evaluates -.I expr -after -.I MzScheme -starts. +.I exprs +and prints each result. .TP .BI \-f \ file\fR,\ \fP \-\^\-load \ file Loads .I file -after -.I MzScheme -starts. -.TP -.BI \-d \ file\fR,\ \fP \-\^\-load-cd \ file -Load/cds -.I file -after -.I MzScheme -starts. +and prints the last result from the file. .TP .BI \-t \ file\fR,\ \fP \-\^\-require \ file Requires .I file -after -.I MzScheme -starts. .TP -.B \-F\fR,\fP \-\^\-Load -.br -Loads all remaining arguments after -.I MzScheme -starts. -.TP -.B \-D\fR,\fP \-\^\-Load-cd -.br -Load/cds all remaining arguments after -.I MzScheme -starts. -.TP -.B \-T\fR,\fP \-\^\-Require -.br -Requires all remaining arguments after -.I MzScheme -starts. -.TP -.BI \-l \ file\fR,\ \fP \-\^\-mzlib \ file +.BI \-l \ path\fR,\ \fP \-\^\-lib \ path Same as .BR -e \ '(require\ (lib\ "\|\c -.I file\|\c -"))'. -.TP -.BI \-L \ file \ coll -Same as -.BR -e \ '(require\ (lib\ "\|\c -.I file\|\c -" "\|\c -.I coll\|\c -"))'. -.TP -.BI \-M \ coll -Same as -.BR -e \ '(require\ (lib\ "\|\c -.I coll\|\c -\|.ss" "\|\c -.I coll\|\c +.I path\|\c "))'. .TP .BI \-p \ file \ user \ package @@ -110,35 +62,14 @@ Same as .I package\|\c "))'. .TP -.BI \-P \ name \ user -Same as -.BR -e \ '(require\ (planet\ "\|\c -.I name\|\c -\|.ss" "\|\c -.I user\|\c -\|" "\|\c -.I name\|\c -\|.plt"))'. .TP .B \-r\fR,\fP \-\^\-script -Script mode: use as last flag for scripts. -Same as -.BR -fmv- . -.TP -.B \-i\fR,\fP \-\^\-script-cd -Like -r, but also sets the directory. -Same as -.BR -dmv- . +Script mode; same as +.BR -f- . .TP .B \-u\fR,\fP \-\^\-require-script -Like -r, but requires a module. -Same as -.BR -tmv- . -.TP -.B \-w\fR,\fP \-\^\-awk -Same as -.B -l -.BR awk.ss . +Module script mode; same as +.BR -t- . .TP .BI \-k \ n \ m\ Load executable-embedded code from file offset @@ -146,10 +77,8 @@ Load executable-embedded code from file offset to .IR m . .TP -.B \-C\fR,\fP \-\^\-main -Like -r, then calls `main' with a list of argument strings. The first -string in the list is the name of the loaded file, and -the rest of the list contains leftover command-line arguments. +.B \-m\fR,\fP \-\^\-main +Calls `main' with command-line arguments. .PP .SH INITIALIZATION OPTIONS diff --git a/src/mzscheme/cmdline.inc b/src/mzscheme/cmdline.inc index fb37388ea1..0c4bfacaeb 100644 --- a/src/mzscheme/cmdline.inc +++ b/src/mzscheme/cmdline.inc @@ -257,7 +257,7 @@ static int finish_cmd_line_run(FinishArgs *fa, Repl_Proc repl) if (!scheme_setjmp(newbuf)) { if (fa->eval_kind[i] == mzcmd_EVAL) { - scheme_eval_string_all_with_prompt(fa->evals_and_loads[i], fa->global_env, 0); + scheme_eval_string_all_with_prompt(fa->evals_and_loads[i], fa->global_env, 2); } else if (fa->eval_kind[i] == mzcmd_EMBEDDED) { Scheme_Object *s, *e, *a[2], *eload; eload = scheme_builtin_value("embedded-load"); @@ -1035,7 +1035,7 @@ static int run_from_cmd_line(int argc, char *_argv[], # endif # endif " File and expression options:\n" - " -e , --eval : Evaluates after " PROGRAM " starts\n" + " -e , --eval : Evaluates , prints results\n" " -f , --load : Like -e '(load \"\")'\n" " -t , --require : Like -e '(require (file \"\"))'\n" " -l , --lib : Like -e '(require (lib \"\"))'\n" diff --git a/src/mzscheme/src/eval.c b/src/mzscheme/src/eval.c index a12da7b427..91060acb5d 100644 --- a/src/mzscheme/src/eval.c +++ b/src/mzscheme/src/eval.c @@ -7365,8 +7365,8 @@ Scheme_Object *scheme_eval_multi_with_prompt(Scheme_Object *obj, Scheme_Env *env { Scheme_Object *expr; expr = scheme_compile_for_eval(obj, env); - return scheme_call_with_prompt(finish_eval_multi_with_prompt, - scheme_make_pair(expr, (Scheme_Object *)env)); + return scheme_call_with_prompt_multi(finish_eval_multi_with_prompt, + scheme_make_pair(expr, (Scheme_Object *)env)); } static void *eval_k(void) @@ -8169,6 +8169,9 @@ expand_stx_to_top_form(int argc, Scheme_Object **argv) } static Scheme_Object *do_eval_string_all(const char *str, Scheme_Env *env, int cont, int w_prompt) +/* cont == -1 => single result + cont == 1 -> multiple result ok + cont == 2 -> multiple result ok, use current_print to show results */ { Scheme_Object *port, *expr, *result = scheme_void; @@ -8187,6 +8190,29 @@ static Scheme_Object *do_eval_string_all(const char *str, Scheme_Env *env, int c result = scheme_eval_multi_with_prompt(expr, env); else result = scheme_eval_multi(expr, env); + + if (cont == 2) { + Scheme_Object **a, *_a[1], *arg[1], *printer; + int cnt, i; + + if (result == SCHEME_MULTIPLE_VALUES) { + Scheme_Thread *p = scheme_current_thread; + if (SAME_OBJ(p->ku.multiple.array, p->values_buffer)) + p->values_buffer = NULL; + a = p->ku.multiple.array; + cnt = p->ku.multiple.count; + } else { + _a[0] = result; + a = _a; + cnt = 1; + } + + for (i = 0; i < cnt; i++) { + printer = scheme_get_param(scheme_current_config(), MZCONFIG_PRINT_HANDLER); + arg[0] = a[i]; + scheme_apply(printer, 1, arg); + } + } } } while (cont > 0);