Scheme_hash_table. Changes throughout.
(warning: doesn't run!)
+2002-09-16 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+ * lily/my-lily-lexer.cc: use SCM module in stead of
+ Scheme_hash_table. Changes throughout.
+
2002-09-15 Han-Wen Nienhuys <hanwen@cs.uu.nl>
* VERSION (MY_PATCH_LEVEL): make 1.7.0
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)
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.")
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);
}
#include "lily-proto.hh"
#include "source.hh"
#include "parray.hh"
-#include "scm-hash.hh"
+#include "protected-scm.hh"
class Input_file_results
{
Array<String> inclusion_names_;
Array<String> target_strings_;
Link_array<Score> scores_;
- /* Global? prefix is bit confusing */
- Scheme_hash_table * header_;
+ Protected_scm header_;
void do_deps ();
void do_scores ();
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.
*/
{
public:
Scheme_hash_table * translator_tab_;
- Scheme_hash_table * variable_tab_;
-
+ SCM scope_;
SCM scaled_fonts_;
SCM style_sheet_;
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);
#include "string.hh"
#include "lily-proto.hh"
+#include "protected-scm.hh"
/**
Output something that was defined in a lilypond file.
class Music_output
{
public:
- Scheme_hash_table * header_;
+ Protected_scm header_;
String default_out_string_;
String origin_string_;
int errorlevel_;
/// 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_;
/*
*/
Protected_scm chordmodifier_tab_;
Protected_scm pitchname_tab_;
-
- Link_array<Scheme_hash_table> scopes_;
Keyword_table * keytable_;
int errorlevel_;
Input here_input () const;
+ void add_scope (SCM);
+ SCM remove_scope ();
+
void start_main_input ();
SCM lookup_identifier (String s);
*/
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&);
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);
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
/// paper_, staves_ and commands_ form the problem definition.
Link_array<Music_output_def> defs_;
SCM music_;
- Scheme_hash_table * header_;
+ SCM header_;
Input_file_results* input_file_;
int errorlevel_;
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++)
{
inclusion_names_.clear ();
if (header_)
- scm_gc_unprotect_object (header_ ->self_scm ());
+ header_ = SCM_EOL;
global_input_file =0;
}
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);
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)) ();
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;
+}
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)
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 ());
}
{
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 ()
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_);
+
}
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_;
}
}
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);
+}
{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)
{
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;
}
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 ());
}
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;
}
/*
}
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);
}
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);
}
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];
{
system_ = l; // ugh.
}
+
main_smob_ = gh_cons (l->self_scm (), main_smob_);
l->pscore_ = this;
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);
%token <scm> REAL
%type <outputdef> output_def
-%type <scmhash> lilypond_header lilypond_header_body
+%type <scm> lilypond_header lilypond_header_body
%type <request> open_request_parens close_request_parens open_request close_request
%type <request> request_with_dir request_that_take_dir verbose_request
%type <i> sub_quotes sup_quotes
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 {
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();
}
;
$$->set_spot (THIS->here_input ());
}
| score_body lilypond_header {
- scm_gc_unprotect_object ($2->self_scm ());
$$->header_ = $2;
}
| score_body output_def {
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<Midi_def*> (id->clone ());
- else
- p = new Midi_def;
- $$ = p;
- THIS->lexer_->scopes_.push (p->variable_tab_);
+ Midi_def* p =0;
+ if (id)
+ p = dynamic_cast<Midi_def*> (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"));
p = dynamic_cast<Paper_def*> (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 {
$$ = 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);
: Input ()
{
input_file_ = 0;
- header_ = 0;
+ header_ = SCM_EOL;
music_ = SCM_EOL;
errorlevel_ = 0;
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 ()
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 ();
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 ());