From: Han-Wen Nienhuys Date: Sun, 15 Sep 2002 23:35:55 +0000 (+0000) Subject: use SCM module in stead of X-Git-Tag: release/1.7.0~11 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=5df02e6bebe82a9da8ae4576bdbc08733161d636;p=lilypond.git use SCM module in stead of Scheme_hash_table. Changes throughout. (warning: doesn't run!) --- diff --git a/ChangeLog b/ChangeLog index c9f34af08c..6f963bc685 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-09-16 Han-Wen Nienhuys + + * lily/my-lily-lexer.cc: use SCM module in stead of + Scheme_hash_table. Changes throughout. + 2002-09-15 Han-Wen Nienhuys * VERSION (MY_PATCH_LEVEL): make 1.7.0 diff --git a/configure.in b/configure.in index 8162b5b0d4..10300587a1 100644 --- a/configure.in +++ b/configure.in @@ -29,7 +29,7 @@ STEPMAKE_GETTEXT STEPMAKE_MSGFMT(REQUIRED) STEPMAKE_TEXMF STEPMAKE_TEXMF_DIRS -STEPMAKE_GUILE_DEVEL(REQUIRED, 1.4) +STEPMAKE_GUILE_DEVEL(REQUIRED, 1.6) STEPMAKE_KPATHSEA STEPMAKE_MAKEINFO(REQUIRED) STEPMAKE_PYTHON_DEVEL(REQUIRED) diff --git a/lily/grob-scheme.cc b/lily/grob-scheme.cc index 0e42044ba7..2cd6bb32d5 100644 --- a/lily/grob-scheme.cc +++ b/lily/grob-scheme.cc @@ -64,6 +64,10 @@ left, and @code{1} for right. return sl->get_bound (to_dir (dir))->self_scm (); } +/* + TODO: make difference between scaled and unscalead variable in + calling (i.e different funcs.) + */ LY_DEFINE(ly_get_paper_var,"ly-get-paper-variable", 2, 0, 0, (SCM grob, SCM sym), "Get a variable from the \\paper block.") @@ -72,7 +76,7 @@ LY_DEFINE(ly_get_paper_var,"ly-get-paper-variable", 2, 0, 0, SCM_ASSERT_TYPE(sc, grob, SCM_ARG1, __FUNCTION__, "grob"); SCM_ASSERT_TYPE(gh_symbol_p (sym), sym, SCM_ARG2, __FUNCTION__, "symbol"); - return sc->get_paper () ->get_scmvar_scm (sym); + return sc->get_paper () ->lookup_variable (sym); } diff --git a/lily/include/input-file-results.hh b/lily/include/input-file-results.hh index 8b6e31582c..1cd5c825ed 100644 --- a/lily/include/input-file-results.hh +++ b/lily/include/input-file-results.hh @@ -13,7 +13,7 @@ #include "lily-proto.hh" #include "source.hh" #include "parray.hh" -#include "scm-hash.hh" +#include "protected-scm.hh" class Input_file_results { @@ -22,8 +22,7 @@ public: Array inclusion_names_; Array target_strings_; Link_array scores_; - /* Global? prefix is bit confusing */ - Scheme_hash_table * header_; + Protected_scm header_; void do_deps (); void do_scores (); diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index e447afb5b1..056ca65d6e 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -225,6 +225,12 @@ SCM index_set_cell (SCM cell, Direction d, SCM val); SCM ly_snoc (SCM s, SCM list); SCM ly_split_list (SCM s, SCM list); SCM ly_unique (SCM list); + + +SCM ly_make_anonymous_module (); +void ly_copy_module_variable (SCM dest, SCM src); +SCM ly_module_to_alist (SCM mod); + /* snarfing. */ diff --git a/lily/include/music-output-def.hh b/lily/include/music-output-def.hh index 0b554ffdec..b01a7e8a3f 100644 --- a/lily/include/music-output-def.hh +++ b/lily/include/music-output-def.hh @@ -23,9 +23,8 @@ class Music_output_def { public: Scheme_hash_table * translator_tab_; - Scheme_hash_table * variable_tab_; - + SCM scope_; SCM scaled_fonts_; SCM style_sheet_; @@ -39,8 +38,13 @@ public: void assign_translator (SCM transdef); SCM find_translator (SCM name) const; String outname_string () ; + SCM get_scmvar (String id)const; + SCM lookup_variable (SCM sym) const; + void set_variable (SCM, SCM sym); DECLARE_SMOBS (Music_output_def,); + + }; DECLARE_UNSMOB(Music_output_def,music_output_def); diff --git a/lily/include/music-output.hh b/lily/include/music-output.hh index d8efb9314a..4d2d41f5ce 100644 --- a/lily/include/music-output.hh +++ b/lily/include/music-output.hh @@ -12,6 +12,7 @@ #include "string.hh" #include "lily-proto.hh" +#include "protected-scm.hh" /** Output something that was defined in a lilypond file. @@ -19,7 +20,7 @@ class Music_output { public: - Scheme_hash_table * header_; + Protected_scm header_; String default_out_string_; String origin_string_; int errorlevel_; diff --git a/lily/include/my-lily-lexer.hh b/lily/include/my-lily-lexer.hh index 8bdcd6ee47..06449288ed 100644 --- a/lily/include/my-lily-lexer.hh +++ b/lily/include/my-lily-lexer.hh @@ -28,10 +28,10 @@ void set_lexer (); /// lexer for Lilypond class My_lily_lexer : public Includable_lexer { + Protected_scm scopes_; public: String main_input_string_; void * lexval; - Scheme_hash_table * toplevel_variable_tab_; bool main_input_b_; /* @@ -39,8 +39,6 @@ public: */ Protected_scm chordmodifier_tab_; Protected_scm pitchname_tab_; - - Link_array scopes_; Keyword_table * keytable_; int errorlevel_; @@ -50,6 +48,9 @@ public: Input here_input () const; + void add_scope (SCM); + SCM remove_scope (); + void start_main_input (); SCM lookup_identifier (String s); diff --git a/lily/include/paper-def.hh b/lily/include/paper-def.hh index b434c92759..3acf25a85f 100644 --- a/lily/include/paper-def.hh +++ b/lily/include/paper-def.hh @@ -60,8 +60,6 @@ public: */ Real get_realvar (SCM symbol) const; Real get_var (String id) const; - SCM get_scmvar (String id)const; - SCM get_scmvar_scm (SCM sym) const; void reinit (); Paper_def (); Paper_def (Paper_def const&); diff --git a/lily/include/paper-outputter.hh b/lily/include/paper-outputter.hh index 56defcc3b2..c36b38a53d 100644 --- a/lily/include/paper-outputter.hh +++ b/lily/include/paper-outputter.hh @@ -43,7 +43,7 @@ public: void output_int_def (String k, int v); void output_Real_def (String k, Real v); void output_String_def (String k, String v); - void output_scope (Scheme_hash_table*, String prefix); + void output_scope (SCM, String prefix); void output_version (); void output_font_def (int i, String str); void output_font_switch (int i); @@ -53,7 +53,7 @@ public: void output_scheme (SCM scm); void write_header_field_to_file (String filename, SCM, SCM); - void write_header_fields_to_file (Scheme_hash_table *); + void write_header_fields_to_file (SCM); }; #endif // PAPER_OUTPUTTER_HH diff --git a/lily/include/score.hh b/lily/include/score.hh index 2af42321e5..414f4d5ef9 100644 --- a/lily/include/score.hh +++ b/lily/include/score.hh @@ -22,7 +22,7 @@ public: /// paper_, staves_ and commands_ form the problem definition. Link_array defs_; SCM music_; - Scheme_hash_table * header_; + SCM header_; Input_file_results* input_file_; int errorlevel_; diff --git a/lily/input-file-results.cc b/lily/input-file-results.cc index beb789209b..7ceb7b2cfc 100644 --- a/lily/input-file-results.cc +++ b/lily/input-file-results.cc @@ -118,8 +118,8 @@ Input_file_results::do_deps () void Input_file_results::do_scores () { - if (!header_) - header_ = new Scheme_hash_table; + if (header_ == SCM_EOL) + header_ = ly_make_anonymous_module (); for (int i=0; i < scores_.size (); i++) { @@ -147,7 +147,7 @@ Input_file_results::~Input_file_results () inclusion_names_.clear (); if (header_) - scm_gc_unprotect_object (header_ ->self_scm ()); + header_ = SCM_EOL; global_input_file =0; } @@ -157,7 +157,7 @@ Input_file_results* global_input_file; Input_file_results::Input_file_results (String init_string, String file_string) { - header_ = 0; + header_ = SCM_EOL; global_input_file = this; ly_set_point_and_click_x (SCM_BOOL_F); diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index 7a08f7d3f3..680696c938 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -198,7 +198,9 @@ void ly_init_guile () { SCM last_mod = scm_current_module (); - scm_set_current_module (scm_c_resolve_module ("guile")); + scm_set_current_module (scm_c_resolve_module ("lily")); + + scm_c_use_module ("guile"); for (int i=scm_init_funcs_->size () ; i--;) (scm_init_funcs_->elem (i)) (); @@ -703,3 +705,47 @@ robust_list_ref(int i, SCM l) return gh_car(l); } + +static int module_count; + +SCM +ly_make_anonymous_module () +{ + String s = "*anonymous-ly-" + to_string (module_count++) + "*"; + SCM mod = scm_c_resolve_module (s.to_str0()); + + scm_module_define (mod, ly_symbol2scm ("symbols-defined-here"), SCM_EOL); + return mod; +} + +void +ly_copy_module_variable (SCM dest, SCM src) +{ + SCM defd = ly_symbol2scm ("symbols-defined-here"); + SCM dvar = scm_module_lookup (src, ly_symbol2scm ("symbols-defined-here")); + SCM lst = scm_variable_ref (dvar); + for (SCM s =lst; gh_pair_p (s); s = gh_cdr (s)) + { + SCM var = scm_module_lookup (src, gh_car (s)); + scm_module_define (dest, gh_car (s), + scm_variable_ref (var)); + } + + scm_module_define (dest, defd, lst); +} + +SCM +ly_module_to_alist (SCM mod) +{ + SCM defd = ly_symbol2scm ("symbols-defined-here"); + SCM dvar = scm_module_lookup (mod, defd); + SCM lst = scm_variable_ref (dvar); + + SCM alist = SCM_EOL; + for (SCM s =lst; gh_pair_p (s); s = gh_cdr (s)) + { + SCM var = scm_module_lookup (mod, gh_car (s)); + alist= scm_cons (scm_cons (gh_car(s), scm_variable_ref (var)), alist); + } + return alist; +} diff --git a/lily/midi-def.cc b/lily/midi-def.cc index 2684973f56..853d56adaf 100644 --- a/lily/midi-def.cc +++ b/lily/midi-def.cc @@ -23,7 +23,7 @@ int Midi_def::get_tempo (Moment one_beat_mom) { SCM wis = ly_symbol2scm ("whole-in-seconds"); - Moment *w = unsmob_moment (variable_tab_->get (wis)); + Moment *w = unsmob_moment (lookup_variable (wis)); Moment wholes_per_min = Moment (60); if (!w) @@ -46,7 +46,7 @@ Midi_def::set_tempo (Moment one_beat_mom, int beats_per_minute_i) Moment beats_per_second = Moment (beats_per_minute_i) / Moment (60); Moment m = Moment (1)/Moment (beats_per_second * one_beat_mom); - variable_tab_->set (ly_symbol2scm ("whole-in-seconds"), m.smobbed_copy ()); + set_variable (ly_symbol2scm ("whole-in-seconds"), m.smobbed_copy ()); } diff --git a/lily/music-output-def.cc b/lily/music-output-def.cc index 4381e4f2ba..401bcb0810 100644 --- a/lily/music-output-def.cc +++ b/lily/music-output-def.cc @@ -29,13 +29,14 @@ Music_output_def::Music_output_def () { style_sheet_ = SCM_EOL; scaled_fonts_ = SCM_EOL; - - variable_tab_ = new Scheme_hash_table; + translator_tab_ = new Scheme_hash_table; - + scope_ = SCM_EOL; + smobify_self (); - scm_gc_unprotect_object (variable_tab_->self_scm ()); - scm_gc_unprotect_object (translator_tab_->self_scm ()); + scm_gc_unprotect_object (translator_tab_->self_scm ()); + + scope_ = ly_make_anonymous_module(); } Music_output_def::~Music_output_def () @@ -44,18 +45,21 @@ Music_output_def::~Music_output_def () Music_output_def::Music_output_def (Music_output_def const &s) { - variable_tab_ = new Scheme_hash_table (*s.variable_tab_); + scope_ = SCM_EOL; translator_tab_ = new Scheme_hash_table (*s.translator_tab_); style_sheet_ = SCM_EOL; scaled_fonts_ = SCM_EOL; smobify_self (); - scm_gc_unprotect_object (variable_tab_->self_scm ()); scm_gc_unprotect_object (translator_tab_->self_scm ()); style_sheet_ = scm_list_copy (s.style_sheet_); scaled_fonts_ = scm_list_copy (s.scaled_fonts_); + + scope_= ly_make_anonymous_module (); + ly_copy_module_variable (scope_, s.scope_); + } @@ -69,7 +73,7 @@ Music_output_def::mark_smob (SCM m) Music_output_def * mo = (Music_output_def*) SCM_CELL_WORD_1 (m); scm_gc_mark (mo->style_sheet_); scm_gc_mark (mo->translator_tab_->self_scm ()); - scm_gc_mark (mo->variable_tab_->self_scm ()); + scm_gc_mark (mo->scope_); return mo->scaled_fonts_; } @@ -149,3 +153,29 @@ Music_output_def::outname_string () } return out; } + + + +SCM +Music_output_def::get_scmvar (String s) const +{ + return lookup_variable (ly_symbol2scm (s.to_str0 ())); +} + + +void +Music_output_def::set_variable (SCM sym, SCM val) +{ + scm_module_define (scope_, sym, val); + + SCM var = scm_module_lookup (scope_, ly_symbol2scm ("symbols-defined-here")); + scm_variable_set_x (var, gh_cons (sym, scm_variable_ref (var))); +} + +SCM +Music_output_def::lookup_variable (SCM sym) const +{ + SCM var = scm_module_lookup (scope_, sym); + + return scm_variable_ref (var); +} diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index 48005225d1..ebe0302cf8 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -94,16 +94,35 @@ static Keyword_ent the_key_tab[]={ {0,0} }; + My_lily_lexer::My_lily_lexer () { keytable_ = new Keyword_table (the_key_tab); - toplevel_variable_tab_ = new Scheme_hash_table ; - scopes_.push (toplevel_variable_tab_); + scopes_ = SCM_EOL; - errorlevel_ = 0; + add_scope(ly_make_anonymous_module()); + main_input_b_ = false; } +void +My_lily_lexer::add_scope (SCM module) +{ + scm_set_current_module (module); + scopes_ = scm_cons (module, scopes_); +} + +SCM +My_lily_lexer::remove_scope () +{ + SCM sc = gh_car (scopes_); + scopes_ = gh_cdr (scopes_); + scm_set_current_module (gh_car (scopes_)); + + return sc; +} + + int My_lily_lexer::lookup_keyword (String s) { @@ -113,14 +132,13 @@ My_lily_lexer::lookup_keyword (String s) SCM My_lily_lexer::lookup_identifier (String s) { - SCM sym = ly_symbol2scm (s.to_str0 ()); - - for (int i = scopes_.size (); i--;) - { - SCM val = SCM_UNSPECIFIED; - if (scopes_[i]->try_retrieve (sym, &val)) - return val; - } + SCM sym = ly_symbol2scm (s.to_str0()); + for (SCM s = scopes_; gh_pair_p (s); s = gh_cdr (s)) + { + SCM var = scm_module_lookup (gh_car (s), sym); + return scm_variable_ref (var); + } + return SCM_UNSPECIFIED; } @@ -143,14 +161,18 @@ My_lily_lexer::set_identifier (SCM name, SCM s) warning (_f ("Identifier name is a keyword: `%s'", str)); free (str); } - - scopes_.top ()->set (scm_string_to_symbol (name), s); + + SCM sym = scm_string_to_symbol (name); + SCM mod = gh_car (scopes_); + SCM var = scm_module_lookup (mod, ly_symbol2scm ("symbols-defined-here")); + + scm_variable_set_x (var, gh_cons (sym, scm_variable_ref (var))); + scm_module_define (mod, sym, s); } My_lily_lexer::~My_lily_lexer () { delete keytable_; - scm_gc_unprotect_object (toplevel_variable_tab_->self_scm ()); } diff --git a/lily/paper-def.cc b/lily/paper-def.cc index f6bf6ec19b..8cc0f7ada5 100644 --- a/lily/paper-def.cc +++ b/lily/paper-def.cc @@ -47,44 +47,14 @@ Paper_def::get_var (String s) const return get_realvar (ly_symbol2scm (s.to_str0 ())); } -SCM -Paper_def::get_scmvar (String s) const -{ - return variable_tab_->get (ly_symbol2scm (s.to_str0 ())); -} - - -SCM -Paper_def::get_scmvar_scm (SCM sym) const -{ - return gh_double2scm (get_realvar (sym)); -} - Real Paper_def::get_realvar (SCM s) const { - SCM val ; - if (!variable_tab_->try_retrieve (s, &val)) - { - programming_error ("unknown paper variable: " + ly_symbol2string (s)); - return 0.0; - } - - Real sc = 1.0; - SCM ssc; - if (variable_tab_->try_retrieve (ly_symbol2scm ("outputscale"), &ssc)) - { - sc = gh_scm2double (ssc); - } - if (gh_number_p (val)) - { - return gh_scm2double (val) / sc; - } - else - { - programming_error ("not a real variable"); - return 0.0; - } + SCM val = lookup_variable (s); + SCM scale = lookup_variable (ly_symbol2scm ("outputscale")); + + Real sc = gh_scm2double (scale); + return gh_scm2double (val) / sc; } /* @@ -158,11 +128,8 @@ Paper_def::find_font (SCM fn, Real m) } else { - SCM ssc; - if (variable_tab_->try_retrieve (ly_symbol2scm ("outputscale"), &ssc)) - { - m /= gh_scm2double (ssc); - } + SCM var = scm_module_lookup (scope_, ly_symbol2scm ("outputscale")); + m /= gh_scm2double (scm_variable_ref (var)); f = all_fonts_global->find_font (ly_scm2string (fn)); SCM val = Scaled_font_metric::make_scaled_font_metric (f, m); diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 2177afffcd..796f94079c 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -92,9 +92,9 @@ Paper_outputter::output_scheme (SCM scm) } void -Paper_outputter::output_scope (Scheme_hash_table *scope, String prefix) +Paper_outputter::output_scope (SCM mod, String prefix) { - SCM al = scope->to_alist (); + SCM al = ly_module_to_alist (mod); for (SCM s = al ; gh_pair_p (s); s = ly_cdr (s)) { SCM k = ly_caar (s); @@ -170,11 +170,12 @@ Paper_outputter::write_header_field_to_file (String filename, SCM key, SCM value } void -Paper_outputter::write_header_fields_to_file (Scheme_hash_table * header) +Paper_outputter::write_header_fields_to_file (SCM mod) { + if (dump_header_fieldnames_global.size ()) { - SCM fields = header->to_alist (); + SCM fields = ly_module_to_alist (mod); for (int i = 0; i < dump_header_fieldnames_global.size (); i++) { String key = dump_header_fieldnames_global[i]; diff --git a/lily/paper-score.cc b/lily/paper-score.cc index 295ba16265..077e5c2f0d 100644 --- a/lily/paper-score.cc +++ b/lily/paper-score.cc @@ -38,6 +38,7 @@ Paper_score::typeset_line (System *l) { system_ = l; // ugh. } + main_smob_ = gh_cons (l->self_scm (), main_smob_); l->pscore_ = this; @@ -115,8 +116,7 @@ Paper_score::process () outputter_->output_comment (_ ("Outputting Score, defined at: ")); outputter_->output_comment (origin_string_); - if (paper_->variable_tab_) - outputter_->output_scope (paper_->variable_tab_, "lilypondpaper"); + outputter_->output_scope (paper_->scope_, "lilypondpaper"); SCM scm = scm_list_n (ly_symbol2scm ("header-end"), SCM_UNDEFINED); outputter_->output_scheme (scm); diff --git a/lily/parser.yy b/lily/parser.yy index 99ff663353..2754f6dd79 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -274,7 +274,7 @@ yylex (YYSTYPE *s, void * v) %token REAL %type output_def -%type lilypond_header lilypond_header_body +%type lilypond_header lilypond_header_body %type open_request_parens close_request_parens open_request close_request %type request_with_dir request_that_take_dir verbose_request %type sub_quotes sup_quotes @@ -350,8 +350,6 @@ toplevel_expression: THIS->lexer_->chordmodifier_tab_ = $1; } | lilypond_header { - if (THIS->input_file_->header_) - scm_gc_unprotect_object (THIS->input_file_->header_->self_scm ()); THIS->input_file_->header_ = $1; } | score_block { @@ -401,18 +399,17 @@ notenames_body: lilypond_header_body: { - $$ = new Scheme_hash_table; - THIS->lexer_-> scopes_.push ($$); + $$ = ly_make_anonymous_module (); + THIS->lexer_->add_scope ($$); } | lilypond_header_body assignment { - + } ; lilypond_header: HEADER '{' lilypond_header_body '}' { - $$ = $3; - THIS->lexer_->scopes_.pop (); + $$ = THIS->lexer_-> remove_scope(); } ; @@ -588,7 +585,6 @@ score_body: $$->set_spot (THIS->here_input ()); } | score_body lilypond_header { - scm_gc_unprotect_object ($2->self_scm ()); $$->header_ = $2; } | score_body output_def { @@ -606,23 +602,23 @@ score_body: output_def: music_output_def_body '}' { $$ = $1; - THIS-> lexer_-> scopes_.pop (); + THIS-> lexer_-> remove_scope (); } ; music_output_def_body: MIDI '{' { - Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultmidi")); + Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultmidi")); - - Midi_def* p =0; - if (id) - p = dynamic_cast (id->clone ()); - else - p = new Midi_def; - $$ = p; - THIS->lexer_->scopes_.push (p->variable_tab_); + Midi_def* p =0; + if (id) + p = dynamic_cast (id->clone ()); + else + p = new Midi_def; + + $$ = p; + THIS->lexer_->add_scope (p->scope_); } | PAPER '{' { Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper")); @@ -631,20 +627,20 @@ music_output_def_body: p = dynamic_cast (id->clone ()); else p = new Paper_def; - THIS-> lexer_-> scopes_.push (p->variable_tab_); + THIS-> lexer_->add_scope (p->scope_); $$ = p; } | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER { Music_output_def *p = unsmob_music_output_def ($3); p = p->clone (); - THIS->lexer_->scopes_.push (p->variable_tab_); + THIS->lexer_->add_scope (p->scope_); $$ = p; } | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER { Music_output_def *p = unsmob_music_output_def ($3); p = p->clone (); - THIS->lexer_->scopes_.push (p->variable_tab_); + THIS->lexer_->add_scope (p->scope_); $$ = p; } | music_output_def_body assignment { @@ -1959,7 +1955,7 @@ simple_element: $$ = velt; } | MULTI_MEASURE_REST optional_notemode_duration { - Input i = THIS->pop_spot (); + THIS->pop_spot (); Skip_req * sk = new Skip_req; sk->set_mus_property ("duration", $2); diff --git a/lily/score.cc b/lily/score.cc index ceb327d9ec..650d7da8ea 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -30,7 +30,7 @@ Score::Score () : Input () { input_file_ = 0; - header_ = 0; + header_ = SCM_EOL; music_ = SCM_EOL; errorlevel_ = 0; @@ -57,12 +57,8 @@ Score::Score (Score const &s) for (int i=0; i < s.defs_.size (); i++) defs_.push (s.defs_[i]->clone ()); errorlevel_ = s.errorlevel_; - if (s.header_) - { - header_ = (s.header_) ? new Scheme_hash_table (*s.header_): 0; - - scm_gc_unprotect_object (header_->self_scm ()); - } + header_ = ly_make_anonymous_module (); + ly_copy_module_variable (header_, s.header_); } Score::~Score () @@ -124,7 +120,7 @@ Score::run_translator (Music_output_def *odef) progress_indication (_f ("elapsed time: %.2f seconds", timer.read ())); if (!header_) - header_ = new Scheme_hash_table; // ugh + header_ = ly_make_anonymous_module(); // ug.h output->header_ = header_; output->origin_string_ = location_string (); @@ -165,8 +161,8 @@ SCM Score::mark_smob (SCM s) { Score * sc = (Score*) SCM_CELL_WORD_1 (s); - if (sc->header_) - scm_gc_mark (sc->header_->self_scm ()); + + scm_gc_mark (sc->header_); for (int i = sc->defs_.size (); i--;) scm_gc_mark (sc->defs_[i]->self_scm ());