Andy Wingo [Sun, 20 Oct 2013 13:49:22 +0000 (15:49 +0200)]
VM has "builtins": primitives addressable by emitted RTL code
* 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.
Andy Wingo [Fri, 18 Oct 2013 17:33:50 +0000 (19:33 +0200)]
Partial continuations are RTL stubs
* libguile/control.c: Implement partial continuations as RTL programs.
* libguile/programs.c (scm_i_rtl_program_minimum_arity): Add partial
continuation case.
* libguile/vm-engine.c (compose-continuation): Fix to look for vm_cont
from the free variables.
* libguile/vm-i-system.c (abort): Poison continuations captured in the
stack VM, as the can't be rewound by the RTL stubs.
Andy Wingo [Sun, 27 Oct 2013 10:25:18 +0000 (11:25 +0100)]
Fix toplevel-ref with named modules before boot in stack VM
* libguile/vm.c (resolve_variable): Fix, as in
e23f9e4423bbbe8521d13e1c9a223612a5e86762.
Andy Wingo [Sun, 27 Oct 2013 08:52:39 +0000 (09:52 +0100)]
Memoized expressions are pairs, not SMOBs
* 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!
Andy Wingo [Sun, 27 Oct 2013 08:14:04 +0000 (09:14 +0100)]
Tree-IL->GLIL: Fix primitive-ref reification bug
* 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.
Andy Wingo [Sat, 26 Oct 2013 20:54:29 +0000 (22:54 +0200)]
Mark current-module as an interesting primitive
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
Add current-module, to allow RTL compilation.
Andy Wingo [Sat, 26 Oct 2013 20:30:54 +0000 (22:30 +0200)]
New pass: elide-values
* module/Makefile.am:
* module/language/cps/elide-values.scm (elide-values): New pass.
* module/language/cps/compile-rtl.scm (optimize): Call the new pass.
Andy Wingo [Sat, 26 Oct 2013 20:06:01 +0000 (22:06 +0200)]
Add make-vector, constant-make-vector instructions
* 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.
Andy Wingo [Sat, 26 Oct 2013 19:30:37 +0000 (21:30 +0200)]
Emit constant-vector-ref, constant-vector-set! for known small indices
* 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.
Andy Wingo [Sat, 26 Oct 2013 19:07:27 +0000 (21:07 +0200)]
New pass: inline-constructors
* module/Makefile.am:
* module/language/cps/constructors.scm (inline-constructors): New pass.
* module/language/cps/compile-rtl.scm (optimize): Call the new pass.
* module/language/tree-il/compile-cps.scm (convert): Don't handle "list"
specially here.
Andy Wingo [Sat, 26 Oct 2013 13:40:49 +0000 (15:40 +0200)]
Compile variable-ref, variable-set!
* 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!.
Andy Wingo [Sat, 26 Oct 2013 13:25:49 +0000 (15:25 +0200)]
Recognize tree-il variable? primitive
* module/language/tree-il/primitives.scm (*interesting-primitive-names*)
(*effect-free-primitives*, *effect+exception-free-primitives*): Add
variable?. Fix nil? spelling.
Andy Wingo [Sat, 26 Oct 2013 13:16:09 +0000 (15:16 +0200)]
RTL compiler: Compile TC7 branches.
* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm (code-annotation):
* module/language/cps/primitives.scm (*branching-primcall-arities*):
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add support
for compiling symbol?, variable?, vector?, and string? branches.
Andy Wingo [Wed, 23 Oct 2013 13:07:34 +0000 (15:07 +0200)]
Fix primcall return arities
* 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.
Andy Wingo [Wed, 23 Oct 2013 08:35:04 +0000 (10:35 +0200)]
RTL compiler: Compile `wind' primcalls
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add handler
for `wind'.
Andy Wingo [Wed, 23 Oct 2013 08:05:28 +0000 (10:05 +0200)]
RTL VM: Fix fluid-ref local addressing.
* libguile/vm-engine.c (push-fluid): Fix variable addressing.
Andy Wingo [Wed, 23 Oct 2013 08:03:17 +0000 (10:03 +0200)]
RTL VM: Fix variable lookup before modules boot
* libguile/vm-engine.c (toplevel-box, module-box): Handle the case where
the module system isn't booted yet.
Andy Wingo [Thu, 24 Oct 2013 08:19:07 +0000 (10:19 +0200)]
Add stringbuf printer
* libguile/strings.h:
* libguile/strings.c (scm_i_print_stringbuf):
* libguile/print.c (iprin1): Add a printer for stringbufs. The
disassembler can print a stringbuf.
Andy Wingo [Wed, 23 Oct 2013 08:35:30 +0000 (10:35 +0200)]
Peval: Fold `thunk?' in more cases.
* module/language/tree-il/peval.scm (peval): Better folding of the
`thunk?' predicate.
Andy Wingo [Sat, 26 Oct 2013 11:12:25 +0000 (13:12 +0200)]
Setting procedure properties does not cause metadata lookup
* libguile/procprop.c (scm_procedure_properties, scm_procedure_property)
(scm_set_procedure_properties_x, scm_set_procedure_property_x)
(scm_procedure_name, scm_procedure_documentation): Rework to treat the
overrides table as complementary to the RTL program properties. In
this way setting a procedure property doesn't require loading up
the (system vm debug) module.
Andy Wingo [Sat, 26 Oct 2013 11:10:43 +0000 (13:10 +0200)]
Evaluator sets same procedure properties as compiler
* 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.
Andy Wingo [Fri, 25 Oct 2013 10:25:53 +0000 (12:25 +0200)]
Evaluator uses two-dimensional environment
* 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.
Andy Wingo [Wed, 23 Oct 2013 14:57:14 +0000 (16:57 +0200)]
Always resolve-primitives in the root module.
* module/language/tree-il/primitives.scm (resolve-primitives): If we are
compiling in the root module, ignore local definitions.
Andy Wingo [Wed, 23 Oct 2013 13:06:24 +0000 (15:06 +0200)]
RTL VM: Fix LOCAL_REF, LOCAL_SET for unsigned indices
* libguile/vm-engine.c (LOCAL_REF, LOCAL_SET): Fix so to work with
unsigned 0. Previously subtracting 1 was making the index wrap
around.
Andy Wingo [Wed, 23 Oct 2013 17:01:03 +0000 (19:01 +0200)]
Optimize closures with only required and rest arguments in eval
* 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.
Andy Wingo [Tue, 22 Oct 2013 20:31:26 +0000 (22:31 +0200)]
Fix assembler for keyword args
* module/system/vm/assembler.scm (begin-kw-arity, kw-prelude): Fix
functions with keywords.
Andy Wingo [Tue, 22 Oct 2013 20:30:54 +0000 (22:30 +0200)]
CPS conversion doesn't automatically produce $values
* 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.
Andy Wingo [Tue, 22 Oct 2013 20:29:56 +0000 (22:29 +0200)]
Contify returns via calls to "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.
Andy Wingo [Mon, 21 Oct 2013 20:25:27 +0000 (22:25 +0200)]
CPS->RTL compiler: add push-fluid and pop-fluid
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add cases for
push-fluid and pop-fluid.
Andy Wingo [Mon, 21 Oct 2013 20:24:54 +0000 (22:24 +0200)]
DFG: Remove lift-definition!
* module/language/cps/dfg.scm: Remove lift-definition!.
Andy Wingo [Mon, 21 Oct 2013 20:24:18 +0000 (22:24 +0200)]
Fix contification bugs
* 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.
Andy Wingo [Mon, 21 Oct 2013 14:59:42 +0000 (16:59 +0200)]
More robust contification
* 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.
Andy Wingo [Mon, 21 Oct 2013 14:32:36 +0000 (16:32 +0200)]
add lookup-block-scope
* module/language/cps/dfg.scm (lookup-block-scope): New interface.
(visit-fun): Give a bit more info if link-blocks! fails.
Andy Wingo [Mon, 21 Oct 2013 14:31:49 +0000 (16:31 +0200)]
DFG fixup.
* module/language/cps/dfg.scm: Remove dead-after-def? and
dead-after-use? export.
Andy Wingo [Mon, 21 Oct 2013 13:45:19 +0000 (15:45 +0200)]
RTL slot allocator uses more precise, correct liveness information
* 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.
Andy Wingo [Mon, 21 Oct 2013 09:51:51 +0000 (11:51 +0200)]
DFG: Add code to compute live variable sets.
* module/language/cps/dfg.scm (compute-live-variables)
(compute-maximum-fixed-point, print-dfa): New code to compute live
variable sets.
Andy Wingo [Mon, 21 Oct 2013 09:51:11 +0000 (11:51 +0200)]
DFG: Use maps have variable names
* module/language/cps/dfg.scm ($use-map): Add variable names to the use
maps.
(visit-fun, lookup-def, lookup-uses, constant-needs-allocation?)
(variable-free-in?, dead-after-def?, dead-after-use?)
(dead-after-branch?): Adapt to use-map change.
Andy Wingo [Fri, 18 Oct 2013 16:44:11 +0000 (18:44 +0200)]
Continuations are RTL stubs
* libguile/continuations.h:
* libguile/continuations.c: Reimplement continuations and the call_cc
stub as RTL programs.
* libguile/programs.c (scm_i_rtl_program_minimum_arity): Add a case for
continuations.
* libguile/vm-engine.c (rtl_vm_debug_engine): Always call the abort
continuation hook with the number of non-procedure locals. Fix
compose-continuation argument count. Enable call/cc.
Andy Wingo [Fri, 18 Oct 2013 16:41:59 +0000 (18:41 +0200)]
(language tree-il analyze) works better with RTL programs
* 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.
Andy Wingo [Fri, 18 Oct 2013 15:41:33 +0000 (17:41 +0200)]
Foreign procedures are RTL programs
* libguile/foreign.c: Convert to using RTL stubs. Because RTL code has
different GC characteristics than objcode -- it's mostly assumed that
RTL code will never go away -- we go ahead and pre-generate code for
100 arguments. This is actually less memory than the stack VM code,
and doesn't require any relocations at load-time: bonus! We'll cross
the >=100 args bridge if we ever come to it.
(get_foreign_stub_code) New function.
(scm_i_foreign_arity): New helper, like scm_i_primitive_arity.
(cif_to_procedure): Rework to make RTL programs.
* libguile/foreign.h: Declare scm_pointer_to_scm and
scm_scm_to_pointer. Declare new internal helpers.
* libguile/gsubr.c (create_subr): Refactor to set the flags when the
object is allocated.
* libguile/instructions.h: Define SCM_PACK_RTL_12_12.
* libguile/programs.c (scm_i_rtl_program_minimum_arity): Dispatch to
scm_i_foreign_arity if the procedure has the FOREIGN flag.
* libguile/programs.h (SCM_F_PROGRAM_IS_FOREIGN)
(SCM_PROGRAM_IS_FOREIGN): New interfaces.
* test-suite/tests/foreign.test ("procedure->pointer"): Add a test for
foreign arities.
Andy Wingo [Fri, 18 Oct 2013 09:47:05 +0000 (11:47 +0200)]
Fix statprof-proc-call-data for recent changes
* module/statprof.scm (statprof-proc-call-data): Fix statprof for recent
fixes.
Andy Wingo [Fri, 18 Oct 2013 08:03:26 +0000 (10:03 +0200)]
Subrs are 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.
Andy Wingo [Fri, 18 Oct 2013 09:38:36 +0000 (11:38 +0200)]
(system vm debug): implement arity-low-pc, arity-high-pc
* module/system/vm/debug.scm (arity-low-pc, arity-high-pc): Implement
these exports.
Andy Wingo [Fri, 18 Oct 2013 07:45:53 +0000 (09:45 +0200)]
class-of fix for RTL programs
* libguile/goops.c (scm_class_of): Use the same logic for RTL programs
and stack VM programs.
Andy Wingo [Thu, 17 Oct 2013 21:25:01 +0000 (23:25 +0200)]
Stack traces skip RTL boot frames
* libguile/frames.c (frame-previous)
* libguile/stacks.c (make-stack): Skip RTL boot frames.
Andy Wingo [Thu, 17 Oct 2013 21:24:16 +0000 (23:24 +0200)]
RTL engine can apply smobs and applicable structs w/o stack VM
* libguile/vm-engine.c (rtl_vm_engine): Allow the RTL VM to handle the
dispatch for SMOBs and applicable structs.
Andy Wingo [Thu, 17 Oct 2013 21:21:29 +0000 (23:21 +0200)]
Fix subr-call
* libguile/vm-engine.c (subr-call): Fix for locals count including the
procedure.
Andy Wingo [Thu, 17 Oct 2013 21:19:57 +0000 (23:19 +0200)]
Fix tail-apply bugs
* libguile/vm-engine.c (tail-apply): Fix for old change that made
the procedure indexed 0 instead of -1.
Andy Wingo [Thu, 17 Oct 2013 21:16:32 +0000 (23:16 +0200)]
Better vm.c support for RTL programs
* libguile/vm.c (scm_c_vm_run): Directly dispatch to the RTL VM for RTL
programs.
(scm_bootstrap_vm): Initialize the RTL program stubs early, and mark
the RTL boot program with the boot flag.
Andy Wingo [Thu, 17 Oct 2013 21:14:56 +0000 (23:14 +0200)]
Procedure traps work with RTL programs.
* module/system/vm/traps.scm (frame-matcher): Work with RTL programs.
Andy Wingo [Thu, 17 Oct 2013 21:14:26 +0000 (23:14 +0200)]
minimal RTL program support in (system xref)
* module/system/xref.scm (procedure-sources*): Work with RTL programs.
Andy Wingo [Thu, 17 Oct 2013 21:13:56 +0000 (23:13 +0200)]
(system vm coverage) works with RTL programs
* module/system/vm/coverage.scm (hashq-proc, assq-proc)
(program-sources*, closed-over-procedures, coverage-data->lcov): Work
with RTl procedures.
Andy Wingo [Thu, 17 Oct 2013 21:12:23 +0000 (23:12 +0200)]
Statprof works better with RTL programs
* module/statprof.scm (get-call-data, procedure=?): Work with RTL
programs.
Andy Wingo [Mon, 14 Oct 2013 19:45:48 +0000 (21:45 +0200)]
bind-rest works in the optional-and-rest-arg case.
* libguile/vm-engine.c (bind-rest): If the sp is below the dst reg,
alloc the frame to ensure there is enough space, and to fill in
intermediate values with SCM_UNDEFINED.
Andy Wingo [Mon, 14 Oct 2013 15:32:16 +0000 (17:32 +0200)]
Refactor vm_abort
* libguile/vm.c (vm_abort):
* libguile/vm-i-system.c (abort): Refactor abort interface so that it is
more amenable to the RTL VM.
Andy Wingo [Mon, 14 Oct 2013 14:43:42 +0000 (16:43 +0200)]
Reify call-thunk/no-inline.
* module/language/cps/reify-primitives.scm (reify-primitives): Remove
call-thunk/no-inline in this late phase.
Andy Wingo [Mon, 14 Oct 2013 14:13:57 +0000 (16:13 +0200)]
RTL: Compile prompts
* 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.
Andy Wingo [Mon, 14 Oct 2013 14:09:43 +0000 (16:09 +0200)]
RTL VM: receive-values has allow-extra? flag
* 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.
Andy Wingo [Mon, 14 Oct 2013 14:05:45 +0000 (16:05 +0200)]
Add SCM_F_DYNSTACK_PROMPT_PUSH_NARGS prompt flag
* libguile/dynstack.h (scm_t_dynstack_prompt_flags): New flag,
SCM_F_DYNSTACK_PROMPT_PUSH_NARGS, set if the continuation expects the
number of args to be pushed on the top of the stack.
* libguile/control.c (scm_c_abort): Only push nargs if requested.
* libguile/eval.c (eval):
* libguile/throw.c (pre_init_catch):
* libguile/vm-i-system.c (prompt): Set
SCM_F_DYNSTACK_PROMPT_PUSH_NARGS.
Andy Wingo [Mon, 14 Oct 2013 10:20:58 +0000 (12:20 +0200)]
call-with-prompt always compiles to CPS $prompt
* module/language/tree-il/compile-cps.scm (convert): For prompts without
inline handlers, eta-convert the handler.
Andy Wingo [Mon, 14 Oct 2013 09:33:41 +0000 (11:33 +0200)]
Put the readline extension in the extensionsdir
* GUILE-VERSION:
* acinclude.m4:
* guile-readline/LIBGUILEREADLINE-VERSION:
* guile-readline/Makefile.am: Rename libguile-readline-v-18.so to
guile-readline.so, and install it to the extensions dir instead of the
libdir.
* guile-readline/ice-9/readline.scm: Load guile-readline instead of
libguile-readline-v-18.
Andy Wingo [Sat, 12 Oct 2013 14:36:28 +0000 (16:36 +0200)]
More precise dead-after-use? for loop variables
* module/language/cps/dfg.scm (dead-after-use?):
(dead-after-branch?): A symbol defined in the header block of a loop
is still within the same loop.
Andy Wingo [Sat, 12 Oct 2013 14:22:45 +0000 (16:22 +0200)]
RTL slot allocation: Don't kill variables that flow into loops
* module/language/cps/dfg.scm (dead-after-use?): Don't kill a variable
if it was defined outside the current loop.
(dead-after-branch?): Likewise, but I don't think this helper is
correct yet :/
Andy Wingo [Sat, 12 Oct 2013 14:11:36 +0000 (16:11 +0200)]
Compute post-dominators
* module/language/cps/dfg.scm ($block): Add pdom and pdom-level fields,
for post-dominators.
(reverse-post-order, convert-predecessors): Arrange to work either
way: for dominators or for post-dominators.
(analyze-control-flow!): Compute post-dominators.
(dominates?): Refactor.
(post-dominates?): New helper.
Andy Wingo [Sat, 12 Oct 2013 13:19:01 +0000 (15:19 +0200)]
Identify loops
* module/language/cps/dfg.scm (compute-dom-edges)
(compute-join-edges, compute-reducible-back-edges)
(compute-irreducible-dom-levels, compute-nodes-by-level)
(mark-loop-body, mark-irreducible-loops, identify-loops): Identify
loops. Irreducible loops are TODO.
* test-suite/tests/rtl-compilation.test ("contification"): Add an
irreducible loop test.
Andy Wingo [Sat, 12 Oct 2013 10:48:08 +0000 (12:48 +0200)]
DFG refactorings
* module/language/cps/dfg.scm ($block): Add "irreducible" field, format
TBD.
(reverse-post-order): Return a vector directly.
(convert-predecessors, compute-dom-levels, compute-idoms):
(analyze-control-flow!): Factor out control flow analsysis a bit
better.
(identify-loops): New helper. Currently a NOP.
(visit-fun): Adapt to compute-dominator-tree rename to
analyze-control-flow!.
Andy Wingo [Fri, 11 Oct 2013 12:10:19 +0000 (14:10 +0200)]
Replace conservatively-dominates? with a precise dominator lookup
* module/language/cps/dfg.scm (dominates?): Use the dominator tree
instead of the scope tree.
Andy Wingo [Fri, 11 Oct 2013 11:35:43 +0000 (13:35 +0200)]
Compute a dominator tree
* module/language/cps/dfg.scm (reverse-post-order, for-each/enumerate)
(convert-predecessors, finish-idoms, compute-dominator-tree): Compute
a dominator tree. We don't use it yet.
Andy Wingo [Thu, 10 Oct 2013 10:42:50 +0000 (12:42 +0200)]
DFG refactor to allow dominator tree construction
* module/language/cps/dfg.scm: Refactor so that we can think about
building a dominator tree. Split continuations out of use maps and
put them in a separate table, which will have more flow information.
(visit-fun): Mark clauses as using their bodies.
(lookup-predecessors, lookup-successors): New exports.
(find-defining-expression): Add an exception for clauses, now that
clauses are in the flow graph.
(continuation-bound-in?): Rename from variable-bound-in?, as it can
currently only be used for continuations.
* module/language/cps/contification.scm (contify): Adapt to use
lookup-predecessors and continuation-bound-in?.
Andy Wingo [Thu, 10 Oct 2013 10:21:55 +0000 (12:21 +0200)]
A couple of fixes when no source info is available
* module/system/vm/assembler.scm (link-debug): If there was no debugging
info, reset the file register to 0 from its default value of 1 before
adding the final row.
* module/system/vm/dwarf.scm (line-prog-scan-to-pc): If we rescanned
from the beginning and still found no source info for this pc, return
#f instead of the default value of the file register (1).
Andy Wingo [Thu, 10 Oct 2013 09:19:02 +0000 (11:19 +0200)]
Fix peval bug with inlining and optional argument initializers
* module/language/tree-il/peval.scm (peval): Fix a bug whereby inlined
function applications with default argument initializers were putting
the initializers in the wrong scope.
* test-suite/tests/peval.test ("partial evaluation"): Add a test.
Andy Wingo [Sat, 5 Oct 2013 13:57:54 +0000 (15:57 +0200)]
Fix slot allocation bug
* module/language/cps/slot-allocation.scm (allocate-slots): Fix
dead-after-use computation to use the expression's label and not its
continuation.
Andy Wingo [Fri, 4 Oct 2013 17:55:12 +0000 (19:55 +0200)]
better RTL debugging
* libguile/frames.c (scm_frame_source, scm_frame_instruction_pointer):
Fix to work with RTL programs.
* module/system/vm/debug.scm (find-debug-context): Allow for the
possibility of there being no ELF image.
(find-program-debug-info, find-program-arities)
(program-minimum-arity, find-program-docstring)
(find-program-properties, find-source-for-addr)
(find-program-die, find-program-sources): Don't bail if we couldn't
get the debug context.
* module/system/vm/frame.scm (frame-next-source)
(frame-call-representation): Allow RTL programs.
* module/system/vm/program.scm (program-arguments-alist): Placeholder
implementation for RTL programs.
(program-arguments-alists): Don't bail if we couldn't get the
arities.
Andy Wingo [Fri, 4 Oct 2013 16:03:29 +0000 (18:03 +0200)]
Fix nested contification bugs
* module/language/cps/contification.scm (contify): Exhaustively replace
contified tail continuations, to fix a bug in nested tail-recursive
contifications. Likewise, call lookup-return-cont when searching for
common return continuations.
Andy Wingo [Fri, 4 Oct 2013 15:30:59 +0000 (17:30 +0200)]
Fix variable-bound-in?
* module/language/cps/dfg.scm (variable-bound-in?): Fix to look up
correct variable.
Andy Wingo [Fri, 4 Oct 2013 14:36:17 +0000 (16:36 +0200)]
Fix verify-cps
* module/language/cps/verify.scm (verify-cps): Fix visiting functions.
Andy Wingo [Fri, 4 Oct 2013 13:28:40 +0000 (15:28 +0200)]
Disassembling RTL prints source information.
* module/system/vm/disassembler.scm (disassemble-buffer): Print source
information.
Andy Wingo [Fri, 4 Oct 2013 13:09:31 +0000 (15:09 +0200)]
add contification test
* test-suite/tests/rtl-compilation.test ("contification"): Add
contification test where non-recursive call is not in tail position
relative to the letrec.
Andy Wingo [Fri, 4 Oct 2013 12:08:52 +0000 (14:08 +0200)]
Contify functions in the scope of their continuation.
* module/language/cps/contification.scm (contify): Fix to contify
functions in the scope of their continuation.
Andy Wingo [Fri, 4 Oct 2013 08:47:55 +0000 (10:47 +0200)]
dfg: variable-free-in?, add variable-bound-in?
* module/language/cps/dfg.scm (variable-free-in?): Rename from
variable-used-in?, to match CWCC language.
(variable-bound-in?): New interface.
* module/language/cps/contification.scm (contify): Adapt caller. Add
more comments.
Andy Wingo [Thu, 3 Oct 2013 20:48:17 +0000 (22:48 +0200)]
anonymous RTl functions print with source info
* module/system/vm/debug.scm (find-program-sources): If there is no
source location before the low-pc of the procedure we're grovelling
for, we were skipping the source loc info. Fix that.
* module/system/vm/program.scm (write-program): Get source info for
anonymous RTL functions.
(program-sources, program-sources-pre-retire): Provide program
counters relative to the beginning of the procedure.
Andy Wingo [Thu, 3 Oct 2013 20:31:37 +0000 (22:31 +0200)]
program-source / program-sources works with RTL programs
* libguile/programs.c (scm_program_sources): Define as %program-sources,
and let Scheme export the program-sources proper.
(scm_program_source): Call out to Scheme.
* module/system/vm/program.scm: Convert to use match instead of pmatch.
Adapt existing callers.
(program-sources, program-source): New Scheme implementations of these
functions.
(program-sources-pre-retire): Add RTL program case.
Andy Wingo [Thu, 3 Oct 2013 19:35:21 +0000 (21:35 +0200)]
Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
libguile/deprecated.h
libguile/programs.c
libguile/programs.h
Andy Wingo [Thu, 3 Oct 2013 17:45:41 +0000 (19:45 +0200)]
Deprecate scm_c_program_source, as it has no internal users.
* libguile/programs.c:
* libguile/programs.h:
* libguile/deprecated.h:
* libguile/deprecated.c (scm_c_program_source): Deprecate.
Mark H Weaver [Thu, 3 Oct 2013 18:25:51 +0000 (14:25 -0400)]
Fix edge case in 'ash'.
* libguile/numbers.c (scm_ash): Fix (ash -1 SCM_I_FIXNUM_BIT-1) to
return a fixnum instead of a bignum.
* test-suite/tests/numbers.test (ash): Add tests.
Andy Wingo [Thu, 3 Oct 2013 14:13:56 +0000 (16:13 +0200)]
Add source location test
* test-suite/tests/dwarf.test: New test, testing that source location
information survives the round-trip through the compiler, back out to
the (system vm debug) interfaces.
Andy Wingo [Thu, 3 Oct 2013 12:44:30 +0000 (14:44 +0200)]
Add (system vm debug) interface to source location information
* module/system/vm/debug.scm (<source>, source-pre-pc)
(source-post-pc, source-file, source-line, source-column)
(source-line-for-user): New data type for source location
information.
(find-source-for-addr, find-program-sources): New procedures to get
source location information for a particular address.
Andy Wingo [Thu, 3 Oct 2013 12:42:49 +0000 (14:42 +0200)]
Add interface to read .debug_line data
* module/system/vm/dwarf.scm (die-line-prog):
(line-prog-advance, line-prog-scan-to-pc): New public interfaces,
allowing clients to interpret the "statement programs" from
.debug_line DWARF sections.
(<meta>, elf->dwarf-context): Record the bounds of the .debug_line
section.
Andy Wingo [Wed, 2 Oct 2013 19:34:38 +0000 (21:34 +0200)]
Serialize source positions into .debug_line
* module/system/vm/assembler.scm (link-debug): Generate a correct DWARF2
line program. Tests come next.
Andy Wingo [Mon, 30 Sep 2013 19:49:12 +0000 (21:49 +0200)]
Emit a placeholder .debug_line section.
* module/system/vm/assembler.scm (link-debug): Emit a .debug_line
section also.
(link-objects): Expect .debug_line.
Andy Wingo [Mon, 30 Sep 2013 19:48:07 +0000 (21:48 +0200)]
Add new "source" macro instruction; compile-rtl emits it.
* module/system/vm/assembler.scm (<asm>): Add "sources" field.
(make-assembler): Adapt to make-asm change.
(source): New macro assembler.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence):
(compile-fun): Emit source instructions as appropriate.
Mark H Weaver [Mon, 30 Sep 2013 16:46:01 +0000 (12:46 -0400)]
Fix minor mistakes in documentation.
Fixes <http://bugs.gnu.org/15487>.
Reported by Josep Portella Florit <jpf@primfilat.com>.
* doc/ref/api-i18n.texi (i18n Introduction, Text Collation,
Internationalization, Internationalization):
LC_MESSAGE --> LC_MESSAGES.
* doc/ref/api-procedures.texi (Compiled Procedures):
program-lambda-alist --> program-lambda-list.
* THANKS: Fix alignment of Josep Portella Florit.
Andy Wingo [Sat, 28 Sep 2013 16:15:44 +0000 (18:15 +0200)]
DWARF linker: encode strings using the correct form
* module/system/vm/assembler.scm (link-debug): Encode strings using the
strp form.
Andy Wingo [Sat, 28 Sep 2013 12:50:48 +0000 (14:50 +0200)]
Emit minimal DWARF information
* module/system/vm/assembler.scm (link-debug): New function, creates the
necessary DWARF debugging sections.
(link-objects): Emit debugging sections.
Andy Wingo [Sat, 9 Jun 2012 16:26:27 +0000 (18:26 +0200)]
add DWARF parser
* module/Makefile.am:
* module/system/vm/dwarf.scm: New module, a DWARF parser.
Mark H Weaver [Fri, 13 Sep 2013 04:24:04 +0000 (00:24 -0400)]
Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
module/srfi/srfi-9.scm
module/web/server.scm
Mark H Weaver [Fri, 13 Sep 2013 03:58:32 +0000 (23:58 -0400)]
Fix truncated documentation for 'put-char'.
Fixes <http://bugs.gnu.org/15152>.
Reported by Josep Portella Florit <jpf@primfilat.com>.
* doc/ref/api-io.texi (R6RS Textual Output): Fix truncated docs
for 'put-char'.
* THANKS: Add Josep Portella Florit to fixes section.
Mark H Weaver [Thu, 12 Sep 2013 22:45:13 +0000 (18:45 -0400)]
Web: Use functional setters in extend-request and extend-response.
* module/web/client.scm (extend-request):
* module/web/server.scm (extend-response): Reimplement using
functional setters.
Mark H Weaver [Thu, 12 Sep 2013 22:34:39 +0000 (18:34 -0400)]
Web client+server: Add Content-Length header for empty bodies.
* module/web/client.scm (sanitize-request): Add a Content-Length
header if a body if given, even if the body is empty.
* module/web/server.scm (sanitize-response): Add a Content-Length
header if a body if given, even if the body is empty.
Mark H Weaver [Thu, 12 Sep 2013 22:14:54 +0000 (18:14 -0400)]
Adapt srfi-9.test to error reporting improvements; update copyright dates.
* module/srfi/srfi-9.scm: Add 2013 copyright date.
* test-suite/tests/srfi-9.test: Adapt to recent error reporting
improvements to procedures defined by 'define-tagged-inlinable'.