1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-29 14:30:34 +02:00

refactors to load.c to support auto-compilation

* libguile/load.c (compiled_is_newer): Factored out of
  scm_primitive_load_path.
  (scm_try_autocompile): New stub, for autocompiling. Currently just
  returns false.
  (scm_primitive_load_path): Refactor, and call out to
  scm_try_autocompile if the .go is missing or not fresh.
This commit is contained in:
Andy Wingo 2009-06-03 09:24:35 +02:00
parent f3130a2ecf
commit 1d022387c8

View file

@ -549,6 +549,43 @@ SCM_DEFINE (scm_sys_search_load_path, "%search-load-path", 1, 0, 0,
#undef FUNC_NAME #undef FUNC_NAME
static int
compiled_is_newer (SCM full_filename, SCM compiled_filename)
{
char *source, *compiled;
struct stat stat_source, stat_compiled;
int res;
source = scm_to_locale_string (full_filename);
compiled = scm_to_locale_string (compiled_filename);
if (stat (source, &stat_source) == 0
&& stat (compiled, &stat_compiled) == 0
&& stat_source.st_mtime <= stat_compiled.st_mtime)
{
res = 1;
}
else
{
scm_puts (";;; note: source file ", scm_current_error_port ());
scm_puts (source, scm_current_error_port ());
scm_puts (" newer than compiled ", scm_current_error_port ());
scm_puts (compiled, scm_current_error_port ());
scm_puts ("\n", scm_current_error_port ());
res = 0;
}
free (source);
free (compiled);
return res;
}
static SCM
scm_try_autocompile (SCM source)
{
return SCM_BOOL_F;
}
SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 1, 0, 0, SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 1, 0, 0,
(SCM filename), (SCM filename),
"Search @var{%load-path} for the file named @var{filename} and\n" "Search @var{%load-path} for the file named @var{filename} and\n"
@ -569,40 +606,16 @@ SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 1, 0, 0,
SCM_MISC_ERROR ("Unable to find file ~S in load path", SCM_MISC_ERROR ("Unable to find file ~S in load path",
scm_list_1 (filename)); scm_list_1 (filename));
if (scm_is_false (compiled_filename)) if (scm_is_false (full_filename)
/* FIXME: autocompile here */ || (scm_is_true (compiled_filename)
return scm_primitive_load (full_filename); && compiled_is_newer (full_filename, compiled_filename)))
if (scm_is_false (full_filename))
return scm_load_compiled_with_vm (compiled_filename); return scm_load_compiled_with_vm (compiled_filename);
{ compiled_filename = scm_try_autocompile (full_filename);
char *source, *compiled; if (scm_is_true (compiled_filename))
struct stat stat_source, stat_compiled; return scm_load_compiled_with_vm (compiled_filename);
else
source = scm_to_locale_string (full_filename); return scm_primitive_load (full_filename);
compiled = scm_to_locale_string (compiled_filename);
if (stat (source, &stat_source) == 0
&& stat (compiled, &stat_compiled) == 0
&& stat_source.st_mtime <= stat_compiled.st_mtime)
{
free (source);
free (compiled);
return scm_load_compiled_with_vm (compiled_filename);
}
else
{
scm_puts (";;; note: source file ", scm_current_error_port ());
scm_puts (source, scm_current_error_port ());
scm_puts (" newer than compiled ", scm_current_error_port ());
scm_puts (compiled, scm_current_error_port ());
scm_puts ("\n", scm_current_error_port ());
free (source);
free (compiled);
return scm_primitive_load (full_filename);
}
}
} }
#undef FUNC_NAME #undef FUNC_NAME