1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-07-02 07:40:30 +02:00
Commit graph

9715 commits

Author SHA1 Message Date
Andy Wingo
f2ad6525e6 Convert scm_gc_malloc* calls to scm_allocate*
* libguile/arrays.c:
* libguile/bitvectors.c:
* libguile/bytevectors.c:
* libguile/chooks.c:
* libguile/continuations.c:
* libguile/control.c:
* libguile/dynstack.c:
* libguile/ephemerons.c:
* libguile/filesys.c:
* libguile/foreign.c:
* libguile/fports.c:
* libguile/frames.c:
* libguile/gsubr.c:
* libguile/hashtab.c:
* libguile/i18n.c:
* libguile/integers.c:
* libguile/intrinsics.c:
* libguile/load.c:
* libguile/loader.c:
* libguile/macros.c:
* libguile/numbers.c:
* libguile/options.c:
* libguile/ports.c:
* libguile/programs.h:
* libguile/random.c:
* libguile/read.c:
* libguile/regex-posix.c:
* libguile/smob.c:
* libguile/srfi-14.c:
* libguile/strings.c:
* libguile/struct.c:
* libguile/threads.c:
* libguile/threads.h:
* libguile/values.c:
* libguile/vm.c: Convert all calls to scm_gc_malloc_pointerless to
scm_allocate_pointerless.  Convert scm_gc_malloc to either
scm_allocate_tagged or scm_allocate_sloppy, depending on whether the
value can be precisely traced or not.
2025-06-20 11:40:01 +02:00
Andy Wingo
290a57b1b0 Add scm_allocate_{pointerless,tagged,sloppy}
* libguile/gc-inline.h (scm_inline_allocate_pointerless):
(scm_inline_allocate_tagged):
(scm_inline_allocate_sloppy):
* libguile/gc.h:
* libguile/gc-malloc.c (scm_allocate_pointerless):
(scm_allocate_tagged):
(scm_allocate_sloppy): New functions.
(scm_gc_malloc):
(scm_gc_malloc_pointerless): Dispatch to scm_allocate functions.
2025-06-20 11:07:34 +02:00
Andy Wingo
a793d371cd Move string-pointer-array handling to posix.c
* libguile/posix.c (free_string_pointers):
(free_string_pointers_on_unwind):
(allocate_string_pointers): Move here from string.c, and use malloc/free
instead of GC facilities. Adapt all users.
* libguile/strings.h:
* libguile/strings.c (scm_i_allocate_string_pointers): Remove.
2025-06-20 11:06:41 +02:00
Andy Wingo
ce2f7847e8 Avoid untagged traced allocation in make-struct/no-tail
* libguile/struct.c (scm_struct_init_1_default):
(scm_struct_init_1): New helpers.
(scm_struct_init_array): Use new helpers.
(scm_struct_init_list): New function.
(scm_make_struct_no_tail): Use scm_struct_init_list instead of mallocing.
2025-06-20 09:27:47 +02:00
Andy Wingo
4d15cb7e6d JIT uses malloc/free instead of gc_malloc
* libguile/jit.c (initialize_thread_jit_state):
(scm_jit_state_free): Use malloc/free, to avoid needing to mark things.
2025-06-19 16:56:30 +02:00
Andy Wingo
278ba99027 Allow precise tracing of dynstacks
Gosh this was a slog

