#include "international.hh"
#include "item.hh"
#include "main.hh"
-#include "simple-closure.hh"
#include "smobs.hh"
#include "spanner.hh"
#include "unpure-pure-container.hh"
return typecheck_grob (symbol, upc->unpure_part ())
&& typecheck_grob (symbol, upc->pure_part ());
return ly_is_procedure (value)
- || unsmob<Simple_closure> (value)
|| type_check_assignment (symbol, value, ly_symbol2scm ("backend-type?"));
}
#include "grob.hh"
-#include "simple-closure.hh"
#include "unpure-pure-container.hh"
#include "lily-imports.hh"
void
add_offset_callback (Grob *g, SCM proc, Axis a)
{
- SCM data = g->get_property_data (axis_offset_symbol (a));
- if (!scm_is_number (data)
- && !ly_is_procedure (data)
- && !unsmob<Simple_closure> (data))
- {
- g->set_property (axis_offset_symbol (a), proc);
- return;
- }
-
- if (ly_is_procedure (data) || unsmob<Unpure_pure_container> (data))
- data = Simple_closure::make_smob (scm_list_1 (data));
- else if (Simple_closure *sc = unsmob<Simple_closure> (data))
- data = sc->expression ();
-
- if (ly_is_procedure (proc))
- proc = Simple_closure::make_smob (scm_list_1 (proc));
-
- SCM expr = scm_list_3 (Guile_user::plus, proc, data);
- g->set_property (axis_offset_symbol (a), Simple_closure::make_smob (expr));
+ SCM sym = axis_offset_symbol (a);
+ SCM data = g->get_property_data (sym);
+ g->set_property (sym, Lily::grob_offset_function (proc, data));
}
/*
chain_callback (Grob *g, SCM proc, SCM sym)
{
SCM data = g->get_property_data (sym);
-
- if (ly_is_procedure (data) || unsmob<Unpure_pure_container> (data))
- data = Simple_closure::make_smob (scm_list_1 (data));
- else if (Simple_closure *sc = unsmob<Simple_closure> (data))
- data = sc->expression ();
- else
- /*
- Data may be nonnumber. In that case, it is assumed to be
- undefined.
- */
-
- data = SCM_UNDEFINED;
-
- SCM expr = scm_list_2 (proc, data);
- g->set_property (sym,
-
- // twice: one as a wrapper for grob property routines,
- // once for the actual delayed binding.
- Simple_closure::make_smob (Simple_closure::make_smob (expr)));
+ g->set_property (sym, Lily::grob_compose_function (proc, data));
}
void
#include "item.hh"
#include "program-option.hh"
#include "profile.hh"
-#include "simple-closure.hh"
#include "unpure-pure-container.hh"
#include "warn.hh"
#include "protected-scm.hh"
if (do_internal_type_checking_global)
{
if (!ly_is_procedure (v)
- && !unsmob<Simple_closure> (v)
&& !unsmob<Unpure_pure_container> (v)
&& !scm_is_eq (v, ly_symbol2scm ("calculation-in-progress")))
type_check_assignment (sym, v, ly_symbol2scm ("backend-type?"));
if (do_internal_type_checking_global && scm_is_pair (handle))
{
SCM val = scm_cdr (handle);
- if (!ly_is_procedure (val) && !unsmob<Simple_closure> (val)
+ if (!ly_is_procedure (val)
&& !unsmob<Unpure_pure_container> (val))
type_check_assignment (sym, val, ly_symbol2scm ("backend-type?"));
if (Unpure_pure_container *upc = unsmob<Unpure_pure_container> (val))
val = upc->unpure_part ();
- if (ly_is_procedure (val)
- || unsmob<Simple_closure> (val))
+ if (ly_is_procedure (val))
{
Grob *me = ((Grob *)this);
val = me->try_callback_on_alist (&me->mutable_property_alist_, sym, val);
return call_pure_function (val, scm_list_1 (self_scm ()), start, end);
}
- if (Simple_closure *sc = unsmob<Simple_closure> (val))
- return evaluate_with_simple_closure (self_scm (),
- sc->expression (),
- true, start, end);
return val;
}
SCM value = SCM_EOL;
if (ly_is_procedure (proc))
value = scm_call_1 (proc, self_scm ());
- else if (Simple_closure *sc = unsmob<Simple_closure> (proc))
- {
- value = evaluate_with_simple_closure (self_scm (),
- sc->expression (),
- false, 0, 0);
- }
#ifdef DEBUG
if (debug_property_callbacks)
{
SCM val = scm_cdr (s);
if (ly_is_procedure (val)
- || unsmob<Simple_closure> (val)
|| unsmob<Unpure_pure_container> (val))
{
Grob *me = ((Grob *)this);
{
SCM pure = upc->pure_part ();
- if (Simple_closure *sc = unsmob<Simple_closure> (pure))
- {
- SCM expr = sc->expression ();
- return evaluate_with_simple_closure (scm_car (args), expr, true, start, end);
- }
-
if (ly_is_procedure (pure))
return scm_apply_0 (pure,
scm_append (scm_list_2 (scm_list_3 (scm_car (args),
return pure;
}
- if (Simple_closure *sc = unsmob<Simple_closure> (unpure))
- {
- SCM expr = sc->expression ();
- return evaluate_with_simple_closure (scm_car (args), expr, true, start, end);
- }
-
if (!ly_is_procedure (unpure))
return unpure;
return SCM_BOOL_F;
}
-
#include "item.hh"
#include "output-def.hh"
#include "paper-score.hh"
-#include "simple-closure.hh"
#include "system.hh"
#include "unpure-pure-container.hh"
#include "warn.hh" // error ()
LY_ASSERT_TYPE (ly_is_symbol, sym, 2);
if (!ly_is_procedure (val)
- && !unsmob<Simple_closure> (val)
&& !type_check_assignment (sym, val, ly_symbol2scm ("backend-type?")))
error ("typecheck failed");
+++ /dev/null
-/*
- This file is part of LilyPond, the GNU music typesetter.
-
- Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
-
- LilyPond is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- LilyPond is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef SIMPLE_CLOSURE_HH
-#define SIMPLE_CLOSURE_HH
-
-#include "lily-guile.hh"
-#include "small-smobs.hh"
-
-class Simple_closure : public Smob1<Simple_closure>
-{
-public:
- SCM expression() const { return scm1 (); }
- int print_smob (SCM, scm_print_state *) const;
- static const char type_p_name_[];
-};
-
-SCM evaluate_with_simple_closure (SCM delayed_argument, SCM expr, bool pure, int start, int end);
-
-#endif /* SIMPLE_CLOSURE_HH */
#include "item.hh"
#include "pointer-group-interface.hh"
-#include "simple-closure.hh"
#include "stream-event.hh"
#include "warn.hh"
+++ /dev/null
-/*
- This file is part of LilyPond, the GNU music typesetter.
-
- Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
-
-
- LilyPond is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- LilyPond is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
-*/
-#include "simple-closure.hh"
-#include "unpure-pure-container.hh"
-
-#include "grob.hh"
-
-SCM
-evaluate_args (SCM delayed_argument, SCM args, bool pure, int start, int end)
-{
- SCM new_args = SCM_EOL;
- SCM *tail = &new_args;
- for (SCM s = args; scm_is_pair (s); s = scm_cdr (s))
- {
- *tail = scm_cons (evaluate_with_simple_closure (delayed_argument, scm_car (s),
- pure, start, end),
- SCM_EOL);
- if (scm_is_eq (scm_car (*tail), SCM_UNSPECIFIED))
- return SCM_UNSPECIFIED;
- tail = SCM_CDRLOC (*tail);
- }
-
- return new_args;
-}
-
-SCM
-evaluate_with_simple_closure (SCM delayed_argument,
- SCM expr,
- bool pure,
- int start,
- int end)
-{
- if (Simple_closure *sc = unsmob<Simple_closure> (expr))
- {
- SCM inside = sc->expression ();
- SCM proc = !pure && unsmob<Unpure_pure_container> (scm_car (inside))
- ? unsmob<Unpure_pure_container> (scm_car (inside))->unpure_part ()
- : scm_car (inside);
- SCM args = scm_cons (delayed_argument,
- evaluate_args (delayed_argument, scm_cdr (inside),
- pure, start, end));
- if (scm_is_eq (scm_cdr (args), SCM_UNSPECIFIED))
- return SCM_UNSPECIFIED;
- if (pure)
- return call_pure_function (proc, args, start, end);
- return scm_apply_0 (proc, args);
- }
- else if (!scm_is_pair (expr))
- return expr;
- else if (scm_is_eq (scm_car (expr), ly_symbol2scm ("quote")))
- return scm_cadr (expr);
- else if (unsmob<Unpure_pure_container> (scm_car (expr))
- || ly_is_procedure (scm_car (expr)))
- {
- SCM proc = !pure && unsmob<Unpure_pure_container> (scm_car (expr))
- ? unsmob<Unpure_pure_container> (scm_car (expr))->unpure_part ()
- : scm_car (expr);
- SCM args = evaluate_args (delayed_argument, scm_cdr (expr), pure, start, end);
- if (scm_is_eq (args, SCM_UNSPECIFIED))
- return SCM_UNSPECIFIED;
- if (pure)
- return call_pure_function (proc, args, start, end);
- return scm_apply_0 (proc, args);
- }
- else
- // ugh. deviation from standard. Should print error?
- return evaluate_args (delayed_argument, scm_cdr (expr), pure, start, end);
-
- assert (false);
- return SCM_EOL;
-}
-
-const char Simple_closure::type_p_name_[] = "ly:simple-closure?";
-
-LY_DEFINE (ly_make_simple_closure, "ly:make-simple-closure",
- 1, 0, 0, (SCM expr),
- "Make a simple closure. @var{expr} should be form of"
- " @code{(@var{func} @var{a1} @var{a2} @dots{})}, and will be"
- " invoked as @code{(@var{func} @var{delayed-arg} @var{a1}"
- " @var{a2} @dots{})}.")
-{
- return Simple_closure::make_smob (expr);
-}
-
-LY_DEFINE (ly_eval_simple_closure, "ly:eval-simple-closure",
- 2, 2, 0, (SCM delayed, SCM closure, SCM scm_start, SCM scm_end),
- "Evaluate a simple @var{closure} with the given @var{delayed}"
- " argument. If @var{scm-start} and @var{scm-end} are defined,"
- " evaluate it purely with those start and end points.")
-{
- LY_ASSERT_SMOB (Simple_closure, closure, 2);
- bool pure = (scm_is_number (scm_start) && scm_is_number (scm_end));
- int start = robust_scm2int (scm_start, 0);
- int end = robust_scm2int (scm_end, 0);
- SCM expr = unsmob<Simple_closure> (closure)->expression ();
- return evaluate_with_simple_closure (delayed, expr, pure, start, end);
-}
-
-int
-Simple_closure::print_smob (SCM port, scm_print_state *) const
-{
- scm_puts ("#<simple-closure ", port);
- scm_display (expression (), port);
- scm_puts (" >", port);
- return 1;
-}
(,ly:pitch? . "pitch")
(,ly:prob? . "property object")
(,ly:score? . "score")
- (,ly:simple-closure? . "simple closure")
(,ly:skyline? . "skyline")
(,ly:skyline-pair? . "pair of skylines")
(,ly:source-file? . "source file")