2 ly-module.cc -- implement guile module stuff.
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "lily-guile.hh"
13 #include "protected-scm.hh"
15 #ifdef MODULE_GC_KLUDGE
16 Protected_scm anonymous_modules = SCM_EOL;
20 clear_anonymous_modules ()
22 for (SCM s = anonymous_modules;
26 SCM module = scm_car (s);
27 SCM closure = SCM_MODULE_EVAL_CLOSURE (module);
28 SCM prop = scm_procedure_property (closure, ly_symbol2scm ("module"));
30 if (ly_is_module (prop))
32 scm_set_procedure_property_x (closure, ly_symbol2scm ("module"),
37 anonymous_modules = SCM_EOL;
41 ly_make_anonymous_module (bool safe)
46 SCM maker = ly_lily_module_constant ("make-module");
48 SCM scm_module = ly_lily_module_constant ("the-scm-module");
50 mod = scm_call_0 (maker);
51 scm_module_define (mod, ly_symbol2scm ("%module-public-interface"),
54 ly_use_module (mod, scm_module);
55 ly_use_module (mod, global_lily_module);
59 SCM proc = ly_lily_module_constant ("make-safe-lilypond-module");
60 mod = scm_call_0 (proc);
63 #ifdef MODULE_GC_KLUDGE
64 anonymous_modules = scm_cons (mod, anonymous_modules);
71 ly_use_module (SCM mod, SCM used)
74 = scm_list_3 (ly_symbol2scm ("module-use!"),
76 scm_list_2 (ly_symbol2scm ("module-public-interface"),
79 return scm_eval (expr, global_lily_module);
82 #define FUNC_NAME __FUNCTION__
85 accumulate_symbol (void *closure, SCM key, SCM val, SCM result)
89 return scm_cons (key, result);
93 ly_module_symbols (SCM mod)
95 SCM_VALIDATE_MODULE (1, mod);
97 SCM obarr = SCM_MODULE_OBARRAY (mod);
98 return scm_internal_hash_fold ((Hash_closure_function) & accumulate_symbol,
99 NULL, SCM_EOL, obarr);
103 entry_to_alist (void *closure, SCM key, SCM val, SCM result)
106 if (scm_variable_bound_p (val) == SCM_BOOL_T)
107 return scm_cons (scm_cons (key, scm_variable_ref (val)), result);
108 programming_error ("unbound variable in module");
112 LY_DEFINE (ly_module2alist, "ly:module->alist",
114 "Dump the contents of module @var{mod} as an alist.")
116 SCM_VALIDATE_MODULE (1, mod);
117 SCM obarr = SCM_MODULE_OBARRAY (mod);
119 return scm_internal_hash_fold ((Hash_closure_function) & entry_to_alist, NULL, SCM_EOL, obarr);
123 ly_export (SCM module, SCM namelist)
125 static SCM export_function;
126 if (!export_function)
127 export_function = scm_permanent_object (scm_c_lookup ("module-export!"));
129 scm_call_2 (SCM_VARIABLE_REF (export_function), module, namelist);
133 ly_reexport_module (SCM mod)
135 ly_export (mod, ly_module_symbols (mod));
138 #ifdef MODULE_GC_KLUDGE
140 redefine_keyval (void *closure, SCM key, SCM val, SCM result)
143 SCM new_tab = result;
144 scm_hashq_set_x (new_tab, key, val);
150 Kludge for older GUILE 1.6 versions.
153 make_stand_in_procs_weak ()
155 SCM old_tab = scm_stand_in_procs;
156 SCM new_tab = scm_make_weak_key_hash_table (scm_from_int (257));
158 new_tab = scm_internal_hash_fold ((Hash_closure_function) & redefine_keyval,
163 scm_stand_in_procs = new_tab;
166 ADD_SCM_INIT_FUNC (make_stand_in_procs_weak, make_stand_in_procs_weak);