* libguile/dynstack.c (dynstack_ensure_space): Use malloc and free.
Threads have off-heap dynstacks, with manual marking.
(scm_trace_dynstack): Implement tracing.
(trace_pinned_trampoline, scm_trace_dynstack_roots): Implement tracing
for active threads.
(scm_dynstack_capture): Tag dynstacks.
* libguile/dynstack.h (scm_t_dynstack): Add a tag.
(scm_t_dynstack_winder_flags): Add SCM_F_DYNSTACK_WINDER_MANAGED.
* libguile/dynwind.h (scm_t_wind_flags): Add SCM_F_WIND_MANAGED.
* libguile/dynwind.c (scm_dynwind_unwind_handler_with_scm)
(scm_dynwind_rewind_handler_with_scm): These values need to be traced by
GC.
* libguile/scm.h (scm_tc16_dynstack_slice): New typecode.  No need for
equality etc because it shouldn't escape to Scheme (currently).
* libguile/trace.h: Add trace decls.
* libguile/threads.c (scm_trace_thread_roots): Trace dynstacks
explicitly here, as they are off-heap.
2025-06-19 16:32:56 +02:00
Andy Wingo
923bfdc7ed String ports have managed streams
* libguile/strports.c (stream_bytevector, stream_pos, stream_len)
(stream_set_bytevector, stream_set_pos, stream_set_len)
(make_stream): New helpers.
* libguile/strports.c (string_port_read):
(string_port_write):
(string_port_seek):
(string_port_truncate):
(scm_mkstrport):
(scm_strport_to_string): Adapt.
(scm_make_string_port_type): Indicate that the stream is managed.
2025-06-18 16:33:36 +02:00
Andy Wingo
765245119b Rework representation of ports
Instead of a 4-word object that has a tag, stream, pt, and ptob, just
add tag, stream, and ptob fields to pt.  Also add a "stream mode",
indicating to the GC how the stream should be traced.

* libguile/custom-ports.c (scm_init_custom_ports): Indicate that streams
are managed.
* libguile/fports.c (scm_make_fptob): Streams are managed.
* libguile/ports-internal.h (scm_t_port_type): Add enum to indicate
stream management.
(scm_t_port): Add type-and-flags, stream, and ptob members.
* libguile/ports.c (scm_port_stream, scm_port_type): New helpers.
(scm_make_port_type): Init stream mode to CONSERVATIVE.
(scm_set_port_stream_mode): New API.
(scm_c_make_port_with_encoding): Adapt to new port representation.
(scm_init_ports): Void ports have unmanaged streams.
* libguile/ports.h (scm_is_port, scm_to_port, scm_from_port): New inline
functions.
(SCM_PORT, SCM_STREAM, SCM_PORT_TYPE): Rework in terms of new functions.
(SCM_SETSTREAM): Remove.
(enum scm_port_stream_mode): New.
(scm_set_port_stream_mode): New.
2025-06-18 16:30:03 +02:00
Andy Wingo
c74499a7e5 Add new API for declaring managed SMOB fields
* libguile/smob.h:
* libguile/smob.c (scm_make_managed_smob_type): New API, to declare that
a SMOB has a certain number of fields, all of which will be traced by
the GC.  0 indicates "unknown", and will disable evacuation.
(scm_make_smob_type): Call scm_make_managed_smob_type with 0 nfields.
(scm_set_smob_field_is_unmanaged): New API to indicate that a field is
unmanaged (and should not be traced by GC).
2025-06-18 14:59:03 +02:00
Andy Wingo
bc43d4f9a7 Locale have static tc16
* libguile/print.c (iprin1):
* libguile/eq.c (scm_equal_p): Add case for locales and also regexps
which we missed in the past.
* libguile/finalizers.h:
* libguile/finalizers.c (scm_i_add_locale_finalizer):
(run_finalizer): Add locale finalizers.
* libguile/scm.h (scm_tc16_locale): New tc16.
* module/oop/goops.scm:
* libguile/goops.c: Add locale class.
* libguile/i18n.c: Give locale objects their own tc16.
2025-06-18 12:18:24 +02:00
Andy Wingo
a5c70aa914 Simplify i18n.c to require POSIX 2008 newlocale, uselocale
* libguile/i18n.c: Remove shim for pre-POSIX 2008, given that gnulib
does appear to have newlocale/uselocale implementations.
* libguile/posix.c: No USE_GNU_LOCALE_API define.
* libguile/r6rs-ports.c: Remove stray include.
2025-06-18 12:02:41 +02:00
Andy Wingo
3f4048f6c8 Move transcoded ports implementation to Scheme
* libguile/r6rs-ports.c: Remove private transcoded ports implementation.
* module/ice-9/binary-ports.scm: Remove stale comment.
* module/rnrs/io/ports.scm (%make-transcoded-port): New implementation
based on custom ports.
2025-06-18 11:06:12 +02:00
Andy Wingo
6ba6fbdf64 Fix GOOPS for <regexp>
* module/oop/goops.scm (<regexp>):
* libguile/goops.c: (scm_class_of): Give regexps their own class; it
doesn't come from smobs.
2025-06-18 10:58:08 +02:00
Andy Wingo
2a015937ca Move bytevector input ports implementation to Scheme
* module/ice-9/binary-ports.scm (open-bytevector-input-port): New
implementation.
* libguile/r6rs-ports.c (scm_open_bytevector_input_port): Proxy to
Scheme.
2025-06-18 10:37:42 +02:00
Andy Wingo
2fc5ff5264 Move bytevector output ports implementation to Scheme
* module/ice-9/binary-ports.scm (bytevector-concatenate-reverse):
(bytevector-copy*): New helpers.
(open-bytevector-output-port): New implementation.
* libguile/r6rs-ports.c (scm_open_bytevector_output_port):
(init_bytevector_port_vars): Arrange to proxy to Scheme.
2025-06-18 10:13:10 +02:00
Andy Wingo
c3e8e9fa6d Remove needless smob.h includes
* libguile/continuations.c: Fix printer.
* libguile/async.c:
* libguile/debug.c:
* libguile/filesys.c:
* libguile/gc.c:
* libguile/init.c:
* libguile/inline.c:
* libguile/keywords.c:
* libguile/macros.c:
* libguile/modules.c:
* libguile/numbers.c:
* libguile/ports.c:
* libguile/srfi-14.c:
* libguile/symbols.c:
* libguile/threads.c:
* libguile/threads.h:
* libguile/variable.c: Remove smob.h includes.
2025-06-17 15:03:32 +02:00
Andy Wingo
ace42e191e Convert regexps to use statically-allocated tc16
* libguile/scm.h: Allocate tc16.
* libguile/regex-posix.h:
* libguile/regex-posix.c:
* libguile/finalizers.h:
* libguile/finalizers.c: Adapt.
2025-06-17 14:35:51 +02:00
Andy Wingo
197345fa02 Fix texi-fragments-to-docstrings to import srfi-14
* libguile/texi-fragments-to-docstrings: Use srfi-14.
2025-06-17 14:35:13 +02:00
Andy Wingo
521662d8b7 Move make-regexp, regexp?, regexp-exec to (ice-9 regex)
Also deprecate the C interface.

