]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4474/1: Move syntax constructors into separate module
authorDavid Kastrup <dak@gnu.org>
Thu, 25 Jun 2015 15:07:26 +0000 (17:07 +0200)
committerDavid Kastrup <dak@gnu.org>
Wed, 8 Jul 2015 05:15:00 +0000 (07:15 +0200)
lily/guile-init.cc
lily/include/lily-imports.hh
lily/lily-imports.cc
lily/music-function.cc
lily/parser.yy
scm/ly-syntax-constructors.scm

index 3259a465775cb5adab71b1a2409731e1f4d9c892..f54fca248293b1a3c133f0fc055efac2b1acc449 100644 (file)
@@ -72,6 +72,7 @@ void
 ly_c_init_guile ()
 {
   Guile_user::module.import ();
+  Syntax::module.boot ();
   Lily::module.boot ();
   scm_c_call_with_current_module (Lily::module, ly_init_ly_module, 0);
   Display::module.import ();
index 68b8102444df29b8d3667c1eb44e5263886f1f37..a7157e39367e3547abb5635c98cadc3a894392ba 100644 (file)
@@ -101,6 +101,11 @@ namespace Lily {
   extern Variable type_name;
   extern Variable volta_bracket_calc_hook_visibility;
   extern Variable write_performances_midis;
+}
+
+namespace Syntax {
+  extern Scm_module module;
+  typedef Module_variable<module> Variable;
 
   extern Variable add_lyrics;
   extern Variable argument_error;
index 37a92578d49155d49ed0c39348a88a1a42c9da3a..061d7ac0d6bb543c4652cdd5f61aaec2d99d9cd5 100644 (file)
@@ -95,6 +95,10 @@ namespace Lily {
   Variable type_name ("type-name");
   Variable volta_bracket_calc_hook_visibility ("volta-bracket::calc-hook-visibility");
   Variable write_performances_midis ("write-performances-midis");
+}
+
+namespace Syntax {
+  Scm_module module ("ly-syntax");
 
   Variable add_lyrics ("add-lyrics");
   Variable argument_error ("argument-error");
index 9b64e311057fe643fe3a3a32f3b6946aa3069953..0249fd8ba7c0ed51d1fdd8637514179bc746d533 100644 (file)
@@ -143,8 +143,8 @@ Music_function::call (SCM rest)
 
       if (scm_is_false (scm_call_1 (pred, arg)))
         {
-          Lily::argument_error (scm_length (args),
-                                pred, arg);
+          Syntax::argument_error (scm_length (args),
+                                  pred, arg);
           SCM val = scm_car (get_signature ());
           val = scm_is_pair (val) ? scm_cdr (val) : SCM_BOOL_F;
           return with_loc (val, location);
@@ -167,5 +167,5 @@ Music_function::call (SCM rest)
   if (scm_is_true (scm_call_1 (pred, res)))
     return with_loc (res, location, false);
 
-  return Lily::music_function_call_error (self_scm (), res);
+  return Syntax::music_function_call_error (self_scm (), res);
 }
index 8c08819d7dd9b52aaea3568ae2bcdf8604671796..ef0962c05eafc9e32e3253a88762c781c0bd110b 100644 (file)
@@ -208,11 +208,11 @@ syntax_call (void *arg)
 /* Syntactic Sugar. */
 #define MAKE_SYNTAX(name, location, ...)                               \
        LOWLEVEL_MAKE_SYNTAX (location,                                 \
-                             scm_list_n (Lily::name,                   \
+                             scm_list_n (Syntax::name,                 \
                                          ##__VA_ARGS__, SCM_UNDEFINED))
 
 #define START_MAKE_SYNTAX(name, ...)                                   \
-       scm_list_n (Lily::name,                                         \
+       scm_list_n (Syntax::name,                                       \
                    ##__VA_ARGS__, SCM_UNDEFINED)
 
 #define FINISH_MAKE_SYNTAX(start, location, ...)                       \
index c987a675ca3782408cfe953ca6ff0e60613fc943..596b0fea3292dbb30314ae239fb07f3769b17d16 100644 (file)
 ;;;; You should have received a copy of the GNU General Public License
 ;;;; along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 
-;; TODO: use separate module for syntax
-;; constructors. Also create wrapper around the constructor?
+(define ly-syntax-module (resolve-module '(ly-syntax)))
+
 (defmacro define-ly-syntax (args . body)
-  `(define ,args ,@body))
+  (if (pair? args)
+      `(module-define! ,ly-syntax-module ',(car args)
+                       (lambda ,(cdr args) ,@body))
+      `(module-define! ,ly-syntax-module ',args ,@body)))
 
 ;; A ly-syntax constructor can access location data as (*location*).
 ;; This is mainly used for reporting errors and warnings. This
@@ -26,7 +29,7 @@
 ;; origin of the returned music object; this behaviour is usually
 ;; desired.
 (defmacro define-ly-syntax-loc (args . body)
-  `(define ,args
+  `(define-ly-syntax ,args
      (let ((m ,(cons 'begin body)))
        (set! (ly:music-property m 'origin) (*location*))
        m)))
@@ -41,6 +44,8 @@
      (*location*))
     (and (pair? (car sig)) (cdar sig))))
 
+(define-ly-syntax music-function-call-error music-function-call-error)
+
 ;; Music function: Apply function and check return value.
 ;; args are in reverse order, rest may specify additional ones
 ;;