1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-07 12:40:19 +02:00
guile/libguile/programs.h
Andy Wingo 464ec999de Make programs.h private
This header file turns out to only have internal details.  Users that
need introspection can use Scheme.

* libguile/programs.h (SCM_PROGRAM_P, SCM_PROGRAM_CODE)
(SCM_PROGRAM_FREE_VARIABLES, SCM_PROGRAM_FREE_VARIABLE_REF)
(SCM_PROGRAM_FREE_VARIABLE_SET, SCM_PROGRAM_NUM_FREE_VARIABLES)
(SCM_VALIDATE_PROGRAM, SCM_F_PROGRAM_IS_BOOT, SCM_F_PROGRAM_IS_PRIMITIVE)
(SCM_F_PROGRAM_IS_PRIMITIVE_GENERIC, SCM_F_PROGRAM_IS_CONTINUATION)
(SCM_F_PROGRAM_IS_PARTIAL_CONTINUATION, SCM_F_PROGRAM_IS_FOREIGN)
(SCM_PROGRAM_IS_BOOT, SCM_PROGRAM_IS_PRIMITIVE)
(SCM_PROGRAM_IS_PRIMITIVE_GENERIC, SCM_PROGRAM_IS_CONTINUATION)
(SCM_PROGRAM_IS_PARTIAL_CONTINUATION, SCM_PROGRAM_IS_FOREIGN): Remove
these macros, as we are making this whole API private.
(struct scm_program, scm_is_program, scm_to_program, scm_from_program)
(scm_program_flags, scm_program_is_boot, scm_program_is_primitive)
(scm_program_is_primitive_generic, scm_program_is_continuation)
(scm_program_is_partial_continuation, scm_program_is_foreign)
(scm_program_code, scm_program_free_variable_count)
(scm_program_free_variable_ref, scm_program_free_variable_set_x)
(scm_i_make_program): New inline functions.
* libguile/Makefile.am (noinst_HEADERS): Add programs.h; no longer
installed.  It was never directly included from libguile.h.
* libguile/continuations.c:
* libguile/continuations.h:
* libguile/control.c:
* libguile/foreign.c:
* libguile/frames.c:
* libguile/frames.h:
* libguile/goops.c:
* libguile/gsubr.c:
* libguile/gsubr.h:
* libguile/intrinsics.h:
* libguile/procprop.c:
* libguile/procs.c:
* libguile/programs.c:
* libguile/stacks.c:
* libguile/vm-engine.c:
* libguile/vm.c:
* libguile/vm.h: Adapt all users.
2025-05-30 12:52:54 +02:00

148 lines
4 KiB
C

/* Copyright 2001,2009-2014,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/>. */
#ifndef _SCM_PROGRAMS_H_
#define _SCM_PROGRAMS_H_
#include <libguile/gc.h>
/*
* Programs
*/
struct scm_program
{
scm_t_bits tag_flags_and_free_variable_count;
const uint32_t *code;
SCM free_variables[];
};
static inline int
scm_is_program (SCM x)
{
return SCM_HAS_TYP7 (x, scm_tc7_program);
}
static inline struct scm_program*
scm_to_program (SCM x)
{
if (!scm_is_program (x))
abort ();
return (struct scm_program*) SCM_UNPACK_POINTER (x);
}
static inline SCM
scm_from_program (struct scm_program *program)
{
return SCM_PACK_POINTER (program);
}
enum scm_program_flags
{
SCM_F_PROGRAM_IS_BOOT = 0x100,
SCM_F_PROGRAM_IS_PRIMITIVE = 0x200,
SCM_F_PROGRAM_IS_PRIMITIVE_GENERIC = 0x400,
SCM_F_PROGRAM_IS_CONTINUATION = 0x800,
SCM_F_PROGRAM_IS_PARTIAL_CONTINUATION = 0x1000,
SCM_F_PROGRAM_IS_FOREIGN = 0x2000
};
static inline scm_t_bits
scm_program_flags (struct scm_program *program)
{
return program->tag_flags_and_free_variable_count & 0xff00;
}
static inline int
scm_program_is_boot (struct scm_program *program)
{
return scm_program_flags (program) & SCM_F_PROGRAM_IS_BOOT;
}
static inline int
scm_program_is_primitive (struct scm_program *program)
{
return scm_program_flags (program) & SCM_F_PROGRAM_IS_PRIMITIVE;
}
static inline int
scm_program_is_primitive_generic (struct scm_program *program)
{
return scm_program_flags (program) & SCM_F_PROGRAM_IS_PRIMITIVE_GENERIC;
}
static inline int
scm_program_is_continuation (struct scm_program *program)
{
return scm_program_flags (program) & SCM_F_PROGRAM_IS_CONTINUATION;
}
static inline int
scm_program_is_partial_continuation (struct scm_program *program)
{
return scm_program_flags (program) & SCM_F_PROGRAM_IS_PARTIAL_CONTINUATION;
}
static inline int
scm_program_is_foreign (struct scm_program *program)
{
return scm_program_flags (program) & SCM_F_PROGRAM_IS_FOREIGN;
}
static inline const uint32_t*
scm_program_code (struct scm_program *program)
{
return program->code;
}
static inline size_t
scm_program_free_variable_count (struct scm_program *program)
{
return program->tag_flags_and_free_variable_count >> 16;
}
static inline SCM
scm_program_free_variable_ref (struct scm_program *program, size_t idx)
{
return program->free_variables[idx];
}
static inline void
scm_program_free_variable_set_x (struct scm_program *program, size_t idx, SCM v)
{
program->free_variables[idx] = v;
}
static inline SCM
scm_i_make_program (const uint32_t *code)
{
struct scm_program *ret =
scm_gc_malloc_pointerless (sizeof (struct scm_program), "program");
ret->tag_flags_and_free_variable_count = scm_tc7_program;
ret->code = code;
return scm_from_program (ret);
}
SCM_INTERNAL SCM scm_i_program_name (SCM program);
SCM_INTERNAL SCM scm_i_program_documentation (SCM program);
SCM_INTERNAL SCM scm_i_program_properties (SCM program);
SCM_INTERNAL SCM scm_find_source_for_addr (SCM ip);
SCM_INTERNAL SCM scm_program_address_range (SCM program);
SCM_INTERNAL int scm_i_program_arity (SCM program, int *req, int *opt, int *rest);
SCM_INTERNAL void scm_i_program_print (SCM program, SCM port,
scm_print_state *pstate);
SCM_INTERNAL void scm_bootstrap_programs (void);
SCM_INTERNAL void scm_init_programs (void);
#endif /* _SCM_PROGRAMS_H_ */