* libguile/Makefile.am: Don't install regex-posix.h.
* libguile/deprecated.c:
* libguile/deprecated.h: Add deprecated shims for scm_make_regexp et al.
* libguile/init.c: Fix comment.
* libguile/regex-posix.c: Privatize some of the implementation details.
Arrange to install into (ice-9 regex) instead of default environment.
* module/ice-9/deprecated.scm: Add deprecation shims.
* module/ice-9/regex.scm: Add new definitions.
* module/ice-9/sandbox.scm:
* module/scripts/read-scheme-source.scm:
* module/system/repl/server.scm:
* module/texinfo/reflection.scm:
* test-suite/tests/r6rs-exceptions.test:
* test-suite/tests/srfi-10.test: Import (ice-9 regex).
2025-06-17 14:10:12 +02:00
Andy Wingo
ccaff3da39 Allocate a static tc16 for random states
* libguile/random.h (scm_t_rstate): Put a tag word in the beginning.
(scm_is_random_state, scm_to_random_state, scm_from_random_state): New
helpers.
(SCM_RSTATEP, SCM_RSTATE): Use the new helpers.
(scm_masktab): Make private.
* libguile/random.c: Adapt random states to not be a smob.
* libguile/eq.c:
* libguile/print.c:
* libguile/scm.h:
* module/oop/goops.scm: Add new random-state cases.  Fix a number of
classes for other types that were recently changed to not be smobs.
2025-06-17 10:45:27 +02:00
Andy Wingo
63317ff480 Move R5RS promises implementation to Scheme
* am/bootstrap.am (SOURCES):
* module/ice-9/promises.scm: New file.
* libguile/promises.h:
* libguile/promises.c: Delete.
* libguile/deprecated.h:
* libguile/deprecated.c: Add promises shims.
* libguile/init.c:
* libguile/Makefile.am:
* libguile.h: Remove promises mentions.
* module/ice-9/deprecated.scm: Add shims to include promises in the
default environment.
* module/ice-9/null.scm:
* module/ice-9/safe-r5rs.scm:
* module/ice-9/sandbox.scm:
* module/language/bytecode.scm:
* module/language/cps/guile-vm/reify-primitives.scm:
* module/language/elisp/parser.scm:
* module/rnrs/r5rs.scm:
* test-suite/tests/00-initial-env.test:
* test-suite/tests/eval.test:
* test-suite/tests/r4rs.test: Import (ice-9 promises).
2025-06-17 09:41:33 +02:00
Andy Wingo
3cf4ca187c Remove print state objects, and ports-with-print-state
The goal was that, as part of a print operation, all nested prints of
contained data would be able to use the same parameters (e.g. write or
not), and also detect cycles, highlight objects, etc.  The mechanism was
a heap-allocated data structure.  However, given that:

  1. Nobody accessed print states from Scheme

  2. `write` and `display` should move to Scheme anyway, in order to be
     suspendable

  3. The "fancyp" and "highlight" options were unused

  4. A simple stack-allocated data structure with a per-thread key could
     do the trick just as well, without needing the weird freelist
     structure

  5. Ports-with-print-states were a source of bugs

