]> git.donarmstrong.com Git - lilypond.git/blob - lily/lily-guile.cc
release: 1.1.7
[lilypond.git] / lily / lily-guile.cc
1 /*
2   lily-guile.cc -- implement assorted guile functions
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
7
8   Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 */
10
11 #include <stdio.h>
12 #include "libc-extension.hh"
13 #include "lily-guile.hh"
14 #include "main.hh"
15 #include "simple-file-storage.hh"
16 #include "file-path.hh"
17
18 SCM
19 ly_list1 (SCM a)
20 {
21   return gh_list (a, SCM_UNDEFINED);
22 }
23
24 SCM
25 ly_quote ()
26 {
27   return gh_eval_str ("'quote");
28 }
29
30 /*
31   scm_m_quote doesn't use any env, but needs one for a good signature in GUILE.
32
33   Why there is no gh_quote () in GUILE  beats me.
34 */
35
36 SCM
37 ly_quote_scm (SCM s)
38 {
39   //  return scm_m_quote (s, SCM_UNDEFINED);
40   return scm_cons2 (scm_i_quote, s, SCM_EOL);
41   
42 }
43
44 SCM
45 ly_eval (SCM a)
46 {
47   return gh_call1 (gh_eval_str ("eval"), a);
48 }
49
50 SCM
51 ly_lambda_o ()
52 {
53   return gh_eval_str ("'(lambda (o))");
54 }
55
56 SCM
57 ly_func_o (char const* name)
58 {
59   char buf[200];                // ugh.
60   snprintf (buf, 200, "'(%s o)", name);
61   return gh_eval_str (buf);
62 }
63
64
65 SCM
66 lambda_scm (String str, Array<int> args_arr)
67 {
68   if (str.empty_b ())
69     {
70       str = "empty";
71       args_arr.clear ();
72     }
73   SCM args_scm = SCM_EOL;
74   for (int i = args_arr.size () - 1; i >= 0; i--)
75     args_scm = gh_cons (gh_int2scm (args_arr[i]), args_scm);
76   SCM scm =
77     gh_append2 (ly_lambda_o (), 
78                 ly_list1 (gh_append2 (ly_func_o (str.ch_l ()), args_scm)));
79   return scm;
80 }
81
82 // scm_top_level_env(SCM_CDR(scm_top_level_lookup_closure_var)))
83 SCM
84 lambda_scm (String str, Array<Scalar> args_arr)
85 {
86   if (str.empty_b ())
87     {
88       str = "empty";
89       args_arr.clear ();
90     }
91   SCM args_scm = SCM_EOL;
92   for (int i = args_arr.size (); i--; )
93     args_scm = gh_cons (gh_str02scm (args_arr[i].ch_l ()), args_scm);
94   SCM scm =
95     gh_append2 (ly_lambda_o (), 
96     ly_list1 (gh_append2 (ly_func_o (str.ch_l ()), args_scm)));
97   return scm;
98 }
99
100 SCM
101 lambda_scm (String str, Array<Real> args_arr)
102 {
103   if (str.empty_b ())
104     {
105       str = "empty";
106       args_arr.clear ();
107     }
108   SCM args_scm = SCM_EOL;
109   for (int i = args_arr.size (); i--; )
110     args_scm = gh_cons (gh_double2scm (args_arr[i]), args_scm);
111   
112   SCM scm =
113     gh_append2 (ly_lambda_o (), 
114     ly_list1 (gh_append2 (ly_func_o (str.ch_l ()), args_scm)));
115   return scm;
116 }
117
118 /**
119
120    Read a file, and shove it down GUILE.  GUILE also has file read
121    functions, but you can't fiddle with the path of those.
122    
123  */
124
125 void
126 read_lily_scm_file (String fn)
127 {
128   String s = global_path.find (fn);
129   Simple_file_storage f(s);
130   
131   gh_eval_str ((char *) f.ch_C());
132 }