From ccebc5251f08d30ac854c7a540f283d2376dca7c Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sun, 6 Nov 2011 19:13:50 +0100 Subject: [PATCH] Permit ly:parser-clone to receive an environment --- lily/include/lily-parser.hh | 3 ++- lily/lily-parser-scheme.cc | 4 ++-- lily/lily-parser.cc | 5 ++++- lily/parse-scm.cc | 4 +++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lily/include/lily-parser.hh b/lily/include/lily-parser.hh index 9839d38f4d..a98c760712 100644 --- a/lily/include/lily-parser.hh +++ b/lily/include/lily-parser.hh @@ -50,13 +50,14 @@ public: Sources *sources_; Duration default_duration_; string output_basename_; + SCM local_environment_; int fatal_error_; int error_level_; bool ignore_version_b_; Lily_parser (Sources *sources); - Lily_parser (Lily_parser const &); + Lily_parser (Lily_parser const &, SCM env = SCM_UNDEFINED); DECLARE_SCHEME_CALLBACK (layout_description, ()); diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc index a5a4e6858f..50f02051b2 100644 --- a/lily/lily-parser-scheme.cc +++ b/lily/lily-parser-scheme.cc @@ -146,12 +146,12 @@ LY_DEFINE (ly_parser_lexer, "ly:parser-lexer", } LY_DEFINE (ly_parser_clone, "ly:parser-clone", - 1, 0, 0, (SCM parser_smob), + 1, 1, 0, (SCM parser_smob, SCM local_environment), "Return a clone of @var{parser-smob}.") { LY_ASSERT_SMOB (Lily_parser, parser_smob, 1); Lily_parser *parser = unsmob_lily_parser (parser_smob); - Lily_parser *clone = new Lily_parser (*parser); + Lily_parser *clone = new Lily_parser (*parser, local_environment); return clone->unprotect (); } diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index 12646bb3b4..d9af8cbb7e 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -44,6 +44,7 @@ Lily_parser::Lily_parser (Sources *sources) sources_ = sources; default_duration_ = Duration (2, 0); error_level_ = 0; + local_environment_ = SCM_UNDEFINED; smobify_self (); @@ -51,13 +52,14 @@ Lily_parser::Lily_parser (Sources *sources) lexer_->unprotect (); } -Lily_parser::Lily_parser (Lily_parser const &src) +Lily_parser::Lily_parser (Lily_parser const &src, SCM env) { lexer_ = 0; sources_ = src.sources_; default_duration_ = src.default_duration_; error_level_ = src.error_level_; output_basename_ = src.output_basename_; + local_environment_ = env; smobify_self (); if (src.lexer_) @@ -76,6 +78,7 @@ SCM Lily_parser::mark_smob (SCM s) { Lily_parser *parser = (Lily_parser *) SCM_CELL_WORD_1 (s); + scm_gc_mark (parser->local_environment_); return (parser->lexer_) ? parser->lexer_->self_scm () : SCM_EOL; } diff --git a/lily/parse-scm.cc b/lily/parse-scm.cc index f5092675b3..0905a8b17e 100644 --- a/lily/parse-scm.cc +++ b/lily/parse-scm.cc @@ -55,7 +55,9 @@ internal_ly_parse_scm (Parse_start *ps) /* Read expression from port. */ if (!SCM_EOF_OBJECT_P (form)) { - if (ps->safe_) + if (ps->parser_ && !SCM_UNBNDP (ps->parser_->local_environment_)) + answer = scm_local_eval (form, ps->parser_->local_environment_); + else if (ps->safe_) { static SCM module = SCM_BOOL_F; if (module == SCM_BOOL_F) -- 2.39.5