In the end we switch print states to be something completely internal to
print.c.  There are no more SCM print-state objects, and no more
ports-with-print-state.

* libguile/print.h: Remove print state from API.
* libguile/print.c (struct scm_print_state): Move definition here.
(scm_print_opts): Remove "highlight-prefix" and "highlight-suffix"
options, as they were not used.
(ENTER_NESTED_DATA): Remove "fancyp" case.
(init_print_state_key, get_print_state, push_print_state)
(maybe_push_print_state, pop_print_state): New facility to manage stack
of active print states.
(scm_iprin1, print_vector): No more fancyp.
(iprin1): Access "writingp" member directly.  Don't make ports with
print states.
(scm_prin1): Manage print state stack.
(scm_iprlist): No more fancyp.
(scm_valid_oport_value_p): Remove; valid outports are SCM_OPOUTPORTP.
* libguile/backtrace.c:
* libguile/filesys.c:
* libguile/fports.c:
* libguile/goops.c:
* libguile/ioext.c:
* libguile/ports.c:
* libguile/posix.c:
* libguile/promises.c:
* libguile/socket.c:
* libguile/struct.c: Remove cases that dealt with
ports-with-print-states.
* libguile/private-options.h: Remove highlight options.
* module/ice-9/ports.scm (inherit-print-state): Deprecate.
* libguile/deprecated.c:
* libguile/deprecated.h: Add deprecation shims for print states, as far
as that is possible.
2025-06-17 09:38:46 +02:00
Andy Wingo
d1b548033c Remove unused "malloc objects"
* libguile/mallocs.c:
* libguile/mallocs.h: Delete files.  These exposed a SMOB interface for
traced mallocs, which is not compatible with precise tracing, and was
unused and undocumented.
* libguile.h:
* libguile/Makefile.am:
* libguile/init.c: Remove mallocs.
* libguile/options.c:
* libguile/ports.c: Remove useless mallocs.h includes
2025-06-16 13:42:04 +02:00
Andy Wingo
383b67c9f1 Give syntax transformers a static tc16
* libguile/scm.h: Allocate a tc16 for syntax transformers.
* libguile/expand.c: Adapt to renamings.
* libguile/eq.c:
* libguile/goops.c:
* libguile/print.c: Add tc16 cases.
* libguile/macros.h:
* libguile/macros.c (scm_i_make_primitive_syntax_transformer):
(scm_i_primitive_syntax_transformer): Rename internal functions from
scm_i_make_primitive_macro, etc.  Use new representation.
(scm_make_syntax_transformer): Update for new representation.
2025-06-16 13:38:02 +02:00
Andy Wingo
f930af2737 Move implementation of hooks to Scheme module
* module/ice-9/hooks.scm: New file.
* am/bootstrap.am: Add new file.
* module/ice-9/deprecated.scm: Add trampolines to (ice-9 hooks).
* module/ice-9/scm-style-repl.scm:
* module/ice-9/session.scm:
* module/ice-9/top-repl.scm:
* module/scripts/scan-api.scm:
* guile-readline/ice-9/readline.scm:
* benchmark-suite/benchmark-suite/lib.scm:
* module/system/repl/command.scm:
* module/system/repl/common.scm:
* module/system/repl/debug.scm:
* module/system/repl/error-handling.scm:
* module/system/repl/hooks.scm:
* module/system/repl/reader.scm:
* module/system/repl/repl.scm:
* module/ice-9/history.scm:
* test-suite/tests/hooks.test: Use the new module.
* module/oop/goops.scm: Remove <hook> class definition.
* libguile/vm.c:
* libguile/init.c:
* libguile/Makefile.am:
* libguile.h: Remove hooks.h includes.
* libguile/hooks.c:
* libguile/hooks.h: Remove.
* libguile/deprecated.h:
* libguile/deprecated.c: Add deprecation shims for C API.
2025-06-16 13:11:28 +02:00
Andy Wingo
04fdc33a54 Replace after-gc-hook with {add,remove}-after-gc-callback!
* libguile/gc.c:
(scm_gc_event_listener_restarting_mutators):
(after_gc_async_thunk):
(scm_init_gc): Instead of using a hook for after-gc callbacks, just use
a list of thunks.  Will allow us to move hooks to Scheme.
(add-after-gc-callback!, remove-after-gc-callback!): New functions.
* libguile/gc.h (scm_after_gc_hook): Remove.
* libguile/scmsigs.c (signal_delivery_thread): Update comment.
* module/statprof.scm (gcprof):
* test-suite/tests/gc.test ("gc"): Update to use new functions.
2025-06-16 11:36:07 +02:00
Andy Wingo
2554e69f78 VM "hooks" actually are just lists
* libguile/vm.c (vm_hook_compute_enabled):
(invoke_hook):
(scm_i_vm_prepare_stack):
(VM_ADD_HOOK):
(VM_REMOVE_HOOK): Since we don't actually expose the hook objects, we
can just use lists; it's clearer and will let us move hook objects to
Scheme.
2025-06-16 11:36:07 +02:00
Andy Wingo
0d1171afe9 Fix creation of VM frames
Fix bug introduced in aa73d31de.

