1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-07-01 15:20:34 +02:00
guile/libguile/gsubr-internal.h
Andy Wingo c79d5bd0f7 Change to be less sloppy as regards functions without prototypes
* libguile/gsubr.h (scm_t_subr_0, scm_t_subr_1, etc): New precise
typedefs.
(SCM_AS_SUBR): Use C11's _Generic to cast subrs to the generic subr
type, while also producing a warning/error if the function isn't
compatible.
(SCM_DEFINE_GSUBR, SCM_PRIMITIVE_GENERIC, SCM_DEFINE_PUBLIC)
(SCM_DEFINE_STATIC, SCM_PROC, SCM_REGISTER_PROC, SCM_GPROC): Use
SCM_AS_SUBR.
* libguile/gsubr-internal.h (scm_t_subr_with_thread_0)
(scm_t_subr_with_thread_1, etc): New precise typedefs.
(SCM_AS_SUBR_WITH_THREAD): Like SCM_AS_SUBR.
* libguile/gsubr.c (scm_apply_subr): Cast callee to the right type
before calling.
* libguile/hash.c (floor): Remove weird unused declaration.
* libguile/init.c (scm_boot_guile): Fix type of main_func in definition.
* libguile/jit.c: Fix type of enter_mcode.
* libguile/smob.c (apply_0, apply_1, apply_2, apply_3): Cast callee to
right type.
(scm_smob_trampoline): Use SCM_AS_SUBR.
* libguile/smob.h (SCM_SMOB_APPLY): Use SCM_AS_SUBR.
* libguile/backtrace.c:
* libguile/control.c:
* libguile/dynl.c:
* libguile/eval.c:
* libguile/exceptions.c:
* libguile/expand.c:
* libguile/finalizers.c:
* libguile/fluids.c:
* libguile/fports.c:
* libguile/frames.c:
* libguile/gc.c:
* libguile/load.c:
* libguile/loader.c:
* libguile/macros.c:
* libguile/memoize.c:
* libguile/pairs.c:
* libguile/poll.c:
* libguile/ports.c:
* libguile/posix.c:
* libguile/rdelim.c:
* libguile/rw.c:
* libguile/vm.c: Adapt scm_c_make_gsubr / scm_c_define_gsubr callers to
use SCM_AS_SUBR.
2025-06-26 15:56:16 +02:00

104 lines
4.1 KiB
C
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef SCM_GSUBR_INTERNAL_H
#define SCM_GSUBR_INTERNAL_H
/* Copyright 1995-1996,1998,2000-2001,2006,2008,2009-2011,2013,2015,2018,2025
Free Software Foundation, Inc.
This file is part of Guile.
Guile is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Guile is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Guile. If not, see
<https://www.gnu.org/licenses/>. */
#include "libguile/gsubr.h"
/* Max number of args to the C procedure backing a gsubr */
#define SCM_GSUBR_MAX 10
#define SCM_PRIMITIVE_P(x) (scm_is_primitive (x))
#define SCM_PRIMITIVE_GENERIC_P(x) (scm_is_primitive_generic (x))
typedef SCM (*scm_t_subr_with_thread_0) (scm_thread*);
typedef SCM (*scm_t_subr_with_thread_1) (scm_thread*, SCM);
typedef SCM (*scm_t_subr_with_thread_2) (scm_thread*, SCM, SCM);
typedef SCM (*scm_t_subr_with_thread_3) (scm_thread*, SCM, SCM, SCM);
typedef SCM (*scm_t_subr_with_thread_4) (scm_thread*, SCM, SCM, SCM, SCM);
typedef SCM (*scm_t_subr_with_thread_5) (scm_thread*, SCM, SCM, SCM, SCM, SCM);
typedef SCM (*scm_t_subr_with_thread_6) (scm_thread*, SCM, SCM, SCM, SCM, SCM, SCM);
typedef SCM (*scm_t_subr_with_thread_7) (scm_thread*, SCM, SCM, SCM, SCM, SCM, SCM, SCM);
typedef SCM (*scm_t_subr_with_thread_8) (scm_thread*, SCM, SCM, SCM, SCM, SCM, SCM, SCM, SCM);
typedef SCM (*scm_t_subr_with_thread_9) (scm_thread*, SCM, SCM, SCM, SCM, SCM, SCM, SCM, SCM, SCM);
typedef SCM (*scm_t_subr_with_thread_10) (scm_thread*, SCM, SCM, SCM, SCM, SCM, SCM, SCM, SCM, SCM, SCM);
#define SCM_AS_SUBR_WITH_THREAD(fn) \
_Generic (fn, \
scm_t_subr_with_thread_0 : (scm_t_subr) fn, \
scm_t_subr_with_thread_1 : (scm_t_subr) fn, \
scm_t_subr_with_thread_2 : (scm_t_subr) fn, \
scm_t_subr_with_thread_3 : (scm_t_subr) fn, \
scm_t_subr_with_thread_4 : (scm_t_subr) fn, \
scm_t_subr_with_thread_5 : (scm_t_subr) fn, \
scm_t_subr_with_thread_6 : (scm_t_subr) fn, \
scm_t_subr_with_thread_7 : (scm_t_subr) fn, \
scm_t_subr_with_thread_8 : (scm_t_subr) fn, \
scm_t_subr_with_thread_9 : (scm_t_subr) fn, \
scm_t_subr_with_thread_10 : (scm_t_subr) fn, \
default: fn)
struct scm_program;
struct scm_thread;
SCM_INTERNAL uint32_t *
scm_i_alloc_primitive_code_with_instrumentation (size_t uint32_count,
uint32_t **write_ptr);
SCM_INTERNAL int scm_i_primitive_code_p (const uint32_t *code);
SCM_INTERNAL uintptr_t scm_i_primitive_call_ip (struct scm_program *subr);
SCM_INTERNAL SCM scm_i_primitive_name (const uint32_t *code);
SCM_INTERNAL int scm_is_primitive (SCM x);
SCM_INTERNAL int scm_is_primitive_generic (SCM x);
SCM_INTERNAL scm_t_subr scm_subr_function_by_index (uint32_t subr_idx);
SCM_INTERNAL int scm_subr_has_closure_argument (uint32_t subr_idx);
SCM_INTERNAL int scm_subr_has_thread_argument (uint32_t subr_idx);
SCM_INTERNAL SCM* scm_subr_generic (SCM x);
SCM_INTERNAL void scm_set_subr_generic (SCM x, SCM g);
SCM_INTERNAL SCM scm_apply_subr (struct scm_thread *thread,
union scm_vm_stack_element *sp,
uint32_t subr_idx, ptrdiff_t nargs);
enum scm_subr_flags
{
SCM_F_SUBR_THREAD = 1,
SCM_F_SUBR_CLOSURE = 2
};
SCM_INTERNAL const uint32_t*
scm_allocate_subr_code (SCM name,
unsigned int nreq, unsigned int nopt, unsigned int rest,
void *fcn, uintptr_t subr_flags);
SCM_INTERNAL struct scm_program*
scm_make_subr_from_code (struct scm_thread *thread, const uint32_t *code,
scm_t_bits program_flags, size_t nfree);
SCM_INTERNAL void scm_init_gsubr (void);
#endif /* SCM_GSUBR_INTERNAL_H */