* libguile/vm-engine.c (make-array): Change to only have
restricted-width operands in the first word. This instruction is
currently unused, however.
* module/system/vm/assembler.scm (assembler):
* module/system/vm/disassembler.scm (disassembler): Disallow
restricted-width operands in tail words.
* module/statprof.scm (profile-signal-handler): Bind in a letrec.
Otherwise the compiler may see the closure slot as dead, and the inner
stack cut won't work.
* module/system/vm/frame.scm (available-bindings): Map indexes in such a
way that the first argument is index 1.
(frame-call-representation): Update to search the bindings for live
bindings.
* module/system/repl/debug.scm (print-locals): Update to work with new
interface.
(frame->module): Update. Still doesn't work due to lack of
`program-module', though.
* module/system/vm/program.scm (make-binding, binding:name)
(binding:definition-offset, program-arity-bindings-for-ip): Remove
these.
* module/system/vm/frame.scm (<binding>): New type.
(available-bindings): Return a list of <binding> instances.
(frame-lookup-binding, frame-binding-set!, frame-binding-ref):
(frame-environment, frame-object-name): Adapt.
* module/system/vm/frame.scm (parse-code, compute-predecessors):
(compute-genv, compute-defs-by-slot, compute-killv, available-bindings):
(frame-bindings): Add a bunch of hairy code to compute the set of
bindings that are live in a frame.
* module/system/vm/disassembler.scm (instruction-length):
(instruction-has-fallthrough?, instruction-relative-jump-targets):
(instruction-slot-clobbers): New interfaces; to be used when
determining the bindings available at a given point of a procedure.
* module/system/vm/debug.scm (arity-definitions): New interface.
* module/system/vm/program.scm (make-binding, binding:boxed?)
(binding:index, binding:start, binding:end): Remove.
(binding:definition-offset, binding:slot): Add.
(program-arity-bindings-for-ip): Rename from program-bindings-for-ip,
as it gives all definitions in an arity. The user will have to do
data-flow analysis to recover the set of variables that are actually
available at any given point.
(arity->arguments-alist): Remove crufty code.
* module/system/vm/frame.scm (frame-call-representation): Fix to work
for primitives.
* test-suite/tests/eval.test ("stacks"): Update expected result for
substring.
* module/system/vm/assembler.scm (put-uleb128, put-sleb128)
(port-position): Lift out these helpers.
(arity-header-len, write-arities, link-arities): Add "nlocals" to the
arity headers. Write names of all locals into the arities section,
not just the arguments. Write them as uleb128's instead of uint32's,
to save space.
* module/system/vm/debug.scm (arity-header-len, arity-nlocals*)
(arity-nlocals, arity-locals, arity-arguments-alist): Adapt to new
encoding for arities.
* module/system/vm/assembler.scm (meta-arities-size, write-arity-links):
* module/system/vm/debug.scm (arity-keyword-args)
(arity-arguments-alist): Rewrite to put they keyword literals link
first. Unfortunately requires a recompile :/
* module/language/cps/slot-allocation.scm (dead-after-def?):
(dead-after-use?, allocate-slots): Remove some needless remapping
between label indexes in the CFA, the DFA, and their names.
* module/language/cps/dfg.scm (analyze-reverse-control-flow): Don't
compute and return an order vector; it's not needed.
($dfa): Remove label renaming. We can just rename labels before
returning the DFA.
(dfa-k-idx, dfa-k-sym, dfa-k-count): Adapt.
(compute-live-variables): Adapt, and rename labels before returning.
* module/system/vm/debug.scm (arity-keyword-args, find-program-arity):
New exports.
* module/system/vm/frame.scm (frame-call-representation): Prefer to use
the frame IP to get the procedure.
* module/statprof.scm (statprof-start, statprof-stop): Don't futz the vm
trace level when we aren't counting calls. With this change, statprof
now imposes no overhead on the measured program.
* module/statprof.scm (statprof-fold-call-data)
(statprof-proc-call-data): Add optional state arg.
(gcprof): Add optional port arg, and pass state arg explicitly.
(statprof-display-anomalies, statprof-display)
(statprof-call-data->stats): Pass state explicitly.
* module/language/cps.scm (make-global-cont-folder): Inline the
fold-values, as peval doesn't do so. Allows closure conversion to
avoid any closure creation.
* module/system/vm/disassembler.scm (code-annotation): Add call-label
and tail-call-label cases.
(disassemble-addr): With call-label we can see sets of mutually
recursive functions, so keep a global "visited?" set.
* module/ice-9/eval.scm (primitive-eval): Expand out the call to
make-general-closure, so that make-general-closure becomes
well-known. Now eval has no more free variables!
* module/language/cps/closure-conversion.scm (analyze-closures): Build a
bound-vars set as well, to resolve introduced self-references.
(prune-free-vars, convert-one): Arrange to eliminate self-references.
* module/language/cps/closure-conversion.scm (convert-free-var):
(convert-free-vars): Take self-known? param, to do the right thing for
well-known closures.
(allocate-closure): New helper. Well-known closures are represented
using pairs or vectors.
(init-closure): Adapt tpo DTRT for well-known closures.
(prune-free-vars): Move up.
(convert-one): Adapt to new well-known closure representation.
* module/language/cps/closure-conversion.scm (init-closure): Return just
one value.
(analyze-closures): Rewrite the well-known set to key off the label
instead of the closure identifiers before returning.
(convert-one): Avoid creating closure objects at runtime or load-time
when "instantiating" or calling well-known closures with no free
variables.
(prune-free-vars): New pass.
(convert-closures): Adapt.
* module/language/cps/closure-conversion.scm (analyze-closures):
(convert-one, convert-closures): Hard-wire calls to known procedures
by transforming $call to $callk.
* module/language/cps.scm ($closure, $program): New CPS types, part of
low-level (first-order) CPS.
(build-cps-exp, build-cps-term, parse-cps, unparse-cps)
(compute-max-label-and-var): Update for new CPS types.
* module/language/cps/closure-conversion.scm: Rewrite to produce a
$program with $closures, and no $funs.
* module/language/cps/reify-primitives.scm:
* module/language/cps/compile-bytecode.scm (compile-fun):
(compile-bytecode): Adapt to new first-order format.
* module/language/cps/dfg.scm (compute-dfg): Add $closure case.
* module/language/cps/renumber.scm (renumber): Allow this pass to work
on either format.
* module/language/cps/slot-allocation.scm (allocate-slots): Add $closure
case.
* module/language/cps.scm (make-global-cont-folder)
(make-local-cont-folder): Separate this macro in two. It's hot and
the difference can be important for perf.
* module/language/cps/dfg.scm (compute-label-and-var-ranges):
* module/language/cps/cse.scm (compute-label-and-var-ranges):
* module/language/cps/dce.scm (compute-live-code): Adapt.
* module/language/cps/closure-conversion.scm: Produce a $kfun $cont.
* module/language/cps/reify-primitives.scm: Produce and consume $kfun
$cont.
* module/language/cps/compile-bytecode.scm: Adapt.
* module/language/cps/compile-bytecode.scm (compile-fun): Change to take
a $kfun $cont instead of a $fun.
(visit-funs): Change likewise, and call the proc on $kfun $cont's, not
$fun's.
(compile-bytecode): Adapt.
* module/language/cps/dfg.scm (analyze-reverse-control-flow): Adapt to
expect a $kfun $cont.
* module/language/cps/self-references.scm: New pass, avoids the need for
self-recursion to allocate free variables.
* module/Makefile.am:
* module/language/cps/compile-bytecode.scm: Wire up the new pass.
* module/language/cps/cse.scm (compute-truthy-expressions):
(compute-equivalent-subexpressions, apply-cse): Arrange to infer
truthiness of expressions, and use that information to elide redundant
tests.