* libguile/frames.c (scm_c_make_frame): GC-malloc the scm_vm_frame, not
the scm_frame.
2025-06-16 11:33:45 +02:00
Andy Wingo
2c186f835b Allocate a static tc16 to directory streams
* libguile/filesys.c: Use a static tc16.
* libguile/eq.c:
* libguile/filesys.h:
* libguile/finalizers.c:
* libguile/finalizers.h:
* libguile/goops.c:
* libguile/print.c:
* libguile/scm.h:
* module/oop/goops.scm: Adapt for the new tc16.
2025-06-13 16:39:39 +02:00
Andy Wingo
df113d1589 Make scm_tc16_dir, SCM_DIRP etc private
* libguile/filesys.h:
* libguile/filesys.c (SCM_DIR_FLAG_OPEN):
(SCM_DIR_OPEN_P):
(SCM_DIRP):
(SCM_VALIDATE_DIR): Move here, from the header.  I don't think people
use them.
2025-06-13 15:09:22 +02:00
Andy Wingo
c1150bec2c Remove trailing whitespace
* libguile/continuations.c (pin_conservative_roots):
2025-06-13 13:31:37 +02:00
Andy Wingo
4e5a132f4f Capturing continuations pins conservative roots
* libguile/continuations.c (pin_conservative_roots): New helper.
(capture_auxiliary_stack):
(scm_i_make_continuation): Pin aux stack, jmpbuf, and stack items.
2025-06-13 13:30:36 +02:00
Andy Wingo
12da6739b1 Give continuations (contregs) their own static tc16
* libguile/continuations-internal.h: New file, for internal definitions.
* libguile/continuations.h: Move out internal definitions.
* libguile/Makefile.am: Add new file.
* libguile/continuations.c: Adapt to put the tag in the beginning of the
continuation (contregs) structure.
* libguile/eq.c:
* libguile/goops.c:
* libguile/init.c:
* libguile/print.c:
* libguile/scm.h:
* libguile/stacks.c:
* libguile/vm.c:
* module/oop/goops.scm: Adapt to contregs tc16 change.
2025-06-13 13:13:02 +02:00
Andy Wingo
f47fe6e752 Convert mutexes, condition vars to statically-allocated tc16
* libguile/scm.h: Add statically allocated tc16s for condvars and
mutexes.
* libguile/threads.c: Adapt to declare tag inline to struct scm_cond and
struct scm_mutex.
* libguile/threads.h: Expose printing procedures internally.
* module/oop/goops.scm:
* libguile/goops.c: Fix to statically allocate condition variable and
mutex classes.
* libguile/eq.c:
* libguile/print.c: Adapt.
2025-06-13 11:48:19 +02:00
Andy Wingo
7a1406891f Move char-set-cursor implementation to Scheme
Also deprecate the C interface.

