MzScheme's -e command-line flag prints results

svn: r7860
This commit is contained in:
Matthew Flatt 2007-11-29 14:32:15 +00:00
parent 8930f31115
commit fd8586e113
4 changed files with 49 additions and 88 deletions

View File

@ -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
======================================================================

View File

@ -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

View File

@ -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 <expr>, --eval <expr> : Evaluates <expr> after " PROGRAM " starts\n"
" -e <exprs>, --eval <exprs> : Evaluates <exprs>, prints results\n"
" -f <file>, --load <file> : Like -e '(load \"<file>\")'\n"
" -t <file>, --require <file> : Like -e '(require (file \"<file>\"))'\n"
" -l <path>, --lib <path> : Like -e '(require (lib \"<path>\"))'\n"

View File

@ -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);