* module/language/cps/hoot/tailify.scm (tailify-tail): Fix control flow
when pushing a prompt.
(compute-tails): Prompt handlers are in the initial split set.
* module/language/cps/utils.scm (compute-defs-and-uses): Add $prim.
Wasn't needed before because this function was only ever called after
reify-primitives.
* module/language/cps/utils.scm (compute-var-representations): $code
makes a 'code. bv-contents makes a 'raw-bytevector.
* module/language/cps/slot-allocation.scm:
* module/language/cps/hoot/tailify.scm:
* module/system/vm/assembler.scm: Adapt.
* module/language/cps/hoot/lower-primcalls.scm: New file.
* module/language/cps/hoot.scm (make-lowerer): Wire in new pass.
* am/bootstrap.am (SOURCES): Add new file.
* module/system/base/target.scm (target-runtime): New export.
* module/language/cps/optimize.scm (make-cps-lowerer): Load a
backend-specific lowering module dynamically.
* module/language/cps/guile-vm.scm: New module for lowering to Guile's
VM.
* module/language/cps/guile-vm/loop-instrumentation.scm:
* module/language/cps/guile-vm/lower-primcalls.scm:
* module/language/cps/guile-vm/reify-primitives.scm: Move here, from
parent dir.
* module/language/cps/hoot.scm: New module for lowering to Wasm/GC via
Hoot.
* module/language/cps/guile-vm/tailify.scm:
* module/language/cps/guile-vm/unify-returns.scm: Move here, from parent
dir.
* am/bootstrap.am: Update for new file list.
* module/language/cps/closure-conversion.scm (convert-one): Add nfree to
the param. This will help the wasm target.
* module/language/cps/effects-analysis.scm (closure-ref, closure-set!):
* module/language/cps/lower-primcalls.scm (closure-ref,closure-set!):
Adapt.
* module/language/cps/optimize.scm (optimize-hoot-backend-cps): There
are a couple optimizations we need to clean up after tailification, so
include those here.
* module/language/cps/optimize.scm (target-runtime): New function.
(make-backend-cps-lowerer): For hoot, choose different backend passes.
* module/language/cps/unify-returns.scm: New file.
* module/language/cps/closure-conversion.scm (convert-one): Build
closures with make-closure, cons, and so on; leave lowering to scm-ref
to the backend.
* module/language/cps/effects-analysis.scm (compute-known-allocations):
For a primcall that allocates, sometimes we will synthesize auxiliary
definitions as part of CSE, for example to indicate that if (cons x y)
is bound to z, that a later call to (car z) should give x unless there
might be an intervening set-car!. We had a bug in which aux definitions
attached to allocations were being incorrectly associated with the first
operand. Probably this is a bug in other contexts but it really starts
to hit with the high-level constructors, e.g. `box`.
* module/language/cps/lower-primcalls.scm (f64->scm): Move here...
* module/language/cps/reify-primitives.scm (reify-primitives): from
here. Seems a more fitting place.
* module/language/cps/optimize.scm (lower-cps/generic): Rename from
lower-cps; these are the lowerings that apply to everyone.
(select-opts-for-optimization-level): Factor out of make-cps-lowerer.
(make-backend-cps-lowerer): New procedure. For the Guile VM backend, we
have a few mandatory passes, including the new lower-primitives.
(make-cps-lowerer): Apply backend-specific lowering pass.
This pass will implement the specialized lowering of object accessors to
Guile's VM primitives.
* am/bootstrap.am (SOURCES): Add new file.
* module/language/cps/lower-primcalls.scm: New file.
* module/language/cps/utils.scm (compute-var-representations): For the
wasm target, these values are (ref $kvarargs), not i64. Will need to
distinguish from bytevector pointers at some point, though.
* module/language/cps/compile-bytecode.scm (compile-function):
The rsh/lsh patterns would never match. I think these would end up
dispatching through emit-text though.
* libguile/exceptions.c (exception_epoch_fluid): Rename from
active_exception_handlers_fluid.
(scm_dynwind_throw_handler): Increment exception epoch instead of
resetting active exception handlers.
(scm_init_exceptions): Update.
* module/ice-9/boot-9.scm (with-exception-handler): Rework to associate
an "epoch" fluid with each exception handler.
(with-throw-handler): Establish a new epoch, during the execution of a
throw handler.
(raise-exception): Rework to avoid capturing a list of exception
handlers, and to use epochs as a way to know which handlers have already
been examined and which are on the dispatch stack.
* test-suite/tests/exceptions.test ("throwing within exception
handlers"): New test.
* module/ice-9/pretty-print.scm (call-with-truncating-output-string):
New function.
* module/ice-9/pretty-print.scm (generic-write): Rewrite so that instead
of keeping track of the column, we just use port-column on the port.
Also, when checking if a possibly-improper list can print on one line,
use new call-with-truncating-output-string so as to always abort early,
even for long bytevectors.
This also makes soft ports suspendable.
* am/bootstrap.am (SOURCES): Add (ice-9 soft-ports).
* libguile/init.c (scm_i_init_guile): No need to init vports.
* libguile/vports.c: Call out to (ice-9 soft-ports).
* libguile/vports.h: Remove internal scm_init_vports.
* module/ice-9/boot-9.scm (the-scm-module): Import (ice-9 soft-ports).
Really this enlarges the boot closure a bit, so we should probably
refactor.
* module/ice-9/soft-ports.scm: New file.