* module/system/vm/linker.scm (<linker-object>): Add name field. This
allows the linker to find sections by name, notably before having
found the .shstrtab section. As there can be multiple sections with
type SHT_STRTAB, this fixes a bug whereby we could use a section
name (a strtab index) into an unrelated strtab. In the past this
worked because with ASCII identifiers there won't be an exception,
although it is possible to accidentally mistake a shared string tail;
but with UTF-8 identifiers, it's possible for a string table index to
point in the middle of a codepoint, which is likely not valid UTF-8
and would raise a bug. Keeping an additional section name field fixes
this bug. Adapt all callers to pass a name argument to
make-linker-object.
(find-shstrndx): Update to look at the name field.
* module/system/vm/assembler.scm (make-object): Pass name to
make-linker-object.
Thanks to Daniel Llorens for the test case.
* libguile/loader.h (SCM_OBJCODE_MINIMUM_MINOR_VERSION):
(SCM_OBJCODE_MINOR_VERSION): Bump version.
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
* libguile/vm-engine.c: Rearrange opcodes to be contiguous and in a
somewhat sensible order.
* libguile/intrinsics.h:
* libguile/intrinsics.c (string_set_x): Change to take size_t and u32 as
args.
(allocate_words): Change to take size_t as arg.
* libguile/vm.c (expand_apply_argument): Rename from rest_arg_length,
and also handle the stack manipulation.
* libguile/vm-engine.c (expand-apply-argument): Update for intrinsic
change.
(call-scm-sz-u32): Rename from call-scm-u64-u64, as it matches its
uses and will compile better on 32-bit systems.
* module/system/vm/assembler.scm (define-scm-sz-u32-intrinsic):
(string-set!): Update for new instrinsic call inst.
* libguile/jit.c (compile_call_scm_sz_u32): Adapt.
* module/system/vm/assembler.scm (<jit-data>, <meta>): Rework to have
<meta> create the <jit-data> in the end-program, so that jit-data
isn't mutable. Record start and end PC values relative to '.rtl-text
so that we don't need any more linker symbols.
(emit-instrument-entry*, emit-instrument-loop*, begin-program):
(end-program): Adapt.
(begin-kw-arity): Include the initial instrument-entry in the first
arity.
(link-data, link-constants): Write the init routine before interning
constants so that we correctly emit the jit-data for the init
routine.
* libguile/programs.c (try_parse_arity): Skip over a
scm_op_instrument_entry, if any.
* am/bootstrap.am (SOURCES):
* module/Makefile.am (SOURCES): Handle renamve of handle-interrupts.scm
to loop-instrumentation.scm.
* libguile/jit.h (SCM_JIT_COUNTER_ENTRY_INCREMENT): Rename from
SCM_JIT_COUNTER_CALL_INCREMENT.
* libguile/vm-engine.c (instrument-entry): Rename from instrument-call.
* module/language/cps/compile-bytecode.scm (compile-function): Add
handle-interrupts code before calls and returns. Compile the
"instrument-loop" primcall to an "instrument-loop" instruction and a
"handle-interrupts" instruction.
(lower-cps): Adapt to add-loop-instrumentation name change.
* module/language/cps/loop-instrumentation.scm: Rename from
handle-interrupts.scm and just add "instrument-loop" primcalls in
loops. The compiler will add handle-interrupts primcalls as
appropriate.
* module/system/vm/assembler.scm (<jit-data>): New data type, for
emitting embedded JIT data.
(<meta>): Add field for current JIT data.
(make-meta): Initialize current JIT data.
(emit-instrument-entry*, emit-instrument-loop*): New instruction
emitters that reference the current JIT data.
(end-program): Now that all labels are known, arrange to serialize the
JIT data.
(link-data): Reserve space for JIT data, and add relocs to initialize
the "start" / "end" fields.
* libguile/jit.h (struct scm_jit_function_data)
(enum scm_jit_counter_value): New data types.
* libguile/jit.c (scm_jit_compute_mcode, scm_jit_enter_mcode): New
function stubs. Adapt label/offset compilers to take pointers.
* libguile/vm-engine.c (instrument-call, instrument-loop): New
instructions.
* libguile/vm.c: Add jit.h include.
* module/system/vm/assembler.scm (emit-instrument-call)
(emit-instrument-loop): New exports.
This should reduce frame sizes.
* libguile/vm-engine.c (halt): Adapt to multiple-values change. Also
adapt to not having the boot closure on the stack.
(receive, receive-values, subr-call, foreign-call): Adapt to expect
values one slot down.
(prompt): Capture one less word for the values return.
* libguile/vm.c (vm_dispatch_pop_continuation_hook):
(vm_dispatch_abort_hook): Adapt for where to expect values.
(vm_builtin_values_code): Add a call to shuffle-down before
returning. This is more overhead than what existed before, but the
hope is that the savings elsewhere pay off.
(vm_builtin_values_code): Adapt to different values location.
(reinstate_continuation_x, compose_continuation): Adapt to place
resume args at right position.
(capture_delimited_continuation): Remove unused sp and ip arguments.
(abort_to_prompt): Adapt to capture_delimited_continuation change.
(scm_call_n): Adapt to not reserve space for the boot closure.
* module/language/cps/compile-bytecode.scm (compile-function): When
returning values, adapt reset-frame call for return calling convention
change. Adapt truncating or rest returns to expect values in the
right place.
* module/language/cps/slot-allocation.scm (compute-shuffles):
(allocate-lazy-vars, allocate-slots): Allocate values from the "proc
slot", not proc-slot + 1.
* module/system/vm/assembler.scm (emit-init-constants): Reset the frame
before returning so that the return value is in the right place.
* test-suite/tests/rtl.test: Update for return convention change.
* libguile/foreign.c (get_foreign_stub_code): Update for return calling
convention change.
* libguile/fluids.c (scm_i_fluid_ref): New internal function.
(scm_fluid_ref): Use scm_i_fluid_ref.
* libguile/intrinsics.h:
* libguile/intrinsics.c (current_module): New intrinsic.
* libguile/modules.c (scm_i_current_module): New internal function.
(scm_current_module): Use new internal function.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
Add current-module as an intrinsic primitive.
* module/system/vm/assembler.scm (define-scm<-thread-intrinsic):
(current-module): Arrange to compile to intrinsic call.
* libguile/intrinsics.c (scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add new define!
intrinsic.
* module/language/cps/compile-bytecode.scm (compile-function): Adapt
compilation for define! to take two arguments.
* module/language/cps/effects-analysis.scm (current-module): Update
define! for two arguments.
* module/language/tree-il/compile-cps.scm (convert): When reifying
"define", grab the current module.
* module/system/vm/assembler.scm (define!): Define assembler as
intrinsic.
* module/system/vm/assembler.scm (<cache-cell>): Remove "scope" member.
Just be an opaque key comparable with equal?.
(intern-cache-cell): Remove scope arg.
(intern-module-cache-cell): Remove; callers use intern-cache-cell now.
(cache-current-module!, cached-toplevel-box, cached-module-box): Create
cache keys that by construction won't collide between types.
(cache-ref, cache-set!): Add new macro assemblers.
* module/language/cps/reify-primitives.scm:
* module/language/cps/compile-bytecode.scm: Add cases for new macro
instructions.
* libguile/intrinsics.c (scm_to_uint64_truncate): New intrinsic.
(scm_bootstrap_intrinsics): Init new intrinsics.
* libguile/intrinsics.h: Add scm->u64, scm->u64/truncate, and scm->s64
as intrinsics, with their corresponding types.
* libguile/vm-engine.c (call-u64<-scm, call-s64<-scm): New intrinsic
calling ops.
(scm->u64, scm->s64, scm->u64/truncate): Disable opcodes.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
Add intrinsics as new macroinstructions.
* module/system/vm/assembler.scm: Declare new intrinsic assemblers.
* module/language/cps/effects-analysis.scm (string-ref): Remove effects
declaration, given that the primitive is exploded now.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
Add string-set!.
* libguile/vm-engine.c (string-set!): Disable opcode.
* module/language/cps/types.scm (string-ref, string-set!): Remove type
checker and inferrers for string-ref and string-set!, as both are
exploded. In the case of string-set! there are still type-check
effects in the intrinsic call but they can't be elided by the checker,
as we don't track when strings are read-only.
* module/language/tree-il/compile-cps.scm (ensure-char): New helper.
(string-set!): New primcall exploded converter.
* libguile/intrinsics.h: Rename intrinsic types added in previous
commit.
* libguile/vm-engine.c (call-scm<-scm-scm, call-scm<-scm-uimm): New
instructions.
* libguile/vm.c: Include intrinsics.h.
* module/language/bytecode.scm
* module/language/bytecode.scm (*intrinsic-codes*, *intrinsic-names*):
New internal definitions.
(intrinsic-name->index, intrinsic-index->name): New exported
definitions.
* module/system/vm/assembler.scm (encode-X8_S8_S8_S8-C32<-/shuffle):
(encode-X8_S8_S8_C8-C32<-/shuffle): New shuffling encoders.
(shuffling-encoder-name): Add case for new shuffling encoders.
(define-scm<-scm-scm-intrinsic, define-scm<-scm-uimm-intrinsic): New
helpers. Define encoders for "add", etc.
* libguile/vm-engine.c (gc-pointer-ref/immediate)
(gc-pointer-set!/immediate): New instructions.
(SP_REF_PTR, SP_SET_PTR): New helper definitions.
* libguile/vm.c (SLOT_DESC_LIVE_GC): Rename from SLOT_DESC_LIVE_SCM, as
it can indicate GC-protected raw pointers also.
(scm_i_vm_mark_stack): Adapt.
* module/system/vm/assembler.scm (write-arities):
* module/system/vm/debug.scm (arity-definitions): Add gcptr
representation. This is a binary-incompatible change!
* module/language/cps/compile-bytecode.scm (compile-function): Add cases
for mutable-vector? and immutable-vector?.
* module/system/vm/assembler.scm: Export emit-mutable-vector? and
emit-immutable-vector?.
* libguile/vm-engine.c (ash): Remove instruction, which hasn't been
emitted for a long time.
* module/system/vm/assembler.scm (emit-ash): Remove export.