Modified-by: Mark H Weaver <mhw@netris.org>
* module/system/repl/coop-server.scm: New module.
* module/system/repl/repl.scm (start-repl): Extract body to start-repl*.
(start-repl*): New procedure.
(run-repl): Extract body to run-repl*.
(run-repl*): New procedure.
* module/system/repl/server.scm (run-server): Extract body to
run-server*.
(run-server*): New procedure.
* doc/ref/api-evaluation.texi (Cooperative REPL Servers): New node.
* module/Makefile.am (SYSTEM_SOURCES): Add system/repl/coop-server.scm.
* module/ice-9/boot-9.scm (current-language): New parameter.
* module/system/base/language.scm (*current-language*): Pull fluid from
parameter.
(current-language): Now a re-exported parameter.
* doc/ref/compiler.texi: Update reference from *current-language* fluid
to current-language parameter.
* module/system/base/compile.scm (compile-and-load):
* module/ice-9/top-repl.scm (top-repl): Default to the current language,
not to Scheme.
* module/ice-9/eval-string.scm:
* module/system/base/language.scm:
* module/system/repl/command.scm:
* module/system/repl/repl.scm: Update to use current-language parameter
and parameterize.
* module/system/repl/command.scm (language): Set the
*current-language*.
* module/system/repl/repl.scm (start-repl): Create a new dynamic scope
for *current-language*.
* module/system/repl/command.scm:
* module/system/repl/debug.scm (terminal-width): Move terminal-width
here, make it thread-local, and export it.
(print-locals, print-frame, print-frames): Default width to
terminal-width.
* module/system/repl/error-handling.scm (call-with-error-handling): Add
`report' and `backtrace' on-error handlers.
* module/system/repl/common.scm (repl-default-options): Add on-error
REPL option, defaulting to `debug', but which may be changed.
* module/system/repl/repl.scm (run-repl): Pass the #:on-error REPL
option to call-with-error-handling.
* module/system/repl/repl.scm (read-comment, read-scheme-line-comment)
(read-scheme-datum-comment): New helpers.
(meta-reader): Take a language instead of a reader. If we have a
nonwhitespace char, first check to see that it's a comment, and if so,
read it off and loop.
(prompting-meta-read): Call meta-reader with the lang.
* module/system/repl/repl.scm (flush-leading-whitespace): Rename from
next-char.
(meta-reader): Use flush-leading-whitespace.
(run-repl): Use flush-to-newline after the evaluation, which seems to
be the same as what we did before.
* module/system/repl/repl.scm (flush-all-input): New helper.
(prompting-meta-read): Flush all input on a read error, as we could be
within some expression or a string or something.
Fixes bug in repl meta-commands after activating readline, which changes
the current input port.
* module/system/repl/common.scm (<repl>): Remove inport and outport
fields.
(make-repl): Adapt.
(repl-read, repl-print): Just read and write to the current ports.
* module/system/repl/repl.scm (meta-reader): Meta-read from the current
input port.
* module/system/repl/command.scm (read-command, define-meta-command):
Read from the current input port.
* module/system/repl/repl.scm (display-syntax-error): New helper,
displays a syntax error.
(abort-on-error, run-repl): Use it.
* libguile/throw.c (handler_message): Re-code the same thing in C.
* module/system/repl/error-handling.scm (error-string): Refactor a
little.
(call-with-error-handling): Ensure a trailing newline when printing
the error-msg.
* module/system/repl/repl.scm (run-repl): We don't know the name of the
meta-command here.
* module/system/repl/error-handling.scm (error-string): Don't call
`display-error' when STACK is empty.
(call-with-error-handling): Display ERROR-MSG instead of using
`format', since ERROR-MSG may contain `format' escapes.
* module/system/repl/repl.scm (run-repl): Add missing argument to
`format'.
* module/system/vm/trap-state.scm (with-default-trap-handler): Don't
enable traps if we are setting a handler of #f.
* module/system/repl/error-handling.scm (call-with-error-handling): Add
#:trap-handler arg.
* module/system/repl/repl.scm (run-repl): Only have traps enabled while
running the thunk. Otherwise we trace on procedures called as part of
the repl.
* module/system/repl/repl.scm (run-repl): Run the thunk in a stack in a
prompt, similar to the default prompt. Gives proper backtraces.
* module/system/repl/error-handling.scm (call-with-error-handling):
Narrow one more outer frame, for the %start-stack thunk invocation.
* module/ice-9/boot-9.scm (%start-stack): Reindent.
* module/system/repl/repl.scm (abort-on-error): New helper.
(run-repl): Don't enter the debugger during parsing or compilation of
a repl expression. If you want to debug compilation, run compilation
from the repl, not as part of the repl.
* module/system/repl/command.scm (read-command): Remove a pk.
* module/system/repl/repl.scm (run-repl): Export. Use % and abort to
implement the prompt.
* module/system/repl/debug.scm: New file, defines a data type to hold
state for a debugger stack, and some helper procedures to print the
stack or print a frame. Most pieces are from (system vm debug).
* module/system/repl/error-handling.scm: New file, implements
call-with-error-handling and with-error-handling, and instead of going
into a debugger, we go into a recursive repl that happens to have
debugging information. Will be removing the old debugger from (system
vm debug) shortly.
* module/Makefile.am (SYSTEM_SOURCES): Add error-handling and debug scm
files.
* module/system/repl/repl.scm (prompting-meta-read): Better error
handling -- we don't want to go into a debugger when reading a
command.
(start-repl): Add #:debug keyword argument, and just dispatch to
run-repl.
(run-repl): New function, with the guts of the old start-repl. Added a
prompt, to which a throw to 'quit will abort.
* module/system/repl/common.scm (repl-prepare-eval-thunk): New
helper. In the future we will use this to not enter the debugger on
errors that happen at compile time.
(repl-eval): Use repl-prepare-eval-thunk.
(repl-print): Run the before-print-hook when printing a value.
* module/system/repl/command.scm (*command-table*): Move `option' to the
`system' group. Move `trace' to the `profile' group. Add `debug' and
`inspect' groups.
(command-abbrevs): Rename from command-abbrev, and allow multiple
abbreviations.
(display-group): Fix the case where abbrev? was #f.
(display-summary): Fix alignment of the command and
abbreviations. Allow multiple abbreviations.
(read-command): Rename from read-datum, and have better error
handling.
(meta-command): Better error handling.
(define-meta-command): Better error handling.
(help, show, import, compile, disassemble, time, profile, trace): Fix
docstrings and error messages.
(define-stack-command): New helper, for commands that operate on a
saved stack.
(backtrace, up, down, frame, procedure, locals): New debugger
commands, in the REPL now.
(inspect, pretty-print): New "inspect" commands.
* module/ice-9/boot-9.scm (*repl-stack*): Instead of repl-level, have a
stack.
(batch-mode?): Change to poke the stack.
* module/ice-9/deprecated.scm (set-batch-mode?!): Update deprecation
method.
* module/system/repl/common.scm (repl-prompt): Update to poke
*repl-stack* to get the level.
* module/system/repl/repl.scm (start-repl): Bind *repl-stack*
appropriately.
* module/system/repl/repl.scm (start-repl): If the debugging ports are
unbound, bind them to the current i/o ports. Allows errors within
with-output-to-foo / with-input-from-foo to be sensibly debugged.
* module/system/repl/repl.scm (prompting-meta-read): Use
call-with-error-handling.
* module/system/vm/debug.scm (call-with-error-handling): Add case for
#:on-error 'pass. Have the catch handler return the unspecified value.
* module/system/repl/repl.scm (prompting-meta-read): Catch and print
read errors here, returning unspecified in that case.
(start-repl): Don't enable the debugger while reading expressions.
Adapt with-backtrace to with-error-handling.
* module/system/vm/debug.scm (run-debugger, debugger-repl): No need to
take a stack, the frames vector is sufficient.
(call-with-error-handling, with-error-handling): New public utilities.
Notably they do not poke the-last-stack.
* module/system/repl/common.scm (*repl-level*): New public fluid.
(repl-prompt): If *repl-level* is a positive integer, add it to the
prompt.
* module/system/repl/repl.scm (start-repl): The `lang' argument is now
optional, and defaults to (current-language). New kwargs level and
welcome; level defaults to 0, or 1+ the existing level, and the
welcome is a boolean, true if level is 0. Parameterize *repl-level*
during the dynamic extent of this repl. Also, parameterize
the-last-stack to #f for the duration of this repl.
* module/system/vm/debug.scm (frame->module, debugger-repl): Stubs of a
recursive repl implementation. The idea is to be a repl in the lexical
context of the error; but it would be nice to be able to operate in
the module of the proc too, for example to export bindings. Hmm.
* module/system/vm/debug.scm: Implement the skeleton of a debugger. Not
very useful yet.
* module/system/repl/repl.scm (call-with-backtrace): Have the pre-unwind
hook drop the user into the debugger. Hopefully we can have something
better within a couple weeks.
* module/language/assembly/spec.scm:
* module/language/brainfuck/spec.scm:
* module/language/bytecode/spec.scm:
* module/language/ecmascript/spec.scm:
* module/language/glil/spec.scm:
* module/language/scheme/spec.scm:
* module/language/tree-il/spec.scm: Language-readers now take two
arguments: the port and the environment. This should allow for
compile-environment-specific reader behavior.
* module/system/base/compile.scm (read-and-compile):
* module/system/repl/common.scm (repl-read): Pass the environment to the
language-reader.
* module/system/repl/repl.scm (meta-reader, prompting-meta-read):
* module/system/repl/command.scm (define-meta-command): Use the second
argument to repl-reader, so we avoid frobbing current-reader.
* module/system/repl/repl.scm (start-repl): Given that the input port of
the repl is line-buffered, it's likely we have #\newline in the input
that is strictly extraneous, an in-band indicator to the repl that it
should begin reading now. So flush out that newline, so that you can
(read-char) at the repl, and it actually does wait for you to type in
a char instead of just returning #\newline.
While it's not an overriding concern, this does fix some brainfuck
programs that want to input from the user.
* module/system/repl/command.scm: Update copyright.
(meta-command): Rework so that it's the various meta-commands that do
the reading for their arguments. This way you can compile forms that
span more than one line, and forms that need to be read with another
language's reader.
(define-meta-command): New helper macro. Update commands to use it.
(help): Allow ,help on commands too.
* module/system/repl/repl.scm: Update copyright.
(start-repl): Adjust to give meta-command what it wants.
* module/ice-9/boot-9.scm (default-pre-unwind-handler): Since we were
tail-called by pre-unwind-handler-dispatch, we can't use
pre-unwind-handler-dispatch as a narrowing argument. Instead just
narrow by one frame.
(pre-unwind-handler-dispatch): Deprecate.
(error-catching-loop): Remove crack comment and code, and just use
default-pre-unwind-handler as our pre-unwind handler.
* module/ice-9/stack-catch.scm (stack-catch):
* module/system/repl/repl.scm (call-with-backtrace): Use
default-pre-unwind-handler directly.
* module/system/repl/command.scm:
* module/system/repl/common.scm:
* module/system/repl/repl.scm:
* module/system/vm/debug.scm:
* module/system/vm/trace.scm: Change #:use-syntax to #:use-module, as
that's really what we want to do.
* module/system/repl/repl.scm (meta-reader): If the (next-char #t)
returns EOF, return that EOF directly, as it seems that with guile -q,
the subsequent `read' actually waits for another C-d. Dunno why.
* module/ice-9/boot-9.scm (default-pre-unwind-handler): Rename from
default-lazy-handler.
(pre-unwind-handler-dispatch): Rename from lazy-hadler-dispatch.
(error-catching-loop): Adjust caller.
* module/system/repl/repl.scm (default-pre-unwind-handler): Remove this
definition, in favor of the default one in boot-9.
(default-catch-handler): Don't do a vm-backtrace, as we will soon be
relying on core machinery to do that for us.
(call-with-backtrace): Start a new stack for the thunk.
(with-backtrace): Macro version of call-with-backtrace.
(start-repl): Use with-backtrace for brevity. Start a stack with #t as
the tag instead of repl-eval, because all traces of repl-eval are gone
after it does a tail-call.
* module/ice-9/debugger.scm:
* module/ice-9/debugging/traps.scm:
* module/ice-9/stack-catch.scm: Adapt to s/lazy/pre-unwind/ in
boot-9.scm.
* module/system/base/language.scm (<language>): Rework so that instead of
hardcoding passes in the language, we define compilers that translate
from one language to another. Add `parser' to the language fields, a
bit of a hack but useful for languages with s-expression external
representations but with record internal representations.
(define-language, *compilation-cache*, invalidate-compilation-cache!)
(compute-compilation-order, lookup-compilation-order): Add an algorithm
that does a depth-first search for a translation path from a source
language to a target language, caching the result in a lookup table.
* module/language/scheme/spec.scm:
* module/language/ghil/spec.scm: Update to the new language format.
* module/language/glil/spec.scm: Add a language specification for GLIL,
with a compiler to objcode. Also there are parsers and printers, for
repl usage, but for some reason this doesn't work yet.
* module/language/objcode/spec.scm: Define a language specification for
object code. There is some sleight of hand here, in the "compiler" to
values; but there is method behind the madness, because this way we
higher levels can pass environments (a module + externals pair) to
objcode->program.
* module/language/value/spec.scm: Define a language specification for
values. There is something intellectually dishonest about this, but it
does serve its purpose as a foundation for the language hierarchy.
* configure.in:
* module/language/Makefile.am
* module/language/ghil/Makefile.am
* module/language/glil/Makefile.am
* module/language/objcode/Makefile.am
* module/language/value/Makefile.am:
Autotomfoolery for the ghil, glil, objcode, and value languages.
* module/language/scheme/translate.scm (translate): Import the bits that
understand `compile-time-environment' here, and pass on the relevant
portions of the environment to the next compiler pass.
* module/system/base/compile.scm (current-language): New procedure, refs
the current language fluid, or lazily sets it to scheme.
(call-once, call-with-output-file/atomic): Refactor these bits to use
with-throw-handler. No functional change.
(compile-file, compile-and-load, compile-passes, compile-fold)
(compile): Refactor the public interface of the compiler to be generic
and simple. Uses `lookup-compilation-order' to find a path from the
source language to the target language.
* module/system/base/syntax.scm (define-type): Adapt to changes in
define-record.
(define-record): Instead of expecting all slots in the first form,
expect them in the body, and let the first form hold the options.
* module/system/il/compile.scm (compile): Adapt to the compilation pass
API (three in and two out).
* module/system/il/ghil.scm (<ghil-var>, <ghil-env>)
(<ghil-toplevel-env>): Adapt to define-record changes.
* module/system/il/glil.scm (<glil-vars>): Adapt to define-record
changes.
(<glil>, print-glil): Add a GLIL record printer that uses unparse.
(parse-glil, unparse-glil): Update unparse (formerly known as pprint),
and write a parse function.
* module/system/repl/common.scm (<repl>): Adapt to define-record changes.
(repl-parse): New function, parses the read form using the current
language. Something of a hack.
(repl-compile): Adapt to changes in `compile'.
(repl-eval): Fix up the does-the-language-have-a-compiler check for
changes in <language>.
* module/system/repl/repl.scm (start-repl): Parse the form before eval.
* module/system/repl/command.scm (describe): Parse.
(compile): Be more generic.
(compile-file): Adapt to changes in compile-file.
(disassemble, time, profile, trace): Parse.
* module/system/vm/debug.scm:
* module/system/vm/assemble.scm: Adapt to define-record changes.
* module/language/scheme/translate.scm (receive): Fix an important bug
that gave `receive' letrec semantics instead of let semantics. Whoops!
* ice-9/boot-9.scm: Allow a compiled load of posix, networking, and
deprecated files.
* module/language/scheme/translate.scm (lookup-transformer): Lookup the
sc-macro by value, not by name. Works around the fact that compiled
macros don't have names, which is probably a bug.
* module/system/base/compile.scm (syntax-error)
(call-with-compile-error-catch): Throw and catch a key that's not used
by anyone else. Write error messages to the error port.
* module/system/repl/repl.scm (default-catch-handler): Call display-error
with the correct number of arguments.
* module/system/vm/frame.scm (frame-program-name): Guard against unbound
variables.
* ice-9/optargs.scm (let-keywords-template): Don't unquote in a helper
procedure. A bit irritating. I suppose we should fix the modules +
syncase situation at some point, and then switch to syncase.