* libguile/deprecated.h:
* libguile/deprecated.c (scm_char_set_cursor):
(scm_char_set_ref):
(scm_char_set_cursor_next):
(scm_end_of_char_set_p): Deprecate.
* libguile/srfi-14.c (charset-mutable?, char-set-ranges)
(charset-set-ranges!): New accessors, exposed internally to srfi-14.scm.
* libguile/srfi-14.c (scm_boot_srfi_14): Remove scm_tc16_charset_cursor.
* module/srfi/srfi-14.scm (<char-set-cursor>): Implement as a record.
2025-06-13 11:13:54 +02:00
Andy Wingo
4516119dd1 Deprecate srfi-14 in default environment
* libguile/srfi-14.c:
* module/srfi/srfi-14.scm: Arrange to define bindings here instead of in
the default environment.
* libguile/init.c:
* libguile/srfi-14.h: Fix so that srfi-14 can register an extension to
be loaded later.
* libguile/unidata_to_charset.awk: Rename private cs_letter_plus_digit
to cs_letter_and_digit.
* module/ice-9/deprecated.scm: Add deprecation trampolines for srfi-14.
* module/ice-9/sandbox.scm:
* module/language/elisp/lexer.scm:
* module/language/scheme/decompile-tree-il.scm:
* module/rnrs/unicode.scm:
* module/sxml/simple.scm:
* module/system/base/syntax.scm:
* module/system/repl/server.scm:
* module/texinfo/serialize.scm:
* module/texinfo/string-utils.scm:
* module/web/http.scm:
* module/web/uri.scm:
* test-suite/tests/strings.test:
* test-suite/tests/tree-il.test: Adapt for srfi-14 being in a module.
2025-06-13 09:03:20 +02:00
Andy Wingo
c794c086d5 Change charsets to use bytevector to store char ranges
This doesn't fundamentally change how charsets are represented, but it
will eventually allow us to migrate more functionality to scheme, as the
charsets have a Scheme-legible representation.  Also, and this is really
the point, give charsets their own type code, so that they can be
traced precisely.

