* module/language/cps/dfg.scm ($block): Remove dominator-related things
from $block.
(reverse-post-order, convert-predecessors): Be more abstract, taking
arbitrary identifiers for nodes instead of assuming the nodes are
continuation names.
(make-block-mapping): New helper.
($cfa): New data type, for dominator and loop analysis. Not yet
public.
(analyze-control-flow): Rewrite to only compute the dominator tree in
one direction, but take that direction as an argument. To be public
once there is some code that uses it.
($dfa): Refactor function fields to be hash tables.
(dfa-k-idx, dfa-var-idx): Adapt to refactor.
(compute-live-variables): Adapt to refactor.
* libguile/vm-engine.c (static-patch!): Replace link-procedure! with
this more versatile primitive.
* module/system/vm/assembler.scm (intern-constant): Emit static-patch!
for static procedures and for strings.
* module/system/vm/disassembler.scm (code-annotation): Remove annotation
for link-procedure!. There can be no annotation for static-patch!, as
neither operand is guaranteed to be a SCM value.
* module/language/cps.scm ($prompt): Add a "pop" field, indicating the
continuation at which this prompt is popped. The body of the prompt
is dominated by the prompt, and post-dominated by the pop. Adapt all
builders and users.
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-rtl.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt.
* module/language/cps/dfg.scm (visit-fun): Add an arc from the pop to
the handler, to keep handler variables alive through the prompt body.
* libguile/Makefile.am:
* libguile/vm-builtins.h: New header, declaring stubs needed by the
compiler like values, apply, and abort-to-prompt.
* libguile/vm.c: Adapt the apply and values stubs to conform to a
standard interface. Add an abort-to-prompt stub. Add call/cc and
call-with-values stubs.
(scm_vm_builtin_ref): New helper, for the builtin-ref opcode.
(scm_vm_builtin_name_to_index)
(scm_vm_builtin_index_to_name): New helpers, for the compiler and
disassembler, respectively.
(scm_init_vm_builtins, scm_bootstrap_vm): Allow the compiler helpers
to be loaded later into a module.
* module/language/rtl.scm: Export builtin-index->name and
builtin-name->index.
* libguile/vm-engine.c (RETURN_VALUE_LIST): Update to use new names of
"apply" and "values".
(tail-call/shuffle): New opcode.
(abort): Update to be a tail VM op, and reorder and renumber other
ops.
(builtin-ref): New opcode.
* libguile/continuations.h:
* libguile/continuations.c (scm_i_call_with_current_continuation):
Move this to vm.[ch], implemented as a builtin.
* module/language/tree-il/compile-cps.scm (convert): Convert to
'abort-to-prompt calls, possibly with 'apply, effectively undoing the
tree-il transformation.
* module/language/cps/reify-primitives.scm (builtin-ref): New helper.
(reify-primitives): Convert builtin primitives to builtin-ref.
* module/language/cps/dfg.scm (constant-needs-allocation?):
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add support
for compiling builtin-ref.
* module/system/vm/disassembler.scm (code-annotation): Add annotation
for builtin-ref.
* libguile/memoize.c (MAKMEMO): Memoized objects are pairs now, not
SMOBs. This lets eval.scm destructure them more efficiently.
(scm_print_memoized, scm_memoized_p, scm_memoized_expression_typecode)
(scm_memoized_expression_data): Remove these interfaces.
(unmemoize, scm_memoize_variable_access_x): Remove SMOB type checks.
(scm_init_memoize): Remove SMOB type definition.
* libguile/memoize.h (scm_tc16_memoized, SCM_MEMOIZED_P)
(scm_memoized_expression_typecode, scm_memoized_expression_data)
(scm_memoized_p): Remove declarations.
* libguile/validate.h (SCM_VALIDATE_MEMOIZED): Remove declaration.
* libguile/eval.c (eval): Remove memoized type check, and inline the
inum unpacking.
* module/ice-9/eval.scm (memoized-expression-case): Use car and cdr to
destructure memoized expressions. A big win!
* module/language/tree-il/compile-glil.scm (flatten-lambda-case): Fix a
bug whereby a primitive that is present in the compilation module but
not at runtime was getting compiled as a toplevel-ref. This was
causing current-module to fail to resolve in R6RS modules.
* module/Makefile.am:
* module/language/cps/elide-values.scm (elide-values): New pass.
* module/language/cps/compile-rtl.scm (optimize): Call the new pass.
* libguile/vm-engine.c (rtl_vm_engine): Add make-vector and
constant-make-vector instructions and renumber.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Emit
constant-make-vector and make-vector as appropriate.
* module/language/cps/dfg.scm (constant-needs-allocation?): In some
cases, make-vector doesn't need to allocate its index.
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*, *primitive-constructors*): Add
make-vector.
* libguile/vm-engine.c (rtl_vm_engine): Add constant-vector-set!
instruction and renumber.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Emit
constant-vector-ref and constant-vector-set! as appropriate.
* module/language/cps/dfg.scm (constant-needs-allocation?): In some
cases, vector-ref and vector-set! don't need to allocate their index.
* libguile/vm-engine (box-ref, box-set!): Instead of aborting if a box
isn't a var, call out to vm_error_not_a_variable. This makes these
instructions equivalent to variable-ref/variable-set!.
(vector-set!): Rename from vector-set.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add
variable-set! case, and adapt vector-set!.
* module/language/cps/primitives.scm (*rtl-instruction-aliases*): Add
variable-ref / variable-set! aliases to box-ref / box-set!.
* module/language/cps/arities.scm (fix-clause-arities): Primcalls of
known arity that continue to ktrunc should, if their return arity does
not match the ktrunc, adapt via a call to `values'. This call may
later get removed.
* libguile/memoize.c (MAKMEMO_LAMBDA, memoize): Instead of passing the
docstring in the memoized lambda, pass the meta as-is. That way we
get all procedure properties, including "name".
* module/ice-9/eval.scm (primitive-eval): Set procedure properties when
making lambdas. Don't set the name when defining toplevel variables
-- before we did so only if the procedure didn't have a name
property, but I would like to avoid calls to procedure-property in
eval, because getting the name for an RTL function requires loading up
other modules.
* libguile/memoize.c (MAKMEMO_LEX_REF, MAKMEMO_LEX_SET): Change to
address lexicals by depth and width.
(try_lookup_rib, lookup_rib, make_pos): New helpers.
(lookup): Adapt to return a pair.
(memoize, unmemoize_bindings, unmemoize_lexical): Adapt.
* libguile/eval.c (eval, prepare_boot_closure_env_for_eval):
(prepare_boot_closure_env_for_apply):
* module/ice-9/eval.scm (make-fixed-closure, make-general-closure)
(eval): Adapt to new environment.
This is currently a slight win for C, and a slight lose for Scheme --
because the lookup loop is so poorly compiled by the stack VM. I expect
that the RTL-compiled eval will fix this.
* module/ice-9/eval.scm: Pregenerate closures with rest arguments, as we
do for fixed arguments. This is important given the amount of (lambda
args (apply foo args)) that we are doing lately.
* module/language/tree-il/compile-cps.scm (convert): Don't convert
values primcalls to $values, because we don't know that the
continuation can accept that number of values.
* module/language/cps/contification.scm: Returns from contified
functions should primcall to 'values, as in general the return
continuation is a multiple value context ($ktrunc or $ktail). A later
pass can elide the primcall if appropriate.
* module/language/cps/contification.scm (compute-contification): Rewrite
to avoid mutating the DFG and the function while we are rewriting.
Instead we compute a contification, and if it is not empty, we apply
it and loop.
* module/language/cps/contification.scm (contify): It could be that
visiting pending contifications could enqueue more contifications, so
iterate to a fixed point. Signal an error if there are any pending
contifications at the end of an iteration.
* module/language/cps/dfg.scm (control-point?): New interface, replaces
branch?.
(dead-after-def?, dead-after-use?, dead-after-branch?): Remove these.
The first one was fine; dead-after-use? was conservative but OK; but
dead-after-branch? was totally bogus. Instead we use precise liveness
information in the allocator.
* module/language/cps/slot-allocation.scm ($allocation): Remove "def"
and "dead" slots. We'll communicate liveness information in some
other way to the compiler.
(allocate-slots): Rework to use precise liveness information.
* module/system/vm/program.scm (program-arguments-alists): Export this
interface. Fall back to grovelling through procedure-minimum-arity if
the program has no arities, as might be the case for continuations.
* module/language/tree-il/analyze.scm (validate-arity): Use
program-arguments-alists instead of the program-arities interface, to
cover both stack VM and RTL programs.
* libguile/gsubr.c: Define RTL stubs instead of stack VM stubs.
(SUBR_STUB_CODE, get_subr_stub_code): Adapt to return a uint32_t*
pointer instead of a SCM value.
(create_subr): Create RTL procedures instead of stack VM procedures.
For RTL procedures, the function pointer, name, and generic address
pointer go inline to the procedure, as free variables.
(scm_i_primitive_arity, scm_i_primitive_call_ip): New helpers.
(scm_c_make_gsubr, scm_c_define_gsubr, scm_c_make_gsubr_with_generic)
(scm_c_define_gsubr_with_generic): Adapt to create_gsubr being renamed
to create_subr.
Remove gsubr test code.
* libguile/gsubr.h (SCM_PRIMITIVE_P, SCM_PRIMITIVE_GENERIC_P): Only RTL
programs can be primitives now.
(SCM_SUBRF, SCM_SUBR_NAME, SCM_SUBR_GENERIC): These fields are now in
the RTL free variables, not the object table.
* libguile/programs.c (scm_i_rtl_program_name):
(scm_i_rtl_program_documentation):
(scm_i_rtl_program_properties):
(scm_i_rtl_program_minimum_arity): Implement these appropriately for
primitives, which lack debugging information.
(scm_primitive_p, scm_primitive_call_ip): New helpers.
* libguile/snarf.h: Remove static allocation for subrs. Since there is
nothing to allocate besides the program itself, which needs runtime
relocation, static allocation is not a win.
* system/vm/program.scm: Fix up various arity-related things for
primitives, which don't use ELF arity info.
* test-suite/tests/eval.test ("stack involving a primitive"): Add an
XFAIL until we get just one VM.
* libguile/vm-engine.c (prompt): Adapt to explicitly set the saved SP so
we know how many incoming values the handler will receive, and to make
escape-only? a flag.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): $prompt
should only be found in a "seq" context, as it just pushes on a prompt
and doesn't bind any values. On the other hand it should emit
appropriate code for the handler to bind its values, so do that.
* module/language/cps/slot-allocation.scm ($cont-allocation): Add a note
that proc-slot is used by prompts as well.
(allocate-slots): Compute the allocation of a prompt handler's args.
* module/language/tree-il/compile-cps.scm (convert): Use "unwind"
instead of the nonexistent "pop-prompt".
* module/system/vm/disassembler.scm (code-annotation): Adapt to change
in prompt VM op.
* libguile/vm-engine.c (receive-values): Add an ALLOW-EXTRA? flag in
unused bits of the third word. Without it, receive-values will check
for the exact number of incoming values.
* libguile/vm.c (vm_error_wrong_number_of_values): New error case.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Adapt to add
the ALLOW-EXTRA? flag.