]> git.donarmstrong.com Git - lilypond.git/commitdiff
(ly_module_define): only define variable if
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 9 May 2004 07:51:50 +0000 (07:51 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 9 May 2004 07:51:50 +0000 (07:51 +0000)
bound.

18 files changed:
ChangeLog
Documentation/topdocs/NEWS.texi
Documentation/user/tutorial.itely
lily/include/ly-module.hh
lily/input-smob.cc
lily/ly-module.cc
lily/music-output-def.cc
lily/my-lily-lexer.cc
lily/my-lily-parser.cc
lily/paper-outputter.cc
lily/parse-scm.cc
lily/parser.yy
lily/scm-option.cc
lily/score.cc
ly/chord-modifiers-init.ly
ly/init.ly
scm/lily.scm
scm/page-layout.scm

index 6c36f33e28b1b6649c11faa1795c282151aedf42..14612d2f9fd4220dc76ba6cd7813e82ce6d45198 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-05-09  Han-Wen Nienhuys   <hanwen@xs4all.nl>
+
+       * lily/ly-module.cc (ly_module_define): only define variable if
+       bound.
+
 2004-05-08  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
        * scripts/lilypond-book.py (compose_ly): remove FRAGMENT_LY.
index 32b2295c3d4757f9ec72c70018b924686b722b75..ed7408392308d681ef4456c6af33f3e888a2c952 100644 (file)
@@ -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
index aafa9faf6085f6a5dc4f58a72ee037097cd71da4..255b54c59316763ceaa31edf3b667ca434656c24 100644 (file)
@@ -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
index cf727a1586b309c6222d2d3500a8e1ce8d52dc94..2619ccfec54936a0a00ad0bc8bddba645a09b042 100644 (file)
@@ -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 */
 
index 0a6f86c7b319c8dd590cd6f48b08f031ad98cd2a..595ee717dac934135ade3cf6bf3870402fdb0ea2 100644 (file)
@@ -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).")
 {
index f93eeb2922ca7ffa2832cb5faac052e83b37b606..754e144bfa9dd74b409c55f86a5340e2af9145e9 100644 (file)
@@ -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;
 }
 
index baf6c66bd4772798a32a290816760cee79a8a59d..d55ebd92a8222310cb8ed7d89eb7663e99c5a6e5 100644 (file)
@@ -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_);
 }
index 971fe0ae7caed5b0714a0bff92058e989f1e7a76..7fa4569c05cdd444ebb30e7cc4cb6f45124ac1f8 100644 (file)
@@ -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_);
 }
index 9a0c36726ca098d88f926746fb11b3fbc6c894db..68e864d5c8edd76407a57e681155870056725e54 100644 (file)
@@ -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 ();
 }
 
index 8de4a29e167e20525238a5edc7ae5abfa3ceb3bf..38ff508b5f0ea402664ab3199bdfcf18430cc42a 100644 (file)
@@ -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 ()
index bd183b2bf2bf0396abeabed828c09cd4b050e9d5..03d1df4ff1df3e4c4f32a28ff162b3960a995591 100644 (file)
@@ -13,7 +13,7 @@
    
    Thanks to Gary Houston <ghouston@freewire.co.uk>  */
 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;  
index d785497338c80b009070b2870d14eb63c2033c36..d9b2dd85db8085cab11abc918999d37282e4c990 100644 (file)
@@ -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  {
index aab7f1d48c58fc0c266ea0fe3321e2ec9111f75e..e7d5a31ec1c622ec184695dc690aa5c7eb317bf8 100644 (file)
@@ -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"
index e194241fd28e382700e4803f58f181ac92b094a4..a917614b265f4bccc9729cb32c9ff76b47dbfdba 100644 (file)
@@ -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_);
 }
index 094fe05552f1f4f970497fac3f1d550e7a0a69e6..e5bd41aea181e09ce9d85949ea11ad065909838b 100644 (file)
@@ -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{
        <c e gis>1-\markup { "+" }
index 9a881e8ec6e2d4348edc2666d42df471747edc1a..cf9571d58bf48a1227c20c490aca4a4492d2f69d 100644 (file)
@@ -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"
index e22e5a5acd686a1f28c9980e5de4a95151f9f775..bf2ed056b48bbe66999dc372dd8593770894160c 100644 (file)
@@ -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"
        ))
 
 
index 1a4c80199ec63b489fa31de52dd9d95fa26a629e..53d4a434188a423a1778d6a21ec53818162599c2 100644 (file)
 
 (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))