1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-15 08:10:17 +02:00

primitive-load returns the value(s) of the last expression

* libguile/load.c (scm_primitive_load): Return the values yielded from
  evaluating the last expression in the file.

* test-suite/tests/load.test ("return value of `load'"): Add tests.
This commit is contained in:
Andy Wingo 2012-01-09 16:07:46 +01:00
parent 9858e52962
commit 017eb4a6be
2 changed files with 25 additions and 7 deletions

View file

@ -87,7 +87,9 @@ SCM_DEFINE (scm_primitive_load, "primitive-load", 1, 0, 0,
#define FUNC_NAME s_scm_primitive_load
{
SCM hook = *scm_loc_load_hook;
SCM ret = SCM_UNSPECIFIED;
char *encoding;
SCM_VALIDATE_STRING (1, filename);
if (scm_is_true (hook) && scm_is_false (scm_procedure_p (hook)))
SCM_MISC_ERROR ("value of %load-hook is neither a procedure nor #f",
@ -96,8 +98,10 @@ SCM_DEFINE (scm_primitive_load, "primitive-load", 1, 0, 0,
if (!scm_is_false (hook))
scm_call_1 (hook, filename);
{ /* scope */
SCM port = scm_open_file (filename, scm_from_locale_string ("r"));
{
SCM port;
port = scm_open_file (filename, scm_from_locale_string ("r"));
scm_dynwind_begin (SCM_F_DYNWIND_REWINDABLE);
scm_i_dynwind_current_load_port (port);
@ -124,13 +128,13 @@ SCM_DEFINE (scm_primitive_load, "primitive-load", 1, 0, 0,
if (SCM_EOF_OBJECT_P (form))
break;
scm_primitive_eval_x (form);
ret = scm_primitive_eval_x (form);
}
scm_dynwind_end ();
scm_close_port (port);
}
return SCM_UNSPECIFIED;
return ret;
}
#undef FUNC_NAME