mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-01 15:20:34 +02:00
Allows us to inline the "struct scm_dynamic_state", avoiding an untagged traced allocation. * libguile/threads-internal.h: New file. * libguile/Makefile.am (noinst_HEADERS): Add new file. Adapt all users, notably of SCM_I_CURRENT_THREAD and scm_i_misc_mutex.
150 lines
4 KiB
C
150 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>
|
|
#include "threads-internal.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_allocate_pointerless (SCM_I_CURRENT_THREAD,
|
|
sizeof (struct scm_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_ */
|