1 ;;;; lily.scm -- toplevel Scheme stuff
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 (if (defined? 'set-debug-cell-accesses!)
10 (set-debug-cell-accesses! #f))
12 ;;(set-debug-cell-accesses! 5000)
14 (use-modules (ice-9 regex)
18 (srfi srfi-13)) ; strings
22 (define-public (myd k v) (display k) (display ": ") (display v) (display ", "))
24 (define-public (print . args)
25 (apply format (cons (current-output-port) args)))
29 ;;; debugging evaluator is slower. This should
30 ;;; have a more sensible default.
32 (if (ly:get-option 'verbose)
35 (debug-enable 'backtrace)
36 (read-enable 'positions)))
38 (define-public (line-column-location file line col)
39 "Print an input location, including column number ."
40 (string-append (number->string line) ":"
41 (number->string col) " " file))
43 (define-public (line-location file line col)
44 "Print an input location, without column number ."
45 (string-append (number->string line) " " file))
47 (define-public point-and-click #f)
49 (define-public tex-backend?
50 (member (ly:output-backend) '("texstr" "tex")))
52 (define-public parser #f)
54 (define-public (lilypond-version)
56 (map (lambda (x) (if (symbol? x)
64 ;; cpp hack to get useful error message
65 (define ifdef "First run this through cpp.")
66 (define ifndef "First run this through cpp.")
68 ;; gettext wrapper for guile < 1.7.2
69 (if (defined? 'gettext)
70 (define-public _ gettext)
71 (define-public _ ly:gettext))
73 (define-public (ly:load x)
74 (let* ((fn (%search-load-path x)))
75 (if (ly:get-option 'verbose)
76 (format (current-error-port) "[~A]" fn))
79 (define-public TEX_STRING_HASHLIMIT 10000000)
81 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
83 (define (type-check-list location signature arguments)
84 "Typecheck a list of arguments against a list of type
85 predicates. Print a message at LOCATION if any predicate failed."
86 (define (recursion-helper signature arguments count)
87 (define (helper pred? arg count)
91 (ly:input-message location
93 (_ "wrong type for argument ~a. Expecting ~a, found ~s")
94 count (type-name pred?) arg))
100 (and (helper (car signature) (car arguments) count)
101 (recursion-helper (cdr signature) (cdr arguments) (1+ count)))))
102 (recursion-helper signature arguments 1))
104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
108 ;;(define-public (output-framework) (write "hello\n"))
110 (define output-tex-module
111 (make-module 1021 (list (resolve-interface '(scm output-tex)))))
112 (define output-ps-module
113 (make-module 1021 (list (resolve-interface '(scm output-ps)))))
115 (define-public (ps-output-expression expr port)
116 (display (eval expr output-ps-module) port))
118 ;; TODO: generate this list by registering the stencil expressions
119 ;; stencil expressions should have docstrings.
120 (define-public (ly:all-stencil-expressions)
121 "Return list of stencil expressions."
146 ;; - generate this list by registering the output-backend-commands
147 ;; output-backend-commands should have docstrings.
148 ;; - remove hard copies in output-ps output-tex
149 (define-public (ly:all-output-backend-commands)
150 "Return list of output backend commands."
158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
164 "define-music-types.scm"
167 "chord-ignatzek-names.scm"
169 "chord-generic-names.scm"
173 "music-functions.scm"
175 "define-music-properties.scm"
181 "define-context-properties.scm"
182 "translation-functions.scm"
192 "define-markup-commands.scm"
193 "define-grob-properties.scm"
195 "define-grob-interfaces.scm"
200 "backend-library.scm"
205 (set! type-p-name-alist
207 (,boolean-or-symbol? . "boolean or symbol")
208 (,boolean? . "boolean")
210 (,grob-list? . "list of grobs")
211 (,hash-table? . "hash table")
212 (,input-port? . "input port")
213 (,integer? . "integer")
215 (,ly:context? . "context")
216 (,ly:dimension? . "dimension, in staff space")
217 (,ly:dir? . "direction")
218 (,ly:duration? . "duration")
219 (,ly:grob? . "layout object")
220 (,ly:input-location? . "input location")
221 (,ly:moment? . "moment")
222 (,ly:music? . "music")
223 (,ly:pitch? . "pitch")
224 (,ly:translator? . "translator")
225 (,ly:font-metric? . "font metric")
226 (,markup-list? . "list of markups")
227 (,markup? . "markup")
228 (,ly:music-list? . "list of music")
229 (,number-or-grob? . "number or grob")
230 (,number-or-string? . "number or string")
231 (,number-pair? . "pair of numbers")
232 (,number? . "number")
233 (,output-port? . "output port")
235 (,procedure? . "procedure")
236 (,scheme? . "any type")
237 (,string? . "string")
238 (,symbol? . "symbol")
239 (,vector? . "vector")))
244 (define gc-protect-stat-count 0)
245 (define-public (dump-gc-protects)
246 (set! gc-protect-stat-count (1+ gc-protect-stat-count))
247 (let* ((protects (sort
248 (hash-table->alist (ly:protects))
250 (< (object-address (car a))
251 (object-address (car b))))))
252 (out-file-name (string-append
253 "gcstat-" (number->string gc-protect-stat-count)
255 (outfile (open-file out-file-name "w")))
257 (display "Dumping gc protected objs to ...\n")
260 (lambda (x) (not (symbol? x)))
267 (map object->string (list (object-address x) c x))
274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
276 (define-public (lilypond-main files)
277 "Entry point for LilyPond."
279 (handler (lambda (key arg) (set! failed (cons arg failed)))))
282 (catch 'ly-file-failed (lambda () (ly:parse-file f)) handler)
289 (newline (current-error-port))
290 (display (_ "error: failed files: ") (current-error-port))
291 (display (string-join failed) (current-error-port))
292 (newline (current-error-port))
293 (newline (current-error-port))
297 (define-public (tweak-grob-property grob sym val)
298 (set! (ly:grob-property grob sym) val))