X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Flily-modules.cc;h=5d35018e72e734d498c237cb83e8c937f2ec6e58;hb=fa512e34722a81101213ac1566175aba4da805dd;hp=b5b61ee6bb27d0ae2638a5ebeda5e100291c4a0d;hpb=91649a0ead8af565c5e0406601ee71c8cda57a57;p=lilypond.git diff --git a/lily/lily-modules.cc b/lily/lily-modules.cc index b5b61ee6bb..5d35018e72 100644 --- a/lily/lily-modules.cc +++ b/lily/lily-modules.cc @@ -18,7 +18,9 @@ */ #include "lily-modules.hh" +#include "international.hh" #include "lily-imports.hh" +#include "warn.hh" struct Scm_module::Variable_record { @@ -46,43 +48,62 @@ Scm_module::boot_init (void *arg) { Scm_module *self = static_cast (arg); - // Establish variables first - for (Variable_record *p = self->variables_; p;) - { - Variable_record *next = p->next_; - p->var_->boot (p->name_); - delete p; - p = next; - } - self->variables_ = 0; + // Establish variables + for (Variable_record *p = self->variables_; p; p = p->next_) + p->var_->boot (p->name_); +} + +static SCM +call_trampoline (void *self) +{ + // One more indirection since void * can only be safely cast to + // pointers to data rather than pointers to function. + (*static_cast (self)) (); + return SCM_UNDEFINED; } void -Scm_module::boot () +Scm_module::boot (void (*init) ()) { assert (SCM_UNBNDP (module_)); module_ = scm_c_define_module (name_, boot_init, static_cast (this)); + // Can't wrap the following in the scm_c_define_module call since + // the init code may need module_ operative. + if (init) + scm_c_call_with_current_module (module_, call_trampoline, static_cast (&init)); + // Verify that every Variable has a definition, either because of + // getting initialized with a value at definition or because of the + // init call providing one. + for (Variable_record *p = variables_; p; ) + { + Variable_record *next = p->next_; + if (SCM_UNBNDP (*p->var_)) + error (_f ("Uninitialized variable `%s' in module (%s)", p->name_, name_)); + delete p; + p = next; + } + variables_ = 0; } void Scm_module::import () { assert (SCM_UNBNDP (module_)); - SCM interface = scm_c_resolve_module (name_); + SCM intrface = scm_c_resolve_module (name_); // Using only the public interface is a voluntary form of access // control in GUILE. It would be cumbersome to do so until // Guile_user itself is imported. if (SCM_MODULEP (Guile_user::module.module_)) - interface = Guile_user::module_public_interface (interface); + intrface = Guile_user::module_public_interface (intrface); for (Variable_record *p = variables_; p;) { Variable_record *next = p->next_; - p->var_->import (interface, p->name_); + p->var_->import (intrface, p->name_); delete p; p = next; } variables_ = 0; - module_ = interface; + module_ = intrface; } void