* module/language/cps/compile-bytecode.scm (compile-function): Always
define a 'closure binding in slot 0.
* module/system/vm/frame.scm (available-bindings): No need to futz
around not having a closure binding.
* module/system/vm/debug.scm (arity-arguments-alist): Expect a closure
binding.
* test-suite/tests/rtl.test: Emit definitions for the closure.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/primitives.scm (*branching-primcall-arities*):
* module/language/cps/type-fold.scm (equal?):
* module/language/cps/types.scm (equal?):
* module/language/tree-il/compile-cps.scm (convert): `equal?' is no
longer a branching primcall, because it isn't inline. The
implementation could lead to bad backtraces also, as it didn't save
the IP, and actually could lead to segfaults as it didn't reload the
SP after the return. There is an eqv? fast-path, though.
* module/system/vm/assembler.scm (br-if-equal): Remove interface.
* module/system/vm/disassembler.scm (code-annotation):
(compute-labels): No need to handle br-if-equal.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump
bytecode version to prevent 2.1.1 users from thinking that they don't
need to make clean after pulling.
* libguile/vm-engine.c (fadd, fsub, fmul, fdiv): New instructions.
* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm: Wire up support for new instructions.
* module/system/vm/assembler.scm: Export emit-fadd and friends.
* module/language/tree-il/compile-cps.scm (convert): Box results of
bv-f32-ref and bv-f64-ref. Unbox the argument to bv-f32-set! and
bv-f64-set!.
* libguile/vm-engine.c (bv-f32-ref, bv-f64-ref): Results are raw.
(bv-f32-set!, bv-f64-set!): Take unboxed arguments.
* module/system/vm/assembler.scm (emit-scm->f64, emit-f64->scm):
Export.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm: Add support for scm->f64 and
f64->scm.
* module/language/cps/slot-allocation.scm (compute-var-representations):
Add cases for primops returning raw values.
* module/language/cps/types.scm (bv-f32-ref, bv-f32-set!)
(bv-f64-ref, bv-f64-set!): Deal in &f64 values instead of reals.
* libguile/loader.c (scm_find_slot_map_unlocked): Rename from
scm_find_dead_slot_map_unlocked.
* libguile/vm.c (struct slot_map_cache_entry, struct slot_map_cache)
(find_slot_map): Rename, changing "dead_slot" to "slot".
(enum slot_desc): New type.
(scm_i_vm_mark_stack): Interpret slot maps as having two bits per
slot, allowing us to indicate that a slot is live but not a pointer.
* module/language/cps/compile-bytecode.scm (compile-function): Adapt to
emit-slot-map name change.
* module/system/vm/assembler.scm (<asm>): Rename dead-slot-maps field to
slot-maps.
(emit-slot-map): Rename from emit-dead-slot-map.
(link-frame-maps): 2 bits per slot.
* module/language/cps/slot-allocation.scm (lookup-slot-map): Rename from
lookup-dead-slot-map.
(compute-var-representations): New function.
(allocate-slots): Adapt to encode two-bit slot representations.
* module/language/cps/compile-bytecode.scm (compile-function): Remove
special cases for nullary and unary returns; instead always use
return-values and rely on hinting to try to place values in the right
slot already.
* module/system/vm/assembler.scm (emit-init-constants): Use
return-values.
* module/system/vm/disassembler.scm (code-annotation): Add annotation
for return-values.
* doc/ref/vm.texi: Update for new stack layout.
* module/system/vm/disassembler.scm (code-annotation): Print the frame
sizes after alloc-frame, reset-frame, etc to make reading the
disassembly easier.
* module/system/vm/disassembler.scm (define-stack-effect-parser)
(stack-effect-parsers, instruction-stack-size-after): New stack size
facility.
(define-clobber-parser, clobber-parsers, instruction-slot-clobbers):
Take incoming and outgoing stack sizes as arguments to interpret
SP-relative clobbers.
* module/system/vm/frame.scm (compute-frame-sizes): New helper that
computes frame sizes for each position in a function.
(compute-killv): Adapt to compute the clobbered set given the computed
frame sizes.
* libguile/vm-engine.c: S24/S12/S8 operands addressed relative to the
SP, not the FP. Cache the SP instead of a FP-relative locals
pointer. Further cleanups to follow.
* libguile/vm.c (vm_builtin_call_with_values_code): Adapt to mov operand
addresing change.
* module/language/cps/compile-bytecode.scm (compile-function): Reify
SP-relative local indexes where appropriate.
* module/system/vm/assembler.scm (emit-fmov*): New helper, exported as
emit-fmov.
(shuffling-assembler, define-shuffling-assembler): Rewrite to shuffle
via push/pop/drop.
(standard-prelude, opt-prelude, kw-prelude): No need to provide for
shuffling args.
* test-suite/tests/rtl.test: Update.
* module/language/cps/slot-allocation.scm: Don't reserve slots 253-255.
* libguile/vm-engine.c: Renumber opcodes, and take the opportunity to
fold recent additions into more logical places. Be more precise when
describing the encoding of operands, to shuffle local references only
and not constants, immediates, or other such values.
(SP_REF, SP_SET): New helpers.
(BR_BINARY, BR_ARITHMETIC): Take full 24-bit operands. Our shuffle
strategy is to emit push when needed to bring far locals near, then
pop afterwards, shuffling away far destination values as needed; but
that doesn't work for conditionals, unless we introduce a trampoline.
Let's just do the simple thing for now. Native compilation will use
condition codes.
(push, pop, drop): Back from the dead! We'll only use these for
temporary shuffling though, when an opcode can't address the full
24-bit range.
(long-fmov): New instruction, like long-mov but relative to the frame
pointer.
(load-typed-array, make-array): Don't use a compressed encoding so
that we can avoid the shuffling case. It would be a pain, given that
they have so many operands already.
* module/language/bytecode.scm (compute-instruction-arity): Update for
new instrution word encodings.
* module/system/vm/assembler.scm: Update to expose some opcodes
directly, without the need for shuffling wrappers. Adapt to
instruction word encodings change.
* module/system/vm/disassembler.scm (disassembler): Adapt to instruction
coding change.
* module/system/repl/debug.scm (print-frame): Pass #:top-frame? #t for
the top frame.
* module/system/vm/frame.scm (available-bindings): Be permissive and
allow #:top-frame? #f even when the IP is at the start of the
function.
* module/system/vm/assembler.scm (link-debug): Fix for source properties
that don't have line and column, as are currently being produced by
the new lalr.
* libguile/vm-engine.c (allocate-struct, struct-ref, struct-set!): New
instructions, to complement their "immediate" variants.
* module/language/cps/compile-bytecode.scm (compile-fun):
* module/system/vm/assembler.scm (system): Wire up the new instructions.
Fixes <http://bugs.gnu.org/19354>.
Reported by Linas Vepstas <linasvepstas@gmail.com>.
* module/system/vm/assembler.scm (write-sources): Intern the filename
only if it's a string. (For sockets, the filename is a symbol).
* module/system/vm/program.scm (print-program): New public interface --
the guts of write-program, but refactored to be able to work when only
given an addr.
(write-program): Use print-program.
* module/system/vm/frame.scm (frame-call-representation): Remove attempt
to abbreviate procedure representations; was confusing because the
result would write as a string, quotes and all.
* libguile/vm-engine.c (vm_engine): Always invoke the apply hook after
the ip has been reset. Avoids problems in frame-bindings, which
builds its bindings map based on the IP. Invoke push-continuation
before linking the new frame, so that more locals are available to the
frame inspector.
* module/system/vm/traps.scm (trap-in-procedure): No need for a
push-cont handler, as the apply handler will exit the frame.
* module/system/vm/frame.scm (frame-call-representation): Change
top-frame? argument to be a keyword instead of an optional argument.
* module/system/vm/trace.scm (print-application): Adapt caller.
* doc/ref/api-debug.texi (Stack Capture): Update make-stack docs.
* libguile/programs.h:
* libguile/programs.c (scm_program_address_range): New internal
procedure.
* libguile/stacks.c (narrow_stack): Interpret a pair of integers as an
address range. If a cut is a procedure, attempt to resolve it to an
address range.
(scm_make_stack): Update docstring.
* module/system/vm/program.scm (program-address-range): New exported
procedure.
* module/statprof.scm (statprof, gcprof): Use program-address-range to
get the outer-cut, for efficiency.
* module/language/cps/slot-allocation.scm (allocate-slots): Avoid
allocating locals in the range [253,255].
* module/system/vm/assembler.scm: List exports explicitly. For
operations with limited-range operands, export wrapper assemblers that
handle shuffling their operands into and out of their range.
(define-assembler): Get rid of enclosing begin.
(shuffling-assembler, define-shuffling-assembler): New helpers to
define shuffling wrapper assemblers.
(emit-mov*, emit-receive*): New functions.
(shuffle-up-args): New helper.
(standard-prelude, opt-prelude, kw-prelude): Call shuffle-up-args
after finishing.
* test-suite/tests/compiler.test ("limits"): Add test cases.
* module/system/vm/assembler.scm (define-inline): Change so that the
defined macro is only defined at expansion-time.
(u32-ref, u32-set!, s32-ref, s32-set!, pack-arity-flags): Use
define-inline.
(pack-flags, assert-match, *block-size*, id-append, assembler)
(define-assembler, visit-opcodes, define-macro-assembler): Wrap in
eval-when expand.
* 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/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/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.