1 ;;;; lily.scm -- toplevel Scheme stuff
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2005 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)
19 (srfi srfi-13)) ; strings
23 (define-public (myd k v) (display k) (display ": ") (display v) (display ", "))
25 (define-public (print . args)
26 (apply format (cons (current-output-port) args)))
30 ;;; debugging evaluator is slower. This should
31 ;;; have a more sensible default.
33 (if (ly:get-option 'verbose)
36 (debug-enable 'backtrace)
37 (read-enable 'positions)))
39 (define-public (line-column-location file line col)
40 "Print an input location, including column number ."
41 (string-append (number->string line) ":"
42 (number->string col) " " file))
44 (define-public (line-location file line col)
45 "Print an input location, without column number ."
46 (string-append (number->string line) " " file))
48 (define-public point-and-click #f)
50 (define-public tex-backend?
51 (member (ly:output-backend) '("texstr" "tex")))
53 (define-public parser #f)
55 (define-public (lilypond-version)
57 (map (lambda (x) (if (symbol? x)
65 ;; cpp hack to get useful error message
66 (define ifdef "First run this through cpp.")
67 (define ifndef "First run this through cpp.")
69 ;; gettext wrapper for guile < 1.7.2
70 (if (defined? 'gettext)
71 (define-public _ gettext)
72 (define-public _ ly:gettext))
74 (define-public (ly:load x)
75 (let* ((file-name (%search-load-path x)))
76 (if (ly:get-option 'verbose)
77 (ly:progress "[~A" file-name))
78 (primitive-load file-name)
79 (if (ly:get-option 'verbose)
82 (define-public TEX_STRING_HASHLIMIT 10000000)
84 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
86 (define (type-check-list location signature arguments)
87 "Typecheck a list of arguments against a list of type
88 predicates. Print a message at LOCATION if any predicate failed."
89 (define (recursion-helper signature arguments count)
90 (define (helper pred? arg count)
97 #f (_ "wrong type for argument ~a. Expecting ~a, found ~s")
98 count (type-name pred?) arg))
102 (if (null? signature)
104 (and (helper (car signature) (car arguments) count)
105 (recursion-helper (cdr signature) (cdr arguments) (1+ count)))))
106 (recursion-helper signature arguments 1))
108 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 ;;(define-public (output-framework) (write "hello\n"))
114 (define output-tex-module
115 (make-module 1021 (list (resolve-interface '(scm output-tex)))))
116 (define output-ps-module
117 (make-module 1021 (list (resolve-interface '(scm output-ps)))))
119 (define-public (ps-output-expression expr port)
120 (display (eval expr output-ps-module) port))
122 ;; TODO: generate this list by registering the stencil expressions
123 ;; stencil expressions should have docstrings.
124 (define-public (ly:all-stencil-expressions)
125 "Return list of stencil expressions."
153 ;; - generate this list by registering the output-backend-commands
154 ;; output-backend-commands should have docstrings.
155 ;; - remove hard copies in output-ps output-tex
156 (define-public (ly:all-output-backend-commands)
157 "Return list of output backend commands."
165 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
166 ;; Safe definitions utility
167 (define safe-objects (list))
169 (define-macro (define-safe-public arglist . body)
170 "Define a variable, export it, and mark it as safe, ie usable in LilyPond safe mode.
171 The syntax is the same as `define*-public'."
172 (define (get-symbol arg)
174 (get-symbol (car arg))
176 (let ((safe-symbol (get-symbol arglist)))
178 (define*-public ,arglist
180 (set! safe-objects (cons (cons ',safe-symbol ,safe-symbol)
185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
192 "define-music-types.scm"
195 "chord-ignatzek-names.scm"
197 "chord-generic-names.scm"
201 "music-functions.scm"
203 "define-music-properties.scm"
209 "define-context-properties.scm"
210 "translation-functions.scm"
220 "define-markup-commands.scm"
221 "define-grob-properties.scm"
223 "define-grob-interfaces.scm"
228 "backend-library.scm"
229 ;; must be after everything has been defined
233 (set! type-p-name-alist
235 (,boolean-or-symbol? . "boolean or symbol")
236 (,boolean? . "boolean")
238 (,grob-list? . "list of grobs")
239 (,hash-table? . "hash table")
240 (,input-port? . "input port")
241 (,integer? . "integer")
243 (,ly:context? . "context")
244 (,ly:dimension? . "dimension, in staff space")
245 (,ly:dir? . "direction")
246 (,ly:duration? . "duration")
247 (,ly:grob? . "layout object")
248 (,ly:input-location? . "input location")
249 (,ly:moment? . "moment")
250 (,ly:music? . "music")
251 (,ly:pitch? . "pitch")
252 (,ly:translator? . "translator")
253 (,ly:font-metric? . "font metric")
254 (,markup-list? . "list of markups")
255 (,markup? . "markup")
256 (,ly:music-list? . "list of music")
257 (,number-or-grob? . "number or grob")
258 (,number-or-string? . "number or string")
259 (,number-pair? . "pair of numbers")
260 (,number? . "number")
261 (,output-port? . "output port")
263 (,procedure? . "procedure")
264 (,scheme? . "any type")
265 (,string? . "string")
266 (,symbol? . "symbol")
267 (,vector? . "vector")))
272 (define gc-protect-stat-count 0)
273 (define-public (dump-gc-protects)
274 (set! gc-protect-stat-count (1+ gc-protect-stat-count))
275 (let* ((protects (sort
276 (hash-table->alist (ly:protects))
278 (< (object-address (car a))
279 (object-address (car b))))))
280 (out-file-name (string-append
281 "gcstat-" (number->string gc-protect-stat-count)
283 (outfile (open-file out-file-name "w")))
285 (display "Dumping gc protected objs to ...\n")
288 (lambda (x) (not (symbol? x)))
295 (map object->string (list (object-address x) c x))
302 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
304 (define-public (lilypond-main files)
305 "Entry point for LilyPond."
307 (handler (lambda (key failed-file)
308 (set! failed (append (list failed-file) failed)))))
309 ;;(handler (lambda (key . arg) (set! failed (append arg failed)))))
312 (catch 'ly-file-failed
313 (lambda () (ly:parse-file f))
314 (lambda (x . args) (handler x f)))
315 ;;(lambda (x) (handler x f)))
321 (ly:error (_ "failed files: ~S") (string-join failed))
323 ;; HACK: be sure to exit with single newline
327 (define-public (tweak-grob-property grob sym val)
328 (set! (ly:grob-property grob sym) val))