2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1999--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
23 #include "lily-guile-macros.hh"
26 #define IMPLEMENT_TYPE_P(CL, FUNCNAME) \
27 SCM CL ## _type_p_proc; \
28 void init_type_ ## CL () \
30 SCM subr = scm_c_define_gsubr (FUNCNAME, 1, 0, 0, \
31 (scm_t_subr) CL::smob_p); \
32 CL ## _type_p_proc = subr; \
33 ly_add_function_documentation (subr, FUNCNAME, "(SCM x)", \
34 "Is @var{x} a @code{" #CL "} object?"); \
35 scm_c_export (FUNCNAME, NULL); \
37 ADD_SCM_INIT_FUNC (init_type_ ## CL, init_type_ ## CL)
39 #define IMPLEMENT_BASE_SMOBS(CL) \
41 CL ## _type_adder () \
43 ly_add_type_predicate ((void*) &CL::unsmob, #CL); \
45 ADD_SCM_INIT_FUNC(CL ## _type_adder_ctor, \
47 const char *CL::smob_name_ = #CL; \
48 scm_t_bits CL::smob_tag_; \
52 if (SCM_NIMP (s) && SCM_CELL_TYPE (s) == smob_tag_) \
62 smob_tag_ = scm_make_smob_type (#CL, 0); \
63 scm_set_smob_mark (smob_tag_, CL::mark_smob); \
64 scm_set_smob_free (smob_tag_, CL::free_smob); \
65 scm_set_smob_print (smob_tag_, CL::print_smob); \
66 scm_set_smob_equalp (smob_tag_, CL::equal_p); \
70 CL::free_smob (SCM ses) \
72 CL *s = (CL *) SCM_CELL_WORD_1 (ses); \
74 /* scm_gc_unregister_collectable_memory (s, sizeof (CL), #CL " smob"); */ \
75 return SMOB_FREE_RETURN_VAL (CL); \
78 ADD_SCM_INIT_FUNC (CL, CL::init_smobs)
80 #define IMPLEMENT_SIMPLE_SMOBS(CL) \
81 IMPLEMENT_BASE_SMOBS (CL); \
82 SCM CL::smobbed_copy () const \
84 CL *ptr = new CL (*this); \
86 s = scm_cons (SCM_PACK (CL::smob_tag_), SCM_PACK (ptr)); \
87 scm_gc_register_collectable_memory ((CL *)this, sizeof (CL), #CL " smob"); \
92 #define IMPLEMENT_SMOBS(CL) \
93 IMPLEMENT_BASE_SMOBS (CL) \
97 protection_cons_ = SCM_EOL; \
98 self_scm_ = unprotected_smobify_self (); \
104 protect_smob (self_scm_, &protection_cons_); \
109 unprotect_smob (self_scm_, &protection_cons_); \
113 CL::unprotected_smobify_self () \
116 This is local. We don't assign to self_scm_ directly, to assure \
117 that S isn't GC-ed from under us. \
119 We don't use smobbed_self () to ensure that mark_smob () doesn't \
120 have to deal half-initialized objects: scm_done_malloc ( ) might \
121 trigger GC.the warning in smobs.hh is just to be doubleplus \
125 SCM_NEWSMOB (s, CL::smob_tag_, this); \
127 scm_gc_register_collectable_memory (this, sizeof (CL), #CL " smob"); \
131 #define IMPLEMENT_DEFAULT_EQUAL_P(CL) \
133 CL::equal_p (SCM a, SCM b) \
135 return a == b ? SCM_BOOL_T : SCM_BOOL_F; \
138 #endif /* LY_SMOBS_ICC */