]> git.donarmstrong.com Git - lilypond.git/blob - lily/lily-guile.cc
patch::: 1.1.8.hwn1
[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
25 /*
26   scm_m_quote doesn't use any env, but needs one for a good signature in GUILE.
27
28   Why there is no gh_quote () in GUILE  beats me.
29 */
30
31 SCM
32 ly_quote_scm (SCM s)
33 {
34   //  return scm_m_quote (s, SCM_UNDEFINED);
35   return scm_cons2 (scm_i_quote, s, SCM_EOL);
36   
37 }
38
39 SCM
40 ly_eval (SCM a)
41 {
42   return gh_call1 (gh_eval_str ("eval"), a);
43 }
44
45 SCM
46 ly_lambda_o ()
47 {
48   return gh_eval_str ("'(lambda (o))");
49 }
50
51 SCM
52 ly_func_o (char const* name)
53 {
54   char buf[200];                // ugh.
55   snprintf (buf, 200, "'(%s o)", name);
56   return gh_eval_str (buf);
57 }
58
59 /*
60   See: libguile/symbols.c
61
62   SCM
63   scm_string_to_symbol(s)
64   
65 */
66 SCM
67 ly_symbol (String name)
68 {
69   return gh_car (scm_intern (name.ch_C(), name.length_i()));
70 }
71
72 SCM
73 lambda_scm (String str, Array<int> args_arr)
74 {
75   if (str.empty_b ())
76     {
77       str = "empty";
78       args_arr.clear ();
79     }
80   SCM args_scm = SCM_EOL;
81   for (int i = args_arr.size () - 1; i >= 0; i--)
82     args_scm = gh_cons (gh_int2scm (args_arr[i]), args_scm);
83   args_scm = gh_cons (ly_symbol (str.ch_l ()), args_scm);
84   return args_scm;
85 }
86
87 // scm_top_level_env(SCM_CDR(scm_top_level_lookup_closure_var)))
88 SCM
89 lambda_scm (String str, Array<Scalar> args_arr)
90 {
91   if (str.empty_b ())
92     {
93       str = "empty";
94       args_arr.clear ();
95     }
96   SCM args_scm = SCM_EOL;
97   for (int i = args_arr.size (); i--; )
98     args_scm = gh_cons (gh_str02scm (args_arr[i].ch_l ()), args_scm);
99   args_scm = gh_cons (ly_symbol (str.ch_l ()), args_scm);
100   return args_scm;
101 }
102
103 SCM
104 lambda_scm (String str, Array<Real> args_arr)
105 {
106   if (str.empty_b ())
107     {
108       str = "empty";
109       args_arr.clear ();
110     }
111   SCM args_scm = SCM_EOL;
112   for (int i = args_arr.size (); i--; )
113     args_scm = gh_cons (gh_double2scm (args_arr[i]), args_scm);
114   
115   args_scm = gh_cons (ly_symbol (str.ch_l ()), args_scm);
116   return args_scm;
117 }
118
119 /**
120
121    Read a file, and shove it down GUILE.  GUILE also has file read
122    functions, but you can't fiddle with the path of those.
123    
124  */
125
126 void
127 read_lily_scm_file (String fn)
128 {
129   String s = global_path.find (fn);
130   Simple_file_storage f(s);
131   
132   gh_eval_str ((char *) f.ch_C());
133 }