From d613b697d6eda2f91df86c1c7205b4344adaaea4 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Thu, 25 Jun 2015 17:07:26 +0200 Subject: [PATCH] Issue 4474/1: Move syntax constructors into separate module --- lily/guile-init.cc | 1 + lily/include/lily-imports.hh | 5 +++++ lily/lily-imports.cc | 4 ++++ lily/music-function.cc | 6 +++--- lily/parser.yy | 4 ++-- scm/ly-syntax-constructors.scm | 13 +++++++++---- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lily/guile-init.cc b/lily/guile-init.cc index 3259a46577..f54fca2482 100644 --- a/lily/guile-init.cc +++ b/lily/guile-init.cc @@ -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 (); diff --git a/lily/include/lily-imports.hh b/lily/include/lily-imports.hh index 68b8102444..a7157e3936 100644 --- a/lily/include/lily-imports.hh +++ b/lily/include/lily-imports.hh @@ -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 Variable; extern Variable add_lyrics; extern Variable argument_error; diff --git a/lily/lily-imports.cc b/lily/lily-imports.cc index 37a92578d4..061d7ac0d6 100644 --- a/lily/lily-imports.cc +++ b/lily/lily-imports.cc @@ -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"); diff --git a/lily/music-function.cc b/lily/music-function.cc index 9b64e31105..0249fd8ba7 100644 --- a/lily/music-function.cc +++ b/lily/music-function.cc @@ -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); } diff --git a/lily/parser.yy b/lily/parser.yy index 8c08819d7d..ef0962c05e 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -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, ...) \ diff --git a/scm/ly-syntax-constructors.scm b/scm/ly-syntax-constructors.scm index c987a675ca..596b0fea32 100644 --- a/scm/ly-syntax-constructors.scm +++ b/scm/ly-syntax-constructors.scm @@ -15,10 +15,13 @@ ;;;; You should have received a copy of the GNU General Public License ;;;; along with LilyPond. If not, see . -;; 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 ;; -- 2.39.2