making (config) an importable module

self-reference handled with new current-environment
This commit is contained in:
Alex Shinn 2010-07-19 22:31:09 +09:00
parent 5308e5b45b
commit d43cf9f6c2
3 changed files with 10 additions and 4 deletions

10
eval.c
View file

@ -12,8 +12,9 @@ static sexp analyze (sexp ctx, sexp x);
static void generate (sexp ctx, sexp x); static void generate (sexp ctx, sexp x);
#if SEXP_USE_MODULES #if SEXP_USE_MODULES
static sexp sexp_load_module_file_op (sexp ctx sexp_api_params(self, n), sexp file, sexp env); sexp sexp_load_module_file_op (sexp ctx sexp_api_params(self, n), sexp file, sexp env);
static sexp sexp_find_module_file_op (sexp ctx sexp_api_params(self, n), sexp file); sexp sexp_find_module_file_op (sexp ctx sexp_api_params(self, n), sexp file);
sexp sexp_current_environment (sexp ctx sexp_api_params(self, n));
#endif #endif
sexp sexp_compile_error (sexp ctx, const char *message, sexp o) { sexp sexp_compile_error (sexp ctx, const char *message, sexp o) {
@ -1511,7 +1512,7 @@ sexp sexp_load_module_file (sexp ctx, const char *file, sexp env) {
} }
#if SEXP_USE_MODULES #if SEXP_USE_MODULES
static sexp sexp_find_module_file_op (sexp ctx sexp_api_params(self, n), sexp file) { sexp sexp_find_module_file_op (sexp ctx sexp_api_params(self, n), sexp file) {
sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, file); sexp_assert_type(ctx, sexp_stringp, SEXP_STRING, file);
return sexp_find_module_file(ctx, sexp_string_data(file)); return sexp_find_module_file(ctx, sexp_string_data(file));
} }
@ -1520,6 +1521,9 @@ sexp sexp_load_module_file_op (sexp ctx sexp_api_params(self, n), sexp file, sex
sexp_assert_type(ctx, sexp_envp, SEXP_ENV, env); sexp_assert_type(ctx, sexp_envp, SEXP_ENV, env);
return sexp_load_module_file(ctx, sexp_string_data(file), env); return sexp_load_module_file(ctx, sexp_string_data(file), env);
} }
sexp sexp_current_environment (sexp ctx sexp_api_params(self, n)) {
return sexp_context_env(ctx);
}
#endif #endif
sexp sexp_add_module_directory_op (sexp ctx sexp_api_params(self, n), sexp dir, sexp appendp) { sexp sexp_add_module_directory_op (sexp ctx sexp_api_params(self, n), sexp dir, sexp appendp) {

View file

@ -1,5 +1,5 @@
;; config.scm -- configuration module ;; config.scm -- configuration module
;; Copyright (c) 2009 Alex Shinn. All rights reserved. ;; Copyright (c) 2009-2010 Alex Shinn. All rights reserved.
;; BSD-style license: http://synthcode.com/license.txt ;; BSD-style license: http://synthcode.com/license.txt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -168,6 +168,7 @@
(define *modules* (define *modules*
(list (cons '(scheme) (make-module #f (interaction-environment) '())) (list (cons '(scheme) (make-module #f (interaction-environment) '()))
(cons '(config) (make-module #f (current-environment) '()))
(cons '(srfi 0) (make-module (list 'cond-expand) (cons '(srfi 0) (make-module (list 'cond-expand)
(interaction-environment) (interaction-environment)
(list (list 'export 'cond-expand)))) (list (list 'export 'cond-expand))))

View file

@ -163,6 +163,7 @@ _FN3(SEXP_STRING, SEXP_FIXNUM, "make-setter", 0, sexp_make_setter_op),
#include "opt/plan9-opcodes.c" #include "opt/plan9-opcodes.c"
#endif #endif
#if SEXP_USE_MODULES #if SEXP_USE_MODULES
_FN0("current-environment", 0, sexp_current_environment),
_FN1(SEXP_ENV, "env-exports", 0, sexp_env_exports_op), _FN1(SEXP_ENV, "env-exports", 0, sexp_env_exports_op),
_FN1(SEXP_STRING, "find-module-file", 0, sexp_find_module_file_op), _FN1(SEXP_STRING, "find-module-file", 0, sexp_find_module_file_op),
_FN2(SEXP_STRING, SEXP_ENV, "load-module-file", 0, sexp_load_module_file_op), _FN2(SEXP_STRING, SEXP_ENV, "load-module-file", 0, sexp_load_module_file_op),