From b230681e00b54adaba3846209250505a0d0b41f0 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 9 May 2004 07:51:50 +0000 Subject: [PATCH] (ly_module_define): only define variable if bound. --- ChangeLog | 5 +++ Documentation/topdocs/NEWS.texi | 4 +-- Documentation/user/tutorial.itely | 7 +++- lily/include/ly-module.hh | 4 +-- lily/input-smob.cc | 3 ++ lily/ly-module.cc | 36 ++++++++++++++++--- lily/music-output-def.cc | 4 +-- lily/my-lily-lexer.cc | 11 ++---- lily/my-lily-parser.cc | 2 +- lily/paper-outputter.cc | 60 +++---------------------------- lily/parse-scm.cc | 26 ++++---------- lily/parser.yy | 2 +- lily/scm-option.cc | 22 ++++++------ lily/score.cc | 2 +- ly/chord-modifiers-init.ly | 6 ++-- ly/init.ly | 2 +- scm/lily.scm | 11 ++++-- scm/page-layout.scm | 2 +- 18 files changed, 93 insertions(+), 116 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6c36f33e28..14612d2f9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-05-09 Han-Wen Nienhuys + + * lily/ly-module.cc (ly_module_define): only define variable if + bound. + 2004-05-08 Han-Wen Nienhuys * scripts/lilypond-book.py (compose_ly): remove FRAGMENT_LY. diff --git a/Documentation/topdocs/NEWS.texi b/Documentation/topdocs/NEWS.texi index 32b2295c3d..ed74083923 100644 --- a/Documentation/topdocs/NEWS.texi +++ b/Documentation/topdocs/NEWS.texi @@ -81,7 +81,7 @@ is the same as The default value is one octave below middle C. @c update-me? formal definition of newaddlyrics, once it works -@item Combining lyrics with music can be @code{newlyrics} +@item Combining lyrics with music can be @code{\newlyrics} @example << @@ -98,7 +98,7 @@ The default value is one octave below middle C. >> @end example -Syntactically, @code{\newlyrics} acts like an infix operator +Syntactically, @code{\newlyrics} acts like an infix operator. @item The parser is encapsulated in a Scheme function @code{ly:parse-file}, so the following fragment processes two files diff --git a/Documentation/user/tutorial.itely b/Documentation/user/tutorial.itely index aafa9faf60..255b54c593 100644 --- a/Documentation/user/tutorial.itely +++ b/Documentation/user/tutorial.itely @@ -482,8 +482,11 @@ Here are key signatures, accidentals and ties in action @end example @c TODO: use relative mode, verbatim, junk \transpose and above @example + + + @lilypond[quote,noindent,linewidth=50\staffspace] -\transpose c c' { +\transpose c c' { \time 4/4 \key g \minor \clef violin @@ -493,8 +496,10 @@ Here are key signatures, accidentals and ties in action gis2 r2 } @end lilypond + @cindex accidentals + @noindent There are some interesting points to note in this example. Bar lines and beams are drawn automatically. Line breaks are calculated diff --git a/lily/include/ly-module.hh b/lily/include/ly-module.hh index cf727a1586..2619ccfec5 100644 --- a/lily/include/ly-module.hh +++ b/lily/include/ly-module.hh @@ -12,7 +12,7 @@ #include "lily-guile.hh" -SCM ly_make_anonymous_module (); +SCM ly_make_anonymous_module (bool safe); void ly_import_module (SCM dest, SCM src); SCM ly_module_to_alist (SCM mod); SCM ly_module_lookup (SCM module, SCM sym); @@ -21,7 +21,7 @@ SCM ly_module_symbols (SCM mod); void ly_reexport_module (SCM mod); inline bool is_module (SCM x) { return SCM_MODULEP(x); } void ly_clear_anonymous_modules (); - +SCM ly_use_module (SCM mod, SCM used); #endif /* LY_MODULE_HH */ diff --git a/lily/input-smob.cc b/lily/input-smob.cc index 0a6f86c7b3..595ee717da 100644 --- a/lily/input-smob.cc +++ b/lily/input-smob.cc @@ -93,6 +93,9 @@ LY_DEFINE (ly_input_message, "ly:input-message", 2, 0, 0, (SCM sip, SCM msg), return SCM_UNDEFINED; } +/* + TODO: rename this function. ly:input-location? vs ly:input-location + */ LY_DEFINE (ly_input_location, "ly:input-location", 1, 0, 0, (SCM sip), "Return input location in @var{sip} as (filename line column).") { diff --git a/lily/ly-module.cc b/lily/ly-module.cc index f93eeb2922..754e144bfa 100644 --- a/lily/ly-module.cc +++ b/lily/ly-module.cc @@ -7,6 +7,7 @@ */ +#include "main.hh" #include "string.hh" #include "lily-guile.hh" #include "ly-module.hh" @@ -20,17 +21,41 @@ void ly_init_anonymous_module (void *data) { (void) data; - scm_c_use_module ("lily"); } SCM -ly_make_anonymous_module () +ly_make_anonymous_module (bool safe) { - String s = "*anonymous-ly-" + to_string (module_count++) + "*"; - SCM mod = scm_c_define_module (s.to_str0 (), ly_init_anonymous_module, 0); + SCM mod = SCM_EOL; + if (!safe) + { + + String s = "*anonymous-ly-" + to_string (module_count++) + "*"; + mod = scm_c_define_module (s.to_str0 (), ly_init_anonymous_module, 0); + + ly_use_module (mod, global_lily_module); + } + else + { + SCM proc = ly_scheme_function ("make-safe-lilypond-module"); + + mod = scm_call_0 (proc); + } return mod; } +SCM +ly_use_module (SCM mod, SCM used) +{ + SCM expr + = scm_list_3 (ly_symbol2scm ("module-use!"), + mod, + scm_list_2 (ly_symbol2scm ("module-public-interface"), + used)); + + return scm_eval (expr, global_lily_module); +} + #define FUNC_NAME __FUNCTION__ static SCM @@ -38,7 +63,8 @@ ly_module_define (void *closure, SCM key, SCM val, SCM result) { (void) result; SCM module = (SCM) closure; - scm_module_define (module, key, scm_variable_ref (val)); + if (scm_variable_bound_p (val) == SCM_BOOL_T) + scm_module_define (module, key, scm_variable_ref (val)); return SCM_EOL; } diff --git a/lily/music-output-def.cc b/lily/music-output-def.cc index baf6c66bd4..d55ebd92a8 100644 --- a/lily/music-output-def.cc +++ b/lily/music-output-def.cc @@ -26,7 +26,7 @@ Music_output_def::Music_output_def () smobify_self (); scm_gc_unprotect_object (translator_tab_->self_scm ()); - scope_ = ly_make_anonymous_module (); + scope_ = ly_make_anonymous_module (false); } Music_output_def::~Music_output_def () @@ -42,7 +42,7 @@ Music_output_def::Music_output_def (Music_output_def const &s) translator_tab_ = new Scheme_hash_table (*s.translator_tab_); scm_gc_unprotect_object (translator_tab_->self_scm ()); - scope_= ly_make_anonymous_module (); + scope_= ly_make_anonymous_module (safe_global_b); if (is_module (s.scope_)) ly_import_module (scope_, s.scope_); } diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index 971fe0ae7c..7fa4569c05 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -104,7 +104,7 @@ My_lily_lexer::My_lily_lexer (Sources *sources) error_level_ = 0; main_input_b_ = false; - add_scope (ly_make_anonymous_module ()); + add_scope (ly_make_anonymous_module (safe_global_b)); } My_lily_lexer::My_lily_lexer (My_lily_lexer const &src) @@ -126,6 +126,7 @@ My_lily_lexer::encoding () const return encoding_ ; } + void My_lily_lexer::add_scope (SCM module) { @@ -133,13 +134,7 @@ My_lily_lexer::add_scope (SCM module) scm_set_current_module (module); for (SCM s = scopes_; ly_c_pair_p (s); s = ly_cdr (s)) { - /* UGH. how to do this more neatly? */ - SCM expr - = scm_list_3 (ly_symbol2scm ("module-use!"), - module, - scm_list_2 (ly_symbol2scm ("module-public-interface"), - ly_car (s))); - scm_primitive_eval (expr); + ly_use_module (module, ly_car (s)); } scopes_ = scm_cons (module, scopes_); } diff --git a/lily/my-lily-parser.cc b/lily/my-lily-parser.cc index 9a0c36726c..68e864d5c8 100644 --- a/lily/my-lily-parser.cc +++ b/lily/my-lily-parser.cc @@ -36,7 +36,7 @@ My_lily_parser::My_lily_parser (Sources *sources) last_beam_start_ = SCM_EOL; header_ = SCM_EOL; - header_ = ly_make_anonymous_module (); + header_ = ly_make_anonymous_module (safe_global_b); smobify_self (); } diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 8de4a29e16..38ff508b5f 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -38,67 +38,15 @@ Paper_outputter::Paper_outputter (String filename) file_ = scm_open_file (scm_makfrom0str (filename.to_str0 ()), scm_makfrom0str ("w")); + /* + UGH. -> global variable. + */ if (safe_global_b) scm_define (ly_symbol2scm ("safe-mode?"), SCM_BOOL_T); String module_name = "scm output-" + output_format_global; - if (safe_global_b) - { - /* In safe mode, start from a GUILE safe-module and import - all symbols from the output module. */ - scm_c_use_module ("ice-9 safe"); - SCM msm = scm_primitive_eval (ly_symbol2scm ("make-safe-module")); - output_module_ = scm_call_0 (msm); - ly_import_module (output_module_, - scm_c_resolve_module (module_name.to_str0 ())); - } - else - output_module_ = scm_c_resolve_module (module_name.to_str0 ()); + output_module_ = scm_c_resolve_module (module_name.to_str0 ()); - /* FIXME: output-lib should be module, that can be imported. */ -#define IMPORT_LESS 1 // only import the list of IMPORTS -#if IMPORT_LESS - scm_c_use_module ("lily"); - scm_c_use_module ("ice-9 regex"); - scm_c_use_module ("srfi srfi-1"); - scm_c_use_module ("srfi srfi-13"); -#endif - char const *imports[] = { - "lilypond-version", /* from lily */ - "ly:output-def-scope", - "ly:gulp-file", - "ly:number->string", - "ly:ragged-page-breaks", - "ly:optimal-page-breaks", - - "ly:number-pair->string", /* output-lib.scm */ - "ly:numbers->string", - "ly:inexact->string", - - "assoc-get", -#if IMPORT_LESS - "remove", /* from srfi srfi-1 */ - "string-index", /* from srfi srfi-13 */ - "string-join", - "regexp-substitute/global", /* from (ice9 regex) */ -#endif - 0, - }; - - for (int i = 0; imports[i]; i++) - { - SCM s = ly_symbol2scm (imports[i]); - scm_module_define (output_module_, s, scm_primitive_eval (s)); - } -#ifndef IMPORT_LESS // rather crude, esp for safe-mode let's not - SCM m = scm_set_current_module (output_module_); - /* not present in current module*/ - scm_c_use_module ("ice-9 regex"); - scm_c_use_module ("srfi srfi-13"); - /* Need only a few of these, see above - scm_c_use_module ("lily"); */ - scm_set_current_module (m); -#endif } Paper_outputter::~Paper_outputter () diff --git a/lily/parse-scm.cc b/lily/parse-scm.cc index bd183b2bf2..03d1df4ff1 100644 --- a/lily/parse-scm.cc +++ b/lily/parse-scm.cc @@ -13,7 +13,7 @@ Thanks to Gary Houston */ SCM -internal_ly_parse_scm (Parse_start * ps, bool safe) +internal_ly_parse_scm (Parse_start * ps) { Source_file* sf =ps->start_location_.source_file_; SCM port = sf->get_port (); @@ -29,17 +29,6 @@ internal_ly_parse_scm (Parse_start * ps, bool safe) /* Read expression from port */ if (!SCM_EOF_OBJECT_P (form = scm_read (port))) { - if (safe) - { - static SCM safe_module; - if (!safe_module) - { - safe_module = scm_primitive_eval (ly_symbol2scm ("safe-module")); - ly_import_module (safe_module, scm_c_resolve_module ("lily")); - } - answer = scm_eval (form, safe_module); - } - else answer = scm_primitive_eval (form); } @@ -62,14 +51,14 @@ SCM catch_protected_parse_body (void *p) { Parse_start *ps = (Parse_start*) p; - return internal_ly_parse_scm (ps, false); + return internal_ly_parse_scm (ps); } SCM safe_catch_protected_parse_body (void *p) { Parse_start *ps = (Parse_start*) p; - return internal_ly_parse_scm (ps, true); + return internal_ly_parse_scm (ps); } SCM @@ -105,11 +94,10 @@ parse_handler (void * data, SCM tag, SCM args) #endif SCM -protected_ly_parse_scm (Parse_start *ps, bool safe) +protected_ly_parse_scm (Parse_start *ps) { return scm_internal_catch (ly_symbol2scm (READ_ERROR), - (safe ? &safe_catch_protected_parse_body - : catch_protected_parse_body), + &catch_protected_parse_body, (void*) ps, &parse_handler, (void*) ps); } @@ -124,8 +112,8 @@ ly_parse_scm (char const* s, int *n, Input i, bool safe) ps.str = s; ps.start_location_ = i; - SCM ans = parse_protect_global ? protected_ly_parse_scm (&ps, safe) - : internal_ly_parse_scm (&ps, safe); + SCM ans = parse_protect_global ? protected_ly_parse_scm (&ps) + : internal_ly_parse_scm (&ps); *n = ps.nchars; return ans; diff --git a/lily/parser.yy b/lily/parser.yy index d785497338..d9b2dd85db 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -500,7 +500,7 @@ embedded_scm: lilypond_header_body: { - $$ = ly_make_anonymous_module (); + $$ = ly_make_anonymous_module (safe_global_b); THIS->lexer_->add_scope ($$); } | lilypond_header_body assignment { diff --git a/lily/scm-option.cc b/lily/scm-option.cc index aab7f1d48c..e7d5a31ec1 100644 --- a/lily/scm-option.cc +++ b/lily/scm-option.cc @@ -46,8 +46,12 @@ bool lily_1_8_compatibility_used = false; */ bool internal_type_checking_global_b; + +/* + What is this function for ? + */ LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (SCM), - "Print ly-set-option usage") + "Print ly:set-option usage") { printf ( _("lilypond -e EXPR means:").to_str0 ()); puts (""); @@ -55,17 +59,11 @@ LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (SCM), puts (""); printf (_ (" Multiple -e options may be given, they will be evaluated sequentially.").to_str0 ()); puts (""); - printf (_(" The function ly-set-option allows for access to some internal variables.").to_str0 ()); + printf (_(" The function ly:set-option allows for access to some internal variables.").to_str0 ()); puts ("\n"); printf (_ ("Usage: lilypond-bin -e \"(ly-set-option SYMBOL VAL)\"").to_str0 ()); puts ("\n"); - printf (_ ("Where SYMBOL VAL pair is any of:").to_str0 ()); - puts (""); - printf ( " help ANY-SYMBOL\n" - " internal-type-checking BOOLEAN\n" - " midi-debug BOOLEAN\n" - " parse-protect BOOLEAN\n" - " testing-level INTEGER\n"); + printf (_ ("Use help as SYMBOL to get online help.").to_str0 ()); exit (0); return SCM_UNSPECIFIED; @@ -77,7 +75,11 @@ LY_DEFINE (ly_option_usage, "ly:option-usage", 0, 0, 0, (SCM), don't timestamp the output @item -t,--test -Switch on any experimental features. Not for general public use. */ +Switch on any experimental features. Not for general public use. + +*/ + + LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val), "Set a global option value. Supported options include\n" "\n" diff --git a/lily/score.cc b/lily/score.cc index e194241fd2..a917614b26 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -86,7 +86,7 @@ Score::Score (Score const &s) for (int i = 0; i < s.defs_.size (); i++) defs_.push (s.defs_[i]->clone ()); - header_ = ly_make_anonymous_module (); + header_ = ly_make_anonymous_module (safe_global_b); if (is_module (s.header_)) ly_import_module (header_, s.header_); } diff --git a/ly/chord-modifiers-init.ly b/ly/chord-modifiers-init.ly index 094fe05552..e5bd41aea1 100644 --- a/ly/chord-modifiers-init.ly +++ b/ly/chord-modifiers-init.ly @@ -2,11 +2,9 @@ chordmodifiers = #default-chord-modifier-list -whiteTriangleMarkup = #(make-override-markup - '(font-encoding . TeX-math) (make-simple-markup "M")) +whiteTriangleMarkup = \markup { \override #'(font-encoding . TeX-math) "M" } -blackTriangleMarkup = #(make-override-markup - '(font-encoding . TeX-math) (make-simple-markup "N")) +blackTriangleMarkup = \markup { \override #'(font-encoding . TeX-math) "N" } ignatzekExceptionMusic = \notes{ 1-\markup { "+" } diff --git a/ly/init.ly b/ly/init.ly index 9a881e8ec6..cf9571d58b 100644 --- a/ly/init.ly +++ b/ly/init.ly @@ -1,7 +1,7 @@ % Toplevel initialisation file. #(define-public point-and-click #f) -#(define-public midi-debug #f) +#(define-public midi-debug #f) \version "2.2.0" diff --git a/scm/lily.scm b/scm/lily.scm index e22e5a5acd..bf2ed056b4 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -20,7 +20,6 @@ (srfi srfi-1) ; lists (srfi srfi-13)) ; strings -(define-public safe-module (make-safe-module)) (define-public (myd k v) (display k) (display ": ") (display v) (display ", ")) @@ -98,6 +97,9 @@ (define-public safe-mode? #f) + + + ;; parser stuff. (define-public (print-music-as-book parser music) (let* ((score (ly:music-scorify music)) @@ -396,6 +398,7 @@ L1 is copied, L2 not. (define-public (ps-output-expression expr port) (display (eval expr output-ps-module) port)) + (define output-alist `( ("tex" . ("TeX output. The default output form." ,tex-output-expression)) @@ -419,6 +422,8 @@ L1 is copied, L2 not. (caddr d) (scm-error "Could not find dumper for format ~s" format)))) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; other files. @@ -445,7 +450,6 @@ L1 is copied, L2 not. "translation-functions.scm" "script.scm" "midi.scm" - "beam.scm" "clef.scm" "slur.scm" @@ -458,6 +462,9 @@ L1 is copied, L2 not. "define-grob-interfaces.scm" "page-layout.scm" "paper.scm" + + ; last: + "safe-lily.scm" )) diff --git a/scm/page-layout.scm b/scm/page-layout.scm index 1a4c80199e..53d4a43418 100644 --- a/scm/page-layout.scm +++ b/scm/page-layout.scm @@ -168,7 +168,7 @@ (define-public (ly:optimal-page-breaks lines book-height text-height first-diff last-diff) - + "DOCME" ;; FIXME: may need some tweaking: square, cubic (define (height-score available used) (let* ((empty (- available used)) -- 2.39.5