* libguile/eq.c:
* libguile/evalext.c:
* libguile/goops.c:
* libguile/print.c:
* module/oop/goops.scm: Adjust to new tc16.
* libguile/srfi-14.h: Make private things private.
* libguile/srfi-14.c: Change to use bytevectors for the ranges.  No
functional change.
2025-06-12 16:49:27 +02:00
Andy Wingo
ec92d6a96e Fix bug whereby taking GC bytevectors was allocating inline storage
* libguile/bytevectors.c (make_bytevector_from_buffer): Whoops, don't
allocate inline storage for this kind of bytevector.
2025-06-12 11:51:14 +02:00
Andy Wingo
5c5b867455 Turn boot closures into subrs
* libguile/eval.c: Instead of applicable smobs, boot closures are subrs.
This gives better JIT and no shuffling in the VM.
(is_boot_closure):
(boot_closure_code):
(boot_closure_env):
(boot_closure_body):
(boot_closure_num_required_args):
(boot_closure_is_fixed):
(boot_closure_has_rest_args):
(boot_closure_is_rest): Inline functions instead of macros.
(eval): Create boot closures as programs, not smobs.
(prepare_boot_closure_env_for_apply):
(prepare_boot_closure_env_for_eval): Adapt to lower-casing of boot
closure inline functions.
(apply_boot_closure): Rename from boot_closure_apply.
(boot_closure_print): Remove.
(scm_init_eval): Update.
2025-06-11 21:59:58 +02:00
Andy Wingo
690845fa1e Convert tc16_catch_handler to be subrs
* libguile/throw.c (call_catch_handler): Rework to expect closure to be
program.
(scm_i_make_catch_handler): Rework to make closures.
(scm_init_throw): Rework to allocate trampoline code.
2025-06-11 16:12:35 +02:00
Andy Wingo
7ddcb48224 Convert tc16_thunk, tc16_exception_handler to be subrs
* libguile/exceptions.c (call_thunk):
(call_exception_handler): Rework to expect closure to be program.
(scm_c_make_thunk):
(scm_c_make_exception_handler): Rework to make closures.
(scm_init_exceptions): Rework to allocate trampoline code.
2025-06-11 16:02:30 +02:00
Andy Wingo
6389acf192 New internal functions to alloc subr closures
* libguile/gsubr.c (scm_allocate_subr_code):
(scm_make_subr_from_code): New functions.
(create_subr): Refactor in terms of new functions.
(scm_c_make_gsubr):
(scm_c_define_gsubr):
(scm_c_make_gsubr_with_generic):
(scm_c_define_gsubr_with_generic): Adapt.
2025-06-11 15:39:58 +02:00
Andy Wingo
710fa4c6f0 Add machinery to pass thread and/or closure when invoking subr
* libguile/gsubr.c: Arrange to store flags alongside array of subrs.
One flag indicates the thread should also be passed as the first
argument; another says that the closure should be passed.  Should remove
the need for arg shuffling in get_callee_vcode eventually.
(record_subr_name): Make the names be a vector; will integrate better
with precise tracing.
(create_subr): Add flags arg.  Adapt callers.
(scm_apply_subr): Allow for passing thread or closure.
* libguile/gsubr-internal.h: Add new interfaces to see whether to pass
closure or thread.  Pass thread to scm_apply_subr.
* libguile/jit.c (compile_subr_call): Allow for passing thread or
closure.
* libguile/vm-engine.c (subr_call): Pass thread.
2025-06-11 13:05:15 +02:00
Andy Wingo
c03071b380 Move subr internals off to internal header file
* libguile/gsubr-internal.h: New file.
* libguile/Makefile.am: Add to build.
* libguile/gsubr.h: Remove internal-only definitions.
* libguile/foreign.c:
* libguile/goops.c:
* libguile/gsubr.c:
* libguile/jit.c:
* libguile/programs.c:
* libguile/vm.c: Include new header.
2025-06-11 12:40:45 +02:00
Andy Wingo
d6e59a1d3e Convert bitvectors to use inline-only word-size units
* libguile/bitvectors.h: Unit of bitvectors is scm_t_bits, not uint32_t.
* libguile/bitvectors.c: Adapt implementation.
(make_bitvector): Malloc pointerless instead, with inline bits.
* libguile/posix.c (scm_setaffinity):
* libguile/bytevectors.c (uniform-array->bytevector): Adapt to unit size
change.
* module/system/vm/assembler.scm (intern-constant, link-data): Adapt to
bitvector representation change.
2025-06-03 16:54:19 +02:00
Andy Wingo
9ff7c0651c Give arrays a proper type in C land
As long as we have a tc7 for arrays, we should be able to access it with
a struct type instead of casting each word.

* libguile/arrays-internal.h: New file.
* libguile/arrays.h (scm_array_p): Take just one argument.
(SCM_I_ARRAYP):
(SCM_I_ARRAY_NDIM):
(SCM_I_ARRAY_V):
(SCM_I_ARRAY_BASE):
(SCM_I_ARRAY_DIMS):
(SCM_I_ARRAY_SET_V):
(SCM_I_ARRAY_SET_BASE): Remove.
(scm_i_raw_array, scm_i_make_array, scm_i_shap2ra, scm_init_arrays):
Remove internally-linked decls.
* libguile/init.c:
* libguile/print.c:
* libguile/array-handle.c: Use interfaces from new file.
* module/system/vm/assembler.scm: Update, as we now shift the dimension
count by only 16.  Requires a rebuild!
2025-06-03 14:55:09 +02:00
Andy Wingo
12e8772403 Move array-map / array-cell functions to Scheme module
* libguile/array-map.c:
* libguile/array-map.h: Remove.

