Andy Wingo [Fri, 8 Nov 2013 13:54:38 +0000 (14:54 +0100)]
Move useful parts of asm-to-bytecode.test to cross-compilation.test
* test-suite/tests/cross-compilation.test: Rename from asm-to-bytecode,
and remove the bits testing assembly->bytecode but keep the
cross-compilation things.
* test-suite/Makefile.am: Adapt.
Andy Wingo [Fri, 8 Nov 2013 13:45:01 +0000 (14:45 +0100)]
Tree-IL warnings tests compile to CPS instead of "assembly"
* test-suite/tests/tree-il.test ("warnings"): Change warnings test to
compile to CPS instead of assembly.
Andy Wingo [Fri, 8 Nov 2013 13:41:22 +0000 (14:41 +0100)]
Remove tree-il->glil test cases
* test-suite/tests/tree-il.test: Remove GLIL test cases. They have
never been helpful to me in the 2.0 series, so there is no loss.
Andy Wingo [Fri, 8 Nov 2013 13:27:13 +0000 (14:27 +0100)]
Remove a couple of uses of GLIL from the test suite.
* test-suite/tests/cse.test ("cse"):
* test-suite/tests/peval.test: Remove uses of GLIL.
Andy Wingo [Fri, 8 Nov 2013 13:19:41 +0000 (14:19 +0100)]
Fix program-minimum-arity to work better with case-lambda.
* module/system/vm/debug.scm (program-minimum-arity): Be more precise
with case-lambdas.
Andy Wingo [Fri, 8 Nov 2013 13:08:42 +0000 (14:08 +0100)]
Builtins have procedure properties
* libguile/vm-builtins.h (FOR_EACH_VM_BUILTIN): Add arity information.
(enum scm_vm_builtins):
* libguile/vm.c (scm_vm_builtin_ref):
(scm_vm_builtin_name_to_index):
(scm_vm_builtin_index_to_name): Adapt to macro interface change.
(scm_init_vm_builtin_properties): New helper, sets procedure
properties on builtins.
(scm_bootstrap_vm): Just define the builtins here. Later in the
bootstrap we set their properties.
(scm_sym_apply): Move definition here from expand.c.
* libguile/procprop.c (scm_init_procprop): Call
scm_init_vm_builtin_properties.
Andy Wingo [Fri, 8 Nov 2013 12:29:03 +0000 (13:29 +0100)]
Fix procedure-arguments on RTL programs, and tweak session.test
* module/ice-9/session.scm (procedure-arguments): Add an rtl-program?
case.
* module/system/vm/debug.scm (arity-arguments-alist): Use the order that
session.test expects.
* test-suite/tests/session.test ("procedure-arguments"): Adapt tests
with keywords for the new starting-with-the-procedure numbering of
locals.
Andy Wingo [Fri, 8 Nov 2013 12:25:08 +0000 (13:25 +0100)]
Fix make-vector peval test
* test-suite/tests/peval.test ("partial evaluation"): Fix to expect a
primcall.
Andy Wingo [Fri, 8 Nov 2013 10:41:28 +0000 (11:41 +0100)]
Fix case-lambda* dispatching to agree with manual.
* module/system/vm/assembler.scm (kw-prelude): Emit br-if-npos-gt as
appropriate.
Andy Wingo [Fri, 8 Nov 2013 10:38:34 +0000 (11:38 +0100)]
Add br-if-npos-gt
* libguile/vm-engine.c (br-if-npos-gt): New instruction (sigh!). For
case-lambda* dispatching on the number of positional args, as the
manual describes. Renumber other opcodes.
Andy Wingo [Fri, 8 Nov 2013 10:36:53 +0000 (11:36 +0100)]
Fix BR_NARGS data type width
* libguile/vm-engine.c (BR_NARGS): Fix width of "expected". Fixes bug
with > 65536 arguments in case-lambda clauses.
Andy Wingo [Fri, 8 Nov 2013 09:59:52 +0000 (10:59 +0100)]
Fix arity selection in compute-contification
* module/language/cps/contification.scm (compute-contification): Fail as
soon as we see an arity with rest, optional, or keyword arguments.
Fixes ((case-lambda ((a . b) #t) ((a b) #f)) 1 2).
Andy Wingo [Fri, 8 Nov 2013 09:37:09 +0000 (10:37 +0100)]
Fix error message in lambda* eval closures with keywords
* module/ice-9/eval.scm (primitive-eval): For ((lambda* (#:key foo) foo) 'bar),
give an "invalid keyword" error instead of a "wrong number of
arguments" error.
Andy Wingo [Fri, 8 Nov 2013 09:03:48 +0000 (10:03 +0100)]
Fix reading and writing arities into DWARF.
* libguile/gsubr.h:
* libguile/gsubr.c (scm_i_primitive_call_ip):
* libguile/programs.c (scm_primitive_call_ip): Adapt to return an
absolute address.
* module/system/vm/assembler.scm (write-arity-headers): Adapt to write
byte addresses (relative to the text base).
* module/system/vm/debug.scm (arity-low-pc, arity-high-pc): Return
absolute addresses, instead of word offsets relative to the text
base.
(find-first-arity): Adapt for absolute addresses.
* module/system/vm/program.scm (program-arguments-alist): Adapt for
arity-low-pc / arity-high-pc absolute addresses.
Andy Wingo [Fri, 8 Nov 2013 08:07:32 +0000 (09:07 +0100)]
Fix eval.test: stack involving a primitive
* test-suite/tests/eval.test ("stacks"): Revert expect-fail introduced
in
27337b6373954e1a975d97d0bf06b5c03d65b64d.
Andy Wingo [Fri, 8 Nov 2013 08:02:30 +0000 (09:02 +0100)]
Fix coverage.test: instrumented-source-files
* test-suite/tests/coverage.test ("instrumented-source-files"): Adapt to
new expectation that all files loaded on the system will be present in
the source information.
Andy Wingo [Fri, 8 Nov 2013 08:00:06 +0000 (09:00 +0100)]
Fix coverage.test: "procedure-execution-count: never"
* test-suite/tests/coverage.test ("procedure-execution-count"): Adapt
test to new behavior of procedure-execution-count of an unseen
procedure: zero, not false.
Andy Wingo [Fri, 8 Nov 2013 07:56:52 +0000 (08:56 +0100)]
Fix coverage.test: "line-execution-counts: one proc hit, one proc unused"
* test-suite/tests/coverage.test ("line-execution-counts"): Fix test for
even/odd? in letrec. The test profiles the execution of even?, not
the letrec, so the last line is in fact not reached.
Andy Wingo [Thu, 7 Nov 2013 22:03:45 +0000 (23:03 +0100)]
frame-instruction-pointer is absolute; rewrite (system vm coverage)
* libguile/frames.c (scm_frame_source): Instead of assuming that
scm_frame_procedure is correct, use the IP to get the source.
(scm_frame_instruction_pointer): Return an absolute value instead of
assuming that slot 0 is correct. (It isn't, when preparing for a tail
call.)
* libguile/programs.h:
* libguile/programs.c (scm_find_source_for_addr): New internal helper.
* module/system/repl/debug.scm (print-registers): Readably print
absolute instruction pointers.
* module/system/vm/coverage.scm: Complete rewrite to use absolute IP's.
We can't assume that frame-procedure is cheap if it is correct, or
correct if it is cheap. Anyway using the address is better anyway.
(coverage-data->lcov): Disable per-function info temporarily.
(loaded-modules, module-procedures, closest-source-line)
(closed-over-procedures): Remove these. Instead of going from
procedures to source info, now we go from ELF image to source info.
* module/system/vm/debug.scm (debug-context-length): New interface.
* module/system/vm/program.scm (source-for-addr): New internal helper.
Andy Wingo [Thu, 7 Nov 2013 17:11:00 +0000 (18:11 +0100)]
scm_from_uintptr_t / scm_from_ptrdiff_t usage
* libguile/frames.c:
* libguile/programs.c: Use scm_from_ptrdiff_t and scm_from_uintptr_t
where appropriate.
Andy Wingo [Thu, 7 Nov 2013 17:00:40 +0000 (18:00 +0100)]
Program sources are always pre-retire now
* module/system/repl/debug.scm (<debug>): Remove for-trap?. Backtraces
with RTL will always happen pre-retire on the top frame, source info
is pre-retire, and continuations will always have a source-marked
receive or receive-values or whatever with the right source marking,
so we can remove this complication.
(print-frame): Use frame-source.
(print-frames): Remove for-trap? kw.
* module/system/repl/command.scm (define-stack-command, backtrace)
(up, down, frame): Remove for-trap? introduced local, and its uses.
(repl-pop-continuation-resumer): Adapt to make-debug change.
* module/system/repl/error-handling.scm (call-with-error-handling):
Adapt to make-debug change.
* module/system/vm/frame.scm (frame-next-source): Remove. RTL sources
are pre-retire.
* module/system/vm/trap-state.scm (add-ephemeral-stepping-trap!): Adapt
to use frame-source. Still some work to do here.
Andy Wingo [Thu, 7 Nov 2013 16:53:04 +0000 (17:53 +0100)]
add fold-all-debug-contexts, fold-source-locations
* module/system/vm/objcode.scm:
* libguile/objcodes.c (scm_all_mapped_elf_images): New proc.
* module/system/vm/debug.scm (fold-all-debug-contexts):
(fold-source-locations): New public interfaces.
Andy Wingo [Thu, 7 Nov 2013 10:16:24 +0000 (11:16 +0100)]
Fix DWARF source test now that we have more precise source info.
* test-suite/tests/dwarf.test: Fix test after the $continue/$cont source
change, which reifies proper source info for the +.
Andy Wingo [Thu, 7 Nov 2013 10:10:36 +0000 (11:10 +0100)]
Fix line advance DWARF opcodes when line advance is exactly 128
* module/system/vm/assembler.scm (link-debug): Fix off-by-one error in
which forward jumps of 128 were mis-rendered.
Andy Wingo [Thu, 7 Nov 2013 09:52:47 +0000 (10:52 +0100)]
Write DWARF files list in correct order.
* module/system/vm/assembler.scm (link-debug): Fix order of writing the
source files list; it was being written backwards.
Andy Wingo [Thu, 7 Nov 2013 09:32:21 +0000 (10:32 +0100)]
Source information goes on the $continue, not the $cont.
* module/language/cps.scm ($continue, $cont): Put source information on
the $continue, not on the $cont. Otherwise it is difficult for CPS
conversion to preserve source information.
($fun): Add a src member to $fun. Otherwise we might miss the source
info for the start of the function.
* .dir-locals.el:
* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-rtl.scm:
* module/language/cps/constructors.scm:
* module/language/cps/contification.scm:
* module/language/cps/dfg.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Update the whole CPS world
for this change.
Andy Wingo [Wed, 6 Nov 2013 16:33:43 +0000 (17:33 +0100)]
Fix first find-program-sources result
* module/system/vm/debug.scm (find-program-sources): Manually set the pc
of the first result in a function.
Andy Wingo [Tue, 5 Nov 2013 20:33:00 +0000 (21:33 +0100)]
compiler.test fix for rtl compilation
* test-suite/tests/compiler.test ("current-reader"): Fix the way we make
programs from objcode.
Andy Wingo [Tue, 5 Nov 2013 20:29:46 +0000 (21:29 +0100)]
fix docstring assembly and fetching
* module/system/vm/assembler.scm (link-docstrs): Write pc offsets as
byte addresses. Works better with native code.
* module/system/vm/debug.scm (find-program-docstring): Fix the linear
search. How embarassing!
Andy Wingo [Tue, 5 Nov 2013 19:18:23 +0000 (20:18 +0100)]
asm-labels is a hash table
* module/system/vm/assembler.scm (make-assembler, label):
(link-data, process-relocs, process-labels): Change labels to be a
hash table.
Andy Wingo [Tue, 5 Nov 2013 18:22:26 +0000 (19:22 +0100)]
fix make-long-immediate, make-long-long-immediate for dst >= 256
* libguile/vm-engine.c (make-long-immediate, make-long-long-immediate):
Fix declaration of "dst" variable.
Andy Wingo [Tue, 5 Nov 2013 17:16:13 +0000 (18:16 +0100)]
Re-add the list hack to compile-cps
* module/language/tree-il/compile-cps.scm (convert): Re-add the list
hack. Ideally these go into some tree-il pass.
Andy Wingo [Tue, 5 Nov 2013 17:06:08 +0000 (18:06 +0100)]
squish to primitive reification
* test-suite/tests/tree-il.test: Update for primitive-ref reification
fix.
Andy Wingo [Sun, 3 Nov 2013 21:00:18 +0000 (22:00 +0100)]
Fix test case for uniform-array->bytevector on bitvectors
* test-suite/tests/bytevectors.test ("uniform-array->bytevector"):
Bitvectors are accessed in 32-bit chunks.
Andy Wingo [Sun, 3 Nov 2013 20:45:34 +0000 (21:45 +0100)]
RTL compiler supports static bitvectors
* libguile/arrays.c (scm_from_contiguous_typed_array):
* libguile/bytevectors.c (scm_uniform_array_to_bytevector): For
bitvectors, round up the length to 32-bit units, as they are stored
internally. Otherwise I think this probably does the wrong thing for
the last word on big-endian systems.
* libguile/bitvectors.c (BITVECTOR_LENGTH, BITVECTOR_BITS):
(scm_c_make_bitvector): Reorder the length and pointer words to match
the layout of bytevectors.
* module/language/cps/primitives.scm (*branching-primcall-arities*):
* module/system/vm/assembler.scm (br-if-bitvector):
* module/system/vm/disassembler.scm (code-annotation): Add bitvector
test support.
* module/system/vm/assembler.scm (<uniform-vector-backing-store>): Add
an element-size field.
(intern-constant): Adapt make-uniform-vector-backing-store call. Use
uniform-array->bytevector, as the old compiler did.
(link-data): Add bitvector cases.
Andy Wingo [Sun, 3 Nov 2013 19:24:54 +0000 (20:24 +0100)]
struct-set! returns a value, yuck
* module/language/cps/arities.scm (fix-clause-arities): Add a hack to
ensure that (struct-set! OBJ POS VAL) evaluates to VAL. Yuck.
Andy Wingo [Sun, 3 Nov 2013 11:28:47 +0000 (12:28 +0100)]
Correctness fix for vector constructor inlining.
* module/language/tree-il/compile-cps.scm (convert): Don't inline the
vector constructor if any arg could capture the current continuation.
Andy Wingo [Sun, 3 Nov 2013 11:16:49 +0000 (12:16 +0100)]
Eval evaluates initializers before creating environment ribs.
* module/ice-9/eval.scm (let-env-evaluator, primitive-eval): Evaluate
initializers of let expressions before creating the environment rib.
This prevents call/cc-related shenanigans.
Andy Wingo [Sun, 3 Nov 2013 11:15:09 +0000 (12:15 +0100)]
"length" is an interesting primitive
* module/language/tree-il/primitives.scm (*effect-free-primitives*):
(*interesting-primitive-names*): Add "length", so that we can
constant-fold it.
Andy Wingo [Fri, 1 Nov 2013 18:43:45 +0000 (19:43 +0100)]
Revert "Compile-time debugging"
This reverts commit
6a37b7faaf150e9fb7945ef79969cb7671d17367.
Andy Wingo [Fri, 1 Nov 2013 18:28:36 +0000 (19:28 +0100)]
Fix call/cc with the RTL VM
* libguile/vm.c (vm_return_to_continuation): The RTL VM saves the
registers for the caller of call/cc, but the caller will expect values
in the normal MV return location: above the frame. Make it so, number
four!
Andy Wingo [Fri, 1 Nov 2013 17:23:51 +0000 (18:23 +0100)]
Fix order of evaluation in elisp lexer
* module/language/elisp/lexer.scm (lex): Use let*, to ensure that the
port position is read before reading the next char.
Andy Wingo [Fri, 1 Nov 2013 17:22:58 +0000 (18:22 +0100)]
Fix contification of non-recursive closures
* module/language/cps/contification.scm (compute-contification): When
eliding let-bound functions, also record the cont that declares the
function.
(apply-contification): Instead of reifying ($values ()) gotos instead
of the elided function, inline the body that binds the function
directly. This ensures that the function gets contified in its own
scope.
Andy Wingo [Fri, 1 Nov 2013 13:37:57 +0000 (14:37 +0100)]
RTL compilation sorts continuations topologically before visiting them
* module/language/cps/compile-rtl.scm (compile-fun): Rewrite to visit
conts in reverse-post-order, which is a topological sort on the basic
blocks.
* module/language/cps/slot-allocation.scm (allocate-slots): Expect a DFG
as an argument.
Andy Wingo [Fri, 1 Nov 2013 12:37:27 +0000 (13:37 +0100)]
Failed match errors generate less code
* module/ice-9/match.upstream.scm (match-next): Call out to an external
procedure on error, and use a begin instead of double-parens. This
results in less generated code.
Andy Wingo [Fri, 1 Nov 2013 07:51:52 +0000 (08:51 +0100)]
Add compile-cps hack for vectors
* module/language/tree-il/compile-cps.scm (convert): Add a special case
for "vector" primcalls. Boo!
Andy Wingo [Thu, 31 Oct 2013 21:57:06 +0000 (22:57 +0100)]
Better range checks in the assembler
* module/system/vm/assembler.scm (pack-u8-u24, pack-u8-s24):
(pack-u1-u7-u24, pack-u8-u12-u12, pack-u8-u8-u16, pack-u8-u8-u8-u8):
Prevent adjacent fields from stompling each other.
Andy Wingo [Thu, 31 Oct 2013 21:16:10 +0000 (22:16 +0100)]
Be smarter about capturing the environment for memoized code
* libguile/memoize.h (SCM_M_CAPTURE_MODULE)
* libguile/memoize.c (MAKMEMO_CAPTURE_MODULE, capture_env):
(maybe_makmemo_capture_module, memoize): Determine when to capture the
module on the environment chain at compile-time, instead of at
runtime. Introduces a new memoized expression type, capture-module.
(scm_memoized_expression): Start memoizing with #f as the
environment.
(unmemoize): Add unmemoizer.
(scm_memoize_variable_access_x): Cope with #f as module, and treat as
the root module (captured before modules were booted).
* libguile/eval.c (eval):
* module/ice-9/eval.scm (primitive-eval): Adapt.
Andy Wingo [Thu, 31 Oct 2013 19:39:22 +0000 (20:39 +0100)]
define! is an interesting primitive
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
Add define!.
Andy Wingo [Thu, 31 Oct 2013 19:24:38 +0000 (20:24 +0100)]
fix compilation of (let lp () (lp))
* module/language/cps/dfg.scm (reverse-post-order): Add an optional
"fold-all-conts" argument.
(compute-live-variables): Take the function as an arg instead of the
start continuation, and implement fold-all-conts so that nodes that
never reach the tail also get liveness information.
Andy Wingo [Thu, 31 Oct 2013 18:24:42 +0000 (19:24 +0100)]
DFG: Export analyze-control-flow.
* module/language/cps/dfg.scm ($cfa, $dominator-analysis): Remove
dominator things from $cfa, to break out to separate structure.
(cfa-k-idx, cfa-k-count, cfa-k-sym, cfa-predecessors): New public
accessors.
(analyze-control-flow): New public function.
(analyze-dominators): Adapt.
Andy Wingo [Thu, 31 Oct 2013 18:21:31 +0000 (19:21 +0100)]
static-patch! for pair and vector fields
* module/system/vm/assembler.scm (intern-constant): Use static-patch!
for fields.
Andy Wingo [Thu, 31 Oct 2013 13:18:25 +0000 (14:18 +0100)]
Better REPL support for disassembling RTL images
* module/system/repl/command.scm (load-image): New helper.
(compile, disassemble): Handle bytevectors.
Andy Wingo [Thu, 31 Oct 2013 13:17:30 +0000 (14:17 +0100)]
Default to compiling to RTL
* module/ice-9/eval-string.scm (eval-string)
* module/language/tree-il/spec.scm (tree-il)
* module/scripts/compile.scm (compile)
* module/system/base/compile.scm (compile-file, read-and-compile)
* module/system/repl/common.scm (repl-compile, repl-prepare-eval-thunk):
Default to compiling to RTL.
* module/language/rtl/spec.scm (rtl->value): Add value compiler.
Andy Wingo [Thu, 31 Oct 2013 11:52:23 +0000 (12:52 +0100)]
Avoid calling procedure-name when doing a make-procedure-with-setter
* libguile/procs.c (scm_make_procedure_with_setter): Don't set the name
of the procedure. Instead rely on procedure-name to look it up from
the wrapped procedure as needed.
* libguile/procprop.c (scm_procedure_name): If there was no override and
the procedure is a procedure-with-setter, recurse on the procedure.
Andy Wingo [Thu, 31 Oct 2013 11:06:06 +0000 (12:06 +0100)]
Better aliased primcall compilation
* libguile/vm-engine.c (define!): Rename from define.
* module/language/cps/arities.scm (fix-clause-arities): If a prim
aliases an RTL instruction with a different name and we reify a
primcall, reify the instruction name.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Update
emit-define! for new name.
* module/language/cps/primitives.scm (*rtl-instruction-aliases*): Add
bytevector native accessors.
Andy Wingo [Thu, 31 Oct 2013 10:39:43 +0000 (11:39 +0100)]
Better compiler support for bytevector ops
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add emitters
for bytevector ops. Add br-if-bytevector emitter.
* module/language/cps/primitives.scm (*branching-primcall-arities*):
Mark bytevector? as a branching primitive.
* module/system/vm/assembler.scm (br-if-bytevector): New instruction
* module/system/vm/disassembler.scm (code-annotation): Add support for
bytevector?.
Andy Wingo [Thu, 31 Oct 2013 10:30:53 +0000 (11:30 +0100)]
Fix bytevector error messages.
* libguile/vm-engine.c (BV_FIXABLE_INT_SET, BV_INT_SET):
(BV_FLOAT_SET): Fix instruction names in error messages.
Andy Wingo [Wed, 30 Oct 2013 20:11:03 +0000 (21:11 +0100)]
Support serialization of uniform vector literals
* libguile/uniform.h:
* libguile/uniform.c (scm_uniform_vector_element_type_code): New
interface, returns a type code as an integer.
* module/system/vm/assembler.scm (<uniform-vector-backing-store>)
(simple-vector?, uniform-array?, statically-allocatable?)
(intern-constant, link-data, link-constants): Support uniform arrays,
and punt on vectors aren't contiguous from 0. Support for general
arrays will come later.
* test-suite/tests/rtl.test ("load-constant"): Add tests.
Andy Wingo [Sun, 27 Oct 2013 19:10:59 +0000 (20:10 +0100)]
Compile-time debugging
* module/language/cps/compile-rtl.scm:
* module/language/cps/contification.scm: Add some compile-time
printouts. Will be removed later.
Andy Wingo [Thu, 31 Oct 2013 09:49:38 +0000 (10:49 +0100)]
DFG: $block no longer stores control-flow analysis
* 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.
Andy Wingo [Thu, 31 Oct 2013 08:44:59 +0000 (09:44 +0100)]
static-patch! replaces link-procedure!
* 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.
Andy Wingo [Wed, 30 Oct 2013 20:08:38 +0000 (21:08 +0100)]
Fix primitive reification for class-of, bytevector-u8-ref, etc
* module/language/cps/reify-primitives.scm (primitive-module): Not all
primitives are bound in (guile).
Andy Wingo [Tue, 29 Oct 2013 22:06:07 +0000 (23:06 +0100)]
DFG: Disable control-flow analysis.
* module/language/cps/dfg.scm (visit-fun): Disable control-flow analysis
for now, as it is not used.
Andy Wingo [Tue, 29 Oct 2013 21:57:29 +0000 (22:57 +0100)]
Add "pop" field to $prompt
* 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.
Andy Wingo [Sun, 27 Oct 2013 19:59:50 +0000 (20:59 +0100)]
DWARF return arity fixen
* module/system/vm/dwarf.scm (read-die-abbrev): Fix return arity.
(read-compilation-unit): Fix return arity of read-die.
Andy Wingo [Sun, 27 Oct 2013 10:40:55 +0000 (11:40 +0100)]
Dynamic-wind doesn't call thunk? on the out-guard.
* module/ice-9/boot-9.scm (dynamic-wind): Remove the thunk? check of the
out-guard.
Andy Wingo [Wed, 23 Oct 2013 15:18:24 +0000 (17:18 +0200)]
Walk the stack to determine extent of partial continuation
* libguile/control.c (reify_partial_continuation): Walk the stack to
determine the bottom of the captured stack.
Andy Wingo [Sun, 20 Oct 2013 16:09:52 +0000 (18:09 +0200)]
Resumable partial continuations in the RTL VM
* libguile/vm-engine.c (receive-values): Bugfix for the case where we
want an exact number of values.
(abort): Advance the IP before capturing. The captured SP is fp - 1,
not fp.
* libguile/vm.c (vm_reinstate_partial_continuation): Don't push on a
number-of-values marker.
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.