diff --git a/mes/module/mes/repl.mes b/mes/module/mes/repl.mes index 45833288..fb38df29 100644 --- a/mes/module/mes/repl.mes +++ b/mes/module/mes/repl.mes @@ -126,6 +126,26 @@ along with GNU Mes. If not, see . (newline)) (core:macro-expand sexp)))) + (define (load-env file-name a) + (push! *input-ports* (current-input-port)) + (set-current-input-port + (open-input-file file-name)) + (let ((x (core:eval (append2 (cons 'begin (read-input-file-env a)) + '((current-module))) + a))) + (set-current-input-port (pop! *input-ports*)) + x)) + + (define (mes-load-module-env module a) + (push! *input-ports* (current-input-port)) + (set-current-input-port + (open-input-file (string-append %moduledir (module->file module)))) + (let ((x (core:eval (append2 (cons 'begin (read-input-file-env a)) + '((current-module))) + a))) + (set-current-input-port (pop! *input-ports*)) + x)) + (define (help . x) (display help-commands) *unspecified*) (define (show . x) (define topic-alist `((#\newline . ,show-commands) @@ -140,7 +160,8 @@ along with GNU Mes. If not, see . (define (use a) (lambda () (let ((module (read))) - (mes-load-module-env module a)))) + (mes-load-module-env module a) + module))) (define (meta command a) (let ((command-alist `((expand . ,(expand a)) (help . ,help) @@ -163,19 +184,26 @@ along with GNU Mes. If not, see . (display sexp) (display "]") (newline)) - (if (and (pair? sexp) (eq? (car sexp) 'mes-use-module)) - (loop (mes-load-module-env (cadr sexp) a)) - (let ((e (if (and (pair? sexp) (eq? (car sexp) (string->symbol "unquote"))) - (meta (cadr sexp) a) - (core:eval sexp a)))) - (if (eq? e *unspecified*) (loop a) - (let ((id (string->symbol (string-append "$" (number->string count))))) - (set! count (+ count 1)) - (display id) - (display " = ") - (write e) - (newline) - (loop (acons id e a))))))))) + (cond + ((and (pair? sexp) (eq? (car sexp) 'mes-use-module)) + (let ((module (cadr sexp))) + (mes-load-module-env module a) + (loop a))) + ((and (pair? sexp) (memq (car sexp) '(include load))) + (load-env (cadr sexp) a) + (loop a)) + (else + (let ((e (if (and (pair? sexp) (eq? (car sexp) (string->symbol "unquote"))) + (meta (cadr sexp) a) + (core:eval sexp a)))) + (if (eq? e *unspecified*) (loop a) + (let ((id (string->symbol (string-append "$" (number->string count))))) + (set! count (+ count 1)) + (display id) + (display " = ") + (write e) + (newline) + (loop (acons id e a)))))))))) (lambda (key . args) (if (defined? 'with-output-to-string) (simple-format (current-error-port) "exception:~a:~a\n" key args)