[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/5] Remove parser/location global variable setup
From: |
David Kastrup |
Subject: |
[PATCH 1/5] Remove parser/location global variable setup |
Date: |
Wed, 27 May 2015 11:45:14 +0200 |
Instead of relying on the global parser/location work horse (or
respective symbols in local scope), now fluids %parser/%location and
getter functions (*parser*)/(*location*) are employed for setting up the
general parsing and providing #{...#} with accurate information.
This patch removes the global setup and internal information flow: there
is still a variable "parser" being set in local parser modules.
---
lily/parse-scm.cc | 16 +++++++++++-----
ly/init.ly | 17 ++++++++---------
scm/lily.scm | 15 +++++++++++++++
scm/parser-ly-from-scheme.scm | 4 ++--
4 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/lily/parse-scm.cc b/lily/parse-scm.cc
index ec0c157..08c67cc 100644
--- a/lily/parse-scm.cc
+++ b/lily/parse-scm.cc
@@ -146,15 +146,15 @@ protected_ly_parse_scm (Parse_start *ps)
}
SCM
-protected_ly_eval_scm (Parse_start *ps)
+protected_ly_eval_scm (void *ps)
{
/*
Catch #t : catch all Scheme level errors.
*/
return scm_internal_catch (SCM_BOOL_T,
catch_protected_eval_body,
- (void *) ps,
- &parse_handler, (void *) ps);
+ ps,
+ &parse_handler, ps);
}
bool parse_protect_global = true;
@@ -178,8 +178,14 @@ ly_eval_scm (SCM form, Input i, bool safe, Lily_parser
*parser)
{
Parse_start ps (form, i, safe, parser);
- SCM ans = parse_protect_global ? protected_ly_eval_scm (&ps)
- : internal_ly_eval_scm (&ps);
+ SCM ans = scm_c_with_fluids
+ (scm_list_2 (ly_lily_module_constant ("%parser"),
+ ly_lily_module_constant ("%location")),
+ scm_list_2 (parser->self_scm (),
+ i.smobbed_copy ()),
+ parse_protect_global ? protected_ly_eval_scm
+ : catch_protected_eval_body, (void *) &ps);
+
scm_remember_upto_here_1 (form);
return ans;
}
diff --git a/ly/init.ly b/ly/init.ly
index d014a40..5075d71 100644
--- a/ly/init.ly
+++ b/ly/init.ly
@@ -17,12 +17,11 @@
;; function has not actually started. A parser clone, in contrast,
;; can run and complete synchronously and shares the module with
;; the current parser.
- (ly:parser-parse-string (ly:parser-clone parser)
+ (ly:parser-parse-string (ly:parser-clone (*parser*))
"\\include \"declarations-init.ly\"")))
-#(note-names-language parser default-language)
+#(note-names-language (*parser*) default-language)
-#(define location #f)
#(define toplevel-scores (list))
#(define toplevel-bookparts (list))
#(define $defaultheader #f)
@@ -38,7 +37,7 @@
#(use-modules (ice-9 pretty-print))
$(if (ly:get-option 'include-settings)
- (ly:parser-include-string parser
+ (ly:parser-include-string (*parser*)
(format #f "\\include \"~a\"" (ly:get-option 'include-settings))))
\maininput
@@ -69,14 +68,14 @@ $(if (ly:get-option 'include-settings)
(ly:book-add-score! book score))
(reverse! toplevel-scores)))
(set! toplevel-scores (list))
- (book-handler parser book)))
+ (book-handler (*parser*) book)))
((or (pair? toplevel-scores) output-empty-score-list)
(let ((book (apply ly:make-book $defaultpaper
$defaultheader toplevel-scores)))
(set! toplevel-scores (list))
- (book-handler parser book)))))
+ (book-handler (*parser*) book)))))
-#(if (eq? expect-error (ly:parser-has-error? parser))
- (ly:parser-clear-error parser)
+#(if (eq? expect-error (ly:parser-has-error? (*parser*)))
+ (ly:parser-clear-error (*parser*))
(if expect-error
- (ly:parser-error parser (_ "expected error, but none found"))))
+ (ly:parser-error (*parser*) (_ "expected error, but none found"))))
diff --git a/scm/lily.scm b/scm/lily.scm
index 27ba76a..b2283e5 100644
--- a/scm/lily.scm
+++ b/scm/lily.scm
@@ -43,6 +43,21 @@
(string-downcase
(car (string-tokenize (utsname:sysname (uname)) char-set:letter)))))
+;; We don't use (srfi srfi-39) (parameter objects) here because that
+;; does not give us a name/handle to the underlying fluids themselves.
+
+(define %parser (make-fluid))
+(define %location (make-fluid))
+;; No public setters: should not get overwritten in action
+(define-public (*parser*) (fluid-ref %parser))
+(define-public (*location*) (fluid-ref %location))
+
+;; It would be nice to convert occurences of parser/location to
+;; (*parser*)/(*location*) using the syncase module but it is utterly
+;; broken in GUILE 1 and would require changing a lot of unrelated
+;; innocuous constructs which just happen to fall apart with
+;; inscrutable error messages.
+
;;
;; Session-handling variables and procedures.
;;
diff --git a/scm/parser-ly-from-scheme.scm b/scm/parser-ly-from-scheme.scm
index dd3e698..7322d9b 100644
--- a/scm/parser-ly-from-scheme.scm
+++ b/scm/parser-ly-from-scheme.scm
@@ -74,8 +74,8 @@ from @var{port} and return the corresponding Scheme music
expression.
(ly:parser-error parser (_ "error in #{ ... #}")))
result))
(list embedded-lilypond
- 'parser lily-string filename line
+ (list *parser*) lily-string filename line
(cons 'list (reverse! closures))
- 'location)))
+ (list *location*))))
(read-hash-extend #\{ read-lily-expression)
--
2.1.4
- [PATCH 1/5] Remove parser/location global variable setup,
David Kastrup <=
- [PATCH 2/5] Fix various jumbled parser/location argument pairs, David Kastrup, 2015/05/27
- [PATCH 3/5] Remove parser/location args from music function calls, David Kastrup, 2015/05/27
- [PATCH 4/5] convert-ly rule for removing parser/location, David Kastrup, 2015/05/27
- [PATCH 5/5] Run scripts/auxiliar/update-with-convert-ly.sh, David Kastrup, 2015/05/27
- Re: [PATCH 1/5] Remove parser/location global variable setup, David Kastrup, 2015/05/27
- Re: [PATCH 1/5] Remove parser/location global variable setup, Dan Eble, 2015/05/27