* module/ice-9/deprecated.scm:
* libguile/deprecated.h:
* libguile/deprecated.c: Add deprecation shims.

* module/ice-9/arrays.scm: Move all array-map functionality here.

* libguile/Makefile.am:
* libguile/init.c:
* libguile.h: Remove array-map.h use.

* libguile/arrays.c (scm_i_array_equal_p, scm_i_array_copy): New
helpers.
(scm_array_cell_ref, scm_array_cell_set_x): Move to Scheme.
* libguile/arrays.h:
* libguile/eq.c (scm_equal_p):
* libguile/sort.c (scm_sort): Use new arrays.c helpers.
* module/ice-9/pretty-print.scm:
* module/oop/goops/save.scm: Import (ice-9 arrays).
2025-06-03 14:34:26 +02:00
Andy Wingo
0134abce74 Move private bytevectors API to a separate header
Also give bytevectors a private type (a struct).

* libguile/bytevectors.h (SCM_BYTEVECTOR_HEADER_SIZE): Remove.
(SCM_BYTEVECTOR_LENGTH):
(SCM_BYTEVECTOR_CONTENTS): Proxy to the C accessors.
(SCM_BYTEVECTOR_PARENT): Remove from public API.
(SCM_BYTEVECTOR_P, SCM_VALIDATE_BYTEVECTOR): Make public.
(scm_c_bytevector_contents): New function.
* libguile/bytevectors-internal.h: New file.
* libguile/Makefile.am (noinst_HEADERS): Add new file.

* libguile/bytevectors.c:
* libguile/array-handle.c:
* libguile/arrays.c:
* libguile/foreign.c:
* libguile/goops.c:
* libguile/init.c:
* libguile/loader.c:
* libguile/print.c:
* libguile/r6rs-ports.c:
* libguile/srfi-4.c:
* libguile/strings.c: Adapt to use bytevectors-internal.h as needed, and
sometimes to use the internal bytevector type.
2025-06-02 09:51:47 +02:00
Andy Wingo
51bc69dd1c Fix bytevector mutators to correctly check for mutability
Previously, bytevectors that were serialized into binaries were actually
mutable by compiled bytevector-u8-set! et al.

* libguile/bytevectors.h (SCM_F_BYTEVECTOR_IMMUTABLE): Renumber to 0x80,
as for immutable vectors.
(SCM_BYTEVECTOR_CONTIGUOUS_P): Just use SCM_CELL_TYPE.
(SCM_BYTEVECTOR_FLAGS): Remove unused accessor.
* module/language/tree-il/compile-cps.scm (bytevector-set-converter):
Emit mutable-bytevector? instead of bytevector?.
* module/system/vm/assembler.scm (link-data): Update immutable flag.
* module/language/cps/compile-bytecode.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm:
* module/system/base/types/internal.scm: Update for immutable-bytevector
predicates.
2025-05-30 16:48:26 +02:00
Andy Wingo
043a5b62bb Rework treatment of bytevector flags
Before, they were always shifted by 7.  Now the flags are just above
0x7f and just the element type is shifted, but by 16.

* libguile/bytevectors.h (SCM_BYTEVECTOR_FLAGS): Rework to not shift.
(SCM_SET_BYTEVECTOR_FLAGS): Remove.
(SCM_MUTABLE_BYTEVECTOR_P): Don't shift the immutable flag.
(SCM_BYTEVECTOR_ELEMENT_TYPE): Shift right by 16.
* libguile/bytevectors.c (SCM_BYTEVECTOR_SET_FLAG): Remove unused
helper.
(make_bytevector_tag): New helper.
(make_bytevector): Use new helper.
(make_bytevector_from_buffer): Add flags and parent args, and use new
helper.
(scm_c_take_gc_bytevector):
(scm_c_take_typed_bytevector):
(scm_bytevector_slice): Update callers.
* module/system/vm/assembler.scm (link-data): Don't shift the flag by 7;
instead shift the element type by 16.
2025-05-30 14:19:30 +02:00