From 89bff2fc106ccde319e48488ff26c824dd8529f4 Mon Sep 17 00:00:00 2001 From: Dirk Herrmann Date: Sat, 1 Nov 2003 07:26:44 +0000 Subject: [PATCH] * libguile/eval.c (s_expression): Added comment. (s_empty_combination, error_unbound_variable): New static identifiers. (SCM_VALIDATE_NON_EMPTY_COMBINATION, SCM_EVALIM2, scm_lookupcar1): Use ASSERT_SYNTAX, syntax_error or error_unbound_variable to signal syntax errors. (SCM_CEVAL): Separated handling of evaluator bytecodes and other scheme objects. * test-suite/tests/syntax.test (exception:missing/extra-expr-misc): Removed. (exception:illegal-empty-combination): New. (exception:missing/extra-expr): Unified capitalization. Adapted test for '()' to the new way of error reporting. --- libguile/ChangeLog | 14 ++++++++++ libguile/eval.c | 51 +++++++++++++++++++++++++----------- test-suite/ChangeLog | 10 +++++++ test-suite/tests/syntax.test | 8 +++--- 4 files changed, 63 insertions(+), 20 deletions(-) diff --git a/libguile/ChangeLog b/libguile/ChangeLog index d22bdad03..d1b8df801 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,17 @@ +2003-11-01 Dirk Herrmann + + * eval.c (s_expression): Added comment. + + (s_empty_combination, error_unbound_variable): New static + identifiers. + + (SCM_VALIDATE_NON_EMPTY_COMBINATION, SCM_EVALIM2, scm_lookupcar1): + Use ASSERT_SYNTAX, syntax_error or error_unbound_variable to + signal syntax errors. + + (SCM_CEVAL): Separated handling of evaluator bytecodes and other + scheme objects. + 2003-10-25 Dirk Herrmann * eval.c (unmemocar, sym_three_question_marks, scm_unmemocar): diff --git a/libguile/eval.c b/libguile/eval.c index 38e33826b..a51455b3f 100644 --- a/libguile/eval.c +++ b/libguile/eval.c @@ -101,6 +101,11 @@ char *alloca (); * expression is expected, a 'Bad expression' error is signalled. */ static const char s_bad_expression[] = "Bad expression"; +/* If a form is detected that holds a different number of expressions than are + * required in that context, a 'Missing or extra expression' error is + * signalled. */ +static const char s_expression[] = "Missing or extra expression in"; + /* If a form is detected that holds less expressions than are required in that * context, a 'Missing expression' error is signalled. */ static const char s_missing_expression[] = "Missing expression in"; @@ -109,6 +114,13 @@ static const char s_missing_expression[] = "Missing expression in"; * context, an 'Extra expression' error is signalled. */ static const char s_extra_expression[] = "Extra expression in"; +/* The empty combination '()' is not allowed as an expression in scheme. If + * it is detected in a place where an expression is expected, an 'Illegal + * empty combination' error is signalled. Note: If you encounter this error + * message, it is very likely that you intended to denote the empty list. To + * do so, you need to quote the empty list like (quote ()) or '(). */ +static const char s_empty_combination[] = "Illegal empty combination"; + /* Case or cond expressions must have at least one clause. If a case or cond * expression without any clauses is detected, a 'Missing clauses' error is * signalled. */ @@ -327,10 +339,7 @@ SCM_DEFINE (scm_dbg_iloc_p, "dbg-iloc?", 1, 0, 0, #define SCM_VALIDATE_NON_EMPTY_COMBINATION(x) \ - do { \ - if (SCM_EQ_P ((x), SCM_EOL)) \ - scm_misc_error (NULL, s_expression, SCM_EOL); \ - } while (0) + ASSERT_SYNTAX (!SCM_EQ_P ((x), SCM_EOL), s_empty_combination, x) @@ -367,7 +376,7 @@ SCM_DEFINE (scm_dbg_iloc_p, "dbg-iloc?", 1, 0, 0, #define SCM_EVALIM2(x) \ ((SCM_EQ_P ((x), SCM_EOL) \ - ? scm_misc_error (NULL, s_expression, SCM_EOL), 0 \ + ? syntax_error (s_empty_combination, (x), SCM_UNDEFINED), 0 \ : 0), \ (x)) @@ -394,7 +403,6 @@ SCM_DEFINE (scm_dbg_iloc_p, "dbg-iloc?", 1, 0, 0, SCM_REC_MUTEX (source_mutex); -static const char s_expression[] = "missing or extra expression"; static const char s_test[] = "bad test"; static const char s_body[] = "bad body"; static const char s_bindings[] = "bad bindings"; @@ -431,6 +439,18 @@ scm_ilookup (SCM iloc, SCM env) } +SCM_SYMBOL (scm_unbound_variable_key, "unbound-variable"); + +static void error_unbound_variable (SCM symbol) SCM_NORETURN; +static void +error_unbound_variable (SCM symbol) +{ + scm_error (scm_unbound_variable_key, NULL, + "Unbound variable: ~S", + scm_list_1 (symbol), SCM_BOOL_F); +} + + /* The Lookup Car Race - by Eva Luator @@ -504,8 +524,6 @@ scm_ilookup (SCM iloc, SCM env) for NULL. I think I've found the only places where this applies. */ -SCM_SYMBOL (scm_unbound_variable_key, "unbound-variable"); - static SCM * scm_lookupcar1 (SCM vloc, SCM genv, int check) { @@ -568,9 +586,7 @@ scm_lookupcar1 (SCM vloc, SCM genv, int check) if (check) { if (SCM_NULLP (env)) - scm_error (scm_unbound_variable_key, NULL, - "Unbound variable: ~S", - scm_list_1 (var), SCM_BOOL_F); + error_unbound_variable (var); else scm_misc_error (NULL, "Damaged environment: ~S", scm_list_1 (var)); @@ -1840,6 +1856,7 @@ scm_m_expand_body (SCM xorig, SCM env) return xorig; } + SCM scm_macroexp (SCM x, SCM env) { @@ -2602,11 +2619,6 @@ dispatch: SCM_TICK; switch (SCM_TYP7 (x)) { - case scm_tc7_symbol: - /* Only happens when called at top level. */ - x = scm_cons (x, SCM_UNDEFINED); - RETURN (*scm_lookupcar (x, env, 1)); - case SCM_BIT7 (SCM_IM_AND): x = SCM_CDR (x); while (!SCM_NULLP (SCM_CDR (x))) @@ -3286,10 +3298,12 @@ dispatch: goto evapply; } + default: proc = x; goto evapply; + case scm_tc7_vector: case scm_tc7_wvect: #if SCM_HAVE_ARRAYS @@ -3315,6 +3329,11 @@ dispatch: case scm_tcs_struct: RETURN (x); + case scm_tc7_symbol: + /* Only happens when called at top level. */ + x = scm_cons (x, SCM_UNDEFINED); + RETURN (*scm_lookupcar (x, env, 1)); + case scm_tc7_variable: RETURN (SCM_VARIABLE_REF(x)); diff --git a/test-suite/ChangeLog b/test-suite/ChangeLog index b86ae9572..0367d4da9 100644 --- a/test-suite/ChangeLog +++ b/test-suite/ChangeLog @@ -1,3 +1,13 @@ +2003-11-01 Dirk Herrmann + + * tests/syntax.test (exception:missing/extra-expr-misc): Removed. + + (exception:illegal-empty-combination): New. + + (exception:missing/extra-expr): Unified capitalization. + + Adapted test for '()' to the new way of error reporting. + 2003-10-19 Kevin Ryde * tests/numbers.test: Use define-module to hide helper defines. diff --git a/test-suite/tests/syntax.test b/test-suite/tests/syntax.test index 82ff4d980..9691f2bfc 100644 --- a/test-suite/tests/syntax.test +++ b/test-suite/tests/syntax.test @@ -24,14 +24,14 @@ (define exception:bad-expression (cons 'syntax-error "Bad expression")) -(define exception:missing/extra-expr-misc - (cons 'misc-error "^missing or extra expression")) (define exception:missing/extra-expr - (cons 'syntax-error "missing or extra expression")) + (cons 'syntax-error "Missing or extra expression")) (define exception:missing-expr (cons 'syntax-error "Missing expression")) (define exception:extra-expr (cons 'syntax-error "Extra expression")) +(define exception:illegal-empty-combination + (cons 'syntax-error "Illegal empty combination")) (define exception:bad-bindings (cons 'syntax-error "Bad bindings")) @@ -86,7 +86,7 @@ ;; Fixed on 2001-3-3 (pass-if-exception "empty parentheses \"()\"" - exception:missing/extra-expr-misc + exception:illegal-empty-combination (eval '() (interaction-environment)))))