From: David Kastrup Date: Sat, 30 Aug 2014 09:11:37 +0000 (+0200) Subject: Issue 4086/3: Reimplement Music_function in terms of Smob2 X-Git-Tag: release/2.19.14-1~25 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=38a54ac8cf2367aa36f649379dbaec3566216e1c;p=lilypond.git Issue 4086/3: Reimplement Music_function in terms of Smob2 --- diff --git a/lily/function-documentation.cc b/lily/function-documentation.cc index ddd1b0c872..7bb4543d2f 100644 --- a/lily/function-documentation.cc +++ b/lily/function-documentation.cc @@ -103,7 +103,7 @@ void init_func_doc () { ly_add_type_predicate ((void *) &is_direction, "direction"); - ly_add_type_predicate ((void *) &is_music_function, "Music_function"); + ly_add_type_predicate ((void *) &Music_function::unsmob, "Music_function"); ly_add_type_predicate ((void *) &ly_is_port, "port"); ly_add_type_predicate ((void *) &ly_cheap_is_list, "list"); ly_add_type_predicate ((void *) &Global_context::unsmob, "Global_context"); diff --git a/lily/include/music-function.hh b/lily/include/music-function.hh index f08b6c5de9..0c3c67a5ca 100644 --- a/lily/include/music-function.hh +++ b/lily/include/music-function.hh @@ -22,12 +22,17 @@ #include "lily-guile.hh" -SCM ly_make_music_function (SCM, SCM); -SCM make_music_function (SCM, SCM); - -SCM get_music_function_transform (SCM); -SCM get_music_function_signature (SCM); -bool is_music_function (SCM); +#include "small-smobs.hh" + +class Music_function : public Smob2 +{ +public: + static const char type_p_name_[]; + static SCM mark_smob (SCM); + static int print_smob (SCM, SCM, scm_print_state *); + SCM get_signature () { return scm1 (); } + SCM get_function () { return scm2 (); } +}; #endif /* MUSIC_FUNCTION_HH */ diff --git a/lily/lexer.ll b/lily/lexer.ll index 760ab9718d..fbe878c56c 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -952,13 +952,13 @@ Lily_lexer::scan_shorthand (const string &str) int Lily_lexer::scan_scm_id (SCM sid) { - if (is_music_function (sid)) + if (Music_function *fun = Music_function::unsmob (sid)) { int funtype = SCM_FUNCTION; yylval = sid; - SCM s = get_music_function_signature (sid); + SCM s = fun->get_signature (); SCM cs = scm_car (s); if (scm_is_pair (cs)) diff --git a/lily/music-function-scheme.cc b/lily/music-function-scheme.cc index e9e9a68ec6..016b96700d 100644 --- a/lily/music-function-scheme.cc +++ b/lily/music-function-scheme.cc @@ -1,28 +1,21 @@ #include "music-function.hh" -LY_DEFINE (ly_music_function_p, "ly:music-function?", 1, 0, 0, - (SCM x), - "Is @var{x} a @code{music-function}?") -{ - return is_music_function (x) ? SCM_BOOL_T : SCM_BOOL_F; -} - LY_DEFINE (ly_music_function_extract, "ly:music-function-extract", 1, 0, 0, (SCM x), "Return the Scheme function inside@tie{}@var{x}.") { - LY_ASSERT_TYPE (is_music_function, x, 1); + LY_ASSERT_TYPE (Music_function::unsmob, x, 1); - return get_music_function_transform (x); + return Music_function::unsmob (x)->get_function (); } LY_DEFINE (ly_music_function_signature, "ly:music-function-signature", 1, 0, 0, (SCM x), "Return the function signature inside@tie{}@var{x}.") { - LY_ASSERT_TYPE (is_music_function, x, 1); + LY_ASSERT_TYPE (Music_function::unsmob, x, 1); - return get_music_function_signature (x); + return Music_function::unsmob (x)->get_signature (); } LY_DEFINE (ly_make_music_function, "ly:make-music-function", 2, 0, 0, @@ -48,5 +41,5 @@ LY_DEFINE (ly_make_music_function, "ly:make-music-function", 2, 0, 0, } } - return make_music_function (signature, func); + return Music_function::make_smob (signature, func); } diff --git a/lily/music-function.cc b/lily/music-function.cc index d519f86283..743b7f6767 100644 --- a/lily/music-function.cc +++ b/lily/music-function.cc @@ -19,71 +19,23 @@ #include "music-function.hh" -#include "music.hh" - -class Musicfunction : public Simple_smob -{ -public: - static SCM mark_smob (SCM); - static int print_smob (SCM, SCM, scm_print_state *); -private: - SCM signature_; - SCM function_; -public: - Musicfunction (SCM signature, SCM function): - signature_ (signature), function_ (function) { } - SCM get_function () { return function_; } - SCM get_signature () { return signature_; } -}; - +const char Music_function::type_p_name_[] = "ly:music-function?"; /* Print a textual represenation of the smob to a given port. */ int -Musicfunction::print_smob (SCM b, SCM port, scm_print_state *) +Music_function::print_smob (SCM b, SCM port, scm_print_state *) { scm_puts ("#get_function (), port); + scm_write (Music_function::unsmob (b)->get_function (), port); scm_puts (">", port); /* Non-zero means success. */ return 1; } -bool -is_music_function (SCM music_function) -{ - return Musicfunction::unsmob (music_function); -} - -SCM -get_music_function_transform (SCM music_function) -{ - if (!is_music_function (music_function)) - return SCM_UNDEFINED; - - return Musicfunction::unsmob (music_function)->get_function (); -} - -SCM -make_music_function (SCM signature, SCM func) -{ - return Musicfunction (signature, func).smobbed_copy (); -} - -SCM -get_music_function_signature (SCM music_function) -{ - if (!is_music_function (music_function)) - return SCM_UNDEFINED; - - return Musicfunction::unsmob (music_function)->get_signature (); -} - SCM -Musicfunction::mark_smob (SCM s) +Music_function::mark_smob (SCM s) { - Musicfunction *p = Musicfunction::unsmob (s); - scm_gc_mark (p->signature_); ASSERT_LIVE_IS_ALLOWED (s); - return p->function_; + return Smob2::mark_smob (s); }