2009-09-10 23:58:57 +02:00
|
|
|
|
;;; -*- mode: scheme; coding: utf-8; -*-
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2010-01-11 18:30:13 +01:00
|
|
|
|
;;;; Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;; Free Software Foundation, Inc.
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;;;
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; This library is free software; you can redistribute it and/or
|
|
|
|
|
|
;;;; modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
|
;;;; License as published by the Free Software Foundation; either
|
2009-06-17 00:22:09 +01:00
|
|
|
|
;;;; version 3 of the License, or (at your option) any later version.
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; This library is distributed in the hope that it will be useful,
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
;;;; Lesser General Public License for more details.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
;;;; License along with this library; if not, write to the Free Software
|
2005-05-23 19:57:22 +00:00
|
|
|
|
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-06-03 23:29:45 +00:00
|
|
|
|
;;;;
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; This file is the first thing loaded into Guile. It adds many mundane
|
|
|
|
|
|
;;; definitions and a few that are interesting.
|
|
|
|
|
|
;;;
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;; The module system (hence the hierarchical namespace) are defined in this
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; file.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
2001-05-02 00:59:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-04-24 23:10:31 +02:00
|
|
|
|
;; Before compiling, make sure any symbols are resolved in the (guile)
|
|
|
|
|
|
;; module, the primary location of those symbols, rather than in
|
|
|
|
|
|
;; (guile-user), the default module that we compile in.
|
|
|
|
|
|
|
|
|
|
|
|
(eval-when (compile)
|
|
|
|
|
|
(set-current-module (resolve-module '(guile))))
|
|
|
|
|
|
|
catch, throw, with-throw-handler implemented in Scheme
* libguile/throw.c (tc16_jmpbuffer, tc16_pre_unwind_data): Remove these
smob types, and associated constructors and accessors (all internal).
(scm_catch, scm_catch_with_pre_unwind_handler):
(scm_with_throw_handler, scm_throw): Simply dispatch to scheme.
Lovely.
(tc16_catch_closure): Introduce a new applicable smob type, for use by
the C catch interface. All constructors and accessors are internal.
(scm_c_catch, scm_internal_catch, scm_c_with_throw_handler): Build
applicable smobs out of the C procedure arguments, so we can then
dispatch through scm_catch et al.
(scm_ithrow): Dispatch to scm_throw.
(pre_init_catch, pre_init_throw): Restricted catch/throw
implementation for use before boot-9 runs.
(scm_init_throw): Bind the pre-init catch and throw definitions.
* module/ice-9/boot-9.scm (prompt, abort): Move these definitions up in
the file.
(catch, throw, with-throw-handler): Implement in Scheme. Whee!
2010-01-31 13:02:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Error handling}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; Define delimited continuation operators, and implement catch and throw in
|
|
|
|
|
|
;; terms of them.
|
|
|
|
|
|
|
|
|
|
|
|
(define (prompt tag thunk handler)
|
|
|
|
|
|
(@prompt tag (thunk) handler))
|
|
|
|
|
|
(define (abort tag . args)
|
|
|
|
|
|
(@abort tag args))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Define catch and with-throw-handler, using some common helper routines and a
|
|
|
|
|
|
;; shared fluid. Hide the helpers in a lexical contour.
|
|
|
|
|
|
|
|
|
|
|
|
(let ()
|
|
|
|
|
|
;; Ideally we'd like to be able to give these default values for all threads,
|
|
|
|
|
|
;; even threads not created by Guile; but alack, that does not currently seem
|
|
|
|
|
|
;; possible. So wrap the getters in thunks.
|
|
|
|
|
|
(define %running-exception-handlers (make-fluid))
|
|
|
|
|
|
(define %exception-handler (make-fluid))
|
|
|
|
|
|
|
|
|
|
|
|
(define (running-exception-handlers)
|
|
|
|
|
|
(or (fluid-ref %running-exception-handlers)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(fluid-set! %running-exception-handlers '())
|
|
|
|
|
|
'())))
|
|
|
|
|
|
(define (exception-handler)
|
|
|
|
|
|
(or (fluid-ref %exception-handler)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(fluid-set! %exception-handler default-exception-handler)
|
|
|
|
|
|
default-exception-handler)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (default-exception-handler k . args)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((eq? k 'quit)
|
|
|
|
|
|
(primitive-exit (cond
|
|
|
|
|
|
((not (pair? args)) 0)
|
|
|
|
|
|
((integer? (car args)) (car args))
|
|
|
|
|
|
((not (car args)) 1)
|
|
|
|
|
|
(else 0))))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(format (current-error-port) "guile: uncaught throw to ~a: ~a\n" k args)
|
|
|
|
|
|
(primitive-exit 1))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (default-throw-handler prompt-tag catch-k)
|
|
|
|
|
|
(let ((prev (exception-handler)))
|
|
|
|
|
|
(lambda (thrown-k . args)
|
|
|
|
|
|
(if (or (eq? thrown-k catch-k) (eqv? catch-k #t))
|
|
|
|
|
|
(apply abort prompt-tag thrown-k args)
|
|
|
|
|
|
(apply prev thrown-k args)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (custom-throw-handler prompt-tag catch-k pre)
|
|
|
|
|
|
(let ((prev (exception-handler)))
|
|
|
|
|
|
(lambda (thrown-k . args)
|
|
|
|
|
|
(if (or (eq? thrown-k catch-k) (eqv? catch-k #t))
|
|
|
|
|
|
(let ((running (running-exception-handlers)))
|
|
|
|
|
|
(with-fluids ((%running-exception-handlers (cons pre running)))
|
|
|
|
|
|
(if (not (memq pre running))
|
|
|
|
|
|
(apply pre thrown-k args))
|
|
|
|
|
|
;; fall through
|
|
|
|
|
|
(if prompt-tag
|
|
|
|
|
|
(apply abort prompt-tag thrown-k args)
|
|
|
|
|
|
(apply prev thrown-k args))))
|
|
|
|
|
|
(apply prev thrown-k args)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define! 'catch
|
|
|
|
|
|
;; Until we get optargs support into Guile's C evaluator, we have to fake it
|
|
|
|
|
|
;; here.
|
|
|
|
|
|
(lambda (k thunk handler . pre-unwind-handler)
|
|
|
|
|
|
"Invoke @var{thunk} in the dynamic context of @var{handler} for
|
|
|
|
|
|
exceptions matching @var{key}. If thunk throws to the symbol
|
|
|
|
|
|
@var{key}, then @var{handler} is invoked this way:
|
|
|
|
|
|
@lisp
|
|
|
|
|
|
(handler key args ...)
|
|
|
|
|
|
@end lisp
|
|
|
|
|
|
|
|
|
|
|
|
@var{key} is a symbol or @code{#t}.
|
|
|
|
|
|
|
|
|
|
|
|
@var{thunk} takes no arguments. If @var{thunk} returns
|
|
|
|
|
|
normally, that is the return value of @code{catch}.
|
|
|
|
|
|
|
|
|
|
|
|
Handler is invoked outside the scope of its own @code{catch}.
|
|
|
|
|
|
If @var{handler} again throws to the same key, a new handler
|
|
|
|
|
|
from further up the call chain is invoked.
|
|
|
|
|
|
|
|
|
|
|
|
If the key is @code{#t}, then a throw to @emph{any} symbol will
|
|
|
|
|
|
match this call to @code{catch}.
|
|
|
|
|
|
|
|
|
|
|
|
If a @var{pre-unwind-handler} is given and @var{thunk} throws
|
|
|
|
|
|
an exception that matches @var{key}, Guile calls the
|
|
|
|
|
|
@var{pre-unwind-handler} before unwinding the dynamic state and
|
|
|
|
|
|
invoking the main @var{handler}. @var{pre-unwind-handler} should
|
|
|
|
|
|
be a procedure with the same signature as @var{handler}, that
|
|
|
|
|
|
is @code{(lambda (key . args))}. It is typically used to save
|
|
|
|
|
|
the stack at the point where the exception occurred, but can also
|
|
|
|
|
|
query other parts of the dynamic state at that point, such as
|
|
|
|
|
|
fluid values.
|
|
|
|
|
|
|
|
|
|
|
|
A @var{pre-unwind-handler} can exit either normally or non-locally.
|
|
|
|
|
|
If it exits normally, Guile unwinds the stack and dynamic context
|
|
|
|
|
|
and then calls the normal (third argument) handler. If it exits
|
|
|
|
|
|
non-locally, that exit determines the continuation."
|
|
|
|
|
|
(if (not (or (symbol? k) (eqv? k #t)))
|
|
|
|
|
|
(scm-error "catch" 'wrong-type-arg
|
|
|
|
|
|
"Wrong type argument in position ~a: ~a"
|
|
|
|
|
|
(list 1 k) (list k)))
|
|
|
|
|
|
(let ((tag (gensym)))
|
|
|
|
|
|
(prompt tag
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(with-fluids
|
|
|
|
|
|
((%exception-handler
|
|
|
|
|
|
(if (null? pre-unwind-handler)
|
|
|
|
|
|
(default-throw-handler tag k)
|
|
|
|
|
|
(custom-throw-handler tag k
|
|
|
|
|
|
(car pre-unwind-handler)))))
|
|
|
|
|
|
(thunk)))
|
|
|
|
|
|
(lambda (cont k . args)
|
|
|
|
|
|
(apply handler k args))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define! 'with-throw-handler
|
|
|
|
|
|
(lambda (k thunk pre-unwind-handler)
|
|
|
|
|
|
"Add @var{handler} to the dynamic context as a throw handler
|
|
|
|
|
|
for key @var{key}, then invoke @var{thunk}."
|
|
|
|
|
|
(if (not (or (symbol? k) (eqv? k #t)))
|
|
|
|
|
|
(scm-error "with-throw-handler" 'wrong-type-arg
|
|
|
|
|
|
"Wrong type argument in position ~a: ~a"
|
|
|
|
|
|
(list 1 k) (list k)))
|
|
|
|
|
|
(with-fluids ((%exception-handler
|
|
|
|
|
|
(custom-throw-handler #f k pre-unwind-handler)))
|
|
|
|
|
|
(thunk))))
|
|
|
|
|
|
|
|
|
|
|
|
(define! 'throw
|
|
|
|
|
|
(lambda (key . args)
|
|
|
|
|
|
"Invoke the catch form matching @var{key}, passing @var{args} to the
|
|
|
|
|
|
@var{handler}.
|
|
|
|
|
|
|
|
|
|
|
|
@var{key} is a symbol. It will match catches of the same symbol or of @code{#t}.
|
|
|
|
|
|
|
|
|
|
|
|
If there is no handler at all, Guile prints an error and then exits."
|
|
|
|
|
|
(if (not (symbol? key))
|
|
|
|
|
|
((exception-handler) 'wrong-type-arg "throw"
|
|
|
|
|
|
"Wrong type argument in position ~a: ~a" (list 1 key) (list key))
|
|
|
|
|
|
(apply (exception-handler) key args)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-03-09 21:40:30 +01:00
|
|
|
|
;;; {R4RS compliance}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(primitive-load-path "ice-9/r4rs")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-04-22 22:23:43 +02:00
|
|
|
|
;;; {Simple Debugging Tools}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; peek takes any number of arguments, writes them to the
|
|
|
|
|
|
;; current ouput port, and returns the last argument.
|
|
|
|
|
|
;; It is handy to wrap around an expression to look at
|
|
|
|
|
|
;; a value each time is evaluated, e.g.:
|
|
|
|
|
|
;;
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;; (+ 10 (troublesome-fn))
|
|
|
|
|
|
;; => (+ 10 (pk 'troublesome-fn-returned (troublesome-fn)))
|
2009-04-22 22:23:43 +02:00
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (peek . stuff)
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(display ";;; ")
|
|
|
|
|
|
(write stuff)
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(car (last-pair stuff)))
|
|
|
|
|
|
|
|
|
|
|
|
(define pk peek)
|
|
|
|
|
|
|
new evaluator, y'all
* libguile/eval.c: So, ladies & gents, a new evaluator. It's similar to
the old one, in that we memoize and then evaluate, but in this
incarnation, memoization of an expression happens before evaluation,
not lazily as the expression is evaluated. This makes the evaluation
itself much cleaner, in addition to being threadsafe. In addition,
since this C evaluator will in the future just serve to bootstrap the
Scheme evaluator, we don't have to pay much concern for debugging
conveniences. So the environment is just a list of values, and the
memoizer pre-computes where it's going to find each individual value
in the environment.
Interface changes are commented below, with eval.h.
(scm_evaluator_traps): No need to reset the debug mode after rnning te
traps thing. But really, the whole traps system needs some love.
* libguile/memoize.h:
* libguile/memoize.c: New memoizer, which runs before evaluation,
checking all syntax before evaluation begins. Significantly, no
debugging information is left for lexical variables, which is not so
great for interactive debugging; perhaps we should change this to have
a var list in the future as per the classic interpreters. But it's
quite fast, and the resulting code is quite good. Also note that it
doesn't produce ilocs, memoized code is a smob whose type is in the
first word of the smob itself.
* libguile/eval.h (scm_sym_and, scm_sym_begin, scm_sym_case)
(scm_sym_cond, scm_sym_define, scm_sym_do, scm_sym_if, scm_sym_lambda)
(scm_sym_let, scm_sym_letstar, scm_sym_letrec, scm_sym_quote)
(scm_sym_quasiquote, scm_sym_unquote, scm_sym_uq_splicing, scm_sym_at)
(scm_sym_atat, scm_sym_atapply, scm_sym_atcall_cc)
(scm_sym_at_call_with_values, scm_sym_delay, scm_sym_eval_when)
(scm_sym_arrow, scm_sym_else, scm_sym_apply, scm_sym_set_x)
(scm_sym_args): Remove public declaration of these symbols.
(scm_ilookup, scm_lookupcar, scm_eval_car, scm_eval_body)
(scm_eval_args, scm_i_eval_x, scm_i_eval): Remove public declaration
of these functions.
(scm_ceval, scm_deval, scm_ceval_ptr): Remove declarations of these
deprecated functions.
(scm_i_print_iloc, scm_i_print_isym, scm_i_unmemocopy_expr)
(scm_i_unmemocopy_body): Remove declarations of these internal
functions.
(scm_primitive_eval_x, scm_eval_x): Redefine as macros for their less
destructive siblings.
* libguile/Makefile.am: Add memoize.[ch] to the build.
* libguile/debug.h (scm_debug_mode_p, scm_check_entry_p)
(scm_check_apply_p, scm_check_exit_p, scm_check_memoize_p)
(scm_debug_eframe_size): Remove these vars that were tied to the old
evaluator's execution model.
(SCM_RESET_DEBUG_MODE): Remove, no more need for this.
(SCM_MEMOIZEDP, SCM_MEMOIZED_EXP, SCM_MEMOIZED_ENV): Remove macros
referring to old memoized code representation.
(scm_local_eval, scm_procedure_environment, scm_memoized_environment)
(scm_make_memoized, scm_memoized_p): Remove functions operating on old
memoized code representation.
(scm_memcons, scm_mem_to_proc, scm_proc_to_mem): Remove debug-only
code for old evaluator.
* libguile/debug.c: Remove code to correspond with debug.h removals.
(scm_debug_options): No need to set the debug mode or frame limit
here, as we don't have C stack limits any more. Perhaps this is a bug,
but as long as we can compile eval.scm, we should be fine.
* libguile/init.c (scm_i_init_guile): Init memoize.c.
* libguile/modules.c (scm_top_level_env, scm_env_top_level)
(scm_env_module, scm_system_module_env_p): Remove these functions.
* libguile/print.c (iprin1): No more need to handle isyms. Adapt to new
form of interpreted procedures.
* libguile/procprop.c (scm_i_procedure_arity): Adapt to new form of
interpreted procedures.
* libguile/procs.c (scm_thunk_p): Adapt to new form of interpreted
procedures.
* libguile/procs.h (SCM_CLOSURE_FORMALS): Removed, this exists no more.
(SCM_CLOSURE_NUM_REQUIRED_ARGS, SCM_CLOSURE_HAS_REST_ARGS): New
accessors.
* libguile/srcprop.c (scm_source_properties, scm_source_property)
(scm_set_source_property_x): Remove special cases for memoized code.
* libguile/stacks.c (read_frame): Remove a source-property case for
interpreted code.
(NEXT_FRAME): Remove a case that I don't fully understand, that seems
to be designed to skip over apply frames. Will be obsolete in the
futures.
(read_frames): Default source value for interpreted frames to #f.
(narrow_stack): Don't pay attention to the system_module thing.
* libguile/tags.h: Remove isyms and ilocs. Whee!
* libguile/validate.h (SCM_VALIDATE_MEMOIZED): Fix to use the new
MEMOIZED_P formulation.
* module/ice-9/psyntax-pp.scm (do, quasiquote, case): Adapt for these no
longer being primitive macros.
* module/ice-9/boot-9.scm: Whitespace change, but just a poke to force a
rebuild due to and/or/cond/... not being primitives any more.
* module/ice-9/deprecated.scm (unmemoize-expr): Deprecate, it's
unmemoize-expression now.
* test-suite/tests/eval.test ("define set procedure-name"): XFAIL a
couple of tests here; I don't know what to do about them. I reckon the
expander should ensure that defined values are named.
* test-suite/tests/chars.test ("basic char handling"): Fix expected
exception when trying to apply a char.
2009-11-28 01:19:50 +01:00
|
|
|
|
|
2009-04-22 22:23:43 +02:00
|
|
|
|
(define (warn . stuff)
|
|
|
|
|
|
(with-output-to-port (current-error-port)
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(display ";;; WARNING ")
|
|
|
|
|
|
(display stuff)
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(car (last-pair stuff)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1996-11-02 20:51:30 +00:00
|
|
|
|
;;; {Features}
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
1996-11-02 20:51:30 +00:00
|
|
|
|
|
|
|
|
|
|
(define (provide sym)
|
|
|
|
|
|
(if (not (memq sym *features*))
|
|
|
|
|
|
(set! *features* (cons sym *features*))))
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;; Return #t iff FEATURE is available to this Guile interpreter. In SLIB,
|
|
|
|
|
|
;; provided? also checks to see if the module is available. We should do that
|
|
|
|
|
|
;; too, but don't.
|
|
|
|
|
|
|
1999-05-02 17:27:05 +00:00
|
|
|
|
(define (provided? feature)
|
|
|
|
|
|
(and (memq feature *features*) #t))
|
|
|
|
|
|
|
2009-04-29 23:12:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {and-map and or-map}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; (and-map fn lst) is like (and (fn (car lst)) (fn (cadr lst)) (fn...) ...)
|
|
|
|
|
|
;;; (or-map fn lst) is like (or (fn (car lst)) (fn (cadr lst)) (fn...) ...)
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; and-map f l
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Apply f to successive elements of l until exhaustion or f returns #f.
|
|
|
|
|
|
;; If returning early, return #f. Otherwise, return the last value returned
|
|
|
|
|
|
;; by f. If f has never been called because l is empty, return #t.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (and-map f lst)
|
|
|
|
|
|
(let loop ((result #t)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(l lst))
|
2009-04-29 23:12:12 +02:00
|
|
|
|
(and result
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(or (and (null? l)
|
|
|
|
|
|
result)
|
|
|
|
|
|
(loop (f (car l)) (cdr l))))))
|
2009-04-29 23:12:12 +02:00
|
|
|
|
|
|
|
|
|
|
;; or-map f l
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Apply f to successive elements of l until exhaustion or while f returns #f.
|
|
|
|
|
|
;; If returning early, return the return value of f.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (or-map f lst)
|
|
|
|
|
|
(let loop ((result #f)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(l lst))
|
2009-04-29 23:12:12 +02:00
|
|
|
|
(or result
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(and (not (null? l))
|
|
|
|
|
|
(loop (f (car l)) (cdr l))))))
|
2009-04-29 23:12:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;; let format alias simple-format until the more complete version is loaded
|
1999-09-26 16:00:36 +00:00
|
|
|
|
|
2000-01-11 18:52:25 +00:00
|
|
|
|
(define format simple-format)
|
|
|
|
|
|
|
2004-12-14 00:21:25 +00:00
|
|
|
|
;; this is scheme wrapping the C code so the final pred call is a tail call,
|
|
|
|
|
|
;; per SRFI-13 spec
|
|
|
|
|
|
(define (string-any char_pred s . rest)
|
|
|
|
|
|
(let ((start (if (null? rest)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
0 (car rest)))
|
|
|
|
|
|
(end (if (or (null? rest) (null? (cdr rest)))
|
|
|
|
|
|
(string-length s) (cadr rest))))
|
2004-12-14 00:21:25 +00:00
|
|
|
|
(if (and (procedure? char_pred)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(> end start)
|
|
|
|
|
|
(<= end (string-length s))) ;; let c-code handle range error
|
|
|
|
|
|
(or (string-any-c-code char_pred s start (1- end))
|
|
|
|
|
|
(char_pred (string-ref s (1- end))))
|
|
|
|
|
|
(string-any-c-code char_pred s start end))))
|
2004-12-14 00:21:25 +00:00
|
|
|
|
|
|
|
|
|
|
;; this is scheme wrapping the C code so the final pred call is a tail call,
|
|
|
|
|
|
;; per SRFI-13 spec
|
|
|
|
|
|
(define (string-every char_pred s . rest)
|
|
|
|
|
|
(let ((start (if (null? rest)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
0 (car rest)))
|
|
|
|
|
|
(end (if (or (null? rest) (null? (cdr rest)))
|
|
|
|
|
|
(string-length s) (cadr rest))))
|
2004-12-14 00:21:25 +00:00
|
|
|
|
(if (and (procedure? char_pred)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(> end start)
|
|
|
|
|
|
(<= end (string-length s))) ;; let c-code handle range error
|
|
|
|
|
|
(and (string-every-c-code char_pred s start (1- end))
|
|
|
|
|
|
(char_pred (string-ref s (1- end))))
|
|
|
|
|
|
(string-every-c-code char_pred s start end))))
|
2004-12-14 00:21:25 +00:00
|
|
|
|
|
2005-06-05 17:24:52 +00:00
|
|
|
|
;; A variant of string-fill! that we keep for compatability
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (substring-fill! str start end fill)
|
|
|
|
|
|
(string-fill! str fill start end))
|
|
|
|
|
|
|
Get Guile to be a little less chatty by default. The new user
should see as little clutter as possible.
* r4rs.scm (%load-verbosely): Make this #f by default.
* boot-9.scm (scm-repl-verbose): Make this #f by default.
(scm-style-repl): Don't run 'pk' on the value passed to quit.
* r4rs.scm: New file.
* boot-9.scm: Load r4rs.scm, first thing.
(OPEN_READ, OPEN_WRITE, OPEN_BOTH, *null-device*, open-input-file,
open-output-file, open-io-file, close-input-port,
close-output-port, close-io-port, call-with-input-file,
call-with-output-file, with-input-from-port, with-output-to-port,
with-error-to-port, with-input-from-file, with-output-to-file,
with-error-to-file, with-input-from-string, with-output-to-string,
with-error-to-string, the-eof-object): Definitions moved to
r4rs.scm. Not all of them are R4RS, but those that are use those
that are not.
(load, %load-verbosely, %load-announce): Moved, along with code to
set %load-hook, to r4rs.scm.
* boot-9.scm (integer?): Definition deleted, in favor of the one
present in libguile (which used to be called int?). I have no
idea why integer? didn't just call int? to begin with.
* boot-9.scm (<, <=, =, >, >=): Definitions in terms of <?, <=?,
=?, >?, and >=? deleted; they're defined that way by libguile now.
1996-10-29 03:47:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-04-29 22:50:45 +02:00
|
|
|
|
;; Define a minimal stub of the module API for psyntax, before modules
|
|
|
|
|
|
;; have booted.
|
2009-04-22 00:17:22 +02:00
|
|
|
|
(define (module-name x)
|
2009-04-24 13:50:14 +02:00
|
|
|
|
'(guile))
|
2009-04-29 21:19:23 +02:00
|
|
|
|
(define (module-define! module sym val)
|
|
|
|
|
|
(let ((v (hashq-ref (%get-pre-modules-obarray) sym)))
|
|
|
|
|
|
(if v
|
|
|
|
|
|
(variable-set! v val)
|
|
|
|
|
|
(hashq-set! (%get-pre-modules-obarray) sym
|
|
|
|
|
|
(make-variable val)))))
|
|
|
|
|
|
(define (module-ref module sym)
|
|
|
|
|
|
(let ((v (module-variable module sym)))
|
|
|
|
|
|
(if v (variable-ref v) (error "badness!" (pk module) (pk sym)))))
|
2009-04-29 22:50:45 +02:00
|
|
|
|
(define (resolve-module . args)
|
|
|
|
|
|
#f)
|
2009-04-29 21:19:23 +02:00
|
|
|
|
|
2009-04-29 23:39:09 +02:00
|
|
|
|
;; Input hook to syncase -- so that we might be able to pass annotated
|
|
|
|
|
|
;; expressions in. Currently disabled. Maybe we should just use
|
|
|
|
|
|
;; source-properties directly.
|
|
|
|
|
|
(define (annotation? x) #f)
|
|
|
|
|
|
|
|
|
|
|
|
;; API provided by psyntax
|
2009-04-26 20:36:58 +02:00
|
|
|
|
(define syntax-violation #f)
|
2009-04-26 20:56:24 +02:00
|
|
|
|
(define datum->syntax #f)
|
|
|
|
|
|
(define syntax->datum #f)
|
|
|
|
|
|
(define identifier? #f)
|
|
|
|
|
|
(define generate-temporaries #f)
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
(define bound-identifier=? #f)
|
|
|
|
|
|
(define free-identifier=? #f)
|
2009-04-29 00:38:12 +02:00
|
|
|
|
(define sc-expand #f)
|
|
|
|
|
|
|
2009-04-29 23:39:09 +02:00
|
|
|
|
;; $sc-expand is an implementation detail of psyntax. It is used by
|
|
|
|
|
|
;; expanded macros, to dispatch an input against a set of patterns.
|
2009-04-29 00:38:12 +02:00
|
|
|
|
(define $sc-dispatch #f)
|
|
|
|
|
|
|
2009-04-29 23:39:09 +02:00
|
|
|
|
;; Load it up!
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
(primitive-load-path "ice-9/psyntax-pp")
|
|
|
|
|
|
|
2009-04-29 23:39:09 +02:00
|
|
|
|
;; %pre-modules-transformer is the Scheme expander from now until the
|
|
|
|
|
|
;; module system has booted up.
|
2009-04-23 13:30:23 +02:00
|
|
|
|
(define %pre-modules-transformer sc-expand)
|
Get Guile to be a little less chatty by default. The new user
should see as little clutter as possible.
* r4rs.scm (%load-verbosely): Make this #f by default.
* boot-9.scm (scm-repl-verbose): Make this #f by default.
(scm-style-repl): Don't run 'pk' on the value passed to quit.
* r4rs.scm: New file.
* boot-9.scm: Load r4rs.scm, first thing.
(OPEN_READ, OPEN_WRITE, OPEN_BOTH, *null-device*, open-input-file,
open-output-file, open-io-file, close-input-port,
close-output-port, close-io-port, call-with-input-file,
call-with-output-file, with-input-from-port, with-output-to-port,
with-error-to-port, with-input-from-file, with-output-to-file,
with-error-to-file, with-input-from-string, with-output-to-string,
with-error-to-string, the-eof-object): Definitions moved to
r4rs.scm. Not all of them are R4RS, but those that are use those
that are not.
(load, %load-verbosely, %load-announce): Moved, along with code to
set %load-hook, to r4rs.scm.
* boot-9.scm (integer?): Definition deleted, in favor of the one
present in libguile (which used to be called int?). I have no
idea why integer? didn't just call int? to begin with.
* boot-9.scm (<, <=, =, >, >=): Definitions in terms of <?, <=?,
=?, >?, and >=? deleted; they're defined that way by libguile now.
1996-10-29 03:47:36 +00:00
|
|
|
|
|
and, or, cond etc use syntax-rules, compile scheme through tree-il
* libguile/vm-i-system.c:
* libguile/vm-engine.h (ASSERT_BOUND): New assertion, that a value is
bound. Used by local-ref and external-ref in paranoid mode.
* module/ice-9/boot-9.scm (and, or, cond, case, do): Since we are
switching to use psyntax as the first pass of the compiler, and perhaps
soon of the interpreter too, we need to make sure it expands out all
forms to primitive expressions. So define expanders for these derived
syntax forms, as in the R5RS report.
* module/ice-9/psyntax-pp.scm: Regenerate, with core forms fully
expanded.
* module/ice-9/psyntax.scm (build-void): New constructor, for making
undefined values.
(build-primref): Add in a hack so that primitive refs in the boot
module expand out to toplevel refs, not module refs.
(chi-void): Use build-void.
(if): Define an expander for if that calls build-conditional.
* module/language/scheme/compile-tree-il.scm (compile-tree-il): Use let*
so as not to depend on binding order for the result of
(current-module).
* module/language/scheme/spec.scm (scheme): Switch over to tree-il as the
primary intermediate language. Not yet fully tested, but at least it
can compile psyntax-pp.scm.
* module/language/tree-il/analyze.scm (analyze-lexicals): Arguments don't
count towards a function's nlocs.
* module/language/tree-il/compile-glil.scm (*comp-module*, compile-glil):
Define a "compilation module" fluid.
(flatten-lambda): Fix a call to make-glil-argument. Fix bug in
heapifying arguments.
(flatten): Fix number of arguments passed to apply instruction. Add a
special case for `(values ...)'. If inlining primitive-refs fails,
try expanding into toplevel-refs if the comp-module's variable is the
same as the root variable.
* module/language/tree-il/optimize.scm (resolve-primitives!): Add missing
src variable for <module-ref>.
* test-suite/tests/tree-il.test ("lambda"): Fix nlocs counts. Add a
closure test case.
2009-05-20 11:15:22 +02:00
|
|
|
|
(define-syntax and
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_) #t)
|
|
|
|
|
|
((_ x) x)
|
|
|
|
|
|
((_ x y ...) (if x (and y ...) #f))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax or
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_) #f)
|
|
|
|
|
|
((_ x) x)
|
|
|
|
|
|
((_ x y ...) (let ((t x)) (if t t (or y ...))))))
|
|
|
|
|
|
|
residualize names into procedures. re-implement srfi-61. module naming foo.
* module/ice-9/boot-9.scm (cond): Implement srfi-61; most of the code is
from the SRFI itself. Yuk.
(%print-module, make-modules-in, %app, (%app modules))
(module-name): Syncase needs to get at the names of modules, even at
anonymous modules. So lazily assign gensyms as module names. Name %app
as (%app), but since (%app modules) is at the top of the module
hierarchy, name it ().
* module/ice-9/psyntax.scm: When building tree-il, try to name lambdas in
definitions and in lets.
(let, letrec): Give more specific errors in a couple of cases.
* module/ice-9/psyntax-pp.scm: Regenerated.
* test-suite/tests/syntax.test: More work. Many exceptions have different
messages than they used to, many more generic; we can roll this back to
be faithful to the original strings, but it doesn't seem necessary to
me.
2009-05-22 12:08:50 +02:00
|
|
|
|
;; The "maybe-more" bits are something of a hack, so that we can support
|
|
|
|
|
|
;; SRFI-61. Rewrites into a standalone syntax-case macro would be
|
|
|
|
|
|
;; appreciated.
|
and, or, cond etc use syntax-rules, compile scheme through tree-il
* libguile/vm-i-system.c:
* libguile/vm-engine.h (ASSERT_BOUND): New assertion, that a value is
bound. Used by local-ref and external-ref in paranoid mode.
* module/ice-9/boot-9.scm (and, or, cond, case, do): Since we are
switching to use psyntax as the first pass of the compiler, and perhaps
soon of the interpreter too, we need to make sure it expands out all
forms to primitive expressions. So define expanders for these derived
syntax forms, as in the R5RS report.
* module/ice-9/psyntax-pp.scm: Regenerate, with core forms fully
expanded.
* module/ice-9/psyntax.scm (build-void): New constructor, for making
undefined values.
(build-primref): Add in a hack so that primitive refs in the boot
module expand out to toplevel refs, not module refs.
(chi-void): Use build-void.
(if): Define an expander for if that calls build-conditional.
* module/language/scheme/compile-tree-il.scm (compile-tree-il): Use let*
so as not to depend on binding order for the result of
(current-module).
* module/language/scheme/spec.scm (scheme): Switch over to tree-il as the
primary intermediate language. Not yet fully tested, but at least it
can compile psyntax-pp.scm.
* module/language/tree-il/analyze.scm (analyze-lexicals): Arguments don't
count towards a function's nlocs.
* module/language/tree-il/compile-glil.scm (*comp-module*, compile-glil):
Define a "compilation module" fluid.
(flatten-lambda): Fix a call to make-glil-argument. Fix bug in
heapifying arguments.
(flatten): Fix number of arguments passed to apply instruction. Add a
special case for `(values ...)'. If inlining primitive-refs fails,
try expanding into toplevel-refs if the comp-module's variable is the
same as the root variable.
* module/language/tree-il/optimize.scm (resolve-primitives!): Add missing
src variable for <module-ref>.
* test-suite/tests/tree-il.test ("lambda"): Fix nlocs counts. Add a
closure test case.
2009-05-20 11:15:22 +02:00
|
|
|
|
(define-syntax cond
|
residualize names into procedures. re-implement srfi-61. module naming foo.
* module/ice-9/boot-9.scm (cond): Implement srfi-61; most of the code is
from the SRFI itself. Yuk.
(%print-module, make-modules-in, %app, (%app modules))
(module-name): Syncase needs to get at the names of modules, even at
anonymous modules. So lazily assign gensyms as module names. Name %app
as (%app), but since (%app modules) is at the top of the module
hierarchy, name it ().
* module/ice-9/psyntax.scm: When building tree-il, try to name lambdas in
definitions and in lets.
(let, letrec): Give more specific errors in a couple of cases.
* module/ice-9/psyntax-pp.scm: Regenerated.
* test-suite/tests/syntax.test: More work. Many exceptions have different
messages than they used to, many more generic; we can roll this back to
be faithful to the original strings, but it doesn't seem necessary to
me.
2009-05-22 12:08:50 +02:00
|
|
|
|
(syntax-rules (=> else)
|
|
|
|
|
|
((_ "maybe-more" test consequent)
|
|
|
|
|
|
(if test consequent))
|
|
|
|
|
|
|
|
|
|
|
|
((_ "maybe-more" test consequent clause ...)
|
|
|
|
|
|
(if test consequent (cond clause ...)))
|
|
|
|
|
|
|
|
|
|
|
|
((_ (else else1 else2 ...))
|
|
|
|
|
|
(begin else1 else2 ...))
|
|
|
|
|
|
|
|
|
|
|
|
((_ (test => receiver) more-clause ...)
|
|
|
|
|
|
(let ((t test))
|
|
|
|
|
|
(cond "maybe-more" t (receiver t) more-clause ...)))
|
|
|
|
|
|
|
|
|
|
|
|
((_ (generator guard => receiver) more-clause ...)
|
|
|
|
|
|
(call-with-values (lambda () generator)
|
|
|
|
|
|
(lambda t
|
|
|
|
|
|
(cond "maybe-more"
|
|
|
|
|
|
(apply guard t) (apply receiver t) more-clause ...))))
|
|
|
|
|
|
|
|
|
|
|
|
((_ (test => receiver ...) more-clause ...)
|
|
|
|
|
|
(syntax-violation 'cond "wrong number of receiver expressions"
|
|
|
|
|
|
'(test => receiver ...)))
|
|
|
|
|
|
((_ (generator guard => receiver ...) more-clause ...)
|
|
|
|
|
|
(syntax-violation 'cond "wrong number of receiver expressions"
|
|
|
|
|
|
'(generator guard => receiver ...)))
|
|
|
|
|
|
|
|
|
|
|
|
((_ (test) more-clause ...)
|
|
|
|
|
|
(let ((t test))
|
|
|
|
|
|
(cond "maybe-more" t t more-clause ...)))
|
|
|
|
|
|
|
|
|
|
|
|
((_ (test body1 body2 ...) more-clause ...)
|
|
|
|
|
|
(cond "maybe-more"
|
|
|
|
|
|
test (begin body1 body2 ...) more-clause ...))))
|
and, or, cond etc use syntax-rules, compile scheme through tree-il
* libguile/vm-i-system.c:
* libguile/vm-engine.h (ASSERT_BOUND): New assertion, that a value is
bound. Used by local-ref and external-ref in paranoid mode.
* module/ice-9/boot-9.scm (and, or, cond, case, do): Since we are
switching to use psyntax as the first pass of the compiler, and perhaps
soon of the interpreter too, we need to make sure it expands out all
forms to primitive expressions. So define expanders for these derived
syntax forms, as in the R5RS report.
* module/ice-9/psyntax-pp.scm: Regenerate, with core forms fully
expanded.
* module/ice-9/psyntax.scm (build-void): New constructor, for making
undefined values.
(build-primref): Add in a hack so that primitive refs in the boot
module expand out to toplevel refs, not module refs.
(chi-void): Use build-void.
(if): Define an expander for if that calls build-conditional.
* module/language/scheme/compile-tree-il.scm (compile-tree-il): Use let*
so as not to depend on binding order for the result of
(current-module).
* module/language/scheme/spec.scm (scheme): Switch over to tree-il as the
primary intermediate language. Not yet fully tested, but at least it
can compile psyntax-pp.scm.
* module/language/tree-il/analyze.scm (analyze-lexicals): Arguments don't
count towards a function's nlocs.
* module/language/tree-il/compile-glil.scm (*comp-module*, compile-glil):
Define a "compilation module" fluid.
(flatten-lambda): Fix a call to make-glil-argument. Fix bug in
heapifying arguments.
(flatten): Fix number of arguments passed to apply instruction. Add a
special case for `(values ...)'. If inlining primitive-refs fails,
try expanding into toplevel-refs if the comp-module's variable is the
same as the root variable.
* module/language/tree-il/optimize.scm (resolve-primitives!): Add missing
src variable for <module-ref>.
* test-suite/tests/tree-il.test ("lambda"): Fix nlocs counts. Add a
closure test case.
2009-05-20 11:15:22 +02:00
|
|
|
|
|
|
|
|
|
|
(define-syntax case
|
|
|
|
|
|
(syntax-rules (else)
|
|
|
|
|
|
((case (key ...)
|
|
|
|
|
|
clauses ...)
|
|
|
|
|
|
(let ((atom-key (key ...)))
|
|
|
|
|
|
(case atom-key clauses ...)))
|
|
|
|
|
|
((case key
|
|
|
|
|
|
(else result1 result2 ...))
|
|
|
|
|
|
(begin result1 result2 ...))
|
|
|
|
|
|
((case key
|
|
|
|
|
|
((atoms ...) result1 result2 ...))
|
|
|
|
|
|
(if (memv key '(atoms ...))
|
|
|
|
|
|
(begin result1 result2 ...)))
|
|
|
|
|
|
((case key
|
|
|
|
|
|
((atoms ...) result1 result2 ...)
|
|
|
|
|
|
clause clauses ...)
|
|
|
|
|
|
(if (memv key '(atoms ...))
|
|
|
|
|
|
(begin result1 result2 ...)
|
|
|
|
|
|
(case key clause clauses ...)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax do
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((do ((var init step ...) ...)
|
|
|
|
|
|
(test expr ...)
|
|
|
|
|
|
command ...)
|
|
|
|
|
|
(letrec
|
|
|
|
|
|
((loop
|
|
|
|
|
|
(lambda (var ...)
|
|
|
|
|
|
(if test
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(if #f #f)
|
|
|
|
|
|
expr ...)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
command
|
|
|
|
|
|
...
|
|
|
|
|
|
(loop (do "step" var step ...)
|
|
|
|
|
|
...))))))
|
|
|
|
|
|
(loop init ...)))
|
|
|
|
|
|
((do "step" x)
|
|
|
|
|
|
x)
|
|
|
|
|
|
((do "step" x y)
|
|
|
|
|
|
y)))
|
|
|
|
|
|
|
2009-05-17 18:04:36 +02:00
|
|
|
|
(define-syntax delay
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ exp) (make-promise (lambda () exp)))))
|
Get Guile to be a little less chatty by default. The new user
should see as little clutter as possible.
* r4rs.scm (%load-verbosely): Make this #f by default.
* boot-9.scm (scm-repl-verbose): Make this #f by default.
(scm-style-repl): Don't run 'pk' on the value passed to quit.
* r4rs.scm: New file.
* boot-9.scm: Load r4rs.scm, first thing.
(OPEN_READ, OPEN_WRITE, OPEN_BOTH, *null-device*, open-input-file,
open-output-file, open-io-file, close-input-port,
close-output-port, close-io-port, call-with-input-file,
call-with-output-file, with-input-from-port, with-output-to-port,
with-error-to-port, with-input-from-file, with-output-to-file,
with-error-to-file, with-input-from-string, with-output-to-string,
with-error-to-string, the-eof-object): Definitions moved to
r4rs.scm. Not all of them are R4RS, but those that are use those
that are not.
(load, %load-verbosely, %load-announce): Moved, along with code to
set %load-hook, to r4rs.scm.
* boot-9.scm (integer?): Definition deleted, in favor of the one
present in libguile (which used to be called int?). I have no
idea why integer? didn't just call int? to begin with.
* boot-9.scm (<, <=, =, >, >=): Definitions in terms of <?, <=?,
=?, >?, and >=? deleted; they're defined that way by libguile now.
1996-10-29 03:47:36 +00:00
|
|
|
|
|
2009-11-14 17:25:12 +01:00
|
|
|
|
(include-from-path "ice-9/quasisyntax")
|
|
|
|
|
|
|
2009-08-20 12:48:11 +02:00
|
|
|
|
;;; @bind is used by the old elisp code as a dynamic scoping mechanism.
|
|
|
|
|
|
;;; Please let the Guile developers know if you are using this macro.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
(define-syntax @bind
|
|
|
|
|
|
(lambda (x)
|
|
|
|
|
|
(define (bound-member id ids)
|
|
|
|
|
|
(cond ((null? ids) #f)
|
|
|
|
|
|
((bound-identifier=? id (car ids)) #t)
|
|
|
|
|
|
((bound-member (car ids) (cdr ids)))))
|
|
|
|
|
|
|
|
|
|
|
|
(syntax-case x ()
|
|
|
|
|
|
((_ () b0 b1 ...)
|
|
|
|
|
|
#'(let () b0 b1 ...))
|
|
|
|
|
|
((_ ((id val) ...) b0 b1 ...)
|
|
|
|
|
|
(and-map identifier? #'(id ...))
|
|
|
|
|
|
(if (let lp ((ids #'(id ...)))
|
|
|
|
|
|
(cond ((null? ids) #f)
|
|
|
|
|
|
((bound-member (car ids) (cdr ids)) #t)
|
|
|
|
|
|
(else (lp (cdr ids)))))
|
|
|
|
|
|
(syntax-violation '@bind "duplicate bound identifier" x)
|
|
|
|
|
|
(with-syntax (((old-v ...) (generate-temporaries #'(id ...)))
|
|
|
|
|
|
((v ...) (generate-temporaries #'(id ...))))
|
|
|
|
|
|
#'(let ((old-v id) ...
|
|
|
|
|
|
(v val) ...)
|
|
|
|
|
|
(dynamic-wind
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(set! id v) ...)
|
|
|
|
|
|
(lambda () b0 b1 ...)
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(set! id old-v) ...)))))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2003-03-26 17:59:22 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;; {Defmacros}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
(define-syntax define-macro
|
|
|
|
|
|
(lambda (x)
|
2009-04-25 16:31:52 +02:00
|
|
|
|
"Define a defmacro."
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
(syntax-case x ()
|
2009-04-25 16:31:52 +02:00
|
|
|
|
((_ (macro . args) doc body1 body ...)
|
2009-12-28 11:44:06 +01:00
|
|
|
|
(string? (syntax->datum #'doc))
|
|
|
|
|
|
#'(define-macro macro doc (lambda args body1 body ...)))
|
2009-04-25 16:31:52 +02:00
|
|
|
|
((_ (macro . args) body ...)
|
2009-12-28 11:44:06 +01:00
|
|
|
|
#'(define-macro macro #f (lambda args body ...)))
|
2009-04-25 16:31:52 +02:00
|
|
|
|
((_ macro doc transformer)
|
2009-12-28 11:44:06 +01:00
|
|
|
|
(or (string? (syntax->datum #'doc))
|
|
|
|
|
|
(not (syntax->datum #'doc)))
|
|
|
|
|
|
#'(define-syntax macro
|
|
|
|
|
|
(lambda (y)
|
|
|
|
|
|
doc
|
|
|
|
|
|
(syntax-case y ()
|
|
|
|
|
|
((_ . args)
|
|
|
|
|
|
(let ((v (syntax->datum #'args)))
|
|
|
|
|
|
(datum->syntax y (apply transformer v)))))))))))
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
|
|
|
|
|
|
(define-syntax defmacro
|
|
|
|
|
|
(lambda (x)
|
2009-04-25 16:31:52 +02:00
|
|
|
|
"Define a defmacro, with the old lispy defun syntax."
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
(syntax-case x ()
|
2009-04-25 16:31:52 +02:00
|
|
|
|
((_ macro args doc body1 body ...)
|
2009-12-28 11:44:06 +01:00
|
|
|
|
(string? (syntax->datum #'doc))
|
|
|
|
|
|
#'(define-macro macro doc (lambda args body1 body ...)))
|
2009-04-25 16:31:52 +02:00
|
|
|
|
((_ macro args body ...)
|
2009-12-28 11:44:06 +01:00
|
|
|
|
#'(define-macro macro #f (lambda args body ...))))))
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
|
|
|
|
|
(provide 'defmacro)
|
2003-03-26 17:59:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;; {Deprecation}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Depends on: defmacro
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(defmacro begin-deprecated forms
|
|
|
|
|
|
(if (include-deprecated-features)
|
2008-09-01 23:40:10 -07:00
|
|
|
|
`(begin ,@forms)
|
2009-03-09 22:01:27 +01:00
|
|
|
|
`(begin)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
Get Guile to be a little less chatty by default. The new user
should see as little clutter as possible.
* r4rs.scm (%load-verbosely): Make this #f by default.
* boot-9.scm (scm-repl-verbose): Make this #f by default.
(scm-style-repl): Don't run 'pk' on the value passed to quit.
* r4rs.scm: New file.
* boot-9.scm: Load r4rs.scm, first thing.
(OPEN_READ, OPEN_WRITE, OPEN_BOTH, *null-device*, open-input-file,
open-output-file, open-io-file, close-input-port,
close-output-port, close-io-port, call-with-input-file,
call-with-output-file, with-input-from-port, with-output-to-port,
with-error-to-port, with-input-from-file, with-output-to-file,
with-error-to-file, with-input-from-string, with-output-to-string,
with-error-to-string, the-eof-object): Definitions moved to
r4rs.scm. Not all of them are R4RS, but those that are use those
that are not.
(load, %load-verbosely, %load-announce): Moved, along with code to
set %load-hook, to r4rs.scm.
* boot-9.scm (integer?): Definition deleted, in favor of the one
present in libguile (which used to be called int?). I have no
idea why integer? didn't just call int? to begin with.
* boot-9.scm (<, <=, =, >, >=): Definitions in terms of <?, <=?,
=?, >?, and >=? deleted; they're defined that way by libguile now.
1996-10-29 03:47:36 +00:00
|
|
|
|
;;; {Trivial Functions}
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
Get Guile to be a little less chatty by default. The new user
should see as little clutter as possible.
* r4rs.scm (%load-verbosely): Make this #f by default.
* boot-9.scm (scm-repl-verbose): Make this #f by default.
(scm-style-repl): Don't run 'pk' on the value passed to quit.
* r4rs.scm: New file.
* boot-9.scm: Load r4rs.scm, first thing.
(OPEN_READ, OPEN_WRITE, OPEN_BOTH, *null-device*, open-input-file,
open-output-file, open-io-file, close-input-port,
close-output-port, close-io-port, call-with-input-file,
call-with-output-file, with-input-from-port, with-output-to-port,
with-error-to-port, with-input-from-file, with-output-to-file,
with-error-to-file, with-input-from-string, with-output-to-string,
with-error-to-string, the-eof-object): Definitions moved to
r4rs.scm. Not all of them are R4RS, but those that are use those
that are not.
(load, %load-verbosely, %load-announce): Moved, along with code to
set %load-hook, to r4rs.scm.
* boot-9.scm (integer?): Definition deleted, in favor of the one
present in libguile (which used to be called int?). I have no
idea why integer? didn't just call int? to begin with.
* boot-9.scm (<, <=, =, >, >=): Definitions in terms of <?, <=?,
=?, >?, and >=? deleted; they're defined that way by libguile now.
1996-10-29 03:47:36 +00:00
|
|
|
|
|
2001-04-15 22:47:25 +00:00
|
|
|
|
(define (identity x) x)
|
1997-01-08 01:27:01 +00:00
|
|
|
|
(define (and=> value procedure) (and value (procedure value)))
|
2003-03-22 00:34:34 +00:00
|
|
|
|
(define call/cc call-with-current-continuation)
|
Get Guile to be a little less chatty by default. The new user
should see as little clutter as possible.
* r4rs.scm (%load-verbosely): Make this #f by default.
* boot-9.scm (scm-repl-verbose): Make this #f by default.
(scm-style-repl): Don't run 'pk' on the value passed to quit.
* r4rs.scm: New file.
* boot-9.scm: Load r4rs.scm, first thing.
(OPEN_READ, OPEN_WRITE, OPEN_BOTH, *null-device*, open-input-file,
open-output-file, open-io-file, close-input-port,
close-output-port, close-io-port, call-with-input-file,
call-with-output-file, with-input-from-port, with-output-to-port,
with-error-to-port, with-input-from-file, with-output-to-file,
with-error-to-file, with-input-from-string, with-output-to-string,
with-error-to-string, the-eof-object): Definitions moved to
r4rs.scm. Not all of them are R4RS, but those that are use those
that are not.
(load, %load-verbosely, %load-announce): Moved, along with code to
set %load-hook, to r4rs.scm.
* boot-9.scm (integer?): Definition deleted, in favor of the one
present in libguile (which used to be called int?). I have no
idea why integer? didn't just call int? to begin with.
* boot-9.scm (<, <=, =, >, >=): Definitions in terms of <?, <=?,
=?, >?, and >=? deleted; they're defined that way by libguile now.
1996-10-29 03:47:36 +00:00
|
|
|
|
|
2001-05-14 16:38:08 +00:00
|
|
|
|
;;; apply-to-args is functionally redundant with apply and, worse,
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; is less general than apply since it only takes two arguments.
|
|
|
|
|
|
;;;
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;; On the other hand, apply-to-args is a syntacticly convenient way to
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; perform binding in many circumstances when the "let" family of
|
|
|
|
|
|
;;; of forms don't cut it. E.g.:
|
|
|
|
|
|
;;;
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;;; (apply-to-args (return-3d-mouse-coords)
|
|
|
|
|
|
;;; (lambda (x y z)
|
|
|
|
|
|
;;; ...))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (apply-to-args args fn) (apply fn args))
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
(defmacro false-if-exception (expr)
|
2009-06-09 23:42:05 +02:00
|
|
|
|
`(catch #t
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
;; avoid saving backtraces inside false-if-exception
|
2010-03-04 16:50:11 +01:00
|
|
|
|
(with-fluids ((the-last-stack (fluid-ref the-last-stack)))
|
|
|
|
|
|
,expr))
|
2009-06-09 23:42:05 +02:00
|
|
|
|
(lambda args #f)))
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {General Properties}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; This is a more modern interface to properties. It will replace all
|
|
|
|
|
|
;; other property-like things eventually.
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-object-property)
|
|
|
|
|
|
(let ((prop (primitive-make-property #f)))
|
|
|
|
|
|
(make-procedure-with-setter
|
|
|
|
|
|
(lambda (obj) (primitive-property-ref prop obj))
|
|
|
|
|
|
(lambda (obj val) (primitive-property-set! prop obj val)))))
|
|
|
|
|
|
|
2001-04-15 22:47:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Symbol Properties}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (symbol-property sym prop)
|
|
|
|
|
|
(let ((pair (assoc prop (symbol-pref sym))))
|
|
|
|
|
|
(and pair (cdr pair))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (set-symbol-property! sym prop val)
|
|
|
|
|
|
(let ((pair (assoc prop (symbol-pref sym))))
|
|
|
|
|
|
(if pair
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(set-cdr! pair val)
|
|
|
|
|
|
(symbol-pset! sym (acons prop val (symbol-pref sym))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (symbol-property-remove! sym prop)
|
|
|
|
|
|
(let ((pair (assoc prop (symbol-pref sym))))
|
|
|
|
|
|
(if pair
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(symbol-pset! sym (delq! pair (symbol-pref sym))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1997-01-25 18:24:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Arrays}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2005-01-10 20:06:03 +00:00
|
|
|
|
(define (array-shape a)
|
|
|
|
|
|
(map (lambda (ind) (if (number? ind) (list 0 (+ -1 ind)) ind))
|
|
|
|
|
|
(array-dimensions a)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Keywords}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (kw-arg-ref args kw)
|
|
|
|
|
|
(let ((rem (member kw args)))
|
|
|
|
|
|
(and rem (pair? (cdr rem)) (cadr rem))))
|
|
|
|
|
|
|
1997-06-04 22:39:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
1997-10-03 00:47:48 +00:00
|
|
|
|
;;; {Structs}
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
1997-06-04 22:39:09 +00:00
|
|
|
|
|
|
|
|
|
|
(define (struct-layout s)
|
1997-10-03 00:47:48 +00:00
|
|
|
|
(struct-ref (struct-vtable s) vtable-index-layout))
|
1997-06-04 22:39:09 +00:00
|
|
|
|
|
2000-08-11 08:45:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Records}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
1997-06-04 22:39:09 +00:00
|
|
|
|
;; Printing records: by default, records are printed as
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; #<type-name field1: val1 field2: val2 ...>
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; You can change that by giving a custom printing function to
|
|
|
|
|
|
;; MAKE-RECORD-TYPE (after the list of field symbols). This function
|
|
|
|
|
|
;; will be called like
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; (<printer> object port)
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; It should print OBJECT to PORT.
|
|
|
|
|
|
|
1997-10-31 22:16:24 +00:00
|
|
|
|
(define (inherit-print-state old-port new-port)
|
1999-08-24 02:22:18 +00:00
|
|
|
|
(if (get-print-state old-port)
|
|
|
|
|
|
(port-with-print-state new-port (get-print-state old-port))
|
1997-10-31 22:16:24 +00:00
|
|
|
|
new-port))
|
|
|
|
|
|
|
1997-10-03 00:47:48 +00:00
|
|
|
|
;; 0: type-name, 1: fields
|
2001-04-28 19:07:38 +00:00
|
|
|
|
(define record-type-vtable
|
1997-10-03 00:47:48 +00:00
|
|
|
|
(make-vtable-vtable "prpr" 0
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(lambda (s p)
|
|
|
|
|
|
(cond ((eq? s record-type-vtable)
|
|
|
|
|
|
(display "#<record-type-vtable>" p))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(display "#<record-type " p)
|
|
|
|
|
|
(display (record-type-name s) p)
|
|
|
|
|
|
(display ">" p))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (record-type? obj)
|
|
|
|
|
|
(and (struct? obj) (eq? record-type-vtable (struct-vtable obj))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-record-type type-name fields . opt)
|
1996-10-03 05:47:12 +00:00
|
|
|
|
(let ((printer-fn (and (pair? opt) (car opt))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let ((struct (make-struct record-type-vtable 0
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(make-struct-layout
|
|
|
|
|
|
(apply string-append
|
|
|
|
|
|
(map (lambda (f) "pw") fields)))
|
|
|
|
|
|
(or printer-fn
|
|
|
|
|
|
(lambda (s p)
|
|
|
|
|
|
(display "#<" p)
|
|
|
|
|
|
(display type-name p)
|
|
|
|
|
|
(let loop ((fields fields)
|
|
|
|
|
|
(off 0))
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((not (null? fields))
|
|
|
|
|
|
(display " " p)
|
|
|
|
|
|
(display (car fields) p)
|
|
|
|
|
|
(display ": " p)
|
|
|
|
|
|
(display (struct-ref s off) p)
|
|
|
|
|
|
(loop (cdr fields) (+ 1 off)))))
|
|
|
|
|
|
(display ">" p)))
|
|
|
|
|
|
type-name
|
|
|
|
|
|
(copy-tree fields))))
|
1999-03-14 16:46:04 +00:00
|
|
|
|
;; Temporary solution: Associate a name to the record type descriptor
|
|
|
|
|
|
;; so that the object system can create a wrapper class for it.
|
|
|
|
|
|
(set-struct-vtable-name! struct (if (symbol? type-name)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
type-name
|
|
|
|
|
|
(string->symbol type-name)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
struct)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (record-type-name obj)
|
|
|
|
|
|
(if (record-type? obj)
|
1997-10-03 00:47:48 +00:00
|
|
|
|
(struct-ref obj vtable-offset-user)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(error 'not-a-record-type obj)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (record-type-fields obj)
|
|
|
|
|
|
(if (record-type? obj)
|
1997-10-03 00:47:48 +00:00
|
|
|
|
(struct-ref obj (+ 1 vtable-offset-user))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(error 'not-a-record-type obj)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (record-constructor rtd . opt)
|
1996-10-03 05:47:12 +00:00
|
|
|
|
(let ((field-names (if (pair? opt) (car opt) (record-type-fields rtd))))
|
2008-09-01 23:43:38 -07:00
|
|
|
|
(primitive-eval
|
|
|
|
|
|
`(lambda ,field-names
|
|
|
|
|
|
(make-struct ',rtd 0 ,@(map (lambda (f)
|
|
|
|
|
|
(if (memq f field-names)
|
|
|
|
|
|
f
|
|
|
|
|
|
#f))
|
|
|
|
|
|
(record-type-fields rtd)))))))
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (record-predicate rtd)
|
|
|
|
|
|
(lambda (obj) (and (struct? obj) (eq? rtd (struct-vtable obj)))))
|
|
|
|
|
|
|
2007-08-08 14:56:02 +00:00
|
|
|
|
(define (%record-type-error rtd obj) ;; private helper
|
2006-10-09 22:59:10 +00:00
|
|
|
|
(or (eq? rtd (record-type-descriptor obj))
|
|
|
|
|
|
(scm-error 'wrong-type-arg "%record-type-check"
|
2009-12-22 00:58:12 +01:00
|
|
|
|
"Wrong type record (want `~S'): ~S"
|
|
|
|
|
|
(list (record-type-name rtd) obj)
|
|
|
|
|
|
#f)))
|
2006-10-09 22:59:10 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (record-accessor rtd field-name)
|
2008-09-01 23:43:38 -07:00
|
|
|
|
(let ((pos (list-index (record-type-fields rtd) field-name)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if (not pos)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(error 'no-such-field field-name))
|
2008-09-01 23:43:38 -07:00
|
|
|
|
(lambda (obj)
|
|
|
|
|
|
(if (eq? (struct-vtable obj) rtd)
|
|
|
|
|
|
(struct-ref obj pos)
|
|
|
|
|
|
(%record-type-error rtd obj)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (record-modifier rtd field-name)
|
2008-09-01 23:43:38 -07:00
|
|
|
|
(let ((pos (list-index (record-type-fields rtd) field-name)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if (not pos)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(error 'no-such-field field-name))
|
2008-09-01 23:43:38 -07:00
|
|
|
|
(lambda (obj val)
|
|
|
|
|
|
(if (eq? (struct-vtable obj) rtd)
|
|
|
|
|
|
(struct-set! obj pos val)
|
|
|
|
|
|
(%record-type-error rtd obj)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (record? obj)
|
|
|
|
|
|
(and (struct? obj) (record-type? (struct-vtable obj))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (record-type-descriptor obj)
|
|
|
|
|
|
(if (struct? obj)
|
|
|
|
|
|
(struct-vtable obj)
|
|
|
|
|
|
(error 'not-a-record obj)))
|
|
|
|
|
|
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(provide 'record)
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Booleans}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (->bool x) (not (not x)))
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Symbols}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (symbol-append . args)
|
2000-08-27 03:20:19 +00:00
|
|
|
|
(string->symbol (apply string-append (map symbol->string args))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (list->symbol . args)
|
|
|
|
|
|
(string->symbol (apply list->string args)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (symbol . args)
|
|
|
|
|
|
(string->symbol (apply string args)))
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Lists}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (list-index l k)
|
|
|
|
|
|
(let loop ((n 0)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(l l))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(and (not (null? l))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(if (eq? (car l) k)
|
|
|
|
|
|
n
|
|
|
|
|
|
(loop (+ n 1) (cdr l))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1999-09-26 16:00:36 +00:00
|
|
|
|
(if (provided? 'posix)
|
2008-09-25 13:46:09 +02:00
|
|
|
|
(primitive-load-path "ice-9/posix"))
|
1996-10-06 06:33:11 +00:00
|
|
|
|
|
1999-09-26 16:00:36 +00:00
|
|
|
|
(if (provided? 'socket)
|
2008-09-25 13:46:09 +02:00
|
|
|
|
(primitive-load-path "ice-9/networking"))
|
1996-10-27 23:26:35 +00:00
|
|
|
|
|
2003-09-15 22:29:32 +00:00
|
|
|
|
;; For reference, Emacs file-exists-p uses stat in this same way.
|
1996-10-06 06:33:11 +00:00
|
|
|
|
(define file-exists?
|
1999-09-26 16:00:36 +00:00
|
|
|
|
(if (provided? 'posix)
|
1996-10-06 06:33:11 +00:00
|
|
|
|
(lambda (str)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(->bool (stat str #f)))
|
1996-10-06 06:33:11 +00:00
|
|
|
|
(lambda (str)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(let ((port (catch 'system-error (lambda () (open-file str OPEN_READ))
|
|
|
|
|
|
(lambda args #f))))
|
|
|
|
|
|
(if port (begin (close-port port) #t)
|
|
|
|
|
|
#f)))))
|
1996-10-06 06:33:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define file-is-directory?
|
1999-09-26 16:00:36 +00:00
|
|
|
|
(if (provided? 'posix)
|
1996-10-06 06:33:11 +00:00
|
|
|
|
(lambda (str)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(eq? (stat:type (stat str)) 'directory))
|
1996-10-06 06:33:11 +00:00
|
|
|
|
(lambda (str)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(let ((port (catch 'system-error
|
|
|
|
|
|
(lambda () (open-file (string-append str "/.")
|
|
|
|
|
|
OPEN_READ))
|
|
|
|
|
|
(lambda args #f))))
|
|
|
|
|
|
(if port (begin (close-port port) #t)
|
|
|
|
|
|
#f)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (has-suffix? str suffix)
|
2008-05-19 12:23:46 +02:00
|
|
|
|
(string-suffix? suffix str))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-06-16 20:14:24 +00:00
|
|
|
|
(define (system-error-errno args)
|
|
|
|
|
|
(if (eq? (car args) 'system-error)
|
|
|
|
|
|
(car (list-ref args 4))
|
|
|
|
|
|
#f))
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Error Handling}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (error . args)
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(save-stack)
|
1996-09-19 09:04:55 +00:00
|
|
|
|
(if (null? args)
|
* boot-9.scm (error): replace another throw with scm-error. Throw
to 'misc-error instead of 'error (no need to distinguish these.)
Don't set up 'error as a key.
Set up regex-error as a key, if regex is available.
(signal-handler): use scm-error, not throw.
(%try-load, try-load-with-path, %load, load-with-path,
basic-try-load-with-path, basic-load-with-path,
try-load-module-with-path,load-module-with-path): deleted, since
they seem redundant.
(try-load): define using %try-load, not try-load-with-path.
(load): rewritten. load tries to open the file directly and
with a .scm extension before searching the library directories
(should "." be added to %load-path? then load could still open
directly files starting with "/").
(try-module-autoload): use load, not load-with-path.
(%load-indent): deleted, -2 was causing errors.
(%read-sharp): use port-line, not line-number.
1996-09-28 19:38:45 +00:00
|
|
|
|
(scm-error 'misc-error #f "?" #f #f)
|
2000-01-11 18:52:25 +00:00
|
|
|
|
(let loop ((msg "~A")
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(rest (cdr args)))
|
|
|
|
|
|
(if (not (null? rest))
|
|
|
|
|
|
(loop (string-append msg " ~S")
|
|
|
|
|
|
(cdr rest))
|
|
|
|
|
|
(scm-error 'misc-error #f msg args #f)))))
|
1996-09-20 09:02:14 +00:00
|
|
|
|
|
1996-10-05 16:55:06 +00:00
|
|
|
|
;; bad-throw is the hook that is called upon a throw to a an unhandled
|
1996-10-17 21:45:04 +00:00
|
|
|
|
;; key (unless the throw has four arguments, in which case
|
|
|
|
|
|
;; it's usually interpreted as an error throw.)
|
|
|
|
|
|
;; If the key has a default handler (a throw-handler-default property),
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; it is applied to the throw.
|
|
|
|
|
|
;;
|
1996-10-05 16:55:06 +00:00
|
|
|
|
(define (bad-throw key . args)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let ((default (symbol-property key 'throw-handler-default)))
|
|
|
|
|
|
(or (and default (apply default key args))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(apply error "unhandled-exception:" key args))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
* boot-9.scm: define accessor procedures for the objects returned
by getpw, getgr, gethost, getnet, getproto, getserv (e.g.,
passwd:name, where the first component is the name of the C structure
and the second is the unprefixed C member name.)
* * boot-9.scm (setpwent, setgrent, sethostent, setnetent, setprotoent,
setservent): no longer take an argument, it was bogus.
1997-03-22 18:26:32 +00:00
|
|
|
|
|
1997-04-05 21:58:35 +00:00
|
|
|
|
(define (tm:sec obj) (vector-ref obj 0))
|
|
|
|
|
|
(define (tm:min obj) (vector-ref obj 1))
|
|
|
|
|
|
(define (tm:hour obj) (vector-ref obj 2))
|
|
|
|
|
|
(define (tm:mday obj) (vector-ref obj 3))
|
|
|
|
|
|
(define (tm:mon obj) (vector-ref obj 4))
|
|
|
|
|
|
(define (tm:year obj) (vector-ref obj 5))
|
|
|
|
|
|
(define (tm:wday obj) (vector-ref obj 6))
|
|
|
|
|
|
(define (tm:yday obj) (vector-ref obj 7))
|
|
|
|
|
|
(define (tm:isdst obj) (vector-ref obj 8))
|
|
|
|
|
|
(define (tm:gmtoff obj) (vector-ref obj 9))
|
|
|
|
|
|
(define (tm:zone obj) (vector-ref obj 10))
|
|
|
|
|
|
|
|
|
|
|
|
(define (set-tm:sec obj val) (vector-set! obj 0 val))
|
|
|
|
|
|
(define (set-tm:min obj val) (vector-set! obj 1 val))
|
|
|
|
|
|
(define (set-tm:hour obj val) (vector-set! obj 2 val))
|
|
|
|
|
|
(define (set-tm:mday obj val) (vector-set! obj 3 val))
|
|
|
|
|
|
(define (set-tm:mon obj val) (vector-set! obj 4 val))
|
|
|
|
|
|
(define (set-tm:year obj val) (vector-set! obj 5 val))
|
|
|
|
|
|
(define (set-tm:wday obj val) (vector-set! obj 6 val))
|
|
|
|
|
|
(define (set-tm:yday obj val) (vector-set! obj 7 val))
|
|
|
|
|
|
(define (set-tm:isdst obj val) (vector-set! obj 8 val))
|
|
|
|
|
|
(define (set-tm:gmtoff obj val) (vector-set! obj 9 val))
|
|
|
|
|
|
(define (set-tm:zone obj val) (vector-set! obj 10 val))
|
|
|
|
|
|
|
* stime.h: prototype for scm_times.
* stime.c (scm_times): new procedure.
* ioext.c (scm_fseek): if the first argument is a file descriptor
call lseek.
(scm_ftell): if the first argument is a file descriptor call lseek
(sic).
* filesys.h: prototypes for scm_open_fdes, scm_fsync.
* filesys.c (scm_chmod): if the first argument is a file descriptor,
call fchmod.
(scm_chown): if the first argument is a port or file descriptor,
call fchown.
(scm_truncate_file): new procedure.
Add DEFER/ALLOW INTS to a few other procedures.
(scm_fsync): new procedure.
(scm_open_fdes): new procedure.
(scm_open): use scm_open_fdes. If mode isn't specified, 666 will
now be used.
(scm_fcntl): the first argument can now be a file descriptor. The
third argument is now optional.
* posix.c (scm_execl, scm_execlp): make the filename argument
compulsory, since omitting it causes SEGV.
(scm_sync): return unspecified instead of #f.
(scm_execle): new procedure.
(environ_list_to_c): new procedure.
(scm_environ): use environ_list_to_c. disable interrupts.
(scm_convert_exec_args): take pos and subr arguments and
improve error checking.
* boot-9.scm: define tms accessors: clock, utime, stime, cutime,
cstime.
1997-08-16 18:48:44 +00:00
|
|
|
|
(define (tms:clock obj) (vector-ref obj 0))
|
|
|
|
|
|
(define (tms:utime obj) (vector-ref obj 1))
|
|
|
|
|
|
(define (tms:stime obj) (vector-ref obj 2))
|
|
|
|
|
|
(define (tms:cutime obj) (vector-ref obj 3))
|
|
|
|
|
|
(define (tms:cstime obj) (vector-ref obj 4))
|
|
|
|
|
|
|
2002-06-01 17:14:17 +00:00
|
|
|
|
(define file-position ftell)
|
|
|
|
|
|
(define (file-set-position port offset . whence)
|
|
|
|
|
|
(let ((whence (if (eq? whence '()) SEEK_SET (car whence))))
|
|
|
|
|
|
(seek port offset whence)))
|
1996-08-04 22:32:07 +00:00
|
|
|
|
|
* ioext.h: removed scm_duplicate_port prototype.
* ioext.c (scm_primitive_dup2): return the new file descriptor
instead of SCM_UNSPECIFIED, since similarity to scm_primitive_dup
is convenient.
(scm_fdopen): bug fix: don't try to make port unbuffered until its
stream has been set.
(scm_duplicate_port): deleted, there's now an implementation in
boot-9.scm.
(scm_primitive_dup2): do nothing if newfd == oldfd.
* boot-9.scm (dup->port, dup->inport, dup->outport, dup->fdes,
dup, fdes->inport, fdes->outport, port->fdes): new procedures.
(duplicate-port): was a C primitive, now it's here.
(move->fdes): allow the first argument to be a file descriptor.
Return the modified port or file descriptor (was unspecified.)
1997-07-21 08:52:26 +00:00
|
|
|
|
(define (move->fdes fd/port fd)
|
|
|
|
|
|
(cond ((integer? fd/port)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(dup->fdes fd/port fd)
|
|
|
|
|
|
(close fd/port)
|
|
|
|
|
|
fd)
|
|
|
|
|
|
(else
|
|
|
|
|
|
(primitive-move->fdes fd/port fd)
|
|
|
|
|
|
(set-port-revealed! fd/port 1)
|
|
|
|
|
|
fd/port)))
|
1996-08-04 22:32:07 +00:00
|
|
|
|
|
|
|
|
|
|
(define (release-port-handle port)
|
|
|
|
|
|
(let ((revealed (port-revealed port)))
|
|
|
|
|
|
(if (> revealed 0)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(set-port-revealed! port (- revealed 1)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
* ioext.h: removed scm_duplicate_port prototype.
* ioext.c (scm_primitive_dup2): return the new file descriptor
instead of SCM_UNSPECIFIED, since similarity to scm_primitive_dup
is convenient.
(scm_fdopen): bug fix: don't try to make port unbuffered until its
stream has been set.
(scm_duplicate_port): deleted, there's now an implementation in
boot-9.scm.
(scm_primitive_dup2): do nothing if newfd == oldfd.
* boot-9.scm (dup->port, dup->inport, dup->outport, dup->fdes,
dup, fdes->inport, fdes->outport, port->fdes): new procedures.
(duplicate-port): was a C primitive, now it's here.
(move->fdes): allow the first argument to be a file descriptor.
Return the modified port or file descriptor (was unspecified.)
1997-07-21 08:52:26 +00:00
|
|
|
|
(define (dup->port port/fd mode . maybe-fd)
|
1997-07-29 02:21:08 +00:00
|
|
|
|
(let ((port (fdopen (apply dup->fdes port/fd maybe-fd)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
mode)))
|
* ioext.h: removed scm_duplicate_port prototype.
* ioext.c (scm_primitive_dup2): return the new file descriptor
instead of SCM_UNSPECIFIED, since similarity to scm_primitive_dup
is convenient.
(scm_fdopen): bug fix: don't try to make port unbuffered until its
stream has been set.
(scm_duplicate_port): deleted, there's now an implementation in
boot-9.scm.
(scm_primitive_dup2): do nothing if newfd == oldfd.
* boot-9.scm (dup->port, dup->inport, dup->outport, dup->fdes,
dup, fdes->inport, fdes->outport, port->fdes): new procedures.
(duplicate-port): was a C primitive, now it's here.
(move->fdes): allow the first argument to be a file descriptor.
Return the modified port or file descriptor (was unspecified.)
1997-07-21 08:52:26 +00:00
|
|
|
|
(if (pair? maybe-fd)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(set-port-revealed! port 1))
|
* ioext.h: removed scm_duplicate_port prototype.
* ioext.c (scm_primitive_dup2): return the new file descriptor
instead of SCM_UNSPECIFIED, since similarity to scm_primitive_dup
is convenient.
(scm_fdopen): bug fix: don't try to make port unbuffered until its
stream has been set.
(scm_duplicate_port): deleted, there's now an implementation in
boot-9.scm.
(scm_primitive_dup2): do nothing if newfd == oldfd.
* boot-9.scm (dup->port, dup->inport, dup->outport, dup->fdes,
dup, fdes->inport, fdes->outport, port->fdes): new procedures.
(duplicate-port): was a C primitive, now it's here.
(move->fdes): allow the first argument to be a file descriptor.
Return the modified port or file descriptor (was unspecified.)
1997-07-21 08:52:26 +00:00
|
|
|
|
port))
|
2001-04-28 19:07:38 +00:00
|
|
|
|
|
* ioext.h: removed scm_duplicate_port prototype.
* ioext.c (scm_primitive_dup2): return the new file descriptor
instead of SCM_UNSPECIFIED, since similarity to scm_primitive_dup
is convenient.
(scm_fdopen): bug fix: don't try to make port unbuffered until its
stream has been set.
(scm_duplicate_port): deleted, there's now an implementation in
boot-9.scm.
(scm_primitive_dup2): do nothing if newfd == oldfd.
* boot-9.scm (dup->port, dup->inport, dup->outport, dup->fdes,
dup, fdes->inport, fdes->outport, port->fdes): new procedures.
(duplicate-port): was a C primitive, now it's here.
(move->fdes): allow the first argument to be a file descriptor.
Return the modified port or file descriptor (was unspecified.)
1997-07-21 08:52:26 +00:00
|
|
|
|
(define (dup->inport port/fd . maybe-fd)
|
|
|
|
|
|
(apply dup->port port/fd "r" maybe-fd))
|
|
|
|
|
|
|
|
|
|
|
|
(define (dup->outport port/fd . maybe-fd)
|
|
|
|
|
|
(apply dup->port port/fd "w" maybe-fd))
|
|
|
|
|
|
|
|
|
|
|
|
(define (dup port/fd . maybe-fd)
|
|
|
|
|
|
(if (integer? port/fd)
|
|
|
|
|
|
(apply dup->fdes port/fd maybe-fd)
|
|
|
|
|
|
(apply dup->port port/fd (port-mode port/fd) maybe-fd)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (duplicate-port port modes)
|
|
|
|
|
|
(dup->port port modes))
|
|
|
|
|
|
|
|
|
|
|
|
(define (fdes->inport fdes)
|
|
|
|
|
|
(let loop ((rest-ports (fdes->ports fdes)))
|
|
|
|
|
|
(cond ((null? rest-ports)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(let ((result (fdopen fdes "r")))
|
|
|
|
|
|
(set-port-revealed! result 1)
|
|
|
|
|
|
result))
|
|
|
|
|
|
((input-port? (car rest-ports))
|
|
|
|
|
|
(set-port-revealed! (car rest-ports)
|
|
|
|
|
|
(+ (port-revealed (car rest-ports)) 1))
|
|
|
|
|
|
(car rest-ports))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(loop (cdr rest-ports))))))
|
* ioext.h: removed scm_duplicate_port prototype.
* ioext.c (scm_primitive_dup2): return the new file descriptor
instead of SCM_UNSPECIFIED, since similarity to scm_primitive_dup
is convenient.
(scm_fdopen): bug fix: don't try to make port unbuffered until its
stream has been set.
(scm_duplicate_port): deleted, there's now an implementation in
boot-9.scm.
(scm_primitive_dup2): do nothing if newfd == oldfd.
* boot-9.scm (dup->port, dup->inport, dup->outport, dup->fdes,
dup, fdes->inport, fdes->outport, port->fdes): new procedures.
(duplicate-port): was a C primitive, now it's here.
(move->fdes): allow the first argument to be a file descriptor.
Return the modified port or file descriptor (was unspecified.)
1997-07-21 08:52:26 +00:00
|
|
|
|
|
|
|
|
|
|
(define (fdes->outport fdes)
|
|
|
|
|
|
(let loop ((rest-ports (fdes->ports fdes)))
|
|
|
|
|
|
(cond ((null? rest-ports)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(let ((result (fdopen fdes "w")))
|
|
|
|
|
|
(set-port-revealed! result 1)
|
|
|
|
|
|
result))
|
|
|
|
|
|
((output-port? (car rest-ports))
|
|
|
|
|
|
(set-port-revealed! (car rest-ports)
|
|
|
|
|
|
(+ (port-revealed (car rest-ports)) 1))
|
|
|
|
|
|
(car rest-ports))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(loop (cdr rest-ports))))))
|
* ioext.h: removed scm_duplicate_port prototype.
* ioext.c (scm_primitive_dup2): return the new file descriptor
instead of SCM_UNSPECIFIED, since similarity to scm_primitive_dup
is convenient.
(scm_fdopen): bug fix: don't try to make port unbuffered until its
stream has been set.
(scm_duplicate_port): deleted, there's now an implementation in
boot-9.scm.
(scm_primitive_dup2): do nothing if newfd == oldfd.
* boot-9.scm (dup->port, dup->inport, dup->outport, dup->fdes,
dup, fdes->inport, fdes->outport, port->fdes): new procedures.
(duplicate-port): was a C primitive, now it's here.
(move->fdes): allow the first argument to be a file descriptor.
Return the modified port or file descriptor (was unspecified.)
1997-07-21 08:52:26 +00:00
|
|
|
|
|
|
|
|
|
|
(define (port->fdes port)
|
|
|
|
|
|
(set-port-revealed! port (+ (port-revealed port) 1))
|
|
|
|
|
|
(fileno port))
|
|
|
|
|
|
|
1997-07-26 20:37:05 +00:00
|
|
|
|
(define (setenv name value)
|
|
|
|
|
|
(if value
|
|
|
|
|
|
(putenv (string-append name "=" value))
|
|
|
|
|
|
(putenv name)))
|
|
|
|
|
|
|
2002-05-09 19:36:30 +00:00
|
|
|
|
(define (unsetenv name)
|
|
|
|
|
|
"Remove the entry for NAME from the environment."
|
|
|
|
|
|
(putenv name))
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Load Paths}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;;; Here for backward compatability
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define scheme-file-suffix (lambda () ".scm"))
|
|
|
|
|
|
|
1996-09-05 16:33:42 +00:00
|
|
|
|
(define (in-vicinity vicinity file)
|
|
|
|
|
|
(let ((tail (let ((len (string-length vicinity)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(if (zero? len)
|
|
|
|
|
|
#f
|
|
|
|
|
|
(string-ref vicinity (- len 1))))))
|
1996-09-05 16:33:42 +00:00
|
|
|
|
(string-append vicinity
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(if (or (not tail)
|
|
|
|
|
|
(eq? tail #\/))
|
|
|
|
|
|
""
|
|
|
|
|
|
"/")
|
|
|
|
|
|
file)))
|
1996-08-30 21:09:23 +00:00
|
|
|
|
|
1997-04-19 13:04:38 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1997-04-19 13:04:38 +00:00
|
|
|
|
;;; {Help for scm_shell}
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
1997-04-19 13:04:38 +00:00
|
|
|
|
;;; The argument-processing code used by Guile-based shells generates
|
|
|
|
|
|
;;; Scheme code based on the argument list. This page contains help
|
|
|
|
|
|
;;; functions for the code it generates.
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
1997-04-19 13:04:38 +00:00
|
|
|
|
|
|
|
|
|
|
(define (command-line) (program-arguments))
|
|
|
|
|
|
|
1997-05-15 21:22:25 +00:00
|
|
|
|
;; This is mostly for the internal use of the code generated by
|
|
|
|
|
|
;; scm_compile_shell_switches.
|
2001-11-05 23:09:10 +00:00
|
|
|
|
|
|
|
|
|
|
(define (turn-on-debugging)
|
|
|
|
|
|
(debug-enable 'debug)
|
|
|
|
|
|
(debug-enable 'backtrace)
|
|
|
|
|
|
(read-enable 'positions))
|
2002-02-26 10:57:54 +00:00
|
|
|
|
|
1997-04-19 13:04:38 +00:00
|
|
|
|
(define (load-user-init)
|
2000-05-14 22:15:13 +00:00
|
|
|
|
(let* ((home (or (getenv "HOME")
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(false-if-exception (passwd:dir (getpwuid (getuid))))
|
|
|
|
|
|
"/")) ;; fallback for cygwin etc.
|
|
|
|
|
|
(init-file (in-vicinity home ".guile")))
|
2000-05-14 22:15:13 +00:00
|
|
|
|
(if (file-exists? init-file)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(primitive-load init-file))))
|
1997-04-19 13:04:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
2008-09-26 12:03:36 +02:00
|
|
|
|
;;; {The interpreter stack}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(defmacro start-stack (tag exp)
|
|
|
|
|
|
`(%start-stack ,tag (lambda () ,exp)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1996-10-29 03:59:35 +00:00
|
|
|
|
;;; {Loading by paths}
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
1996-10-29 03:59:35 +00:00
|
|
|
|
|
|
|
|
|
|
;;; Load a Scheme source file named NAME, searching for it in the
|
|
|
|
|
|
;;; directories listed in %load-path, and applying each of the file
|
|
|
|
|
|
;;; name extensions listed in %load-extensions.
|
|
|
|
|
|
(define (load-from-path name)
|
|
|
|
|
|
(start-stack 'load-stack
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(primitive-load-path name)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2009-04-24 14:08:32 +02:00
|
|
|
|
(define %load-verbosely #f)
|
|
|
|
|
|
(define (assert-load-verbosity v) (set! %load-verbosely v))
|
|
|
|
|
|
|
|
|
|
|
|
(define (%load-announce file)
|
|
|
|
|
|
(if %load-verbosely
|
|
|
|
|
|
(with-output-to-port (current-error-port)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(lambda ()
|
|
|
|
|
|
(display ";;; ")
|
|
|
|
|
|
(display "loading ")
|
|
|
|
|
|
(display file)
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(force-output)))))
|
2009-04-24 14:08:32 +02:00
|
|
|
|
|
|
|
|
|
|
(set! %load-hook %load-announce)
|
|
|
|
|
|
|
|
|
|
|
|
(define (load name . reader)
|
2009-10-15 15:48:14 +02:00
|
|
|
|
;; Returns the .go file corresponding to `name'. Does not search load
|
|
|
|
|
|
;; paths, only the fallback path. If the .go file is missing or out of
|
|
|
|
|
|
;; date, and autocompilation is enabled, will try autocompilation, just
|
|
|
|
|
|
;; as primitive-load-path does internally. primitive-load is
|
|
|
|
|
|
;; unaffected. Returns #f if autocompilation failed or was disabled.
|
2010-02-16 21:11:27 +01:00
|
|
|
|
;;
|
|
|
|
|
|
;; NB: Unless we need to compile the file, this function should not cause
|
|
|
|
|
|
;; (system base compile) to be loaded up. For that reason compiled-file-name
|
|
|
|
|
|
;; partially duplicates functionality from (system base compile).
|
|
|
|
|
|
(define (compiled-file-name canon-path)
|
|
|
|
|
|
(and %compile-fallback-path
|
|
|
|
|
|
(string-append
|
|
|
|
|
|
%compile-fallback-path
|
|
|
|
|
|
;; no need for '/' separator here, canon-path is absolute
|
|
|
|
|
|
canon-path
|
|
|
|
|
|
(cond ((or (null? %load-compiled-extensions)
|
|
|
|
|
|
(string-null? (car %load-compiled-extensions)))
|
|
|
|
|
|
(warn "invalid %load-compiled-extensions"
|
|
|
|
|
|
%load-compiled-extensions)
|
|
|
|
|
|
".go")
|
|
|
|
|
|
(else (car %load-compiled-extensions))))))
|
|
|
|
|
|
(define (fresh-compiled-file-name go-path)
|
2009-10-15 15:48:14 +02:00
|
|
|
|
(catch #t
|
|
|
|
|
|
(lambda ()
|
2010-02-16 21:11:27 +01:00
|
|
|
|
(let* ((scmstat (stat name))
|
|
|
|
|
|
(gostat (stat go-path #f)))
|
2009-10-15 15:48:14 +02:00
|
|
|
|
(if (and gostat (= (stat:mtime gostat) (stat:mtime scmstat)))
|
2010-02-16 21:11:27 +01:00
|
|
|
|
go-path
|
2009-10-15 15:48:14 +02:00
|
|
|
|
(begin
|
|
|
|
|
|
(if gostat
|
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
|
";;; note: source file ~a\n;;; newer than compiled ~a\n"
|
2010-02-16 21:11:27 +01:00
|
|
|
|
name go-path))
|
2009-10-15 15:48:14 +02:00
|
|
|
|
(cond
|
|
|
|
|
|
(%load-should-autocompile
|
|
|
|
|
|
(%warn-autocompilation-enabled)
|
|
|
|
|
|
(format (current-error-port) ";;; compiling ~a\n" name)
|
|
|
|
|
|
(let ((cfn ((@ (system base compile) compile-file) name
|
|
|
|
|
|
#:env (current-module))))
|
|
|
|
|
|
(format (current-error-port) ";;; compiled ~a\n" cfn)
|
|
|
|
|
|
cfn))
|
|
|
|
|
|
(else #f))))))
|
|
|
|
|
|
(lambda (k . args)
|
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
|
";;; WARNING: compilation of ~a failed:\n;;; key ~a, throw_args ~s\n"
|
|
|
|
|
|
name k args)
|
|
|
|
|
|
#f)))
|
2010-03-04 16:50:11 +01:00
|
|
|
|
(with-fluids ((current-reader (and (pair? reader) (car reader))))
|
|
|
|
|
|
(let ((cfn (and=> (and=> (false-if-exception (canonicalize-path name))
|
|
|
|
|
|
compiled-file-name)
|
|
|
|
|
|
fresh-compiled-file-name)))
|
|
|
|
|
|
(if cfn
|
|
|
|
|
|
(load-compiled cfn)
|
|
|
|
|
|
(start-stack 'load-stack
|
|
|
|
|
|
(primitive-load name))))))
|
* boot-9.scm (error): replace another throw with scm-error. Throw
to 'misc-error instead of 'error (no need to distinguish these.)
Don't set up 'error as a key.
Set up regex-error as a key, if regex is available.
(signal-handler): use scm-error, not throw.
(%try-load, try-load-with-path, %load, load-with-path,
basic-try-load-with-path, basic-load-with-path,
try-load-module-with-path,load-module-with-path): deleted, since
they seem redundant.
(try-load): define using %try-load, not try-load-with-path.
(load): rewritten. load tries to open the file directly and
with a .scm extension before searching the library directories
(should "." be added to %load-path? then load could still open
directly files starting with "/").
(try-module-autoload): use load, not load-with-path.
(%load-indent): deleted, -2 was causing errors.
(%read-sharp): use port-line, not line-number.
1996-09-28 19:38:45 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Reader Extensions}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Reader code for various "#c" forms.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2001-07-06 17:38:40 +00:00
|
|
|
|
(define read-eval? (make-fluid))
|
|
|
|
|
|
(fluid-set! read-eval? #f)
|
|
|
|
|
|
(read-hash-extend #\.
|
|
|
|
|
|
(lambda (c port)
|
|
|
|
|
|
(if (fluid-ref read-eval?)
|
|
|
|
|
|
(eval (read port) (interaction-environment))
|
|
|
|
|
|
(error
|
2001-07-09 14:28:03 +00:00
|
|
|
|
"#. read expansion found and read-eval? is #f."))))
|
1997-03-08 19:02:20 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Command Line Options}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (get-option argv kw-opts kw-args return)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((null? argv)
|
|
|
|
|
|
(return #f #f argv))
|
|
|
|
|
|
|
|
|
|
|
|
((or (not (eq? #\- (string-ref (car argv) 0)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(eq? (string-length (car argv)) 1))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(return 'normal-arg (car argv) (cdr argv)))
|
|
|
|
|
|
|
|
|
|
|
|
((eq? #\- (string-ref (car argv) 1))
|
|
|
|
|
|
(let* ((kw-arg-pos (or (string-index (car argv) #\=)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(string-length (car argv))))
|
|
|
|
|
|
(kw (symbol->keyword (substring (car argv) 2 kw-arg-pos)))
|
|
|
|
|
|
(kw-opt? (member kw kw-opts))
|
|
|
|
|
|
(kw-arg? (member kw kw-args))
|
|
|
|
|
|
(arg (or (and (not (eq? kw-arg-pos (string-length (car argv))))
|
|
|
|
|
|
(substring (car argv)
|
|
|
|
|
|
(+ kw-arg-pos 1)
|
|
|
|
|
|
(string-length (car argv))))
|
|
|
|
|
|
(and kw-arg?
|
|
|
|
|
|
(begin (set! argv (cdr argv)) (car argv))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if (or kw-opt? kw-arg?)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(return kw arg (cdr argv))
|
|
|
|
|
|
(return 'usage-error kw (cdr argv)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(else
|
|
|
|
|
|
(let* ((char (substring (car argv) 1 2))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(kw (symbol->keyword char)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(cond
|
|
|
|
|
|
|
|
|
|
|
|
((member kw kw-opts)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(let* ((rest-car (substring (car argv) 2 (string-length (car argv))))
|
|
|
|
|
|
(new-argv (if (= 0 (string-length rest-car))
|
|
|
|
|
|
(cdr argv)
|
|
|
|
|
|
(cons (string-append "-" rest-car) (cdr argv)))))
|
|
|
|
|
|
(return kw #f new-argv)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
((member kw kw-args)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(let* ((rest-car (substring (car argv) 2 (string-length (car argv))))
|
|
|
|
|
|
(arg (if (= 0 (string-length rest-car))
|
|
|
|
|
|
(cadr argv)
|
|
|
|
|
|
rest-car))
|
|
|
|
|
|
(new-argv (if (= 0 (string-length rest-car))
|
|
|
|
|
|
(cddr argv)
|
|
|
|
|
|
(cdr argv))))
|
|
|
|
|
|
(return kw arg new-argv)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(else (return 'usage-error kw argv)))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (for-next-option proc argv kw-opts kw-args)
|
|
|
|
|
|
(let loop ((argv argv))
|
|
|
|
|
|
(get-option argv kw-opts kw-args
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(lambda (opt opt-arg argv)
|
|
|
|
|
|
(and opt (proc opt opt-arg argv loop))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (display-usage-report kw-desc)
|
|
|
|
|
|
(for-each
|
|
|
|
|
|
(lambda (kw)
|
|
|
|
|
|
(or (eq? (car kw) #t)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(eq? (car kw) 'else)
|
|
|
|
|
|
(let* ((opt-desc kw)
|
|
|
|
|
|
(help (cadr opt-desc))
|
|
|
|
|
|
(opts (car opt-desc))
|
|
|
|
|
|
(opts-proper (if (string? (car opts)) (cdr opts) opts))
|
|
|
|
|
|
(arg-name (if (string? (car opts))
|
|
|
|
|
|
(string-append "<" (car opts) ">")
|
|
|
|
|
|
""))
|
|
|
|
|
|
(left-part (string-append
|
|
|
|
|
|
(with-output-to-string
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(map (lambda (x) (display (keyword->symbol x)) (display " "))
|
|
|
|
|
|
opts-proper)))
|
|
|
|
|
|
arg-name))
|
|
|
|
|
|
(middle-part (if (and (< (string-length left-part) 30)
|
|
|
|
|
|
(< (string-length help) 40))
|
|
|
|
|
|
(make-string (- 30 (string-length left-part)) #\ )
|
|
|
|
|
|
"\n\t")))
|
|
|
|
|
|
(display left-part)
|
|
|
|
|
|
(display middle-part)
|
|
|
|
|
|
(display help)
|
|
|
|
|
|
(newline))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
kw-desc))
|
|
|
|
|
|
|
2001-04-28 19:07:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (transform-usage-lambda cases)
|
|
|
|
|
|
(let* ((raw-usage (delq! 'else (map car cases)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(usage-sans-specials (map (lambda (x)
|
|
|
|
|
|
(or (and (not (list? x)) x)
|
|
|
|
|
|
(and (symbol? (car x)) #t)
|
|
|
|
|
|
(and (boolean? (car x)) #t)
|
|
|
|
|
|
x))
|
|
|
|
|
|
raw-usage))
|
|
|
|
|
|
(usage-desc (delq! #t usage-sans-specials))
|
|
|
|
|
|
(kw-desc (map car usage-desc))
|
|
|
|
|
|
(kw-opts (apply append (map (lambda (x) (and (not (string? (car x))) x)) kw-desc)))
|
|
|
|
|
|
(kw-args (apply append (map (lambda (x) (and (string? (car x)) (cdr x))) kw-desc)))
|
|
|
|
|
|
(transmogrified-cases (map (lambda (case)
|
|
|
|
|
|
(cons (let ((opts (car case)))
|
|
|
|
|
|
(if (or (boolean? opts) (eq? 'else opts))
|
|
|
|
|
|
opts
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((symbol? (car opts)) opts)
|
|
|
|
|
|
((boolean? (car opts)) opts)
|
|
|
|
|
|
((string? (caar opts)) (cdar opts))
|
|
|
|
|
|
(else (car opts)))))
|
|
|
|
|
|
(cdr case)))
|
|
|
|
|
|
cases)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
`(let ((%display-usage (lambda () (display-usage-report ',usage-desc))))
|
|
|
|
|
|
(lambda (%argv)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(let %next-arg ((%argv %argv))
|
|
|
|
|
|
(get-option %argv
|
|
|
|
|
|
',kw-opts
|
|
|
|
|
|
',kw-args
|
|
|
|
|
|
(lambda (%opt %arg %new-argv)
|
|
|
|
|
|
(case %opt
|
|
|
|
|
|
,@ transmogrified-cases))))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Low Level Modules}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; These are the low level data structures for modules.
|
|
|
|
|
|
;;;
|
2003-11-16 13:54:26 +00:00
|
|
|
|
;;; Every module object is of the type 'module-type', which is a record
|
|
|
|
|
|
;;; consisting of the following members:
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; - eval-closure: the function that defines for its module the strategy that
|
|
|
|
|
|
;;; shall be followed when looking up symbols in the module.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; An eval-closure is a function taking two arguments: the symbol to be
|
|
|
|
|
|
;;; looked up and a boolean value telling whether a binding for the symbol
|
|
|
|
|
|
;;; should be created if it does not exist yet. If the symbol lookup
|
|
|
|
|
|
;;; succeeded (either because an existing binding was found or because a new
|
|
|
|
|
|
;;; binding was created), a variable object representing the binding is
|
|
|
|
|
|
;;; returned. Otherwise, the value #f is returned. Note that the eval
|
|
|
|
|
|
;;; closure does not take the module to be searched as an argument: During
|
|
|
|
|
|
;;; construction of the eval-closure, the eval-closure has to store the
|
|
|
|
|
|
;;; module it belongs to in its environment. This means, that any
|
|
|
|
|
|
;;; eval-closure can belong to only one module.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; The eval-closure of a module can be defined arbitrarily. However, three
|
|
|
|
|
|
;;; special cases of eval-closures are to be distinguished: During startup
|
|
|
|
|
|
;;; the module system is not yet activated. In this phase, no modules are
|
|
|
|
|
|
;;; defined and all bindings are automatically stored by the system in the
|
|
|
|
|
|
;;; pre-modules-obarray. Since no eval-closures exist at this time, the
|
|
|
|
|
|
;;; functions which require an eval-closure as their argument need to be
|
|
|
|
|
|
;;; passed the value #f.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; The other two special cases of eval-closures are the
|
|
|
|
|
|
;;; standard-eval-closure and the standard-interface-eval-closure. Both
|
|
|
|
|
|
;;; behave equally for the case that no new binding is to be created. The
|
|
|
|
|
|
;;; difference between the two comes in, when the boolean argument to the
|
|
|
|
|
|
;;; eval-closure indicates that a new binding shall be created if it is not
|
|
|
|
|
|
;;; found.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Given that no new binding shall be created, both standard eval-closures
|
|
|
|
|
|
;;; define the following standard strategy of searching bindings in the
|
|
|
|
|
|
;;; module: First, the module's obarray is searched for the symbol. Second,
|
|
|
|
|
|
;;; if no binding for the symbol was found in the module's obarray, the
|
|
|
|
|
|
;;; module's binder procedure is exececuted. If this procedure did not
|
|
|
|
|
|
;;; return a binding for the symbol, the modules referenced in the module's
|
|
|
|
|
|
;;; uses list are recursively searched for a binding of the symbol. If the
|
|
|
|
|
|
;;; binding can not be found in these modules also, the symbol lookup has
|
|
|
|
|
|
;;; failed.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; If a new binding shall be created, the standard-interface-eval-closure
|
|
|
|
|
|
;;; immediately returns indicating failure. That is, it does not even try
|
|
|
|
|
|
;;; to look up the symbol. In contrast, the standard-eval-closure would
|
|
|
|
|
|
;;; first search the obarray, and if no binding was found there, would
|
|
|
|
|
|
;;; create a new binding in the obarray, therefore not calling the binder
|
|
|
|
|
|
;;; procedure or searching the modules in the uses list.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; The explanation of the following members obarray, binder and uses
|
|
|
|
|
|
;;; assumes that the symbol lookup follows the strategy that is defined in
|
|
|
|
|
|
;;; the standard-eval-closure and the standard-interface-eval-closure.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; - obarray: a hash table that maps symbols to variable objects. In this
|
|
|
|
|
|
;;; hash table, the definitions are found that are local to the module (that
|
|
|
|
|
|
;;; is, not imported from other modules). When looking up bindings in the
|
|
|
|
|
|
;;; module, this hash table is searched first.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; - binder: either #f or a function taking a module and a symbol argument.
|
|
|
|
|
|
;;; If it is a function it is called after the obarray has been
|
|
|
|
|
|
;;; unsuccessfully searched for a binding. It then can provide bindings
|
|
|
|
|
|
;;; that would otherwise not be found locally in the module.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; - uses: a list of modules from which non-local bindings can be inherited.
|
|
|
|
|
|
;;; These modules are the third place queried for bindings after the obarray
|
|
|
|
|
|
;;; has been unsuccessfully searched and the binder function did not deliver
|
|
|
|
|
|
;;; a result either.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; - transformer: either #f or a function taking a scheme expression as
|
|
|
|
|
|
;;; delivered by read. If it is a function, it will be called to perform
|
|
|
|
|
|
;;; syntax transformations (e. g. makro expansion) on the given scheme
|
|
|
|
|
|
;;; expression. The output of the transformer function will then be passed
|
|
|
|
|
|
;;; to Guile's internal memoizer. This means that the output must be valid
|
|
|
|
|
|
;;; scheme code. The only exception is, that the output may make use of the
|
|
|
|
|
|
;;; syntax extensions provided to identify the modules that a binding
|
|
|
|
|
|
;;; belongs to.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; - name: the name of the module. This is used for all kinds of printing
|
|
|
|
|
|
;;; outputs. In certain places the module name also serves as a way of
|
|
|
|
|
|
;;; identification. When adding a module to the uses list of another
|
|
|
|
|
|
;;; module, it is made sure that the new uses list will not contain two
|
|
|
|
|
|
;;; modules of the same name.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; - kind: classification of the kind of module. The value is (currently?)
|
|
|
|
|
|
;;; only used for printing. It has no influence on how a module is treated.
|
|
|
|
|
|
;;; Currently the following values are used when setting the module kind:
|
|
|
|
|
|
;;; 'module, 'directory, 'interface, 'custom-interface. If no explicit kind
|
|
|
|
|
|
;;; is set, it defaults to 'module.
|
|
|
|
|
|
;;;
|
2007-05-05 20:38:57 +00:00
|
|
|
|
;;; - duplicates-handlers: a list of procedures that get called to make a
|
|
|
|
|
|
;;; choice between two duplicate bindings when name clashes occur. See the
|
|
|
|
|
|
;;; `duplicate-handlers' global variable below.
|
2003-11-16 13:54:26 +00:00
|
|
|
|
;;;
|
2007-05-05 20:38:57 +00:00
|
|
|
|
;;; - observers: a list of procedures that get called when the module is
|
|
|
|
|
|
;;; modified.
|
2003-11-16 13:54:26 +00:00
|
|
|
|
;;;
|
2007-05-05 20:38:57 +00:00
|
|
|
|
;;; - weak-observers: a weak-key hash table of procedures that get called
|
|
|
|
|
|
;;; when the module is modified. See `module-observe-weak' for details.
|
2003-11-16 13:54:26 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;; In addition, the module may (must?) contain a binding for
|
2007-05-05 20:38:57 +00:00
|
|
|
|
;;; `%module-public-interface'. This variable should be bound to a module
|
|
|
|
|
|
;;; representing the exported interface of a module. See the
|
|
|
|
|
|
;;; `module-public-interface' and `module-export!' procedures.
|
2003-11-16 13:54:26 +00:00
|
|
|
|
;;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; !!! warning: The interface to lazy binder procedures is going
|
|
|
|
|
|
;;; to be changed in an incompatible way to permit all the basic
|
|
|
|
|
|
;;; module ops to be virtualized.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; (make-module size use-list lazy-binding-proc) => module
|
|
|
|
|
|
;;; module-{obarray,uses,binder}[|-set!]
|
|
|
|
|
|
;;; (module? obj) => [#t|#f]
|
|
|
|
|
|
;;; (module-locally-bound? module symbol) => [#t|#f]
|
|
|
|
|
|
;;; (module-bound? module symbol) => [#t|#f]
|
|
|
|
|
|
;;; (module-symbol-locally-interned? module symbol) => [#t|#f]
|
|
|
|
|
|
;;; (module-symbol-interned? module symbol) => [#t|#f]
|
|
|
|
|
|
;;; (module-local-variable module symbol) => [#<variable ...> | #f]
|
|
|
|
|
|
;;; (module-variable module symbol) => [#<variable ...> | #f]
|
|
|
|
|
|
;;; (module-symbol-binding module symbol opt-value)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;;; => [ <obj> | opt-value | an error occurs ]
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; (module-make-local-var! module symbol) => #<variable...>
|
|
|
|
|
|
;;; (module-add! module symbol var) => unspecified
|
|
|
|
|
|
;;; (module-remove! module symbol) => unspecified
|
|
|
|
|
|
;;; (module-for-each proc module) => unspecified
|
|
|
|
|
|
;;; (make-scm-module) => module ; a lazy copy of the symhash module
|
|
|
|
|
|
;;; (set-current-module module) => unspecified
|
|
|
|
|
|
;;; (current-module) => #<module...>
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-10-16 22:29:19 +00:00
|
|
|
|
;;; {Printing Modules}
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
|
1996-10-16 22:29:19 +00:00
|
|
|
|
;; This is how modules are printed. You can re-define it.
|
1997-06-04 22:39:09 +00:00
|
|
|
|
;; (Redefining is actually more complicated than simply redefining
|
|
|
|
|
|
;; %print-module because that would only change the binding and not
|
|
|
|
|
|
;; the value stored in the vtable that determines how record are
|
|
|
|
|
|
;; printed. Sigh.)
|
|
|
|
|
|
|
|
|
|
|
|
(define (%print-module mod port) ; unused args: depth length style table)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(display "#<" port)
|
|
|
|
|
|
(display (or (module-kind mod) "module") port)
|
residualize names into procedures. re-implement srfi-61. module naming foo.
* module/ice-9/boot-9.scm (cond): Implement srfi-61; most of the code is
from the SRFI itself. Yuk.
(%print-module, make-modules-in, %app, (%app modules))
(module-name): Syncase needs to get at the names of modules, even at
anonymous modules. So lazily assign gensyms as module names. Name %app
as (%app), but since (%app modules) is at the top of the module
hierarchy, name it ().
* module/ice-9/psyntax.scm: When building tree-il, try to name lambdas in
definitions and in lets.
(let, letrec): Give more specific errors in a couple of cases.
* module/ice-9/psyntax-pp.scm: Regenerated.
* test-suite/tests/syntax.test: More work. Many exceptions have different
messages than they used to, many more generic; we can roll this back to
be faithful to the original strings, but it doesn't seem necessary to
me.
2009-05-22 12:08:50 +02:00
|
|
|
|
(display " " port)
|
|
|
|
|
|
(display (module-name mod) port)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(display " " port)
|
|
|
|
|
|
(display (number->string (object-address mod) 16) port)
|
|
|
|
|
|
(display ">" port))
|
|
|
|
|
|
|
|
|
|
|
|
;; module-type
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; A module is characterized by an obarray in which local symbols
|
|
|
|
|
|
;; are interned, a list of modules, "uses", from which non-local
|
|
|
|
|
|
;; bindings can be inherited, and an optional lazy-binder which
|
1996-11-21 16:16:46 +00:00
|
|
|
|
;; is a (CLOSURE module symbol) which, as a last resort, can provide
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; bindings that would otherwise not be found locally in the module.
|
|
|
|
|
|
;;
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;; NOTE: If you change anything here, you also need to change
|
|
|
|
|
|
;; libguile/modules.h.
|
2000-08-11 08:45:35 +00:00
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define module-type
|
1997-09-10 20:07:04 +00:00
|
|
|
|
(make-record-type 'module
|
2009-12-22 00:58:12 +01:00
|
|
|
|
'(obarray uses binder eval-closure transformer name kind
|
|
|
|
|
|
duplicates-handlers import-obarray
|
2009-12-22 00:33:12 +01:00
|
|
|
|
observers weak-observers version)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
%print-module))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-10-16 02:18:33 +00:00
|
|
|
|
;; make-module &opt size uses binder
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;
|
1996-10-16 02:18:33 +00:00
|
|
|
|
;; Create a new module, perhaps with a particular size of obarray,
|
|
|
|
|
|
;; initial uses list, or binding procedure.
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;
|
|
|
|
|
|
(define make-module
|
|
|
|
|
|
(lambda args
|
|
|
|
|
|
|
1996-10-16 02:18:33 +00:00
|
|
|
|
(define (parse-arg index default)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(if (> (length args) index)
|
|
|
|
|
|
(list-ref args index)
|
|
|
|
|
|
default))
|
1996-10-16 02:18:33 +00:00
|
|
|
|
|
2007-05-05 20:38:57 +00:00
|
|
|
|
(define %default-import-size
|
|
|
|
|
|
;; Typical number of imported bindings actually used by a module.
|
|
|
|
|
|
600)
|
|
|
|
|
|
|
1996-10-16 02:18:33 +00:00
|
|
|
|
(if (> (length args) 3)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(error "Too many args to make-module." args))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2003-02-19 16:16:46 +00:00
|
|
|
|
(let ((size (parse-arg 0 31))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(uses (parse-arg 1 '()))
|
|
|
|
|
|
(binder (parse-arg 2 #f)))
|
|
|
|
|
|
|
|
|
|
|
|
(if (not (integer? size))
|
|
|
|
|
|
(error "Illegal size to make-module." size))
|
|
|
|
|
|
(if (not (and (list? uses)
|
|
|
|
|
|
(and-map module? uses)))
|
|
|
|
|
|
(error "Incorrect use list." uses))
|
|
|
|
|
|
(if (and binder (not (procedure? binder)))
|
|
|
|
|
|
(error
|
|
|
|
|
|
"Lazy-binder expected to be a procedure or #f." binder))
|
|
|
|
|
|
|
|
|
|
|
|
(let ((module (module-constructor (make-hash-table size)
|
|
|
|
|
|
uses binder #f %pre-modules-transformer
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
#f #f #f
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(make-hash-table %default-import-size)
|
|
|
|
|
|
'()
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(make-weak-key-hash-table 31) #f)))
|
1996-10-16 02:18:33 +00:00
|
|
|
|
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;; We can't pass this as an argument to module-constructor,
|
|
|
|
|
|
;; because we need it to close over a pointer to the module
|
|
|
|
|
|
;; itself.
|
|
|
|
|
|
(set-module-eval-closure! module (standard-eval-closure module))
|
1996-10-16 02:18:33 +00:00
|
|
|
|
|
2009-12-22 00:58:12 +01:00
|
|
|
|
module))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-10-16 02:18:33 +00:00
|
|
|
|
(define module-constructor (record-constructor module-type))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define module-obarray (record-accessor module-type 'obarray))
|
|
|
|
|
|
(define set-module-obarray! (record-modifier module-type 'obarray))
|
|
|
|
|
|
(define module-uses (record-accessor module-type 'uses))
|
|
|
|
|
|
(define set-module-uses! (record-modifier module-type 'uses))
|
|
|
|
|
|
(define module-binder (record-accessor module-type 'binder))
|
|
|
|
|
|
(define set-module-binder! (record-modifier module-type 'binder))
|
1998-11-22 12:03:34 +00:00
|
|
|
|
|
|
|
|
|
|
;; NOTE: This binding is used in libguile/modules.c.
|
1996-11-21 16:16:46 +00:00
|
|
|
|
(define module-eval-closure (record-accessor module-type 'eval-closure))
|
1998-11-22 12:03:34 +00:00
|
|
|
|
|
really boot primitive-eval from scheme.
* libguile/eval.c (scm_primitive_eval, scm_c_primitive_eval):
(scm_init_eval): Rework so that scm_primitive_eval always calls out to
the primitive-eval variable. The previous definition is the default
value, which is probably overridden by scm_init_eval_in_scheme.
* libguile/init.c (scm_i_init_guile): Move ports and load-path up, so we
can debug when initing eval. Call scm_init_eval_in_scheme. Awesome.
* libguile/load.h:
* libguile/load.c (scm_init_eval_in_scheme): New procedure, loads up
ice-9/eval.scm to replace the primitive-eval definition, if everything
is there and up-to-date.
* libguile/modules.c (scm_module_transformer): Export to Scheme, so it's
there for eval.go.
* module/ice-9/boot-9.scm: No need to define module-transformer.
* module/ice-9/eval.scm (capture-env): Only reference the-root-module if
modules are booted.
(primitive-eval): Inline a definition for identity. Throw a more
standard error for "wrong number of arguments".
* module/ice-9/psyntax.scm (chi-install-global): The macro binding for a
syncase macro is now a pair: the transformer, and the module that was
current when the transformer was installed. The latter is used for
hygiene purposes, replacing the use of procedure-module, which didn't
work with the interpreter's shared-code closures.
(chi-macro): Adapt for the binding being a pair, and get the hygiene
from the cdr.
(eval-local-transformer): Adapt to new form of macro bindings.
* module/ice-9/psyntax-pp.scm: Regenerated.
* .gitignore: Ignore eval.go.stamp.
* module/Makefile.am: Reorder for fastest serial compilation, now that
there are no ordering constraints. I did a number of experiments here
and this seems to be the best; but the bulk of the time is compiling
psyntax-pp.scm with eval.scm. Not so great.
* libguile/vm-engine.c (vm-engine): Throw a more standard error for
"wrong type to apply".
* test-suite/tests/gc.test ("gc"): Remove a hack that shouldn't affect
the new evaluator, and throw in another (gc) for good measure.
* test-suite/tests/goops.test ("defining classes"):
* test-suite/tests/hooks.test (proc1): We can't currently check what the
arity is of a closure made by eval.scm -- or more accurately all
closures have 0 required args and no rest args. So punt for now.
* test-suite/tests/syntax.test ("letrec"): The scheme evaluator can't
check that a variable is unbound, currently; perhaps the full "fixing
letrec" expansion could fix this. But barring that, punt.
2009-12-01 23:54:25 +01:00
|
|
|
|
;; (define module-transformer (record-accessor module-type 'transformer))
|
1997-09-10 20:07:04 +00:00
|
|
|
|
(define set-module-transformer! (record-modifier module-type 'transformer))
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(define module-version (record-accessor module-type 'version))
|
|
|
|
|
|
(define set-module-version! (record-modifier module-type 'version))
|
2009-04-24 13:50:14 +02:00
|
|
|
|
;; (define module-name (record-accessor module-type 'name)) wait until mods are booted
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define set-module-name! (record-modifier module-type 'name))
|
|
|
|
|
|
(define module-kind (record-accessor module-type 'kind))
|
|
|
|
|
|
(define set-module-kind! (record-modifier module-type 'kind))
|
2003-03-12 14:30:03 +00:00
|
|
|
|
(define module-duplicates-handlers
|
|
|
|
|
|
(record-accessor module-type 'duplicates-handlers))
|
|
|
|
|
|
(define set-module-duplicates-handlers!
|
|
|
|
|
|
(record-modifier module-type 'duplicates-handlers))
|
GOOPS needs the observer protocol specified for the new module
system. Here's a simple version for the old module system:
* boot-9.scm (module-observers, module-weak-observers,
module-observer-id, set-module-observers!,
set-module-observer-id!): New accessors.
(module-type): Added slots `observers', `weak-observers' and
`observer-id'.
(module-observe, module-observe-weak, module-unobserve,
module-modified!): New procedures.
(module-make-local-var!, module-add!, module-remove!,
module-clear!, module-define!, module-use!): Call module-modified!.
1999-08-05 12:05:57 +00:00
|
|
|
|
(define module-observers (record-accessor module-type 'observers))
|
|
|
|
|
|
(define set-module-observers! (record-modifier module-type 'observers))
|
|
|
|
|
|
(define module-weak-observers (record-accessor module-type 'weak-observers))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define module? (record-predicate module-type))
|
|
|
|
|
|
|
2007-05-05 20:38:57 +00:00
|
|
|
|
(define module-import-obarray (record-accessor module-type 'import-obarray))
|
|
|
|
|
|
|
1999-03-12 09:48:18 +00:00
|
|
|
|
(define set-module-eval-closure!
|
|
|
|
|
|
(let ((setter (record-modifier module-type 'eval-closure)))
|
|
|
|
|
|
(lambda (module closure)
|
|
|
|
|
|
(setter module closure)
|
2005-07-31 23:36:50 +00:00
|
|
|
|
;; Make it possible to lookup the module from the environment.
|
|
|
|
|
|
;; This implementation is correct since an eval closure can belong
|
|
|
|
|
|
;; to maximally one module.
|
2008-11-05 18:50:23 +01:00
|
|
|
|
|
|
|
|
|
|
;; XXX: The following line introduces a circular reference that
|
|
|
|
|
|
;; precludes garbage collection of modules with the current weak hash
|
|
|
|
|
|
;; table semantics (see
|
2009-09-15 22:31:45 +02:00
|
|
|
|
;; http://lists.gnu.org/archive/html/guile-devel/2009-01/msg00102.html and
|
2008-11-05 18:50:23 +01:00
|
|
|
|
;; http://thread.gmane.org/gmane.comp.programming.garbage-collection.boehmgc/2465
|
|
|
|
|
|
;; for details). Since it doesn't appear to be used (only in
|
|
|
|
|
|
;; `scm_lookup_closure_module ()', which has 1 caller), we just comment
|
|
|
|
|
|
;; it out.
|
|
|
|
|
|
|
|
|
|
|
|
;(set-procedure-property! closure 'module module)
|
|
|
|
|
|
)))
|
1996-10-16 02:18:33 +00:00
|
|
|
|
|
GOOPS needs the observer protocol specified for the new module
system. Here's a simple version for the old module system:
* boot-9.scm (module-observers, module-weak-observers,
module-observer-id, set-module-observers!,
set-module-observer-id!): New accessors.
(module-type): Added slots `observers', `weak-observers' and
`observer-id'.
(module-observe, module-observe-weak, module-unobserve,
module-modified!): New procedures.
(module-make-local-var!, module-add!, module-remove!,
module-clear!, module-define!, module-use!): Call module-modified!.
1999-08-05 12:05:57 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
GOOPS needs the observer protocol specified for the new module
system. Here's a simple version for the old module system:
* boot-9.scm (module-observers, module-weak-observers,
module-observer-id, set-module-observers!,
set-module-observer-id!): New accessors.
(module-type): Added slots `observers', `weak-observers' and
`observer-id'.
(module-observe, module-observe-weak, module-unobserve,
module-modified!): New procedures.
(module-make-local-var!, module-add!, module-remove!,
module-clear!, module-define!, module-use!): Call module-modified!.
1999-08-05 12:05:57 +00:00
|
|
|
|
;;; {Observer protocol}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (module-observe module proc)
|
|
|
|
|
|
(set-module-observers! module (cons proc (module-observers module)))
|
|
|
|
|
|
(cons module proc))
|
|
|
|
|
|
|
2007-05-05 20:38:57 +00:00
|
|
|
|
(define (module-observe-weak module observer-id . proc)
|
|
|
|
|
|
;; Register PROC as an observer of MODULE under name OBSERVER-ID (which can
|
|
|
|
|
|
;; be any Scheme object). PROC is invoked and passed MODULE any time
|
|
|
|
|
|
;; MODULE is modified. PROC gets unregistered when OBSERVER-ID gets GC'd
|
|
|
|
|
|
;; (thus, it is never unregistered if OBSERVER-ID is an immediate value,
|
|
|
|
|
|
;; for instance).
|
|
|
|
|
|
|
|
|
|
|
|
;; The two-argument version is kept for backward compatibility: when called
|
|
|
|
|
|
;; with two arguments, the observer gets unregistered when closure PROC
|
|
|
|
|
|
;; gets GC'd (making it impossible to use an anonymous lambda for PROC).
|
|
|
|
|
|
|
|
|
|
|
|
(let ((proc (if (null? proc) observer-id (car proc))))
|
|
|
|
|
|
(hashq-set! (module-weak-observers module) observer-id proc)))
|
GOOPS needs the observer protocol specified for the new module
system. Here's a simple version for the old module system:
* boot-9.scm (module-observers, module-weak-observers,
module-observer-id, set-module-observers!,
set-module-observer-id!): New accessors.
(module-type): Added slots `observers', `weak-observers' and
`observer-id'.
(module-observe, module-observe-weak, module-unobserve,
module-modified!): New procedures.
(module-make-local-var!, module-add!, module-remove!,
module-clear!, module-define!, module-use!): Call module-modified!.
1999-08-05 12:05:57 +00:00
|
|
|
|
|
|
|
|
|
|
(define (module-unobserve token)
|
|
|
|
|
|
(let ((module (car token))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(id (cdr token)))
|
GOOPS needs the observer protocol specified for the new module
system. Here's a simple version for the old module system:
* boot-9.scm (module-observers, module-weak-observers,
module-observer-id, set-module-observers!,
set-module-observer-id!): New accessors.
(module-type): Added slots `observers', `weak-observers' and
`observer-id'.
(module-observe, module-observe-weak, module-unobserve,
module-modified!): New procedures.
(module-make-local-var!, module-add!, module-remove!,
module-clear!, module-define!, module-use!): Call module-modified!.
1999-08-05 12:05:57 +00:00
|
|
|
|
(if (integer? id)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(hash-remove! (module-weak-observers module) id)
|
|
|
|
|
|
(set-module-observers! module (delq1! id (module-observers module)))))
|
GOOPS needs the observer protocol specified for the new module
system. Here's a simple version for the old module system:
* boot-9.scm (module-observers, module-weak-observers,
module-observer-id, set-module-observers!,
set-module-observer-id!): New accessors.
(module-type): Added slots `observers', `weak-observers' and
`observer-id'.
(module-observe, module-observe-weak, module-unobserve,
module-modified!): New procedures.
(module-make-local-var!, module-add!, module-remove!,
module-clear!, module-define!, module-use!): Call module-modified!.
1999-08-05 12:05:57 +00:00
|
|
|
|
*unspecified*)
|
|
|
|
|
|
|
2003-03-12 14:11:42 +00:00
|
|
|
|
(define module-defer-observers #f)
|
2009-02-20 14:23:55 +01:00
|
|
|
|
(define module-defer-observers-mutex (make-mutex 'recursive))
|
2003-03-12 14:11:42 +00:00
|
|
|
|
(define module-defer-observers-table (make-hash-table))
|
|
|
|
|
|
|
1999-08-05 17:56:15 +00:00
|
|
|
|
(define (module-modified m)
|
2003-03-12 14:11:42 +00:00
|
|
|
|
(if module-defer-observers
|
|
|
|
|
|
(hash-set! module-defer-observers-table m #t)
|
|
|
|
|
|
(module-call-observers m)))
|
|
|
|
|
|
|
|
|
|
|
|
;;; This function can be used to delay calls to observers so that they
|
|
|
|
|
|
;;; can be called once only in the face of massive updating of modules.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
(define (call-with-deferred-observers thunk)
|
|
|
|
|
|
(dynamic-wind
|
|
|
|
|
|
(lambda ()
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(lock-mutex module-defer-observers-mutex)
|
|
|
|
|
|
(set! module-defer-observers #t))
|
2003-03-12 14:11:42 +00:00
|
|
|
|
thunk
|
|
|
|
|
|
(lambda ()
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(set! module-defer-observers #f)
|
|
|
|
|
|
(hash-for-each (lambda (m dummy)
|
|
|
|
|
|
(module-call-observers m))
|
|
|
|
|
|
module-defer-observers-table)
|
|
|
|
|
|
(hash-clear! module-defer-observers-table)
|
|
|
|
|
|
(unlock-mutex module-defer-observers-mutex))))
|
2003-03-12 14:11:42 +00:00
|
|
|
|
|
|
|
|
|
|
(define (module-call-observers m)
|
GOOPS needs the observer protocol specified for the new module
system. Here's a simple version for the old module system:
* boot-9.scm (module-observers, module-weak-observers,
module-observer-id, set-module-observers!,
set-module-observer-id!): New accessors.
(module-type): Added slots `observers', `weak-observers' and
`observer-id'.
(module-observe, module-observe-weak, module-unobserve,
module-modified!): New procedures.
(module-make-local-var!, module-add!, module-remove!,
module-clear!, module-define!, module-use!): Call module-modified!.
1999-08-05 12:05:57 +00:00
|
|
|
|
(for-each (lambda (proc) (proc m)) (module-observers m))
|
2007-05-05 20:38:57 +00:00
|
|
|
|
|
|
|
|
|
|
;; We assume that weak observers don't (un)register themselves as they are
|
|
|
|
|
|
;; called since this would preclude proper iteration over the hash table
|
|
|
|
|
|
;; elements.
|
|
|
|
|
|
(hash-for-each (lambda (id proc) (proc m)) (module-weak-observers m)))
|
GOOPS needs the observer protocol specified for the new module
system. Here's a simple version for the old module system:
* boot-9.scm (module-observers, module-weak-observers,
module-observer-id, set-module-observers!,
set-module-observer-id!): New accessors.
(module-type): Added slots `observers', `weak-observers' and
`observer-id'.
(module-observe, module-observe-weak, module-unobserve,
module-modified!): New procedures.
(module-make-local-var!, module-add!, module-remove!,
module-clear!, module-define!, module-use!): Call module-modified!.
1999-08-05 12:05:57 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Module Searching in General}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; We sometimes want to look for properties of a symbol
|
|
|
|
|
|
;;; just within the obarray of one module. If the property
|
|
|
|
|
|
;;; holds, then it is said to hold ``locally'' as in, ``The symbol
|
|
|
|
|
|
;;; DISPLAY is locally rebound in the module `safe-guile'.''
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Other times, we want to test for a symbol property in the obarray
|
|
|
|
|
|
;;; of M and, if it is not found there, try each of the modules in the
|
|
|
|
|
|
;;; uses list of M. This is the normal way of testing for some
|
|
|
|
|
|
;;; property, so we state these properties without qualification as
|
|
|
|
|
|
;;; in: ``The symbol 'fnord is interned in module M because it is
|
|
|
|
|
|
;;; interned locally in module M2 which is a member of the uses list
|
|
|
|
|
|
;;; of M.''
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; module-search fn m
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; return the first non-#f result of FN applied to M and then to
|
|
|
|
|
|
;; the modules in the uses of m, and so on recursively. If all applications
|
|
|
|
|
|
;; return #f, then so does this function.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-search fn m v)
|
|
|
|
|
|
(define (loop pos)
|
|
|
|
|
|
(and (pair? pos)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(or (module-search fn (car pos) v)
|
|
|
|
|
|
(loop (cdr pos)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(or (fn m v)
|
|
|
|
|
|
(loop (module-uses m))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Is a symbol bound in a module?}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Symbol S in Module M is bound if S is interned in M and if the binding
|
|
|
|
|
|
;;; of S in M has been set to some well-defined value.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; module-locally-bound? module symbol
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Is a symbol bound (interned and defined) locally in a given module?
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-locally-bound? m v)
|
|
|
|
|
|
(let ((var (module-local-variable m v)))
|
|
|
|
|
|
(and var
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(variable-bound? var))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;; module-bound? module symbol
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Is a symbol bound (interned and defined) anywhere in a given module
|
|
|
|
|
|
;; or its uses?
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-bound? m v)
|
2009-04-26 11:35:23 +02:00
|
|
|
|
(let ((var (module-variable m v)))
|
|
|
|
|
|
(and var
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(variable-bound? var))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Is a symbol interned in a module?}
|
|
|
|
|
|
;;;
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;; Symbol S in Module M is interned if S occurs in
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; of S in M has been set to some well-defined value.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; It is possible to intern a symbol in a module without providing
|
|
|
|
|
|
;;; an initial binding for the corresponding variable. This is done
|
|
|
|
|
|
;;; with:
|
|
|
|
|
|
;;; (module-add! module symbol (make-undefined-variable))
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; In that case, the symbol is interned in the module, but not
|
|
|
|
|
|
;;; bound there. The unbound symbol shadows any binding for that
|
|
|
|
|
|
;;; symbol that might otherwise be inherited from a member of the uses list.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (module-obarray-get-handle ob key)
|
|
|
|
|
|
((if (symbol? key) hashq-get-handle hash-get-handle) ob key))
|
|
|
|
|
|
|
|
|
|
|
|
(define (module-obarray-ref ob key)
|
|
|
|
|
|
((if (symbol? key) hashq-ref hash-ref) ob key))
|
|
|
|
|
|
|
|
|
|
|
|
(define (module-obarray-set! ob key val)
|
|
|
|
|
|
((if (symbol? key) hashq-set! hash-set!) ob key val))
|
|
|
|
|
|
|
|
|
|
|
|
(define (module-obarray-remove! ob key)
|
|
|
|
|
|
((if (symbol? key) hashq-remove! hash-remove!) ob key))
|
|
|
|
|
|
|
|
|
|
|
|
;; module-symbol-locally-interned? module symbol
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; is a symbol interned (not neccessarily defined) locally in a given module
|
|
|
|
|
|
;; or its uses? Interned symbols shadow inherited bindings even if
|
|
|
|
|
|
;; they are not themselves bound to a defined value.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-symbol-locally-interned? m v)
|
|
|
|
|
|
(not (not (module-obarray-get-handle (module-obarray m) v))))
|
|
|
|
|
|
|
|
|
|
|
|
;; module-symbol-interned? module symbol
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; is a symbol interned (not neccessarily defined) anywhere in a given module
|
|
|
|
|
|
;; or its uses? Interned symbols shadow inherited bindings even if
|
|
|
|
|
|
;; they are not themselves bound to a defined value.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-symbol-interned? m v)
|
|
|
|
|
|
(module-search module-symbol-locally-interned? m v))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Mapping modules x symbols --> variables}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; module-local-variable module symbol
|
|
|
|
|
|
;; return the local variable associated with a MODULE and SYMBOL.
|
|
|
|
|
|
;;
|
|
|
|
|
|
;;; This function is very important. It is the only function that can
|
|
|
|
|
|
;;; return a variable from a module other than the mutators that store
|
|
|
|
|
|
;;; new variables in modules. Therefore, this function is the location
|
|
|
|
|
|
;;; of the "lazy binder" hack.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; If symbol is defined in MODULE, and if the definition binds symbol
|
|
|
|
|
|
;;; to a variable, return that variable object.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; If the symbols is not found at first, but the module has a lazy binder,
|
|
|
|
|
|
;;; then try the binder.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; If the symbol is not found at all, return #f.
|
|
|
|
|
|
;;;
|
2007-05-05 20:38:57 +00:00
|
|
|
|
;;; (This is now written in C, see `modules.c'.)
|
|
|
|
|
|
;;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Mapping modules x symbols --> bindings}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; These are similar to the mapping to variables, except that the
|
|
|
|
|
|
;;; variable is dereferenced.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; module-symbol-binding module symbol opt-value
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; return the binding of a variable specified by name within
|
|
|
|
|
|
;; a given module, signalling an error if the variable is unbound.
|
|
|
|
|
|
;; If the OPT-VALUE is passed, then instead of signalling an error,
|
|
|
|
|
|
;; return OPT-VALUE.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-symbol-local-binding m v . opt-val)
|
|
|
|
|
|
(let ((var (module-local-variable m v)))
|
2003-03-07 13:12:47 +00:00
|
|
|
|
(if (and var (variable-bound? var))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(variable-ref var)
|
|
|
|
|
|
(if (not (null? opt-val))
|
|
|
|
|
|
(car opt-val)
|
|
|
|
|
|
(error "Locally unbound variable." v)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;; module-symbol-binding module symbol opt-value
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; return the binding of a variable specified by name within
|
|
|
|
|
|
;; a given module, signalling an error if the variable is unbound.
|
|
|
|
|
|
;; If the OPT-VALUE is passed, then instead of signalling an error,
|
|
|
|
|
|
;; return OPT-VALUE.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-symbol-binding m v . opt-val)
|
|
|
|
|
|
(let ((var (module-variable m v)))
|
2003-03-07 13:12:47 +00:00
|
|
|
|
(if (and var (variable-bound? var))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(variable-ref var)
|
|
|
|
|
|
(if (not (null? opt-val))
|
|
|
|
|
|
(car opt-val)
|
|
|
|
|
|
(error "Unbound variable." v)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Adding Variables to Modules}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; module-make-local-var! module symbol
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; ensure a variable for V in the local namespace of M.
|
|
|
|
|
|
;; If no variable was already there, then create a new and uninitialzied
|
|
|
|
|
|
;; variable.
|
|
|
|
|
|
;;
|
2003-03-12 14:11:42 +00:00
|
|
|
|
;; This function is used in modules.c.
|
|
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (module-make-local-var! m v)
|
|
|
|
|
|
(or (let ((b (module-obarray-ref (module-obarray m) v)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(and (variable? b)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
;; Mark as modified since this function is called when
|
|
|
|
|
|
;; the standard eval closure defines a binding
|
|
|
|
|
|
(module-modified m)
|
|
|
|
|
|
b)))
|
2004-12-22 14:50:56 +00:00
|
|
|
|
|
2007-05-05 20:38:57 +00:00
|
|
|
|
;; Create a new local variable.
|
|
|
|
|
|
(let ((local-var (make-undefined-variable)))
|
|
|
|
|
|
(module-add! m v local-var)
|
|
|
|
|
|
local-var)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-06-04 22:14:16 +00:00
|
|
|
|
;; module-ensure-local-variable! module symbol
|
2001-06-02 18:33:25 +00:00
|
|
|
|
;;
|
2001-06-04 22:14:16 +00:00
|
|
|
|
;; Ensure that there is a local variable in MODULE for SYMBOL. If
|
|
|
|
|
|
;; there is no binding for SYMBOL, create a new uninitialized
|
|
|
|
|
|
;; variable. Return the local variable.
|
2001-06-02 18:33:25 +00:00
|
|
|
|
;;
|
2001-06-04 22:14:16 +00:00
|
|
|
|
(define (module-ensure-local-variable! module symbol)
|
|
|
|
|
|
(or (module-local-variable module symbol)
|
2001-06-02 18:33:25 +00:00
|
|
|
|
(let ((var (make-undefined-variable)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(module-add! module symbol var)
|
|
|
|
|
|
var)))
|
2001-06-02 18:33:25 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; module-add! module symbol var
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; ensure a particular variable for V in the local namespace of M.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-add! m v var)
|
|
|
|
|
|
(if (not (variable? var))
|
|
|
|
|
|
(error "Bad variable to module-add!" var))
|
GOOPS needs the observer protocol specified for the new module
system. Here's a simple version for the old module system:
* boot-9.scm (module-observers, module-weak-observers,
module-observer-id, set-module-observers!,
set-module-observer-id!): New accessors.
(module-type): Added slots `observers', `weak-observers' and
`observer-id'.
(module-observe, module-observe-weak, module-unobserve,
module-modified!): New procedures.
(module-make-local-var!, module-add!, module-remove!,
module-clear!, module-define!, module-use!): Call module-modified!.
1999-08-05 12:05:57 +00:00
|
|
|
|
(module-obarray-set! (module-obarray m) v var)
|
1999-08-05 17:56:15 +00:00
|
|
|
|
(module-modified m))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;; module-remove!
|
|
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; make sure that a symbol is undefined in the local namespace of M.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-remove! m v)
|
* hooks.c (scm_c_hook_add): Fixed bug in append mode.
* environments.c (obarray_enter, obarray_retrieve, obarray_remove,
leaf_environment_fold, obarray_remove_all): Use hashtable
accessors.
* gc.c (scm_init_storage): Moved hook initialization to
scm_storage_prehistory.
(scm_storage_prehistory): New function.
(scm_igc): Added commentary about placement of
scm_after_sweep_c_hook.
* gc-mark.c (scm_mark_all): Use hashtable accessors.
(scm_gc_mark_dependencies): Use SCM_WVECT_WEAK_KEY_P and
SCM_WVECT_WEAK_VALUE_P.
* hashtab.c, hashtab.h (scm_hash_for_each, scm_hash_map): New
functions.
(scm_vector_to_hash_table, scm_c_make_resizing_hash_table):
Removed.
(scm_make_weak_key_hash_table, scm_make_weak_value_hash_table,
scm_make_doubly_weak_hash_table): Moved here from weaks.c.
* init.c (scm_init_guile_1): Removed call to scm_init_weaks; Added
calls to scm_storage_prehistory and scm_hashtab_prehistory.
* modules.c (module-reverse-lookup): Use hashtable accessors.
* symbols.c, symbols.h (scm_i_hash_symbol): New function.
* weaks.c, weaks.h (scm_make_weak_key_alist_vector,
scm_make_weak_value_alist_vector,
scm_make_doubly_weak_alist_vector): New functions.
* weaks.c (scm_init_weaks_builtins): New function.
* weaks.h (SCM_WVECTF_WEAK_KEY, SCM_WVECTF_WEAK_VALUE,
SCM_WVECTF_NOSCAN, SCM_WVECT_WEAK_KEY_P, SCM_WVECT_WEAK_VALUE_P,
SCM_WVECT_NOSCAN_P): New macros.
* weaks.c (scm_scan_weak_vectors): Use SCM_WVECT_WEAK_KEY_P
and SCM_WVECT_WEAK_VALUE_P.
* weaks.c, weaks.h (scm_i_allocate_weak_vector): Renamed from
allocate_weak_vector and exported.
* Makefile.am (ice9_sources): Added weak-vector.scm.
* weak-vector.scm: New file.
* boot-9.scm (module-clear!): Use hash-clear!.
(module-for-each): Use hash-for-each.
(module-map): Use hash-map.
2003-02-19 15:04:51 +00:00
|
|
|
|
(module-obarray-remove! (module-obarray m) v)
|
1999-08-05 17:56:15 +00:00
|
|
|
|
(module-modified m))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (module-clear! m)
|
* hooks.c (scm_c_hook_add): Fixed bug in append mode.
* environments.c (obarray_enter, obarray_retrieve, obarray_remove,
leaf_environment_fold, obarray_remove_all): Use hashtable
accessors.
* gc.c (scm_init_storage): Moved hook initialization to
scm_storage_prehistory.
(scm_storage_prehistory): New function.
(scm_igc): Added commentary about placement of
scm_after_sweep_c_hook.
* gc-mark.c (scm_mark_all): Use hashtable accessors.
(scm_gc_mark_dependencies): Use SCM_WVECT_WEAK_KEY_P and
SCM_WVECT_WEAK_VALUE_P.
* hashtab.c, hashtab.h (scm_hash_for_each, scm_hash_map): New
functions.
(scm_vector_to_hash_table, scm_c_make_resizing_hash_table):
Removed.
(scm_make_weak_key_hash_table, scm_make_weak_value_hash_table,
scm_make_doubly_weak_hash_table): Moved here from weaks.c.
* init.c (scm_init_guile_1): Removed call to scm_init_weaks; Added
calls to scm_storage_prehistory and scm_hashtab_prehistory.
* modules.c (module-reverse-lookup): Use hashtable accessors.
* symbols.c, symbols.h (scm_i_hash_symbol): New function.
* weaks.c, weaks.h (scm_make_weak_key_alist_vector,
scm_make_weak_value_alist_vector,
scm_make_doubly_weak_alist_vector): New functions.
* weaks.c (scm_init_weaks_builtins): New function.
* weaks.h (SCM_WVECTF_WEAK_KEY, SCM_WVECTF_WEAK_VALUE,
SCM_WVECTF_NOSCAN, SCM_WVECT_WEAK_KEY_P, SCM_WVECT_WEAK_VALUE_P,
SCM_WVECT_NOSCAN_P): New macros.
* weaks.c (scm_scan_weak_vectors): Use SCM_WVECT_WEAK_KEY_P
and SCM_WVECT_WEAK_VALUE_P.
* weaks.c, weaks.h (scm_i_allocate_weak_vector): Renamed from
allocate_weak_vector and exported.
* Makefile.am (ice9_sources): Added weak-vector.scm.
* weak-vector.scm: New file.
* boot-9.scm (module-clear!): Use hash-clear!.
(module-for-each): Use hash-for-each.
(module-map): Use hash-map.
2003-02-19 15:04:51 +00:00
|
|
|
|
(hash-clear! (module-obarray m))
|
1999-08-05 17:56:15 +00:00
|
|
|
|
(module-modified m))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;; MODULE-FOR-EACH -- exported
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; Call PROC on each symbol in MODULE, with arguments of (SYMBOL VARIABLE).
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-for-each proc module)
|
* hooks.c (scm_c_hook_add): Fixed bug in append mode.
* environments.c (obarray_enter, obarray_retrieve, obarray_remove,
leaf_environment_fold, obarray_remove_all): Use hashtable
accessors.
* gc.c (scm_init_storage): Moved hook initialization to
scm_storage_prehistory.
(scm_storage_prehistory): New function.
(scm_igc): Added commentary about placement of
scm_after_sweep_c_hook.
* gc-mark.c (scm_mark_all): Use hashtable accessors.
(scm_gc_mark_dependencies): Use SCM_WVECT_WEAK_KEY_P and
SCM_WVECT_WEAK_VALUE_P.
* hashtab.c, hashtab.h (scm_hash_for_each, scm_hash_map): New
functions.
(scm_vector_to_hash_table, scm_c_make_resizing_hash_table):
Removed.
(scm_make_weak_key_hash_table, scm_make_weak_value_hash_table,
scm_make_doubly_weak_hash_table): Moved here from weaks.c.
* init.c (scm_init_guile_1): Removed call to scm_init_weaks; Added
calls to scm_storage_prehistory and scm_hashtab_prehistory.
* modules.c (module-reverse-lookup): Use hashtable accessors.
* symbols.c, symbols.h (scm_i_hash_symbol): New function.
* weaks.c, weaks.h (scm_make_weak_key_alist_vector,
scm_make_weak_value_alist_vector,
scm_make_doubly_weak_alist_vector): New functions.
* weaks.c (scm_init_weaks_builtins): New function.
* weaks.h (SCM_WVECTF_WEAK_KEY, SCM_WVECTF_WEAK_VALUE,
SCM_WVECTF_NOSCAN, SCM_WVECT_WEAK_KEY_P, SCM_WVECT_WEAK_VALUE_P,
SCM_WVECT_NOSCAN_P): New macros.
* weaks.c (scm_scan_weak_vectors): Use SCM_WVECT_WEAK_KEY_P
and SCM_WVECT_WEAK_VALUE_P.
* weaks.c, weaks.h (scm_i_allocate_weak_vector): Renamed from
allocate_weak_vector and exported.
* Makefile.am (ice9_sources): Added weak-vector.scm.
* weak-vector.scm: New file.
* boot-9.scm (module-clear!): Use hash-clear!.
(module-for-each): Use hash-for-each.
(module-map): Use hash-map.
2003-02-19 15:04:51 +00:00
|
|
|
|
(hash-for-each proc (module-obarray module)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (module-map proc module)
|
2004-02-13 23:15:37 +00:00
|
|
|
|
(hash-map->list proc (module-obarray module)))
|
* hooks.c (scm_c_hook_add): Fixed bug in append mode.
* environments.c (obarray_enter, obarray_retrieve, obarray_remove,
leaf_environment_fold, obarray_remove_all): Use hashtable
accessors.
* gc.c (scm_init_storage): Moved hook initialization to
scm_storage_prehistory.
(scm_storage_prehistory): New function.
(scm_igc): Added commentary about placement of
scm_after_sweep_c_hook.
* gc-mark.c (scm_mark_all): Use hashtable accessors.
(scm_gc_mark_dependencies): Use SCM_WVECT_WEAK_KEY_P and
SCM_WVECT_WEAK_VALUE_P.
* hashtab.c, hashtab.h (scm_hash_for_each, scm_hash_map): New
functions.
(scm_vector_to_hash_table, scm_c_make_resizing_hash_table):
Removed.
(scm_make_weak_key_hash_table, scm_make_weak_value_hash_table,
scm_make_doubly_weak_hash_table): Moved here from weaks.c.
* init.c (scm_init_guile_1): Removed call to scm_init_weaks; Added
calls to scm_storage_prehistory and scm_hashtab_prehistory.
* modules.c (module-reverse-lookup): Use hashtable accessors.
* symbols.c, symbols.h (scm_i_hash_symbol): New function.
* weaks.c, weaks.h (scm_make_weak_key_alist_vector,
scm_make_weak_value_alist_vector,
scm_make_doubly_weak_alist_vector): New functions.
* weaks.c (scm_init_weaks_builtins): New function.
* weaks.h (SCM_WVECTF_WEAK_KEY, SCM_WVECTF_WEAK_VALUE,
SCM_WVECTF_NOSCAN, SCM_WVECT_WEAK_KEY_P, SCM_WVECT_WEAK_VALUE_P,
SCM_WVECT_NOSCAN_P): New macros.
* weaks.c (scm_scan_weak_vectors): Use SCM_WVECT_WEAK_KEY_P
and SCM_WVECT_WEAK_VALUE_P.
* weaks.c, weaks.h (scm_i_allocate_weak_vector): Renamed from
allocate_weak_vector and exported.
* Makefile.am (ice9_sources): Added weak-vector.scm.
* weak-vector.scm: New file.
* boot-9.scm (module-clear!): Use hash-clear!.
(module-for-each): Use hash-for-each.
(module-map): Use hash-map.
2003-02-19 15:04:51 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Low Level Bootstrapping}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;; make-root-module
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-05-15 14:59:42 +00:00
|
|
|
|
;; A root module uses the pre-modules-obarray as its obarray. This
|
|
|
|
|
|
;; special obarray accumulates all bindings that have been established
|
|
|
|
|
|
;; before the module system is fully booted.
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;
|
2001-05-15 14:59:42 +00:00
|
|
|
|
;; (The obarray continues to be used by code that has been closed over
|
|
|
|
|
|
;; before the module system has been booted.)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (make-root-module)
|
2001-05-15 14:59:42 +00:00
|
|
|
|
(let ((m (make-module 0)))
|
|
|
|
|
|
(set-module-obarray! m (%get-pre-modules-obarray))
|
|
|
|
|
|
m))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-05-15 19:33:43 +00:00
|
|
|
|
;; make-scm-module
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-05-15 14:59:42 +00:00
|
|
|
|
;; The root interface is a module that uses the same obarray as the
|
|
|
|
|
|
;; root module. It does not allow new definitions, tho.
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2000-06-04 01:34:27 +00:00
|
|
|
|
(define (make-scm-module)
|
2001-05-15 14:59:42 +00:00
|
|
|
|
(let ((m (make-module 0)))
|
|
|
|
|
|
(set-module-obarray! m (%get-pre-modules-obarray))
|
|
|
|
|
|
(set-module-eval-closure! m (standard-interface-eval-closure m))
|
|
|
|
|
|
m))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Module-based Loading}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (save-module-excursion thunk)
|
|
|
|
|
|
(let ((inner-module (current-module))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(outer-module #f))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(dynamic-wind (lambda ()
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(set! outer-module (current-module))
|
|
|
|
|
|
(set-current-module inner-module)
|
|
|
|
|
|
(set! inner-module #f))
|
|
|
|
|
|
thunk
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(set! inner-module (current-module))
|
|
|
|
|
|
(set-current-module outer-module)
|
|
|
|
|
|
(set! outer-module #f)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define basic-load load)
|
|
|
|
|
|
|
2005-12-14 00:21:11 +00:00
|
|
|
|
(define (load-module filename . reader)
|
1998-06-18 23:59:24 +00:00
|
|
|
|
(save-module-excursion
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(let ((oldname (and (current-load-port)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(port-filename (current-load-port)))))
|
2005-12-14 00:21:11 +00:00
|
|
|
|
(apply basic-load
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(if (and oldname
|
|
|
|
|
|
(> (string-length filename) 0)
|
|
|
|
|
|
(not (char=? (string-ref filename 0) #\/))
|
|
|
|
|
|
(not (string=? (dirname oldname) ".")))
|
|
|
|
|
|
(string-append (dirname oldname) "/" filename)
|
|
|
|
|
|
filename)
|
|
|
|
|
|
reader)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-10-16 22:29:19 +00:00
|
|
|
|
;;; {MODULE-REF -- exported}
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; Returns the value of a variable called NAME in MODULE or any of its
|
|
|
|
|
|
;; used modules. If there is no such variable, then if the optional third
|
|
|
|
|
|
;; argument DEFAULT is present, it is returned; otherwise an error is signaled.
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (module-ref module name . rest)
|
|
|
|
|
|
(let ((variable (module-variable module name)))
|
|
|
|
|
|
(if (and variable (variable-bound? variable))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(variable-ref variable)
|
|
|
|
|
|
(if (null? rest)
|
|
|
|
|
|
(error "No variable named" name 'in module)
|
|
|
|
|
|
(car rest) ; default value
|
|
|
|
|
|
))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;; MODULE-SET! -- exported
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Sets the variable called NAME in MODULE (or in a module that MODULE uses)
|
|
|
|
|
|
;; to VALUE; if there is no such variable, an error is signaled.
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (module-set! module name value)
|
|
|
|
|
|
(let ((variable (module-variable module name)))
|
|
|
|
|
|
(if variable
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(variable-set! variable value)
|
|
|
|
|
|
(error "No variable named" name 'in module))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;; MODULE-DEFINE! -- exported
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Sets the variable called NAME in MODULE to VALUE; if there is no such
|
|
|
|
|
|
;; variable, it is added first.
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (module-define! module name value)
|
|
|
|
|
|
(let ((variable (module-local-variable module name)))
|
|
|
|
|
|
(if variable
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(begin
|
|
|
|
|
|
(variable-set! variable value)
|
|
|
|
|
|
(module-modified module))
|
|
|
|
|
|
(let ((variable (make-variable value)))
|
|
|
|
|
|
(module-add! module name variable)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1997-02-27 15:36:04 +00:00
|
|
|
|
;; MODULE-DEFINED? -- exported
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Return #t iff NAME is defined in MODULE (or in a module that MODULE
|
|
|
|
|
|
;; uses)
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-defined? module name)
|
|
|
|
|
|
(let ((variable (module-variable module name)))
|
|
|
|
|
|
(and variable (variable-bound? variable))))
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;; MODULE-USE! module interface
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Add INTERFACE to the list of interfaces used by MODULE.
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (module-use! module interface)
|
2009-03-18 00:44:26 +01:00
|
|
|
|
(if (not (or (eq? module interface)
|
|
|
|
|
|
(memq interface (module-uses module))))
|
2007-05-05 20:38:57 +00:00
|
|
|
|
(begin
|
|
|
|
|
|
;; Newly used modules must be appended rather than consed, so that
|
|
|
|
|
|
;; `module-variable' traverses the use list starting from the first
|
|
|
|
|
|
;; used module.
|
|
|
|
|
|
(set-module-uses! module
|
|
|
|
|
|
(append (filter (lambda (m)
|
|
|
|
|
|
(not
|
|
|
|
|
|
(equal? (module-name m)
|
|
|
|
|
|
(module-name interface))))
|
|
|
|
|
|
(module-uses module))
|
|
|
|
|
|
(list interface)))
|
|
|
|
|
|
|
|
|
|
|
|
(module-modified module))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2003-03-07 13:12:47 +00:00
|
|
|
|
;; MODULE-USE-INTERFACES! module interfaces
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Same as MODULE-USE! but add multiple interfaces and check for duplicates
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-use-interfaces! module interfaces)
|
2007-05-05 20:38:57 +00:00
|
|
|
|
(set-module-uses! module
|
|
|
|
|
|
(append (module-uses module) interfaces))
|
|
|
|
|
|
(module-modified module))
|
2003-03-07 13:12:47 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Recursive Namespaces}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; A hierarchical namespace emerges if we consider some module to be
|
|
|
|
|
|
;;; root, and variables bound to modules as nested namespaces.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; The routines in this file manage variable names in hierarchical namespace.
|
|
|
|
|
|
;;; Each variable name is a list of elements, looked up in successively nested
|
|
|
|
|
|
;;; modules.
|
|
|
|
|
|
;;;
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;;; (nested-ref some-root-module '(foo bar baz))
|
|
|
|
|
|
;;; => <value of a variable named baz in the module bound to bar in
|
|
|
|
|
|
;;; the module bound to foo in some-root-module>
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; There are:
|
|
|
|
|
|
;;;
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;;; ;; a-root is a module
|
|
|
|
|
|
;;; ;; name is a list of symbols
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;;; nested-ref a-root name
|
|
|
|
|
|
;;; nested-set! a-root name val
|
|
|
|
|
|
;;; nested-define! a-root name val
|
|
|
|
|
|
;;; nested-remove! a-root name
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; (current-module) is a natural choice for a-root so for convenience there are
|
|
|
|
|
|
;;; also:
|
|
|
|
|
|
;;;
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;;; local-ref name == nested-ref (current-module) name
|
|
|
|
|
|
;;; local-set! name val == nested-set! (current-module) name val
|
|
|
|
|
|
;;; local-define! name val == nested-define! (current-module) name val
|
|
|
|
|
|
;;; local-remove! name == nested-remove! (current-module) name
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
1996-09-13 03:02:38 +00:00
|
|
|
|
(define (nested-ref root names)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let loop ((cur root)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(elts names))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(cond
|
2009-12-22 00:58:12 +01:00
|
|
|
|
((null? elts) cur)
|
|
|
|
|
|
((not (module? cur)) #f)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(else (loop (module-ref cur (car elts) #f) (cdr elts))))))
|
|
|
|
|
|
|
1996-09-13 03:02:38 +00:00
|
|
|
|
(define (nested-set! root names val)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let loop ((cur root)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(elts names))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if (null? (cdr elts))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(module-set! cur (car elts) val)
|
|
|
|
|
|
(loop (module-ref cur (car elts)) (cdr elts)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-09-13 03:02:38 +00:00
|
|
|
|
(define (nested-define! root names val)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let loop ((cur root)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(elts names))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if (null? (cdr elts))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(module-define! cur (car elts) val)
|
|
|
|
|
|
(loop (module-ref cur (car elts)) (cdr elts)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-09-13 03:02:38 +00:00
|
|
|
|
(define (nested-remove! root names)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let loop ((cur root)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(elts names))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if (null? (cdr elts))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(module-remove! cur (car elts))
|
|
|
|
|
|
(loop (module-ref cur (car elts)) (cdr elts)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1996-09-13 03:02:38 +00:00
|
|
|
|
(define (local-ref names) (nested-ref (current-module) names))
|
|
|
|
|
|
(define (local-set! names val) (nested-set! (current-module) names val))
|
|
|
|
|
|
(define (local-define names val) (nested-define! (current-module) names val))
|
|
|
|
|
|
(define (local-remove names) (nested-remove! (current-module) names))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
2004-12-01 00:02:24 +00:00
|
|
|
|
;;; {The (%app) module}
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;; The root of conventionally named objects not directly in the top level.
|
|
|
|
|
|
;;;
|
2004-12-01 00:02:24 +00:00
|
|
|
|
;;; (%app modules)
|
|
|
|
|
|
;;; (%app modules guile)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;; The directory of all modules and the standard root module.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2008-09-29 21:36:25 +02:00
|
|
|
|
;; module-public-interface is defined in C.
|
1999-03-12 09:48:18 +00:00
|
|
|
|
(define (set-module-public-interface! m i)
|
|
|
|
|
|
(module-define! m '%module-public-interface i))
|
|
|
|
|
|
(define (set-system-module! m s)
|
|
|
|
|
|
(set-procedure-property! (module-eval-closure m) 'system-module s))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define the-root-module (make-root-module))
|
|
|
|
|
|
(define the-scm-module (make-scm-module))
|
|
|
|
|
|
(set-module-public-interface! the-root-module the-scm-module)
|
2000-06-11 18:29:57 +00:00
|
|
|
|
(set-module-name! the-root-module '(guile))
|
|
|
|
|
|
(set-module-name! the-scm-module '(guile))
|
|
|
|
|
|
(set-module-kind! the-scm-module 'interface)
|
2009-03-06 16:57:17 +01:00
|
|
|
|
(set-system-module! the-root-module #t)
|
|
|
|
|
|
(set-system-module! the-scm-module #t)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-05-15 14:59:42 +00:00
|
|
|
|
;; NOTE: This binding is used in libguile/modules.c.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (make-modules-in module name)
|
|
|
|
|
|
(if (null? name)
|
|
|
|
|
|
module
|
runtime byte compilation of goops methods, whooooo
* ice-9/boot-9.scm (make-modules-in): Change to make sure that we are
making modules in modules; that is, that a global binding of `compile'
doesn't prevent a module from importing a submodule named `compile'.
(resolve-module): Clean up a bit, and serialize the logic.
* libguile/objects.c (scm_mcache_lookup_cmethod, scm_apply_generic):
* libguile/eval.i.c (CEVAL): Now that cmethod entries can have a program
as their tail instead of a memoized proc, we have to change the halting
condition on the method cache search, in both places: the one that's
inlined into eval.i.c and the one in objects.c. If the cmethod isn't a
pair, apply it.
* libguile/goops.c (make): In the `make' procedure that's used before
GOOPS is booted, bind #:formals, #:body, and #:compile-env on methods.
* oop/goops/compile.scm (compute-entry-with-cmethod): There was a
terrible trick here that involved putting a dummy pair in the cache,
then modifying it in place with the result of memoization. The note
claimed that this was to cut recursion short, or something. I can't see
how it could recurse, given that `methods' is changing each time. Also,
the pair trick doesn't work with byte-compiled methods. So, remove it.
(compile-method): Dispatch to the appropriate method compiler, based on
whether the method was defined with the interpreter or with the
compiler.
(make-next-method): New function, generically computes a `next-method'
procedure, though the caller has to supply the arguments.
(compile-method/vm): Exciting method byte compiler!
(make-make-next-method/memoizer, compile-method/memoizer): Add the
/memoizer suffix, and move all this code to the bottom of the file.
2008-10-30 13:42:40 +01:00
|
|
|
|
(make-modules-in
|
|
|
|
|
|
(let* ((var (module-local-variable module (car name)))
|
|
|
|
|
|
(val (and var (variable-bound? var) (variable-ref var))))
|
|
|
|
|
|
(if (module? val)
|
|
|
|
|
|
val
|
|
|
|
|
|
(let ((m (make-module 31)))
|
|
|
|
|
|
(set-module-kind! m 'directory)
|
residualize names into procedures. re-implement srfi-61. module naming foo.
* module/ice-9/boot-9.scm (cond): Implement srfi-61; most of the code is
from the SRFI itself. Yuk.
(%print-module, make-modules-in, %app, (%app modules))
(module-name): Syncase needs to get at the names of modules, even at
anonymous modules. So lazily assign gensyms as module names. Name %app
as (%app), but since (%app modules) is at the top of the module
hierarchy, name it ().
* module/ice-9/psyntax.scm: When building tree-il, try to name lambdas in
definitions and in lets.
(let, letrec): Give more specific errors in a couple of cases.
* module/ice-9/psyntax-pp.scm: Regenerated.
* test-suite/tests/syntax.test: More work. Many exceptions have different
messages than they used to, many more generic; we can roll this back to
be faithful to the original strings, but it doesn't seem necessary to
me.
2009-05-22 12:08:50 +02:00
|
|
|
|
(set-module-name! m (append (module-name module)
|
runtime byte compilation of goops methods, whooooo
* ice-9/boot-9.scm (make-modules-in): Change to make sure that we are
making modules in modules; that is, that a global binding of `compile'
doesn't prevent a module from importing a submodule named `compile'.
(resolve-module): Clean up a bit, and serialize the logic.
* libguile/objects.c (scm_mcache_lookup_cmethod, scm_apply_generic):
* libguile/eval.i.c (CEVAL): Now that cmethod entries can have a program
as their tail instead of a memoized proc, we have to change the halting
condition on the method cache search, in both places: the one that's
inlined into eval.i.c and the one in objects.c. If the cmethod isn't a
pair, apply it.
* libguile/goops.c (make): In the `make' procedure that's used before
GOOPS is booted, bind #:formals, #:body, and #:compile-env on methods.
* oop/goops/compile.scm (compute-entry-with-cmethod): There was a
terrible trick here that involved putting a dummy pair in the cache,
then modifying it in place with the result of memoization. The note
claimed that this was to cut recursion short, or something. I can't see
how it could recurse, given that `methods' is changing each time. Also,
the pair trick doesn't work with byte-compiled methods. So, remove it.
(compile-method): Dispatch to the appropriate method compiler, based on
whether the method was defined with the interpreter or with the
compiler.
(make-next-method): New function, generically computes a `next-method'
procedure, though the caller has to supply the arguments.
(compile-method/vm): Exciting method byte compiler!
(make-make-next-method/memoizer, compile-method/memoizer): Add the
/memoizer suffix, and move all this code to the bottom of the file.
2008-10-30 13:42:40 +01:00
|
|
|
|
(list (car name))))
|
|
|
|
|
|
(module-define! module (car name) m)
|
|
|
|
|
|
m)))
|
|
|
|
|
|
(cdr name))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-05-15 14:59:42 +00:00
|
|
|
|
(define (beautify-user-module! module)
|
|
|
|
|
|
(let ((interface (module-public-interface module)))
|
|
|
|
|
|
(if (or (not interface)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(eq? interface module))
|
|
|
|
|
|
(let ((interface (make-module 31)))
|
|
|
|
|
|
(set-module-name! interface (module-name module))
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(set-module-version! interface (module-version module))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(set-module-kind! interface 'interface)
|
|
|
|
|
|
(set-module-public-interface! module interface))))
|
2001-05-15 14:59:42 +00:00
|
|
|
|
(if (and (not (memq the-scm-module (module-uses module)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(not (eq? module the-root-module)))
|
2007-05-05 20:38:57 +00:00
|
|
|
|
;; Import the default set of bindings (from the SCM module) in MODULE.
|
|
|
|
|
|
(module-use! module the-scm-module)))
|
1999-03-19 05:14:09 +00:00
|
|
|
|
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(define (version-matches? version-ref target)
|
|
|
|
|
|
(define (any pred lst)
|
|
|
|
|
|
(and (not (null? lst)) (or (pred (car lst)) (any pred (cdr lst)))))
|
|
|
|
|
|
(define (every pred lst)
|
|
|
|
|
|
(or (null? lst) (and (pred (car lst)) (every pred (cdr lst)))))
|
|
|
|
|
|
(define (sub-versions-match? v-refs t)
|
|
|
|
|
|
(define (sub-version-matches? v-ref t)
|
|
|
|
|
|
(define (curried-sub-version-matches? v)
|
|
|
|
|
|
(sub-version-matches? v t))
|
|
|
|
|
|
(cond ((number? v-ref) (eqv? v-ref t))
|
|
|
|
|
|
((list? v-ref)
|
|
|
|
|
|
(let ((cv (car v-ref)))
|
|
|
|
|
|
(cond ((eq? cv '>=) (>= t (cadr v-ref)))
|
|
|
|
|
|
((eq? cv '<=) (<= t (cadr v-ref)))
|
|
|
|
|
|
((eq? cv 'and)
|
|
|
|
|
|
(every curried-sub-version-matches? (cdr v-ref)))
|
|
|
|
|
|
((eq? cv 'or)
|
|
|
|
|
|
(any curried-sub-version-matches? (cdr v-ref)))
|
|
|
|
|
|
((eq? cv 'not) (not (sub-version-matches? (cadr v-ref) t)))
|
|
|
|
|
|
(else (error "Incompatible sub-version reference" cv)))))
|
|
|
|
|
|
(else (error "Incompatible sub-version reference" v-ref))))
|
|
|
|
|
|
(or (null? v-refs)
|
|
|
|
|
|
(and (not (null? t))
|
|
|
|
|
|
(sub-version-matches? (car v-refs) (car t))
|
|
|
|
|
|
(sub-versions-match? (cdr v-refs) (cdr t)))))
|
|
|
|
|
|
(define (curried-version-matches? v)
|
|
|
|
|
|
(version-matches? v target))
|
|
|
|
|
|
(or (null? version-ref)
|
|
|
|
|
|
(let ((cv (car version-ref)))
|
|
|
|
|
|
(cond ((eq? cv 'and) (every curried-version-matches? (cdr version-ref)))
|
|
|
|
|
|
((eq? cv 'or) (any curried-version-matches? (cdr version-ref)))
|
2009-12-22 22:52:48 +01:00
|
|
|
|
((eq? cv 'not) (not (version-matches? (cadr version-ref) target)))
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(else (sub-versions-match? version-ref target))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (find-versioned-module dir-hint name version-ref roots)
|
|
|
|
|
|
(define (subdir-pair-less pair1 pair2)
|
|
|
|
|
|
(define (numlist-less lst1 lst2)
|
|
|
|
|
|
(or (null? lst2)
|
|
|
|
|
|
(and (not (null? lst1))
|
|
|
|
|
|
(cond ((> (car lst1) (car lst2)) #t)
|
|
|
|
|
|
((< (car lst1) (car lst2)) #f)
|
|
|
|
|
|
(else (numlist-less (cdr lst1) (cdr lst2)))))))
|
|
|
|
|
|
(numlist-less (car pair1) (car pair2)))
|
|
|
|
|
|
(define (match-version-and-file pair)
|
|
|
|
|
|
(and (version-matches? version-ref (car pair))
|
|
|
|
|
|
(let ((filenames
|
|
|
|
|
|
(filter (lambda (file)
|
|
|
|
|
|
(let ((s (false-if-exception (stat file))))
|
|
|
|
|
|
(and s (eq? (stat:type s) 'regular))))
|
|
|
|
|
|
(map (lambda (ext)
|
|
|
|
|
|
(string-append (cdr pair) "/" name ext))
|
|
|
|
|
|
%load-extensions))))
|
|
|
|
|
|
(and (not (null? filenames))
|
|
|
|
|
|
(cons (car pair) (car filenames))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (match-version-recursive root-pairs leaf-pairs)
|
|
|
|
|
|
(define (filter-subdirs root-pairs ret)
|
|
|
|
|
|
(define (filter-subdir root-pair dstrm subdir-pairs)
|
|
|
|
|
|
(let ((entry (readdir dstrm)))
|
|
|
|
|
|
(if (eof-object? entry)
|
|
|
|
|
|
subdir-pairs
|
|
|
|
|
|
(let* ((subdir (string-append (cdr root-pair) "/" entry))
|
|
|
|
|
|
(num (string->number entry))
|
|
|
|
|
|
(num (and num (append (car root-pair) (list num)))))
|
|
|
|
|
|
(if (and num (eq? (stat:type (stat subdir)) 'directory))
|
|
|
|
|
|
(filter-subdir
|
|
|
|
|
|
root-pair dstrm (cons (cons num subdir) subdir-pairs))
|
|
|
|
|
|
(filter-subdir root-pair dstrm subdir-pairs))))))
|
|
|
|
|
|
|
|
|
|
|
|
(or (and (null? root-pairs) ret)
|
|
|
|
|
|
(let* ((rp (car root-pairs))
|
|
|
|
|
|
(dstrm (false-if-exception (opendir (cdr rp)))))
|
|
|
|
|
|
(if dstrm
|
|
|
|
|
|
(let ((subdir-pairs (filter-subdir rp dstrm '())))
|
|
|
|
|
|
(closedir dstrm)
|
|
|
|
|
|
(filter-subdirs (cdr root-pairs)
|
|
|
|
|
|
(or (and (null? subdir-pairs) ret)
|
|
|
|
|
|
(append ret subdir-pairs))))
|
|
|
|
|
|
(filter-subdirs (cdr root-pairs) ret)))))
|
|
|
|
|
|
|
|
|
|
|
|
(or (and (null? root-pairs) leaf-pairs)
|
|
|
|
|
|
(let ((matching-subdir-pairs (filter-subdirs root-pairs '())))
|
|
|
|
|
|
(match-version-recursive
|
|
|
|
|
|
matching-subdir-pairs
|
|
|
|
|
|
(append leaf-pairs (filter pair? (map match-version-and-file
|
|
|
|
|
|
matching-subdir-pairs)))))))
|
|
|
|
|
|
(define (make-root-pair root)
|
|
|
|
|
|
(cons '() (string-append root "/" dir-hint)))
|
|
|
|
|
|
|
|
|
|
|
|
(let* ((root-pairs (map make-root-pair roots))
|
|
|
|
|
|
(matches (if (null? version-ref)
|
|
|
|
|
|
(filter pair? (map match-version-and-file root-pairs))
|
|
|
|
|
|
'()))
|
|
|
|
|
|
(matches (append matches (match-version-recursive root-pairs '()))))
|
|
|
|
|
|
(and (null? matches) (error "No matching modules found."))
|
|
|
|
|
|
(cdar (sort matches subdir-pair-less))))
|
|
|
|
|
|
|
compilation enviroments are always modules; simplifications & refactorings
* module/ice-9/boot-9.scm (make-fresh-user-module): New public function,
makes an anonymous beautified module.
* module/language/objcode/spec.scm: We used to have some things in here
that allowed lexical variable names and values to be a part of the
environment, but no more. Now an environment is just a module. If you
want to "inject" free variables into code, just use lambda.
* module/language/scheme/compile-tree-il.scm (compile-tree-il): Same
here. Also, rely on the fact that an environment *will* be a module --
because (system base compile) guarantees that for us.
* module/language/scheme/spec.scm (scheme): In the reader, rely on the
environment being a module. Define a #:make-default-environment
handler, which returns a beautified module, augmented with a fresh
definition for current-reader, so that side effects to current-reader
are restricted to the compilation unit.
* module/language/tree-il/analyze.scm
(report-possibly-unbound-variables):
* module/language/tree-il/compile-glil.scm (compile-glil):
* module/language/tree-il/optimize.scm (optimize!): The environment will
be a module.
* module/system/base/language.scm (<language>): New field,
`make-default-environment'. Defaults to `make-fresh-user-module'.
(default-environment): New accessor, returns a default environment for
a language.
* module/system/repl/common.scm (repl-compile): Always compile relative
to the current module, because a module is always acceptable as an
environment.
* module/system/base/compile.scm (compile-file, compile-and-load): Both
of these have a new keyword argument, #:env. For `compile-file', it
defaults to the default environment of the source language, and for
`compile-and-load', to the current module.
(read-and-compile): If there are no expressions read, pass the joiner
its default environment (via `default-environment joint').
2009-10-16 15:27:10 +02:00
|
|
|
|
(define (make-fresh-user-module)
|
|
|
|
|
|
(let ((m (make-module)))
|
|
|
|
|
|
(beautify-user-module! m)
|
|
|
|
|
|
m))
|
|
|
|
|
|
|
1998-11-26 17:56:36 +00:00
|
|
|
|
;; NOTE: This binding is used in libguile/modules.c.
|
|
|
|
|
|
;;
|
2008-09-02 00:40:57 -07:00
|
|
|
|
(define resolve-module
|
|
|
|
|
|
(let ((the-root-module the-root-module))
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(lambda (name . args)
|
2008-09-02 00:40:57 -07:00
|
|
|
|
(if (equal? name '(guile))
|
|
|
|
|
|
the-root-module
|
|
|
|
|
|
(let ((full-name (append '(%app modules) name)))
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(let* ((already (nested-ref the-root-module full-name))
|
|
|
|
|
|
(numargs (length args))
|
|
|
|
|
|
(autoload (or (= numargs 0) (car args)))
|
|
|
|
|
|
(version (and (> numargs 1) (cadr args))))
|
runtime byte compilation of goops methods, whooooo
* ice-9/boot-9.scm (make-modules-in): Change to make sure that we are
making modules in modules; that is, that a global binding of `compile'
doesn't prevent a module from importing a submodule named `compile'.
(resolve-module): Clean up a bit, and serialize the logic.
* libguile/objects.c (scm_mcache_lookup_cmethod, scm_apply_generic):
* libguile/eval.i.c (CEVAL): Now that cmethod entries can have a program
as their tail instead of a memoized proc, we have to change the halting
condition on the method cache search, in both places: the one that's
inlined into eval.i.c and the one in objects.c. If the cmethod isn't a
pair, apply it.
* libguile/goops.c (make): In the `make' procedure that's used before
GOOPS is booted, bind #:formals, #:body, and #:compile-env on methods.
* oop/goops/compile.scm (compute-entry-with-cmethod): There was a
terrible trick here that involved putting a dummy pair in the cache,
then modifying it in place with the result of memoization. The note
claimed that this was to cut recursion short, or something. I can't see
how it could recurse, given that `methods' is changing each time. Also,
the pair trick doesn't work with byte-compiled methods. So, remove it.
(compile-method): Dispatch to the appropriate method compiler, based on
whether the method was defined with the interpreter or with the
compiler.
(make-next-method): New function, generically computes a `next-method'
procedure, though the caller has to supply the arguments.
(compile-method/vm): Exciting method byte compiler!
(make-make-next-method/memoizer, compile-method/memoizer): Add the
/memoizer suffix, and move all this code to the bottom of the file.
2008-10-30 13:42:40 +01:00
|
|
|
|
(cond
|
|
|
|
|
|
((and already (module? already)
|
|
|
|
|
|
(or (not autoload) (module-public-interface already)))
|
|
|
|
|
|
;; A hit, a palpable hit.
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(if (and version
|
|
|
|
|
|
(not (version-matches? version (module-version already))))
|
|
|
|
|
|
(error "incompatible module version already loaded" name))
|
runtime byte compilation of goops methods, whooooo
* ice-9/boot-9.scm (make-modules-in): Change to make sure that we are
making modules in modules; that is, that a global binding of `compile'
doesn't prevent a module from importing a submodule named `compile'.
(resolve-module): Clean up a bit, and serialize the logic.
* libguile/objects.c (scm_mcache_lookup_cmethod, scm_apply_generic):
* libguile/eval.i.c (CEVAL): Now that cmethod entries can have a program
as their tail instead of a memoized proc, we have to change the halting
condition on the method cache search, in both places: the one that's
inlined into eval.i.c and the one in objects.c. If the cmethod isn't a
pair, apply it.
* libguile/goops.c (make): In the `make' procedure that's used before
GOOPS is booted, bind #:formals, #:body, and #:compile-env on methods.
* oop/goops/compile.scm (compute-entry-with-cmethod): There was a
terrible trick here that involved putting a dummy pair in the cache,
then modifying it in place with the result of memoization. The note
claimed that this was to cut recursion short, or something. I can't see
how it could recurse, given that `methods' is changing each time. Also,
the pair trick doesn't work with byte-compiled methods. So, remove it.
(compile-method): Dispatch to the appropriate method compiler, based on
whether the method was defined with the interpreter or with the
compiler.
(make-next-method): New function, generically computes a `next-method'
procedure, though the caller has to supply the arguments.
(compile-method/vm): Exciting method byte compiler!
(make-make-next-method/memoizer, compile-method/memoizer): Add the
/memoizer suffix, and move all this code to the bottom of the file.
2008-10-30 13:42:40 +01:00
|
|
|
|
already)
|
|
|
|
|
|
(autoload
|
|
|
|
|
|
;; Try to autoload the module, and recurse.
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(try-load-module name version)
|
runtime byte compilation of goops methods, whooooo
* ice-9/boot-9.scm (make-modules-in): Change to make sure that we are
making modules in modules; that is, that a global binding of `compile'
doesn't prevent a module from importing a submodule named `compile'.
(resolve-module): Clean up a bit, and serialize the logic.
* libguile/objects.c (scm_mcache_lookup_cmethod, scm_apply_generic):
* libguile/eval.i.c (CEVAL): Now that cmethod entries can have a program
as their tail instead of a memoized proc, we have to change the halting
condition on the method cache search, in both places: the one that's
inlined into eval.i.c and the one in objects.c. If the cmethod isn't a
pair, apply it.
* libguile/goops.c (make): In the `make' procedure that's used before
GOOPS is booted, bind #:formals, #:body, and #:compile-env on methods.
* oop/goops/compile.scm (compute-entry-with-cmethod): There was a
terrible trick here that involved putting a dummy pair in the cache,
then modifying it in place with the result of memoization. The note
claimed that this was to cut recursion short, or something. I can't see
how it could recurse, given that `methods' is changing each time. Also,
the pair trick doesn't work with byte-compiled methods. So, remove it.
(compile-method): Dispatch to the appropriate method compiler, based on
whether the method was defined with the interpreter or with the
compiler.
(make-next-method): New function, generically computes a `next-method'
procedure, though the caller has to supply the arguments.
(compile-method/vm): Exciting method byte compiler!
(make-make-next-method/memoizer, compile-method/memoizer): Add the
/memoizer suffix, and move all this code to the bottom of the file.
2008-10-30 13:42:40 +01:00
|
|
|
|
(resolve-module name #f))
|
|
|
|
|
|
(else
|
|
|
|
|
|
;; A module is not bound (but maybe something else is),
|
|
|
|
|
|
;; we're not autoloading -- here's the weird semantics,
|
|
|
|
|
|
;; we create an empty module.
|
|
|
|
|
|
(make-modules-in the-root-module full-name)))))))))
|
2001-04-28 19:07:38 +00:00
|
|
|
|
|
2001-05-19 01:30:02 +00:00
|
|
|
|
;; Cheat. These bindings are needed by modules.c, but we don't want
|
|
|
|
|
|
;; to move their real definition here because that would be unnatural.
|
|
|
|
|
|
;;
|
2001-05-15 14:59:42 +00:00
|
|
|
|
(define try-module-autoload #f)
|
2001-05-19 01:30:02 +00:00
|
|
|
|
(define process-define-module #f)
|
|
|
|
|
|
(define process-use-modules #f)
|
|
|
|
|
|
(define module-export! #f)
|
2007-05-05 20:38:57 +00:00
|
|
|
|
(define default-duplicate-binding-procedures #f)
|
2001-05-15 14:59:42 +00:00
|
|
|
|
|
2004-12-01 00:02:24 +00:00
|
|
|
|
(define %app (make-module 31))
|
residualize names into procedures. re-implement srfi-61. module naming foo.
* module/ice-9/boot-9.scm (cond): Implement srfi-61; most of the code is
from the SRFI itself. Yuk.
(%print-module, make-modules-in, %app, (%app modules))
(module-name): Syncase needs to get at the names of modules, even at
anonymous modules. So lazily assign gensyms as module names. Name %app
as (%app), but since (%app modules) is at the top of the module
hierarchy, name it ().
* module/ice-9/psyntax.scm: When building tree-il, try to name lambdas in
definitions and in lets.
(let, letrec): Give more specific errors in a couple of cases.
* module/ice-9/psyntax-pp.scm: Regenerated.
* test-suite/tests/syntax.test: More work. Many exceptions have different
messages than they used to, many more generic; we can roll this back to
be faithful to the original strings, but it doesn't seem necessary to
me.
2009-05-22 12:08:50 +02:00
|
|
|
|
(set-module-name! %app '(%app))
|
2004-12-01 00:02:24 +00:00
|
|
|
|
(define app %app) ;; for backwards compatability
|
2008-09-02 00:42:39 -07:00
|
|
|
|
|
residualize names into procedures. re-implement srfi-61. module naming foo.
* module/ice-9/boot-9.scm (cond): Implement srfi-61; most of the code is
from the SRFI itself. Yuk.
(%print-module, make-modules-in, %app, (%app modules))
(module-name): Syncase needs to get at the names of modules, even at
anonymous modules. So lazily assign gensyms as module names. Name %app
as (%app), but since (%app modules) is at the top of the module
hierarchy, name it ().
* module/ice-9/psyntax.scm: When building tree-il, try to name lambdas in
definitions and in lets.
(let, letrec): Give more specific errors in a couple of cases.
* module/ice-9/psyntax-pp.scm: Regenerated.
* test-suite/tests/syntax.test: More work. Many exceptions have different
messages than they used to, many more generic; we can roll this back to
be faithful to the original strings, but it doesn't seem necessary to
me.
2009-05-22 12:08:50 +02:00
|
|
|
|
(let ((m (make-module 31)))
|
|
|
|
|
|
(set-module-name! m '())
|
|
|
|
|
|
(local-define '(%app modules) m))
|
2004-12-01 00:02:24 +00:00
|
|
|
|
(local-define '(%app modules guile) the-root-module)
|
2001-05-15 14:59:42 +00:00
|
|
|
|
|
2008-09-02 00:42:39 -07:00
|
|
|
|
;; This boots the module system. All bindings needed by modules.c
|
|
|
|
|
|
;; must have been defined by now.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(set-current-module the-root-module)
|
residualize names into procedures. re-implement srfi-61. module naming foo.
* module/ice-9/boot-9.scm (cond): Implement srfi-61; most of the code is
from the SRFI itself. Yuk.
(%print-module, make-modules-in, %app, (%app modules))
(module-name): Syncase needs to get at the names of modules, even at
anonymous modules. So lazily assign gensyms as module names. Name %app
as (%app), but since (%app modules) is at the top of the module
hierarchy, name it ().
* module/ice-9/psyntax.scm: When building tree-il, try to name lambdas in
definitions and in lets.
(let, letrec): Give more specific errors in a couple of cases.
* module/ice-9/psyntax-pp.scm: Regenerated.
* test-suite/tests/syntax.test: More work. Many exceptions have different
messages than they used to, many more generic; we can roll this back to
be faithful to the original strings, but it doesn't seem necessary to
me.
2009-05-22 12:08:50 +02:00
|
|
|
|
;; definition deferred for syncase's benefit.
|
|
|
|
|
|
(define module-name
|
|
|
|
|
|
(let ((accessor (record-accessor module-type 'name)))
|
|
|
|
|
|
(lambda (mod)
|
|
|
|
|
|
(or (accessor mod)
|
2009-08-12 19:22:19 +02:00
|
|
|
|
(let ((name (list (gensym))))
|
|
|
|
|
|
;; Name MOD and bind it in THE-ROOT-MODULE so that it's visible
|
|
|
|
|
|
;; to `resolve-module'. This is important as `psyntax' stores
|
|
|
|
|
|
;; module names and relies on being able to `resolve-module'
|
|
|
|
|
|
;; them.
|
|
|
|
|
|
(set-module-name! mod name)
|
|
|
|
|
|
(nested-define! the-root-module `(%app modules ,@name) mod)
|
residualize names into procedures. re-implement srfi-61. module naming foo.
* module/ice-9/boot-9.scm (cond): Implement srfi-61; most of the code is
from the SRFI itself. Yuk.
(%print-module, make-modules-in, %app, (%app modules))
(module-name): Syncase needs to get at the names of modules, even at
anonymous modules. So lazily assign gensyms as module names. Name %app
as (%app), but since (%app modules) is at the top of the module
hierarchy, name it ().
* module/ice-9/psyntax.scm: When building tree-il, try to name lambdas in
definitions and in lets.
(let, letrec): Give more specific errors in a couple of cases.
* module/ice-9/psyntax-pp.scm: Regenerated.
* test-suite/tests/syntax.test: More work. Many exceptions have different
messages than they used to, many more generic; we can roll this back to
be faithful to the original strings, but it doesn't seem necessary to
me.
2009-05-22 12:08:50 +02:00
|
|
|
|
(accessor mod))))))
|
2008-09-02 00:42:39 -07:00
|
|
|
|
|
2004-12-01 00:02:24 +00:00
|
|
|
|
;; (define-special-value '(%app modules new-ws) (lambda () (make-scm-module)))
|
2001-05-15 14:59:42 +00:00
|
|
|
|
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(define (try-load-module name version)
|
|
|
|
|
|
(try-module-autoload name version))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2000-06-21 01:16:45 +00:00
|
|
|
|
(define (purify-module! module)
|
|
|
|
|
|
"Removes bindings in MODULE which are inherited from the (guile) module."
|
|
|
|
|
|
(let ((use-list (module-uses module)))
|
|
|
|
|
|
(if (and (pair? use-list)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(eq? (car (last-pair use-list)) the-scm-module))
|
|
|
|
|
|
(set-module-uses! module (reverse (cdr (reverse use-list)))))))
|
2000-06-21 01:16:45 +00:00
|
|
|
|
|
2002-02-26 10:57:54 +00:00
|
|
|
|
;; Return a module that is an interface to the module designated by
|
2001-06-01 20:15:10 +00:00
|
|
|
|
;; NAME.
|
|
|
|
|
|
;;
|
2003-03-11 19:58:14 +00:00
|
|
|
|
;; `resolve-interface' takes four keyword arguments:
|
2001-06-01 20:15:10 +00:00
|
|
|
|
;;
|
|
|
|
|
|
;; #:select SELECTION
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; SELECTION is a list of binding-specs to be imported; A binding-spec
|
|
|
|
|
|
;; is either a symbol or a pair of symbols (ORIG . SEEN), where ORIG
|
|
|
|
|
|
;; is the name in the used module and SEEN is the name in the using
|
|
|
|
|
|
;; module. Note that SEEN is also passed through RENAMER, below. The
|
|
|
|
|
|
;; default is to select all bindings. If you specify no selection but
|
2002-02-26 10:57:54 +00:00
|
|
|
|
;; a renamer, only the bindings that already exist in the used module
|
2001-06-01 20:15:10 +00:00
|
|
|
|
;; are made available in the interface. Bindings that are added later
|
|
|
|
|
|
;; are not picked up.
|
|
|
|
|
|
;;
|
2003-03-11 19:58:14 +00:00
|
|
|
|
;; #:hide BINDINGS
|
2001-06-01 20:15:10 +00:00
|
|
|
|
;;
|
2003-03-11 19:58:14 +00:00
|
|
|
|
;; BINDINGS is a list of bindings which should not be imported.
|
2003-03-10 23:18:05 +00:00
|
|
|
|
;;
|
|
|
|
|
|
;; #:prefix PREFIX
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; PREFIX is a symbol that will be appended to each exported name.
|
|
|
|
|
|
;; The default is to not perform any renaming.
|
2001-06-01 20:15:10 +00:00
|
|
|
|
;;
|
2003-03-11 19:58:14 +00:00
|
|
|
|
;; #:renamer RENAMER
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; RENAMER is a procedure that takes a symbol and returns its new
|
|
|
|
|
|
;; name. The default is not perform any renaming.
|
|
|
|
|
|
;;
|
2001-06-01 20:15:10 +00:00
|
|
|
|
;; Signal "no code for module" error if module name is not resolvable
|
|
|
|
|
|
;; or its public interface is not available. Signal "no binding"
|
|
|
|
|
|
;; error if selected binding does not exist in the used module.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (resolve-interface name . args)
|
|
|
|
|
|
|
|
|
|
|
|
(define (get-keyword-arg args kw def)
|
|
|
|
|
|
(cond ((memq kw args)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
=> (lambda (kw-arg)
|
|
|
|
|
|
(if (null? (cdr kw-arg))
|
|
|
|
|
|
(error "keyword without value: " kw))
|
|
|
|
|
|
(cadr kw-arg)))
|
|
|
|
|
|
(else
|
|
|
|
|
|
def)))
|
2001-06-01 20:15:10 +00:00
|
|
|
|
|
|
|
|
|
|
(let* ((select (get-keyword-arg args #:select #f))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(hide (get-keyword-arg args #:hide '()))
|
|
|
|
|
|
(renamer (or (get-keyword-arg args #:renamer #f)
|
|
|
|
|
|
(let ((prefix (get-keyword-arg args #:prefix #f)))
|
|
|
|
|
|
(and prefix (symbol-prefix-proc prefix)))
|
|
|
|
|
|
identity))
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(version (get-keyword-arg args #:version #f))
|
|
|
|
|
|
(module (resolve-module name #t version))
|
2001-05-15 19:33:43 +00:00
|
|
|
|
(public-i (and module (module-public-interface module))))
|
|
|
|
|
|
(and (or (not module) (not public-i))
|
|
|
|
|
|
(error "no code for module" name))
|
2003-03-11 19:58:14 +00:00
|
|
|
|
(if (and (not select) (null? hide) (eq? renamer identity))
|
2001-05-15 19:33:43 +00:00
|
|
|
|
public-i
|
2001-06-01 20:15:10 +00:00
|
|
|
|
(let ((selection (or select (module-map (lambda (sym var) sym)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
public-i)))
|
2001-05-15 19:33:43 +00:00
|
|
|
|
(custom-i (make-module 31)))
|
2003-03-11 19:58:14 +00:00
|
|
|
|
(set-module-kind! custom-i 'custom-interface)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(set-module-name! custom-i name)
|
|
|
|
|
|
;; XXX - should use a lazy binder so that changes to the
|
|
|
|
|
|
;; used module are picked up automatically.
|
|
|
|
|
|
(for-each (lambda (bspec)
|
|
|
|
|
|
(let* ((direct? (symbol? bspec))
|
|
|
|
|
|
(orig (if direct? bspec (car bspec)))
|
|
|
|
|
|
(seen (if direct? bspec (cdr bspec)))
|
|
|
|
|
|
(var (or (module-local-variable public-i orig)
|
|
|
|
|
|
(module-local-variable module orig)
|
|
|
|
|
|
(error
|
|
|
|
|
|
;; fixme: format manually for now
|
|
|
|
|
|
(simple-format
|
|
|
|
|
|
#f "no binding `~A' in module ~A"
|
|
|
|
|
|
orig name)))))
|
|
|
|
|
|
(if (memq orig hide)
|
|
|
|
|
|
(set! hide (delq! orig hide))
|
|
|
|
|
|
(module-add! custom-i
|
|
|
|
|
|
(renamer seen)
|
|
|
|
|
|
var))))
|
|
|
|
|
|
selection)
|
|
|
|
|
|
;; Check that we are not hiding bindings which don't exist
|
|
|
|
|
|
(for-each (lambda (binding)
|
|
|
|
|
|
(if (not (module-local-variable public-i binding))
|
|
|
|
|
|
(error
|
|
|
|
|
|
(simple-format
|
|
|
|
|
|
#f "no binding `~A' to hide in module ~A"
|
|
|
|
|
|
binding name))))
|
|
|
|
|
|
hide)
|
2001-05-15 19:33:43 +00:00
|
|
|
|
custom-i))))
|
2001-05-10 22:00:22 +00:00
|
|
|
|
|
|
|
|
|
|
(define (symbol-prefix-proc prefix)
|
|
|
|
|
|
(lambda (symbol)
|
|
|
|
|
|
(symbol-append prefix symbol)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-11-23 21:43:44 +00:00
|
|
|
|
;; This function is called from "modules.c". If you change it, be
|
|
|
|
|
|
;; sure to update "modules.c" as well.
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (process-define-module args)
|
2001-05-18 17:28:03 +00:00
|
|
|
|
(let* ((module-id (car args))
|
|
|
|
|
|
(module (resolve-module module-id #f))
|
|
|
|
|
|
(kws (cdr args))
|
|
|
|
|
|
(unrecognized (lambda (arg)
|
|
|
|
|
|
(error "unrecognized define-module argument" arg))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(beautify-user-module! module)
|
1996-12-21 09:50:38 +00:00
|
|
|
|
(let loop ((kws kws)
|
2008-09-12 17:59:59 +02:00
|
|
|
|
(reversed-interfaces '())
|
|
|
|
|
|
(exports '())
|
|
|
|
|
|
(re-exports '())
|
|
|
|
|
|
(replacements '())
|
2007-05-05 20:38:57 +00:00
|
|
|
|
(autoloads '()))
|
2005-06-11 01:48:19 +00:00
|
|
|
|
|
1996-12-21 09:50:38 +00:00
|
|
|
|
(if (null? kws)
|
2008-09-12 17:59:59 +02:00
|
|
|
|
(call-with-deferred-observers
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(module-use-interfaces! module (reverse reversed-interfaces))
|
|
|
|
|
|
(module-export! module exports)
|
|
|
|
|
|
(module-replace! module replacements)
|
|
|
|
|
|
(module-re-export! module re-exports)
|
2007-05-05 20:38:57 +00:00
|
|
|
|
(if (not (null? autoloads))
|
|
|
|
|
|
(apply module-autoload! module autoloads))))
|
2008-09-12 17:59:59 +02:00
|
|
|
|
(case (car kws)
|
|
|
|
|
|
((#:use-module #:use-syntax)
|
|
|
|
|
|
(or (pair? (cdr kws))
|
|
|
|
|
|
(unrecognized kws))
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
(cond
|
|
|
|
|
|
((equal? (caadr kws) '(ice-9 syncase))
|
|
|
|
|
|
(issue-deprecation-warning
|
|
|
|
|
|
"(ice-9 syncase) is deprecated. Support for syntax-case is now in Guile core.")
|
2008-09-12 17:59:59 +02:00
|
|
|
|
(loop (cddr kws)
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
reversed-interfaces
|
2008-09-12 17:59:59 +02:00
|
|
|
|
exports
|
|
|
|
|
|
re-exports
|
|
|
|
|
|
replacements
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
autoloads))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(let* ((interface-args (cadr kws))
|
|
|
|
|
|
(interface (apply resolve-interface interface-args)))
|
|
|
|
|
|
(and (eq? (car kws) #:use-syntax)
|
|
|
|
|
|
(or (symbol? (caar interface-args))
|
|
|
|
|
|
(error "invalid module name for use-syntax"
|
|
|
|
|
|
(car interface-args)))
|
|
|
|
|
|
(set-module-transformer!
|
|
|
|
|
|
module
|
|
|
|
|
|
(module-ref interface
|
|
|
|
|
|
(car (last-pair (car interface-args)))
|
|
|
|
|
|
#f)))
|
|
|
|
|
|
(loop (cddr kws)
|
|
|
|
|
|
(cons interface reversed-interfaces)
|
|
|
|
|
|
exports
|
|
|
|
|
|
re-exports
|
|
|
|
|
|
replacements
|
|
|
|
|
|
autoloads)))))
|
2008-09-12 17:59:59 +02:00
|
|
|
|
((#:autoload)
|
|
|
|
|
|
(or (and (pair? (cdr kws)) (pair? (cddr kws)))
|
|
|
|
|
|
(unrecognized kws))
|
|
|
|
|
|
(loop (cdddr kws)
|
2007-05-05 20:38:57 +00:00
|
|
|
|
reversed-interfaces
|
2008-09-12 17:59:59 +02:00
|
|
|
|
exports
|
|
|
|
|
|
re-exports
|
|
|
|
|
|
replacements
|
2007-05-05 20:38:57 +00:00
|
|
|
|
(let ((name (cadr kws))
|
|
|
|
|
|
(bindings (caddr kws)))
|
|
|
|
|
|
(cons* name bindings autoloads))))
|
2008-09-12 17:59:59 +02:00
|
|
|
|
((#:no-backtrace)
|
|
|
|
|
|
(set-system-module! module #t)
|
|
|
|
|
|
(loop (cdr kws) reversed-interfaces exports re-exports
|
2007-05-05 20:38:57 +00:00
|
|
|
|
replacements autoloads))
|
2008-09-12 17:59:59 +02:00
|
|
|
|
((#:pure)
|
|
|
|
|
|
(purify-module! module)
|
|
|
|
|
|
(loop (cdr kws) reversed-interfaces exports re-exports
|
2007-05-05 20:38:57 +00:00
|
|
|
|
replacements autoloads))
|
2009-12-22 00:33:12 +01:00
|
|
|
|
((#:version)
|
|
|
|
|
|
(or (pair? (cdr kws))
|
|
|
|
|
|
(unrecognized kws))
|
|
|
|
|
|
(let ((version (cadr kws)))
|
|
|
|
|
|
(set-module-version! module version)
|
|
|
|
|
|
(set-module-version! (module-public-interface module) version))
|
|
|
|
|
|
(loop (cddr kws) reversed-interfaces exports re-exports
|
|
|
|
|
|
replacements autoloads))
|
2008-09-12 17:59:59 +02:00
|
|
|
|
((#:duplicates)
|
|
|
|
|
|
(if (not (pair? (cdr kws)))
|
|
|
|
|
|
(unrecognized kws))
|
|
|
|
|
|
(set-module-duplicates-handlers!
|
|
|
|
|
|
module
|
|
|
|
|
|
(lookup-duplicates-handlers (cadr kws)))
|
|
|
|
|
|
(loop (cddr kws) reversed-interfaces exports re-exports
|
2007-05-05 20:38:57 +00:00
|
|
|
|
replacements autoloads))
|
2008-09-12 17:59:59 +02:00
|
|
|
|
((#:export #:export-syntax)
|
|
|
|
|
|
(or (pair? (cdr kws))
|
|
|
|
|
|
(unrecognized kws))
|
|
|
|
|
|
(loop (cddr kws)
|
|
|
|
|
|
reversed-interfaces
|
|
|
|
|
|
(append (cadr kws) exports)
|
|
|
|
|
|
re-exports
|
|
|
|
|
|
replacements
|
2007-05-05 20:38:57 +00:00
|
|
|
|
autoloads))
|
2008-09-12 17:59:59 +02:00
|
|
|
|
((#:re-export #:re-export-syntax)
|
|
|
|
|
|
(or (pair? (cdr kws))
|
|
|
|
|
|
(unrecognized kws))
|
|
|
|
|
|
(loop (cddr kws)
|
|
|
|
|
|
reversed-interfaces
|
|
|
|
|
|
exports
|
|
|
|
|
|
(append (cadr kws) re-exports)
|
|
|
|
|
|
replacements
|
2007-05-05 20:38:57 +00:00
|
|
|
|
autoloads))
|
2008-09-12 17:59:59 +02:00
|
|
|
|
((#:replace #:replace-syntax)
|
|
|
|
|
|
(or (pair? (cdr kws))
|
|
|
|
|
|
(unrecognized kws))
|
|
|
|
|
|
(loop (cddr kws)
|
|
|
|
|
|
reversed-interfaces
|
|
|
|
|
|
exports
|
|
|
|
|
|
re-exports
|
|
|
|
|
|
(append (cadr kws) replacements)
|
2007-05-05 20:38:57 +00:00
|
|
|
|
autoloads))
|
2008-09-12 17:59:59 +02:00
|
|
|
|
(else
|
|
|
|
|
|
(unrecognized kws)))))
|
2002-12-28 20:14:21 +00:00
|
|
|
|
(run-hook module-defined-hook module)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
module))
|
1998-12-01 17:06:34 +00:00
|
|
|
|
|
2002-12-28 20:14:21 +00:00
|
|
|
|
;; `module-defined-hook' is a hook that is run whenever a new module
|
|
|
|
|
|
;; is defined. Its members are called with one argument, the new
|
|
|
|
|
|
;; module.
|
|
|
|
|
|
(define module-defined-hook (make-hook 1))
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
1998-12-01 17:06:34 +00:00
|
|
|
|
;;; {Autoload}
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
1998-12-01 17:06:34 +00:00
|
|
|
|
|
|
|
|
|
|
(define (make-autoload-interface module name bindings)
|
|
|
|
|
|
(let ((b (lambda (a sym definep)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(and (memq sym bindings)
|
|
|
|
|
|
(let ((i (module-public-interface (resolve-module name))))
|
|
|
|
|
|
(if (not i)
|
|
|
|
|
|
(error "missing interface for module" name))
|
|
|
|
|
|
(let ((autoload (memq a (module-uses module))))
|
|
|
|
|
|
;; Replace autoload-interface with actual interface if
|
|
|
|
|
|
;; that has not happened yet.
|
|
|
|
|
|
(if (pair? autoload)
|
|
|
|
|
|
(set-car! autoload i)))
|
|
|
|
|
|
(module-local-variable i sym))))))
|
2007-05-05 20:38:57 +00:00
|
|
|
|
(module-constructor (make-hash-table 0) '() b #f #f name 'autoload #f
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(make-hash-table 0) '() (make-weak-value-hash-table 31) #f)))
|
2007-05-05 20:38:57 +00:00
|
|
|
|
|
|
|
|
|
|
(define (module-autoload! module . args)
|
|
|
|
|
|
"Have @var{module} automatically load the module named @var{name} when one
|
|
|
|
|
|
of the symbols listed in @var{bindings} is looked up. @var{args} should be a
|
|
|
|
|
|
list of module-name/binding-list pairs, e.g., as in @code{(module-autoload!
|
|
|
|
|
|
module '(ice-9 q) '(make-q q-length))}."
|
|
|
|
|
|
(let loop ((args args))
|
|
|
|
|
|
(cond ((null? args)
|
|
|
|
|
|
#t)
|
|
|
|
|
|
((null? (cdr args))
|
|
|
|
|
|
(error "invalid name+binding autoload list" args))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(let ((name (car args))
|
|
|
|
|
|
(bindings (cadr args)))
|
|
|
|
|
|
(module-use! module (make-autoload-interface module
|
|
|
|
|
|
name bindings))
|
|
|
|
|
|
(loop (cddr args)))))))
|
|
|
|
|
|
|
1998-12-01 17:06:34 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-10-16 22:29:19 +00:00
|
|
|
|
;;; {Autoloading modules}
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define autoloads-in-progress '())
|
|
|
|
|
|
|
2001-11-23 21:43:44 +00:00
|
|
|
|
;; This function is called from "modules.c". If you change it, be
|
|
|
|
|
|
;; sure to update "modules.c" as well.
|
|
|
|
|
|
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(define (try-module-autoload module-name . args)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let* ((reverse-name (reverse module-name))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(name (symbol->string (car reverse-name)))
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(version (and (not (null? args)) (car args)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(dir-hint-module-name (reverse (cdr reverse-name)))
|
|
|
|
|
|
(dir-hint (apply string-append
|
|
|
|
|
|
(map (lambda (elt)
|
|
|
|
|
|
(string-append (symbol->string elt) "/"))
|
|
|
|
|
|
dir-hint-module-name))))
|
1996-12-21 09:50:38 +00:00
|
|
|
|
(resolve-module dir-hint-module-name #f)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(and (not (autoload-done-or-in-progress? dir-hint name))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(let ((didit #f))
|
|
|
|
|
|
(dynamic-wind
|
|
|
|
|
|
(lambda () (autoload-in-progress! dir-hint name))
|
|
|
|
|
|
(lambda ()
|
2010-03-04 16:50:11 +01:00
|
|
|
|
(with-fluids ((current-reader #f))
|
|
|
|
|
|
(save-module-excursion
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(if version
|
|
|
|
|
|
(load (find-versioned-module
|
|
|
|
|
|
dir-hint name version %load-path))
|
|
|
|
|
|
(primitive-load-path (in-vicinity dir-hint name) #f))
|
|
|
|
|
|
(set! didit #t)))))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(lambda () (set-autoloaded! dir-hint name didit)))
|
|
|
|
|
|
didit))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1998-12-01 17:06:34 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Dynamic linking of modules}
|
|
|
|
|
|
;;;
|
1997-01-18 11:29:20 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define autoloads-done '((guile . guile)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (autoload-done-or-in-progress? p m)
|
|
|
|
|
|
(let ((n (cons p m)))
|
|
|
|
|
|
(->bool (or (member n autoloads-done)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(member n autoloads-in-progress)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (autoload-done! p m)
|
|
|
|
|
|
(let ((n (cons p m)))
|
|
|
|
|
|
(set! autoloads-in-progress
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(delete! n autoloads-in-progress))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(or (member n autoloads-done)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(set! autoloads-done (cons n autoloads-done)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (autoload-in-progress! p m)
|
|
|
|
|
|
(let ((n (cons p m)))
|
|
|
|
|
|
(set! autoloads-done
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(delete! n autoloads-done))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(set! autoloads-in-progress (cons n autoloads-in-progress))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (set-autoloaded! p m done?)
|
|
|
|
|
|
(if done?
|
|
|
|
|
|
(autoload-done! p m)
|
|
|
|
|
|
(let ((n (cons p m)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(set! autoloads-done (delete! n autoloads-done))
|
|
|
|
|
|
(set! autoloads-in-progress (delete! n autoloads-in-progress)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-09-28 20:12:17 +00:00
|
|
|
|
;;; {Run-time options}
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
1997-09-28 20:12:17 +00:00
|
|
|
|
|
2008-09-01 23:51:30 -07:00
|
|
|
|
(defmacro define-option-interface (option-group)
|
2009-06-10 00:03:52 +02:00
|
|
|
|
(let* ((option-name 'car)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(option-value 'cadr)
|
|
|
|
|
|
(option-documentation 'caddr)
|
2001-01-26 16:58:48 +00:00
|
|
|
|
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;; Below follow the macros defining the run-time option interfaces.
|
2001-01-26 16:58:48 +00:00
|
|
|
|
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(make-options (lambda (interface)
|
|
|
|
|
|
`(lambda args
|
|
|
|
|
|
(cond ((null? args) (,interface))
|
|
|
|
|
|
((list? (car args))
|
|
|
|
|
|
(,interface (car args)) (,interface))
|
|
|
|
|
|
(else (for-each
|
2008-09-01 23:51:30 -07:00
|
|
|
|
(lambda (option)
|
2009-06-10 00:03:52 +02:00
|
|
|
|
(display (,option-name option))
|
2008-09-01 23:51:30 -07:00
|
|
|
|
(if (< (string-length
|
2009-06-10 00:03:52 +02:00
|
|
|
|
(symbol->string (,option-name option)))
|
2008-09-01 23:51:30 -07:00
|
|
|
|
8)
|
|
|
|
|
|
(display #\tab))
|
|
|
|
|
|
(display #\tab)
|
2009-06-10 00:03:52 +02:00
|
|
|
|
(display (,option-value option))
|
2008-09-01 23:51:30 -07:00
|
|
|
|
(display #\tab)
|
2009-06-10 00:03:52 +02:00
|
|
|
|
(display (,option-documentation option))
|
2008-09-01 23:51:30 -07:00
|
|
|
|
(newline))
|
|
|
|
|
|
(,interface #t)))))))
|
2001-01-26 16:58:48 +00:00
|
|
|
|
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(make-enable (lambda (interface)
|
|
|
|
|
|
`(lambda flags
|
|
|
|
|
|
(,interface (append flags (,interface)))
|
|
|
|
|
|
(,interface))))
|
|
|
|
|
|
|
|
|
|
|
|
(make-disable (lambda (interface)
|
|
|
|
|
|
`(lambda flags
|
|
|
|
|
|
(let ((options (,interface)))
|
|
|
|
|
|
(for-each (lambda (flag)
|
|
|
|
|
|
(set! options (delq! flag options)))
|
|
|
|
|
|
flags)
|
|
|
|
|
|
(,interface options)
|
|
|
|
|
|
(,interface))))))
|
2008-09-01 23:51:30 -07:00
|
|
|
|
(let* ((interface (car option-group))
|
|
|
|
|
|
(options/enable/disable (cadr option-group)))
|
|
|
|
|
|
`(begin
|
|
|
|
|
|
(define ,(car options/enable/disable)
|
|
|
|
|
|
,(make-options interface))
|
|
|
|
|
|
(define ,(cadr options/enable/disable)
|
|
|
|
|
|
,(make-enable interface))
|
|
|
|
|
|
(define ,(caddr options/enable/disable)
|
|
|
|
|
|
,(make-disable interface))
|
|
|
|
|
|
(defmacro ,(caaddr option-group) (opt val)
|
|
|
|
|
|
`(,',(car options/enable/disable)
|
|
|
|
|
|
(append (,',(car options/enable/disable))
|
|
|
|
|
|
(list ',opt ,val))))))))
|
2001-01-26 16:58:48 +00:00
|
|
|
|
|
|
|
|
|
|
(define-option-interface
|
|
|
|
|
|
(eval-options-interface
|
|
|
|
|
|
(eval-options eval-enable eval-disable)
|
|
|
|
|
|
(eval-set!)))
|
|
|
|
|
|
|
|
|
|
|
|
(define-option-interface
|
|
|
|
|
|
(debug-options-interface
|
|
|
|
|
|
(debug-options debug-enable debug-disable)
|
|
|
|
|
|
(debug-set!)))
|
|
|
|
|
|
|
|
|
|
|
|
(define-option-interface
|
|
|
|
|
|
(evaluator-traps-interface
|
|
|
|
|
|
(traps trap-enable trap-disable)
|
|
|
|
|
|
(trap-set!)))
|
|
|
|
|
|
|
|
|
|
|
|
(define-option-interface
|
|
|
|
|
|
(read-options-interface
|
|
|
|
|
|
(read-options read-enable read-disable)
|
|
|
|
|
|
(read-set!)))
|
|
|
|
|
|
|
|
|
|
|
|
(define-option-interface
|
|
|
|
|
|
(print-options-interface
|
|
|
|
|
|
(print-options print-enable print-disable)
|
|
|
|
|
|
(print-set!)))
|
1997-09-28 20:12:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Running Repls}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define (repl read evaler print)
|
1997-03-08 19:02:20 +00:00
|
|
|
|
(let loop ((source (read (current-input-port))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(print (evaler source))
|
1997-03-08 19:02:20 +00:00
|
|
|
|
(loop (read (current-input-port)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
;; A provisional repl that acts like the SCM repl:
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define scm-repl-silent #f)
|
|
|
|
|
|
(define (assert-repl-silence v) (set! scm-repl-silent v))
|
|
|
|
|
|
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(define *unspecified* (if #f #f))
|
|
|
|
|
|
(define (unspecified? v) (eq? v *unspecified*))
|
|
|
|
|
|
|
|
|
|
|
|
(define scm-repl-print-unspecified #f)
|
|
|
|
|
|
(define (assert-repl-print-unspecified v) (set! scm-repl-print-unspecified v))
|
|
|
|
|
|
|
Get Guile to be a little less chatty by default. The new user
should see as little clutter as possible.
* r4rs.scm (%load-verbosely): Make this #f by default.
* boot-9.scm (scm-repl-verbose): Make this #f by default.
(scm-style-repl): Don't run 'pk' on the value passed to quit.
* r4rs.scm: New file.
* boot-9.scm: Load r4rs.scm, first thing.
(OPEN_READ, OPEN_WRITE, OPEN_BOTH, *null-device*, open-input-file,
open-output-file, open-io-file, close-input-port,
close-output-port, close-io-port, call-with-input-file,
call-with-output-file, with-input-from-port, with-output-to-port,
with-error-to-port, with-input-from-file, with-output-to-file,
with-error-to-file, with-input-from-string, with-output-to-string,
with-error-to-string, the-eof-object): Definitions moved to
r4rs.scm. Not all of them are R4RS, but those that are use those
that are not.
(load, %load-verbosely, %load-announce): Moved, along with code to
set %load-hook, to r4rs.scm.
* boot-9.scm (integer?): Definition deleted, in favor of the one
present in libguile (which used to be called int?). I have no
idea why integer? didn't just call int? to begin with.
* boot-9.scm (<, <=, =, >, >=): Definitions in terms of <?, <=?,
=?, >?, and >=? deleted; they're defined that way by libguile now.
1996-10-29 03:47:36 +00:00
|
|
|
|
(define scm-repl-verbose #f)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (assert-repl-verbosity v) (set! scm-repl-verbose v))
|
|
|
|
|
|
|
* * debug.scm: *Warning* This feature is a bit premature. I add
it anyway because 1. it is very useful, and, 2. you can start
making it less premature by complaining to me and by modifying
the source! :-)
(trace): Given one or more procedure objects, trace each one.
Given no arguments, show all traced procedures.
(untrace): Given one or more procedure objects, untrace each one.
Given no arguments, untrace all traced procedures. The tracing in
Guile have an advantage to most other systems: We don't create new
procedure objects, but mark the procedure objects themselves.
This means that also anonymous and internal procedures can be
traced.
* boot-9.scm (error-catching-loop): Added handling of apply-frame
and exit-frame exceptions.
* * boot-9.scm (assert-repl-prompt, the-prompt-string): Removed.
(set-repl-prompt!): Setter for repl prompt.
(scm-style-repl): If prompt is #f, don't prompt; if prompt is a
string, display it; if prompt is a thunk, call it and display its
result; otherwise display "> ".
(Change suggested by Roland Orre <orre@nada.kth.se>.)
1997-02-28 23:11:22 +00:00
|
|
|
|
(define scm-repl-prompt "guile> ")
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
* * debug.scm: *Warning* This feature is a bit premature. I add
it anyway because 1. it is very useful, and, 2. you can start
making it less premature by complaining to me and by modifying
the source! :-)
(trace): Given one or more procedure objects, trace each one.
Given no arguments, show all traced procedures.
(untrace): Given one or more procedure objects, untrace each one.
Given no arguments, untrace all traced procedures. The tracing in
Guile have an advantage to most other systems: We don't create new
procedure objects, but mark the procedure objects themselves.
This means that also anonymous and internal procedures can be
traced.
* boot-9.scm (error-catching-loop): Added handling of apply-frame
and exit-frame exceptions.
* * boot-9.scm (assert-repl-prompt, the-prompt-string): Removed.
(set-repl-prompt!): Setter for repl prompt.
(scm-style-repl): If prompt is #f, don't prompt; if prompt is a
string, display it; if prompt is a thunk, call it and display its
result; otherwise display "> ".
(Change suggested by Roland Orre <orre@nada.kth.se>.)
1997-02-28 23:11:22 +00:00
|
|
|
|
(define (set-repl-prompt! v) (set! scm-repl-prompt v))
|
|
|
|
|
|
|
2008-12-26 16:44:02 +01:00
|
|
|
|
(define (default-pre-unwind-handler key . args)
|
2009-05-26 21:47:45 +02:00
|
|
|
|
(save-stack 1)
|
1997-03-01 01:01:09 +00:00
|
|
|
|
(apply throw key args))
|
|
|
|
|
|
|
2009-05-26 21:47:45 +02:00
|
|
|
|
(begin-deprecated
|
|
|
|
|
|
(define (pre-unwind-handler-dispatch key . args)
|
|
|
|
|
|
(apply default-pre-unwind-handler key args)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
* boot-9.scm (beautify-user-module!): Beautify also if public
interface is set to the module itself. In this way we can use
beautify-user-module! to beautify a module prepared for object
code.
(process-define-module): Special case: Try to load object code as
well if a module does :use-module on itself.
* boot-9.scm: Bugfix: Since boot-9.scm is now loaded from
invoke_main_func, we can no longer be sure that all modules have
been registered when boot-9.scm is loaded.
(register-modules): New function: Register and tag modules
registered by scm_register_module_xxx since last call to this
function. Modules are tagged with the dynamic object passed as
argument. (Already linked modules should be tagged with #f.)
(init-dynamic-module, link-dynamic-module): Call register-modules
first to register linked modules.
* boot-9.scm (init-dynamic-module): Remove module from
registered-modules as soon as possible in case we are recursively
invoked; Set public interface before doing the dynamic-call.
* boot-9.scm (map-in-order): Removed (replaced by scm_serial_map).
(abort-hook, before-error-hook, after-error-hook,
before-backtrace-hook, after-backtrace-hook, before-read-hook,
after-read-hook, exit-hook): Make hooks with `make-hook'.
* boot-9.scm: Make hooks first class citizens and make them easier
to use from C:
(make-hook, add-hook!, remove-hook!, run-hooks): Moved to
libguile/feature.c.
* boot-9.scm: Added warnings about bindings used in
libguile/modules.c: the-module, set-current-module,
make-modules-in, beautify-user-module!, module-eval-closure.
1998-11-23 02:36:43 +00:00
|
|
|
|
(define abort-hook (make-hook))
|
1997-03-01 01:34:23 +00:00
|
|
|
|
|
1997-11-09 23:36:17 +00:00
|
|
|
|
;; these definitions are used if running a script.
|
|
|
|
|
|
;; otherwise redefined in error-catching-loop.
|
|
|
|
|
|
(define (set-batch-mode?! arg) #t)
|
|
|
|
|
|
(define (batch-mode?) #t)
|
1997-10-11 20:42:24 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (error-catching-loop thunk)
|
1997-10-11 20:42:24 +00:00
|
|
|
|
(let ((status #f)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(interactive #t))
|
1997-03-02 06:09:41 +00:00
|
|
|
|
(define (loop first)
|
2001-04-28 19:07:38 +00:00
|
|
|
|
(let ((next
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(catch #t
|
|
|
|
|
|
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(call-with-unblocked-asyncs
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(with-traps
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(first)
|
|
|
|
|
|
|
|
|
|
|
|
;; This line is needed because mark
|
|
|
|
|
|
;; doesn't do closures quite right.
|
|
|
|
|
|
;; Unreferenced locals should be
|
|
|
|
|
|
;; collected.
|
|
|
|
|
|
(set! first #f)
|
|
|
|
|
|
(let loop ((v (thunk)))
|
|
|
|
|
|
(loop (thunk)))
|
|
|
|
|
|
#f)))))
|
|
|
|
|
|
|
|
|
|
|
|
(lambda (key . args)
|
|
|
|
|
|
(case key
|
|
|
|
|
|
((quit)
|
|
|
|
|
|
(set! status args)
|
|
|
|
|
|
#f)
|
|
|
|
|
|
|
|
|
|
|
|
((switch-repl)
|
|
|
|
|
|
(apply throw 'switch-repl args))
|
|
|
|
|
|
|
|
|
|
|
|
((abort)
|
|
|
|
|
|
;; This is one of the closures that require
|
|
|
|
|
|
;; (set! first #f) above
|
|
|
|
|
|
;;
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(run-hook abort-hook)
|
|
|
|
|
|
(force-output (current-output-port))
|
|
|
|
|
|
(display "ABORT: " (current-error-port))
|
|
|
|
|
|
(write args (current-error-port))
|
|
|
|
|
|
(newline (current-error-port))
|
|
|
|
|
|
(if interactive
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(if (and
|
|
|
|
|
|
(not has-shown-debugger-hint?)
|
|
|
|
|
|
(not (memq 'backtrace
|
|
|
|
|
|
(debug-options-interface)))
|
|
|
|
|
|
(stack? (fluid-ref the-last-stack)))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(newline (current-error-port))
|
|
|
|
|
|
(display
|
|
|
|
|
|
"Type \"(backtrace)\" to get more information or \"(debug)\" to enter the debugger.\n"
|
|
|
|
|
|
(current-error-port))
|
|
|
|
|
|
(set! has-shown-debugger-hint? #t)))
|
|
|
|
|
|
(force-output (current-error-port)))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(primitive-exit 1)))
|
|
|
|
|
|
(set! stack-saved? #f)))
|
|
|
|
|
|
|
|
|
|
|
|
(else
|
|
|
|
|
|
;; This is the other cons-leak closure...
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(cond ((= (length args) 4)
|
|
|
|
|
|
(apply handle-system-error key args))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(apply bad-throw key args)))))))
|
2006-02-04 14:36:06 +00:00
|
|
|
|
|
2009-05-26 21:47:45 +02:00
|
|
|
|
default-pre-unwind-handler)))
|
2006-02-04 14:36:06 +00:00
|
|
|
|
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(if next (loop next) status)))
|
1999-07-29 18:12:21 +00:00
|
|
|
|
(set! set-batch-mode?! (lambda (arg)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(cond (arg
|
|
|
|
|
|
(set! interactive #f)
|
|
|
|
|
|
(restore-signals))
|
|
|
|
|
|
(#t
|
|
|
|
|
|
(error "sorry, not implemented")))))
|
1999-07-29 18:12:21 +00:00
|
|
|
|
(set! batch-mode? (lambda () (not interactive)))
|
2002-10-09 22:47:34 +00:00
|
|
|
|
(call-with-blocked-asyncs
|
|
|
|
|
|
(lambda () (loop (lambda () #t))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1997-11-29 01:11:21 +00:00
|
|
|
|
;;(define the-last-stack (make-fluid)) Defined by scm_init_backtrace ()
|
1999-09-16 23:44:33 +00:00
|
|
|
|
(define before-signal-stack (make-fluid))
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(define stack-saved? #f)
|
|
|
|
|
|
|
|
|
|
|
|
(define (save-stack . narrowing)
|
1999-03-12 09:48:18 +00:00
|
|
|
|
(or stack-saved?
|
|
|
|
|
|
(cond ((not (memq 'debug (debug-options-interface)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(fluid-set! the-last-stack #f)
|
|
|
|
|
|
(set! stack-saved? #t))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(fluid-set!
|
|
|
|
|
|
the-last-stack
|
|
|
|
|
|
(case (stack-id #t)
|
|
|
|
|
|
((repl-stack)
|
|
|
|
|
|
(apply make-stack #t save-stack primitive-eval #t 0 narrowing))
|
|
|
|
|
|
((load-stack)
|
|
|
|
|
|
(apply make-stack #t save-stack 0 #t 0 narrowing))
|
|
|
|
|
|
((#t)
|
|
|
|
|
|
(apply make-stack #t save-stack 0 1 narrowing))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(let ((id (stack-id #t)))
|
|
|
|
|
|
(and (procedure? id)
|
|
|
|
|
|
(apply make-stack #t save-stack id #t 0 narrowing))))))
|
|
|
|
|
|
(set! stack-saved? #t)))))
|
1996-10-17 23:43:23 +00:00
|
|
|
|
|
* boot-9.scm (beautify-user-module!): Beautify also if public
interface is set to the module itself. In this way we can use
beautify-user-module! to beautify a module prepared for object
code.
(process-define-module): Special case: Try to load object code as
well if a module does :use-module on itself.
* boot-9.scm: Bugfix: Since boot-9.scm is now loaded from
invoke_main_func, we can no longer be sure that all modules have
been registered when boot-9.scm is loaded.
(register-modules): New function: Register and tag modules
registered by scm_register_module_xxx since last call to this
function. Modules are tagged with the dynamic object passed as
argument. (Already linked modules should be tagged with #f.)
(init-dynamic-module, link-dynamic-module): Call register-modules
first to register linked modules.
* boot-9.scm (init-dynamic-module): Remove module from
registered-modules as soon as possible in case we are recursively
invoked; Set public interface before doing the dynamic-call.
* boot-9.scm (map-in-order): Removed (replaced by scm_serial_map).
(abort-hook, before-error-hook, after-error-hook,
before-backtrace-hook, after-backtrace-hook, before-read-hook,
after-read-hook, exit-hook): Make hooks with `make-hook'.
* boot-9.scm: Make hooks first class citizens and make them easier
to use from C:
(make-hook, add-hook!, remove-hook!, run-hooks): Moved to
libguile/feature.c.
* boot-9.scm: Added warnings about bindings used in
libguile/modules.c: the-module, set-current-module,
make-modules-in, beautify-user-module!, module-eval-closure.
1998-11-23 02:36:43 +00:00
|
|
|
|
(define before-error-hook (make-hook))
|
|
|
|
|
|
(define after-error-hook (make-hook))
|
|
|
|
|
|
(define before-backtrace-hook (make-hook))
|
|
|
|
|
|
(define after-backtrace-hook (make-hook))
|
1996-10-17 23:43:23 +00:00
|
|
|
|
|
1996-11-02 20:51:30 +00:00
|
|
|
|
(define has-shown-debugger-hint? #f)
|
|
|
|
|
|
|
1996-10-17 21:56:22 +00:00
|
|
|
|
(define (handle-system-error key . args)
|
|
|
|
|
|
(let ((cep (current-error-port)))
|
1997-11-29 01:11:21 +00:00
|
|
|
|
(cond ((not (stack? (fluid-ref the-last-stack))))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
((memq 'backtrace (debug-options-interface))
|
|
|
|
|
|
(let ((highlights (if (or (eq? key 'wrong-type-arg)
|
|
|
|
|
|
(eq? key 'out-of-range))
|
|
|
|
|
|
(list-ref args 3)
|
|
|
|
|
|
'())))
|
|
|
|
|
|
(run-hook before-backtrace-hook)
|
|
|
|
|
|
(newline cep)
|
|
|
|
|
|
(display "Backtrace:\n")
|
|
|
|
|
|
(display-backtrace (fluid-ref the-last-stack) cep
|
|
|
|
|
|
#f #f highlights)
|
|
|
|
|
|
(newline cep)
|
|
|
|
|
|
(run-hook after-backtrace-hook))))
|
1998-11-26 08:31:02 +00:00
|
|
|
|
(run-hook before-error-hook)
|
1997-11-29 01:11:21 +00:00
|
|
|
|
(apply display-error (fluid-ref the-last-stack) cep args)
|
1998-11-26 08:31:02 +00:00
|
|
|
|
(run-hook after-error-hook)
|
1996-10-17 21:56:22 +00:00
|
|
|
|
(force-output cep)
|
|
|
|
|
|
(throw 'abort key)))
|
1996-11-02 20:51:30 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (quit . args)
|
|
|
|
|
|
(apply throw 'quit args))
|
|
|
|
|
|
|
1997-03-02 19:53:32 +00:00
|
|
|
|
(define exit quit)
|
|
|
|
|
|
|
1997-02-10 01:05:50 +00:00
|
|
|
|
;;(define has-shown-backtrace-hint? #f) Defined by scm_init_backtrace ()
|
|
|
|
|
|
|
|
|
|
|
|
;; Replaced by C code:
|
|
|
|
|
|
;;(define (backtrace)
|
1997-11-29 01:11:21 +00:00
|
|
|
|
;; (if (fluid-ref the-last-stack)
|
1997-02-10 01:05:50 +00:00
|
|
|
|
;; (begin
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;; (newline)
|
|
|
|
|
|
;; (display-backtrace (fluid-ref the-last-stack) (current-output-port))
|
|
|
|
|
|
;; (newline)
|
|
|
|
|
|
;; (if (and (not has-shown-backtrace-hint?)
|
|
|
|
|
|
;; (not (memq 'backtrace (debug-options-interface))))
|
|
|
|
|
|
;; (begin
|
|
|
|
|
|
;; (display
|
1997-02-10 01:05:50 +00:00
|
|
|
|
;;"Type \"(debug-enable 'backtrace)\" if you would like a backtrace
|
|
|
|
|
|
;;automatically if an error occurs in the future.\n")
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;; (set! has-shown-backtrace-hint? #t))))
|
1997-02-10 01:05:50 +00:00
|
|
|
|
;; (display "No backtrace available.\n")))
|
1996-11-02 20:51:30 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (error-catching-repl r e p)
|
2001-05-15 00:51:06 +00:00
|
|
|
|
(error-catching-loop
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(call-with-values (lambda () (e (r)))
|
|
|
|
|
|
(lambda the-values (for-each p the-values))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(define (gc-run-time)
|
|
|
|
|
|
(cdr (assq 'gc-time-taken (gc-stats))))
|
|
|
|
|
|
|
* boot-9.scm (beautify-user-module!): Beautify also if public
interface is set to the module itself. In this way we can use
beautify-user-module! to beautify a module prepared for object
code.
(process-define-module): Special case: Try to load object code as
well if a module does :use-module on itself.
* boot-9.scm: Bugfix: Since boot-9.scm is now loaded from
invoke_main_func, we can no longer be sure that all modules have
been registered when boot-9.scm is loaded.
(register-modules): New function: Register and tag modules
registered by scm_register_module_xxx since last call to this
function. Modules are tagged with the dynamic object passed as
argument. (Already linked modules should be tagged with #f.)
(init-dynamic-module, link-dynamic-module): Call register-modules
first to register linked modules.
* boot-9.scm (init-dynamic-module): Remove module from
registered-modules as soon as possible in case we are recursively
invoked; Set public interface before doing the dynamic-call.
* boot-9.scm (map-in-order): Removed (replaced by scm_serial_map).
(abort-hook, before-error-hook, after-error-hook,
before-backtrace-hook, after-backtrace-hook, before-read-hook,
after-read-hook, exit-hook): Make hooks with `make-hook'.
* boot-9.scm: Make hooks first class citizens and make them easier
to use from C:
(make-hook, add-hook!, remove-hook!, run-hooks): Moved to
libguile/feature.c.
* boot-9.scm: Added warnings about bindings used in
libguile/modules.c: the-module, set-current-module,
make-modules-in, beautify-user-module!, module-eval-closure.
1998-11-23 02:36:43 +00:00
|
|
|
|
(define before-read-hook (make-hook))
|
|
|
|
|
|
(define after-read-hook (make-hook))
|
2001-03-17 15:32:17 +00:00
|
|
|
|
(define before-eval-hook (make-hook 1))
|
|
|
|
|
|
(define after-eval-hook (make-hook 1))
|
|
|
|
|
|
(define before-print-hook (make-hook 1))
|
|
|
|
|
|
(define after-print-hook (make-hook 1))
|
1996-10-17 23:43:23 +00:00
|
|
|
|
|
1998-05-12 23:59:21 +00:00
|
|
|
|
;;; The default repl-reader function. We may override this if we've
|
|
|
|
|
|
;;; the readline library.
|
|
|
|
|
|
(define repl-reader
|
2009-10-16 13:30:52 +02:00
|
|
|
|
(lambda (prompt . reader)
|
2008-05-09 16:42:44 +02:00
|
|
|
|
(display (if (string? prompt) prompt (prompt)))
|
1998-05-12 23:59:21 +00:00
|
|
|
|
(force-output)
|
1998-11-26 08:31:02 +00:00
|
|
|
|
(run-hook before-read-hook)
|
2009-10-16 13:30:52 +02:00
|
|
|
|
((or (and (pair? reader) (car reader))
|
|
|
|
|
|
(fluid-ref current-reader)
|
|
|
|
|
|
read)
|
|
|
|
|
|
(current-input-port))))
|
1998-05-12 23:59:21 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define (scm-style-repl)
|
2001-01-21 22:11:29 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(letrec (
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(start-gc-rt #f)
|
|
|
|
|
|
(start-rt #f)
|
|
|
|
|
|
(repl-report-start-timing (lambda ()
|
|
|
|
|
|
(set! start-gc-rt (gc-run-time))
|
|
|
|
|
|
(set! start-rt (get-internal-run-time))))
|
|
|
|
|
|
(repl-report (lambda ()
|
|
|
|
|
|
(display ";;; ")
|
|
|
|
|
|
(display (inexact->exact
|
|
|
|
|
|
(* 1000 (/ (- (get-internal-run-time) start-rt)
|
|
|
|
|
|
internal-time-units-per-second))))
|
|
|
|
|
|
(display " msec (")
|
|
|
|
|
|
(display (inexact->exact
|
|
|
|
|
|
(* 1000 (/ (- (gc-run-time) start-gc-rt)
|
|
|
|
|
|
internal-time-units-per-second))))
|
|
|
|
|
|
(display " msec in gc)\n")))
|
|
|
|
|
|
|
|
|
|
|
|
(consume-trailing-whitespace
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(let ((ch (peek-char)))
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((eof-object? ch))
|
|
|
|
|
|
((or (char=? ch #\space) (char=? ch #\tab))
|
|
|
|
|
|
(read-char)
|
|
|
|
|
|
(consume-trailing-whitespace))
|
|
|
|
|
|
((char=? ch #\newline)
|
|
|
|
|
|
(read-char))))))
|
|
|
|
|
|
(-read (lambda ()
|
|
|
|
|
|
(let ((val
|
|
|
|
|
|
(let ((prompt (cond ((string? scm-repl-prompt)
|
|
|
|
|
|
scm-repl-prompt)
|
|
|
|
|
|
((thunk? scm-repl-prompt)
|
|
|
|
|
|
(scm-repl-prompt))
|
|
|
|
|
|
(scm-repl-prompt "> ")
|
|
|
|
|
|
(else ""))))
|
|
|
|
|
|
(repl-reader prompt))))
|
|
|
|
|
|
|
|
|
|
|
|
;; As described in R4RS, the READ procedure updates the
|
|
|
|
|
|
;; port to point to the first character past the end of
|
|
|
|
|
|
;; the external representation of the object. This
|
|
|
|
|
|
;; means that it doesn't consume the newline typically
|
|
|
|
|
|
;; found after an expression. This means that, when
|
|
|
|
|
|
;; debugging Guile with GDB, GDB gets the newline, which
|
|
|
|
|
|
;; it often interprets as a "continue" command, making
|
|
|
|
|
|
;; breakpoints kind of useless. So, consume any
|
|
|
|
|
|
;; trailing newline here, as well as any whitespace
|
|
|
|
|
|
;; before it.
|
|
|
|
|
|
;; But not if EOF, for control-D.
|
|
|
|
|
|
(if (not (eof-object? val))
|
|
|
|
|
|
(consume-trailing-whitespace))
|
|
|
|
|
|
(run-hook after-read-hook)
|
|
|
|
|
|
(if (eof-object? val)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(repl-report-start-timing)
|
|
|
|
|
|
(if scm-repl-verbose
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(display ";;; EOF -- quitting")
|
|
|
|
|
|
(newline)))
|
|
|
|
|
|
(quit 0)))
|
|
|
|
|
|
val)))
|
|
|
|
|
|
|
|
|
|
|
|
(-eval (lambda (sourc)
|
|
|
|
|
|
(repl-report-start-timing)
|
|
|
|
|
|
(run-hook before-eval-hook sourc)
|
|
|
|
|
|
(let ((val (start-stack 'repl-stack
|
|
|
|
|
|
;; If you change this procedure
|
|
|
|
|
|
;; (primitive-eval), please also
|
|
|
|
|
|
;; modify the repl-stack case in
|
|
|
|
|
|
;; save-stack so that stack cutting
|
|
|
|
|
|
;; continues to work.
|
|
|
|
|
|
(primitive-eval sourc))))
|
|
|
|
|
|
(run-hook after-eval-hook sourc)
|
|
|
|
|
|
val)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(-print (let ((maybe-print (lambda (result)
|
|
|
|
|
|
(if (or scm-repl-print-unspecified
|
|
|
|
|
|
(not (unspecified? result)))
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(write result)
|
|
|
|
|
|
(newline))))))
|
|
|
|
|
|
(lambda (result)
|
|
|
|
|
|
(if (not scm-repl-silent)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(run-hook before-print-hook result)
|
|
|
|
|
|
(maybe-print result)
|
|
|
|
|
|
(run-hook after-print-hook result)
|
|
|
|
|
|
(if scm-repl-verbose
|
|
|
|
|
|
(repl-report))
|
|
|
|
|
|
(force-output))))))
|
|
|
|
|
|
|
|
|
|
|
|
(-quit (lambda (args)
|
|
|
|
|
|
(if scm-repl-verbose
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(display ";;; QUIT executed, repl exitting")
|
|
|
|
|
|
(newline)
|
|
|
|
|
|
(repl-report)))
|
|
|
|
|
|
args)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1997-03-02 06:09:41 +00:00
|
|
|
|
(let ((status (error-catching-repl -read
|
2009-12-22 00:58:12 +01:00
|
|
|
|
-eval
|
|
|
|
|
|
-print)))
|
1997-03-02 06:09:41 +00:00
|
|
|
|
(-quit status))))
|
2001-04-28 19:07:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-10-16 22:29:19 +00:00
|
|
|
|
;;; {IOTA functions: generating lists of numbers}
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1999-06-05 05:59:26 +00:00
|
|
|
|
(define (iota n)
|
|
|
|
|
|
(let loop ((count (1- n)) (result '()))
|
|
|
|
|
|
(if (< count 0) result
|
|
|
|
|
|
(loop (1- count) (cons count result)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1998-11-12 16:03:11 +00:00
|
|
|
|
;;; {collect}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Similar to `begin' but returns a list of the results of all constituent
|
|
|
|
|
|
;;; forms instead of the result of the last form.
|
|
|
|
|
|
;;; (The definition relies on the current left-to-right
|
|
|
|
|
|
;;; order of evaluation of operands in applications.)
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
1998-11-12 16:03:11 +00:00
|
|
|
|
|
|
|
|
|
|
(defmacro collect forms
|
|
|
|
|
|
(cons 'list forms))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
2003-08-12 21:38:21 +00:00
|
|
|
|
;;; {While}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; with `continue' and `break'.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; The inner `do' loop avoids re-establishing a catch every iteration,
|
2003-08-17 00:36:04 +00:00
|
|
|
|
;; that's only necessary if continue is actually used. A new key is
|
|
|
|
|
|
;; generated every time, so break and continue apply to their originating
|
2008-10-11 15:03:00 +02:00
|
|
|
|
;; `while' even when recursing.
|
2005-01-27 21:20:47 +00:00
|
|
|
|
;;
|
2008-10-11 15:03:00 +02:00
|
|
|
|
;; FIXME: This macro is unintentionally unhygienic with respect to let,
|
|
|
|
|
|
;; make-symbol, do, throw, catch, lambda, and not.
|
2005-01-27 21:20:47 +00:00
|
|
|
|
;;
|
2003-08-12 21:38:21 +00:00
|
|
|
|
(define-macro (while cond . body)
|
2008-10-11 15:03:00 +02:00
|
|
|
|
(let ((keyvar (make-symbol "while-keyvar")))
|
|
|
|
|
|
`(let ((,keyvar (make-symbol "while-key")))
|
|
|
|
|
|
(do ()
|
|
|
|
|
|
((catch ,keyvar
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(let ((break (lambda () (throw ,keyvar #t)))
|
|
|
|
|
|
(continue (lambda () (throw ,keyvar #f))))
|
|
|
|
|
|
(do ()
|
|
|
|
|
|
((not ,cond))
|
|
|
|
|
|
,@body)
|
|
|
|
|
|
#t))
|
|
|
|
|
|
(lambda (key arg)
|
|
|
|
|
|
arg)))))))
|
2003-08-17 00:36:04 +00:00
|
|
|
|
|
2003-08-12 21:38:21 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;; {Module System Macros}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
2001-06-01 20:15:10 +00:00
|
|
|
|
;; Return a list of expressions that evaluate to the appropriate
|
|
|
|
|
|
;; arguments for resolve-interface according to SPEC.
|
|
|
|
|
|
|
Replace eval-case with eval-when
* module/ice-9/boot-9.scm (eval-when): Replace eval-case with eval-when.
Eval-when is *much* simpler, and more expressive to boot. Perhaps in
the future we'll get 'visit and 'revisit too.
* module/ice-9/deprecated.scm (eval-case): Provide mostly-working
deprecated version of eval-case.
* module/ice-9/boot-9.scm (defmacro, define-macro): Relax condition: we
can make defmacros that are not at the toplevel now. But in the future
we should replace this implementation of defmacros with one written in
syntax-case.
(define-module, use-modules, use-syntax): Allow at non-toplevel.
(define-public, defmacro-public, export, re-export): Don't evaluate at
compile-time, I can't see how that helps things. Allow `export' and
`re-export' at non-toplevel.
* module/ice-9/getopt-long.scm:
* module/ice-9/i18n.scm:
* module/oop/goops.scm:
* module/oop/goops/compile.scm:
* module/oop/goops/dispatch.scm: Switch to use eval-when, not
eval-case.
* module/language/scheme/compile-ghil.scm (eval-when): Replace eval-case
transformer with eval-when transformer. Sooooo much simpler, and it
will get better once we separate expansion from compilation.
* module/language/scheme/expand.scm (quasiquote): Hm, expand quasiquote
properly. Not hygienic. Syncase needed.
(lambda): Handle internal defines with docstrings propertly.
2009-03-06 13:29:13 +01:00
|
|
|
|
(eval-when
|
2009-03-06 16:57:17 +01:00
|
|
|
|
(compile)
|
|
|
|
|
|
(if (memq 'prefix (read-options))
|
|
|
|
|
|
(error "boot-9 must be compiled with #:kw, not :kw")))
|
2008-09-09 06:56:06 +02:00
|
|
|
|
|
2001-06-01 20:15:10 +00:00
|
|
|
|
(define (compile-interface-spec spec)
|
|
|
|
|
|
(define (make-keyarg sym key quote?)
|
|
|
|
|
|
(cond ((or (memq sym spec)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(memq key spec))
|
|
|
|
|
|
=> (lambda (rest)
|
|
|
|
|
|
(if quote?
|
|
|
|
|
|
(list key (list 'quote (cadr rest)))
|
|
|
|
|
|
(list key (cadr rest)))))
|
|
|
|
|
|
(else
|
|
|
|
|
|
'())))
|
2001-06-01 20:15:10 +00:00
|
|
|
|
(define (map-apply func list)
|
|
|
|
|
|
(map (lambda (args) (apply func args)) list))
|
2001-08-30 23:25:34 +00:00
|
|
|
|
(define keys
|
2001-06-01 20:15:10 +00:00
|
|
|
|
;; sym key quote?
|
|
|
|
|
|
'((:select #:select #t)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(:hide #:hide #t)
|
2003-03-10 23:18:05 +00:00
|
|
|
|
(:prefix #:prefix #t)
|
2009-12-22 00:33:12 +01:00
|
|
|
|
(:renamer #:renamer #f)
|
|
|
|
|
|
(:version #:version #t)))
|
2001-06-01 20:15:10 +00:00
|
|
|
|
(if (not (pair? (car spec)))
|
|
|
|
|
|
`(',spec)
|
|
|
|
|
|
`(',(car spec)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
,@(apply append (map-apply make-keyarg keys)))))
|
2001-06-01 20:15:10 +00:00
|
|
|
|
|
|
|
|
|
|
(define (keyword-like-symbol->keyword sym)
|
|
|
|
|
|
(symbol->keyword (string->symbol (substring (symbol->string sym) 1))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (compile-define-module-args args)
|
|
|
|
|
|
;; Just quote everything except #:use-module and #:use-syntax. We
|
|
|
|
|
|
;; need to know about all arguments regardless since we want to turn
|
|
|
|
|
|
;; symbols that look like keywords into real keywords, and the
|
|
|
|
|
|
;; keyword args in a define-module form are not regular
|
|
|
|
|
|
;; (i.e. no-backtrace doesn't take a value).
|
|
|
|
|
|
(let loop ((compiled-args `((quote ,(car args))))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(args (cdr args)))
|
2001-06-01 20:15:10 +00:00
|
|
|
|
(cond ((null? args)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(reverse! compiled-args))
|
|
|
|
|
|
;; symbol in keyword position
|
|
|
|
|
|
((symbol? (car args))
|
|
|
|
|
|
(loop compiled-args
|
|
|
|
|
|
(cons (keyword-like-symbol->keyword (car args)) (cdr args))))
|
|
|
|
|
|
((memq (car args) '(#:no-backtrace #:pure))
|
|
|
|
|
|
(loop (cons (car args) compiled-args)
|
|
|
|
|
|
(cdr args)))
|
|
|
|
|
|
((null? (cdr args))
|
|
|
|
|
|
(error "keyword without value:" (car args)))
|
|
|
|
|
|
((memq (car args) '(#:use-module #:use-syntax))
|
|
|
|
|
|
(loop (cons* `(list ,@(compile-interface-spec (cadr args)))
|
|
|
|
|
|
(car args)
|
|
|
|
|
|
compiled-args)
|
|
|
|
|
|
(cddr args)))
|
|
|
|
|
|
((eq? (car args) #:autoload)
|
|
|
|
|
|
(loop (cons* `(quote ,(caddr args))
|
|
|
|
|
|
`(quote ,(cadr args))
|
|
|
|
|
|
(car args)
|
|
|
|
|
|
compiled-args)
|
|
|
|
|
|
(cdddr args)))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(loop (cons* `(quote ,(cadr args))
|
|
|
|
|
|
(car args)
|
|
|
|
|
|
compiled-args)
|
|
|
|
|
|
(cddr args))))))
|
2001-06-01 20:15:10 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(defmacro define-module args
|
Replace eval-case with eval-when
* module/ice-9/boot-9.scm (eval-when): Replace eval-case with eval-when.
Eval-when is *much* simpler, and more expressive to boot. Perhaps in
the future we'll get 'visit and 'revisit too.
* module/ice-9/deprecated.scm (eval-case): Provide mostly-working
deprecated version of eval-case.
* module/ice-9/boot-9.scm (defmacro, define-macro): Relax condition: we
can make defmacros that are not at the toplevel now. But in the future
we should replace this implementation of defmacros with one written in
syntax-case.
(define-module, use-modules, use-syntax): Allow at non-toplevel.
(define-public, defmacro-public, export, re-export): Don't evaluate at
compile-time, I can't see how that helps things. Allow `export' and
`re-export' at non-toplevel.
* module/ice-9/getopt-long.scm:
* module/ice-9/i18n.scm:
* module/oop/goops.scm:
* module/oop/goops/compile.scm:
* module/oop/goops/dispatch.scm: Switch to use eval-when, not
eval-case.
* module/language/scheme/compile-ghil.scm (eval-when): Replace eval-case
transformer with eval-when transformer. Sooooo much simpler, and it
will get better once we separate expansion from compilation.
* module/language/scheme/expand.scm (quasiquote): Hm, expand quasiquote
properly. Not hygienic. Syncase needed.
(lambda): Handle internal defines with docstrings propertly.
2009-03-06 13:29:13 +01:00
|
|
|
|
`(eval-when
|
|
|
|
|
|
(eval load compile)
|
|
|
|
|
|
(let ((m (process-define-module
|
|
|
|
|
|
(list ,@(compile-define-module-args args)))))
|
|
|
|
|
|
(set-current-module m)
|
|
|
|
|
|
m)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-06-01 20:15:10 +00:00
|
|
|
|
;; The guts of the use-modules macro. Add the interfaces of the named
|
|
|
|
|
|
;; modules to the use-list of the current module, in order.
|
|
|
|
|
|
|
2001-11-23 21:43:44 +00:00
|
|
|
|
;; This function is called by "modules.c". If you change it, be sure
|
|
|
|
|
|
;; to change scm_c_use_module as well.
|
|
|
|
|
|
|
2001-06-01 20:15:10 +00:00
|
|
|
|
(define (process-use-modules module-interface-args)
|
2003-03-12 14:11:42 +00:00
|
|
|
|
(let ((interfaces (map (lambda (mif-args)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(or (apply resolve-interface mif-args)
|
|
|
|
|
|
(error "no such module" mif-args)))
|
|
|
|
|
|
module-interface-args)))
|
2003-03-12 14:11:42 +00:00
|
|
|
|
(call-with-deferred-observers
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(module-use-interfaces! (current-module) interfaces)))))
|
1997-04-29 18:22:54 +00:00
|
|
|
|
|
1997-01-05 23:38:10 +00:00
|
|
|
|
(defmacro use-modules modules
|
Replace eval-case with eval-when
* module/ice-9/boot-9.scm (eval-when): Replace eval-case with eval-when.
Eval-when is *much* simpler, and more expressive to boot. Perhaps in
the future we'll get 'visit and 'revisit too.
* module/ice-9/deprecated.scm (eval-case): Provide mostly-working
deprecated version of eval-case.
* module/ice-9/boot-9.scm (defmacro, define-macro): Relax condition: we
can make defmacros that are not at the toplevel now. But in the future
we should replace this implementation of defmacros with one written in
syntax-case.
(define-module, use-modules, use-syntax): Allow at non-toplevel.
(define-public, defmacro-public, export, re-export): Don't evaluate at
compile-time, I can't see how that helps things. Allow `export' and
`re-export' at non-toplevel.
* module/ice-9/getopt-long.scm:
* module/ice-9/i18n.scm:
* module/oop/goops.scm:
* module/oop/goops/compile.scm:
* module/oop/goops/dispatch.scm: Switch to use eval-when, not
eval-case.
* module/language/scheme/compile-ghil.scm (eval-when): Replace eval-case
transformer with eval-when transformer. Sooooo much simpler, and it
will get better once we separate expansion from compilation.
* module/language/scheme/expand.scm (quasiquote): Hm, expand quasiquote
properly. Not hygienic. Syncase needed.
(lambda): Handle internal defines with docstrings propertly.
2009-03-06 13:29:13 +01:00
|
|
|
|
`(eval-when
|
|
|
|
|
|
(eval load compile)
|
|
|
|
|
|
(process-use-modules
|
|
|
|
|
|
(list ,@(map (lambda (m)
|
|
|
|
|
|
`(list ,@(compile-interface-spec m)))
|
|
|
|
|
|
modules)))
|
|
|
|
|
|
*unspecified*))
|
1997-01-05 23:38:10 +00:00
|
|
|
|
|
1998-06-07 10:29:40 +00:00
|
|
|
|
(defmacro use-syntax (spec)
|
Replace eval-case with eval-when
* module/ice-9/boot-9.scm (eval-when): Replace eval-case with eval-when.
Eval-when is *much* simpler, and more expressive to boot. Perhaps in
the future we'll get 'visit and 'revisit too.
* module/ice-9/deprecated.scm (eval-case): Provide mostly-working
deprecated version of eval-case.
* module/ice-9/boot-9.scm (defmacro, define-macro): Relax condition: we
can make defmacros that are not at the toplevel now. But in the future
we should replace this implementation of defmacros with one written in
syntax-case.
(define-module, use-modules, use-syntax): Allow at non-toplevel.
(define-public, defmacro-public, export, re-export): Don't evaluate at
compile-time, I can't see how that helps things. Allow `export' and
`re-export' at non-toplevel.
* module/ice-9/getopt-long.scm:
* module/ice-9/i18n.scm:
* module/oop/goops.scm:
* module/oop/goops/compile.scm:
* module/oop/goops/dispatch.scm: Switch to use eval-when, not
eval-case.
* module/language/scheme/compile-ghil.scm (eval-when): Replace eval-case
transformer with eval-when transformer. Sooooo much simpler, and it
will get better once we separate expansion from compilation.
* module/language/scheme/expand.scm (quasiquote): Hm, expand quasiquote
properly. Not hygienic. Syncase needed.
(lambda): Handle internal defines with docstrings propertly.
2009-03-06 13:29:13 +01:00
|
|
|
|
`(eval-when
|
|
|
|
|
|
(eval load compile)
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
(issue-deprecation-warning
|
|
|
|
|
|
"`use-syntax' is deprecated. Please contact guile-devel for more info.")
|
|
|
|
|
|
(process-use-modules (list (list ,@(compile-interface-spec spec))))
|
|
|
|
|
|
*unspecified*))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
(define-syntax define-private
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ foo bar)
|
|
|
|
|
|
(define foo bar))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax define-public
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ (name . args) . body)
|
|
|
|
|
|
(define-public name (lambda args . body)))
|
|
|
|
|
|
((_ name val)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(define name val)
|
|
|
|
|
|
(export name)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax defmacro-public
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ name args . body)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(defmacro name args . body)
|
|
|
|
|
|
(export-syntax name)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2009-09-10 23:58:57 +02:00
|
|
|
|
;; And now for the most important macro.
|
|
|
|
|
|
(define-syntax λ
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ formals body ...)
|
|
|
|
|
|
(lambda formals body ...))))
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-06-04 22:14:16 +00:00
|
|
|
|
;; Export a local variable
|
2001-11-23 21:43:44 +00:00
|
|
|
|
|
|
|
|
|
|
;; This function is called from "modules.c". If you change it, be
|
|
|
|
|
|
;; sure to update "modules.c" as well.
|
|
|
|
|
|
|
2000-06-21 01:16:45 +00:00
|
|
|
|
(define (module-export! m names)
|
|
|
|
|
|
(let ((public-i (module-public-interface m)))
|
|
|
|
|
|
(for-each (lambda (name)
|
2009-12-10 00:29:11 -05:00
|
|
|
|
(let* ((internal-name (if (pair? name) (car name) name))
|
|
|
|
|
|
(external-name (if (pair? name) (cdr name) name))
|
|
|
|
|
|
(var (module-ensure-local-variable! m internal-name)))
|
|
|
|
|
|
(module-add! public-i external-name var)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
names)))
|
2001-06-04 22:14:16 +00:00
|
|
|
|
|
2003-03-10 23:18:05 +00:00
|
|
|
|
(define (module-replace! m names)
|
|
|
|
|
|
(let ((public-i (module-public-interface m)))
|
|
|
|
|
|
(for-each (lambda (name)
|
2009-12-10 00:29:11 -05:00
|
|
|
|
(let* ((internal-name (if (pair? name) (car name) name))
|
|
|
|
|
|
(external-name (if (pair? name) (cdr name) name))
|
|
|
|
|
|
(var (module-ensure-local-variable! m internal-name)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(set-object-property! var 'replace #t)
|
2009-12-10 00:29:11 -05:00
|
|
|
|
(module-add! public-i external-name var)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
names)))
|
2003-03-10 23:18:05 +00:00
|
|
|
|
|
2001-06-04 22:14:16 +00:00
|
|
|
|
;; Re-export a imported variable
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (module-re-export! m names)
|
|
|
|
|
|
(let ((public-i (module-public-interface m)))
|
|
|
|
|
|
(for-each (lambda (name)
|
2009-12-10 00:29:11 -05:00
|
|
|
|
(let* ((internal-name (if (pair? name) (car name) name))
|
|
|
|
|
|
(external-name (if (pair? name) (cdr name) name))
|
|
|
|
|
|
(var (module-variable m internal-name)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(cond ((not var)
|
2009-12-10 00:29:11 -05:00
|
|
|
|
(error "Undefined variable:" internal-name))
|
|
|
|
|
|
((eq? var (module-local-variable m internal-name))
|
|
|
|
|
|
(error "re-exporting local variable:" internal-name))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(else
|
2009-12-10 00:29:11 -05:00
|
|
|
|
(module-add! public-i external-name var)))))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
names)))
|
2000-06-21 01:16:45 +00:00
|
|
|
|
|
1998-07-15 23:01:45 +00:00
|
|
|
|
(defmacro export names
|
2010-01-11 18:30:13 +01:00
|
|
|
|
`(eval-when (eval load compile)
|
|
|
|
|
|
(call-with-deferred-observers
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(module-export! (current-module) ',names)))))
|
1998-07-15 23:01:45 +00:00
|
|
|
|
|
2001-06-04 22:14:16 +00:00
|
|
|
|
(defmacro re-export names
|
2010-01-11 18:30:13 +01:00
|
|
|
|
`(eval-when (eval load compile)
|
|
|
|
|
|
(call-with-deferred-observers
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(module-re-export! (current-module) ',names)))))
|
2001-06-04 22:14:16 +00:00
|
|
|
|
|
2002-11-16 15:05:29 +00:00
|
|
|
|
(defmacro export-syntax names
|
2002-11-16 15:40:27 +00:00
|
|
|
|
`(export ,@names))
|
1998-07-15 23:01:45 +00:00
|
|
|
|
|
2002-11-24 08:28:05 +00:00
|
|
|
|
(defmacro re-export-syntax names
|
|
|
|
|
|
`(re-export ,@names))
|
1998-07-15 23:01:45 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(define load load-module)
|
|
|
|
|
|
|
recompiling with compile environments, fluid languages, cleanups
* ice-9/boot-9.scm (compile-time-environment): Remove definition from
boot-9 -- instead, autoload it and `compile' from (system base
compile).
* libguile/objcodes.h:
* libguile/objcodes.c (scm_objcode_to_program): Add an optional argument,
`external', the external list to set on the returned program.
* libguile/vm-i-system.c (externals): New instruction, returns the
external list. Only used by (compile-time-environment).
* libguile/vm.c (scm_load_compiled_with_vm): Adapt to
scm_objcode_to_program change.
* module/language/scheme/translate.scm (translate): Actually pay
attention to the environment passed as an argument.
(custom-transformer-table): Expand out (compile-time-environment) to
something that can be passed to `compile'.
* module/system/base/compile.scm (*current-language*): Instead of
hard-coding `scheme' in various places, use a current language fluid,
initialized to `scheme'.
(compile-file, load-source-file): Adapt to *current-language*.
(load-source-file): Ada
(scheme-eval): Removed, no one used this.
(compiled-file-name): Don't hard-code "scm" and "go"; instead use the
%load-extensions and %load-compiled-extensions.
(cenv-module, cenv-ghil-env, cenv-externals): Some accessors for
compile-time environments.
(compile-time-environment): Here we define (compile-time-environment)
to something that will return #f; the compiler however produces
different code as noted above.
(compile): New function, compiles an expression into a thunk, then runs
the thunk to get the value. Useful for procedures. The optional second
argument can be either a module or a compile-time-environment; in the
latter case, we can recompile even with lexical bindings.
(compile-in): If the env specifies a module, set that module for the
duration of the compilation.
* module/system/base/syntax.scm (%compute-initargs): Fix a bug where the
default value for a field would always replace a user-supplied value.
Whoops.
* module/system/il/ghil.scm (ghil-env-dereify): New function, takes the
result of ghil-env-reify and turns it back into a GHIL environment.
* scripts/compile (compile): Remove some of the tricky error handling, as
the library procedures handle this for us.
* test-suite/tests/compiler.test: Add a test for the dynamic compilation
bits.
2008-10-30 10:57:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
2003-03-10 23:18:05 +00:00
|
|
|
|
;;; {Parameters}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define make-mutable-parameter
|
|
|
|
|
|
(let ((make (lambda (fluid converter)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(lambda args
|
|
|
|
|
|
(if (null? args)
|
|
|
|
|
|
(fluid-ref fluid)
|
|
|
|
|
|
(fluid-set! fluid (converter (car args))))))))
|
2003-03-10 23:18:05 +00:00
|
|
|
|
(lambda (init . converter)
|
|
|
|
|
|
(let ((fluid (make-fluid))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(converter (if (null? converter)
|
|
|
|
|
|
identity
|
|
|
|
|
|
(car converter))))
|
|
|
|
|
|
(fluid-set! fluid (converter init))
|
|
|
|
|
|
(make fluid converter)))))
|
2003-03-10 23:18:05 +00:00
|
|
|
|
|
2003-03-07 13:12:47 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
2003-03-07 13:12:47 +00:00
|
|
|
|
;;; {Handling of duplicate imported bindings}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; Duplicate handlers take the following arguments:
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; module importing module
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;; name conflicting name
|
|
|
|
|
|
;; int1 old interface where name occurs
|
|
|
|
|
|
;; val1 value of binding in old interface
|
|
|
|
|
|
;; int2 new interface where name occurs
|
|
|
|
|
|
;; val2 value of binding in new interface
|
|
|
|
|
|
;; var previous resolution or #f
|
|
|
|
|
|
;; val value of previous resolution
|
2003-03-07 13:12:47 +00:00
|
|
|
|
;;
|
|
|
|
|
|
;; A duplicate handler can take three alternative actions:
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; 1. return #f => leave responsibility to next handler
|
|
|
|
|
|
;; 2. exit with an error
|
|
|
|
|
|
;; 3. return a variable resolving the conflict
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
|
|
(define duplicate-handlers
|
|
|
|
|
|
(let ((m (make-module 7)))
|
2003-03-10 23:18:05 +00:00
|
|
|
|
|
|
|
|
|
|
(define (check module name int1 val1 int2 val2 var val)
|
|
|
|
|
|
(scm-error 'misc-error
|
2009-12-22 00:58:12 +01:00
|
|
|
|
#f
|
|
|
|
|
|
"~A: `~A' imported from both ~A and ~A"
|
|
|
|
|
|
(list (module-name module)
|
|
|
|
|
|
name
|
|
|
|
|
|
(module-name int1)
|
|
|
|
|
|
(module-name int2))
|
|
|
|
|
|
#f))
|
2003-03-10 23:18:05 +00:00
|
|
|
|
|
2003-03-12 19:27:15 +00:00
|
|
|
|
(define (warn module name int1 val1 int2 val2 var val)
|
2007-09-01 16:54:26 +00:00
|
|
|
|
(format (current-error-port)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
"WARNING: ~A: `~A' imported from both ~A and ~A\n"
|
|
|
|
|
|
(module-name module)
|
|
|
|
|
|
name
|
|
|
|
|
|
(module-name int1)
|
|
|
|
|
|
(module-name int2))
|
2003-03-12 19:27:15 +00:00
|
|
|
|
#f)
|
2003-03-10 23:18:05 +00:00
|
|
|
|
|
|
|
|
|
|
(define (replace module name int1 val1 int2 val2 var val)
|
|
|
|
|
|
(let ((old (or (and var (object-property var 'replace) var)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(module-variable int1 name)))
|
|
|
|
|
|
(new (module-variable int2 name)))
|
|
|
|
|
|
(if (object-property old 'replace)
|
|
|
|
|
|
(and (or (eq? old new)
|
|
|
|
|
|
(not (object-property new 'replace)))
|
|
|
|
|
|
old)
|
|
|
|
|
|
(and (object-property new 'replace)
|
|
|
|
|
|
new))))
|
2003-03-10 23:18:05 +00:00
|
|
|
|
|
2003-03-12 19:27:15 +00:00
|
|
|
|
(define (warn-override-core module name int1 val1 int2 val2 var val)
|
|
|
|
|
|
(and (eq? int1 the-scm-module)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(begin
|
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
|
"WARNING: ~A: imported module ~A overrides core binding `~A'\n"
|
|
|
|
|
|
(module-name module)
|
|
|
|
|
|
(module-name int2)
|
|
|
|
|
|
name)
|
|
|
|
|
|
(module-local-variable int2 name))))
|
2003-03-10 23:18:05 +00:00
|
|
|
|
|
2003-03-12 19:27:15 +00:00
|
|
|
|
(define (first module name int1 val1 int2 val2 var val)
|
|
|
|
|
|
(or var (module-local-variable int1 name)))
|
2003-03-10 23:18:05 +00:00
|
|
|
|
|
2003-03-12 19:27:15 +00:00
|
|
|
|
(define (last module name int1 val1 int2 val2 var val)
|
|
|
|
|
|
(module-local-variable int2 name))
|
2003-03-10 23:18:05 +00:00
|
|
|
|
|
2003-03-12 19:27:15 +00:00
|
|
|
|
(define (noop module name int1 val1 int2 val2 var val)
|
|
|
|
|
|
#f)
|
|
|
|
|
|
|
2003-03-07 13:12:47 +00:00
|
|
|
|
(set-module-name! m 'duplicate-handlers)
|
|
|
|
|
|
(set-module-kind! m 'interface)
|
2003-03-10 23:18:05 +00:00
|
|
|
|
(module-define! m 'check check)
|
|
|
|
|
|
(module-define! m 'warn warn)
|
|
|
|
|
|
(module-define! m 'replace replace)
|
|
|
|
|
|
(module-define! m 'warn-override-core warn-override-core)
|
|
|
|
|
|
(module-define! m 'first first)
|
|
|
|
|
|
(module-define! m 'last last)
|
2003-03-12 19:27:15 +00:00
|
|
|
|
(module-define! m 'merge-generics noop)
|
|
|
|
|
|
(module-define! m 'merge-accessors noop)
|
2003-03-07 13:12:47 +00:00
|
|
|
|
m))
|
|
|
|
|
|
|
2003-03-10 23:18:05 +00:00
|
|
|
|
(define (lookup-duplicates-handlers handler-names)
|
2003-03-11 15:58:02 +00:00
|
|
|
|
(and handler-names
|
|
|
|
|
|
(map (lambda (handler-name)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(or (module-symbol-local-binding
|
|
|
|
|
|
duplicate-handlers handler-name #f)
|
|
|
|
|
|
(error "invalid duplicate handler name:"
|
|
|
|
|
|
handler-name)))
|
|
|
|
|
|
(if (list? handler-names)
|
|
|
|
|
|
handler-names
|
|
|
|
|
|
(list handler-names)))))
|
2003-03-10 23:18:05 +00:00
|
|
|
|
|
2003-03-12 10:03:25 +00:00
|
|
|
|
(define default-duplicate-binding-procedures
|
|
|
|
|
|
(make-mutable-parameter #f))
|
|
|
|
|
|
|
|
|
|
|
|
(define default-duplicate-binding-handler
|
2003-03-12 17:16:36 +00:00
|
|
|
|
(make-mutable-parameter '(replace warn-override-core warn last)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(lambda (handler-names)
|
|
|
|
|
|
(default-duplicate-binding-procedures
|
|
|
|
|
|
(lookup-duplicates-handlers handler-names))
|
|
|
|
|
|
handler-names)))
|
2003-03-10 23:18:05 +00:00
|
|
|
|
|
2001-05-11 05:41:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {`cond-expand' for SRFI-0 support.}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; This syntactic form expands into different commands or
|
|
|
|
|
|
;;; definitions, depending on the features provided by the Scheme
|
|
|
|
|
|
;;; implementation.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Syntax:
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; <cond-expand>
|
|
|
|
|
|
;;; --> (cond-expand <cond-expand-clause>+)
|
|
|
|
|
|
;;; | (cond-expand <cond-expand-clause>* (else <command-or-definition>))
|
|
|
|
|
|
;;; <cond-expand-clause>
|
|
|
|
|
|
;;; --> (<feature-requirement> <command-or-definition>*)
|
|
|
|
|
|
;;; <feature-requirement>
|
|
|
|
|
|
;;; --> <feature-identifier>
|
|
|
|
|
|
;;; | (and <feature-requirement>*)
|
|
|
|
|
|
;;; | (or <feature-requirement>*)
|
|
|
|
|
|
;;; | (not <feature-requirement>)
|
|
|
|
|
|
;;; <feature-identifier>
|
|
|
|
|
|
;;; --> <a symbol which is the name or alias of a SRFI>
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Additionally, this implementation provides the
|
|
|
|
|
|
;;; <feature-identifier>s `guile' and `r5rs', so that programs can
|
|
|
|
|
|
;;; determine the implementation type and the supported standard.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; Currently, the following feature identifiers are supported:
|
|
|
|
|
|
;;;
|
2005-12-06 21:32:09 +00:00
|
|
|
|
;;; guile r5rs srfi-0 srfi-4 srfi-6 srfi-13 srfi-14 srfi-55 srfi-61
|
2001-05-11 05:41:03 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;; Remember to update the features list when adding more SRFIs.
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
2001-05-11 05:41:03 +00:00
|
|
|
|
|
2001-05-23 05:08:17 +00:00
|
|
|
|
(define %cond-expand-features
|
2001-05-15 20:20:51 +00:00
|
|
|
|
;; Adjust the above comment when changing this.
|
2004-07-09 23:44:48 +00:00
|
|
|
|
'(guile
|
2009-10-21 23:41:56 +02:00
|
|
|
|
guile-2
|
2004-07-09 23:44:48 +00:00
|
|
|
|
r5rs
|
|
|
|
|
|
srfi-0 ;; cond-expand itself
|
2004-10-26 17:05:32 +00:00
|
|
|
|
srfi-4 ;; homogenous numeric vectors
|
2004-07-09 23:44:48 +00:00
|
|
|
|
srfi-6 ;; open-input-string etc, in the guile core
|
2004-08-24 22:20:47 +00:00
|
|
|
|
srfi-13 ;; string library
|
|
|
|
|
|
srfi-14 ;; character sets
|
2005-02-12 06:12:21 +00:00
|
|
|
|
srfi-55 ;; require-extension
|
2005-12-06 21:32:09 +00:00
|
|
|
|
srfi-61 ;; general cond clause
|
2004-07-09 23:44:48 +00:00
|
|
|
|
))
|
2001-05-14 19:09:50 +00:00
|
|
|
|
|
2001-05-23 05:08:17 +00:00
|
|
|
|
;; This table maps module public interfaces to the list of features.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define %cond-expand-table (make-hash-table 31))
|
|
|
|
|
|
|
|
|
|
|
|
;; Add one or more features to the `cond-expand' feature list of the
|
|
|
|
|
|
;; module `module'.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (cond-expand-provide module features)
|
|
|
|
|
|
(let ((mod (module-public-interface module)))
|
|
|
|
|
|
(and mod
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(hashq-set! %cond-expand-table mod
|
|
|
|
|
|
(append (hashq-ref %cond-expand-table mod '())
|
|
|
|
|
|
features)))))
|
2001-05-23 05:08:17 +00:00
|
|
|
|
|
2009-06-19 22:46:07 +02:00
|
|
|
|
(define-macro (cond-expand . clauses)
|
|
|
|
|
|
(let ((syntax-error (lambda (cl)
|
|
|
|
|
|
(error "invalid clause in `cond-expand'" cl))))
|
|
|
|
|
|
(letrec
|
|
|
|
|
|
((test-clause
|
|
|
|
|
|
(lambda (clause)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((symbol? clause)
|
|
|
|
|
|
(or (memq clause %cond-expand-features)
|
|
|
|
|
|
(let lp ((uses (module-uses (current-module))))
|
|
|
|
|
|
(if (pair? uses)
|
|
|
|
|
|
(or (memq clause
|
|
|
|
|
|
(hashq-ref %cond-expand-table
|
|
|
|
|
|
(car uses) '()))
|
|
|
|
|
|
(lp (cdr uses)))
|
|
|
|
|
|
#f))))
|
|
|
|
|
|
((pair? clause)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((eq? 'and (car clause))
|
|
|
|
|
|
(let lp ((l (cdr clause)))
|
|
|
|
|
|
(cond ((null? l)
|
|
|
|
|
|
#t)
|
|
|
|
|
|
((pair? l)
|
|
|
|
|
|
(and (test-clause (car l)) (lp (cdr l))))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(syntax-error clause)))))
|
|
|
|
|
|
((eq? 'or (car clause))
|
|
|
|
|
|
(let lp ((l (cdr clause)))
|
|
|
|
|
|
(cond ((null? l)
|
|
|
|
|
|
#f)
|
|
|
|
|
|
((pair? l)
|
|
|
|
|
|
(or (test-clause (car l)) (lp (cdr l))))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(syntax-error clause)))))
|
|
|
|
|
|
((eq? 'not (car clause))
|
|
|
|
|
|
(cond ((not (pair? (cdr clause)))
|
|
|
|
|
|
(syntax-error clause))
|
|
|
|
|
|
((pair? (cddr clause))
|
|
|
|
|
|
((syntax-error clause))))
|
|
|
|
|
|
(not (test-clause (cadr clause))))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(syntax-error clause))))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(syntax-error clause))))))
|
|
|
|
|
|
(let lp ((c clauses))
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((null? c)
|
|
|
|
|
|
(error "Unfulfilled `cond-expand'"))
|
|
|
|
|
|
((not (pair? c))
|
|
|
|
|
|
(syntax-error c))
|
|
|
|
|
|
((not (pair? (car c)))
|
|
|
|
|
|
(syntax-error (car c)))
|
|
|
|
|
|
((test-clause (caar c))
|
|
|
|
|
|
`(begin ,@(cdar c)))
|
|
|
|
|
|
((eq? (caar c) 'else)
|
|
|
|
|
|
(if (pair? (cdr c))
|
|
|
|
|
|
(syntax-error c))
|
|
|
|
|
|
`(begin ,@(cdar c)))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(lp (cdr c))))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
2001-05-15 20:20:51 +00:00
|
|
|
|
;; This procedure gets called from the startup code with a list of
|
|
|
|
|
|
;; numbers, which are the numbers of the SRFIs to be loaded on startup.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(define (use-srfis srfis)
|
2007-01-15 23:22:36 +00:00
|
|
|
|
(process-use-modules
|
|
|
|
|
|
(map (lambda (num)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(list (list 'srfi (string->symbol
|
|
|
|
|
|
(string-append "srfi-" (number->string num))))))
|
|
|
|
|
|
srfis)))
|
2001-05-18 17:28:03 +00:00
|
|
|
|
|
1998-10-19 13:49:29 +00:00
|
|
|
|
|
2001-01-21 22:11:29 +00:00
|
|
|
|
|
2005-02-12 06:12:21 +00:00
|
|
|
|
;;; srfi-55: require-extension
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (require-extension extension-spec)
|
|
|
|
|
|
;; This macro only handles the srfi extension, which, at present, is
|
|
|
|
|
|
;; the only one defined by the standard.
|
|
|
|
|
|
(if (not (pair? extension-spec))
|
|
|
|
|
|
(scm-error 'wrong-type-arg "require-extension"
|
|
|
|
|
|
"Not an extension: ~S" (list extension-spec) #f))
|
|
|
|
|
|
(let ((extension (car extension-spec))
|
|
|
|
|
|
(extension-args (cdr extension-spec)))
|
|
|
|
|
|
(case extension
|
|
|
|
|
|
((srfi)
|
|
|
|
|
|
(let ((use-list '()))
|
|
|
|
|
|
(for-each
|
|
|
|
|
|
(lambda (i)
|
|
|
|
|
|
(if (not (integer? i))
|
|
|
|
|
|
(scm-error 'wrong-type-arg "require-extension"
|
|
|
|
|
|
"Invalid srfi name: ~S" (list i) #f))
|
|
|
|
|
|
(let ((srfi-sym (string->symbol
|
|
|
|
|
|
(string-append "srfi-" (number->string i)))))
|
|
|
|
|
|
(if (not (memq srfi-sym %cond-expand-features))
|
|
|
|
|
|
(set! use-list (cons `(use-modules (srfi ,srfi-sym))
|
|
|
|
|
|
use-list)))))
|
|
|
|
|
|
extension-args)
|
|
|
|
|
|
(if (pair? use-list)
|
|
|
|
|
|
;; i.e. (begin (use-modules x) (use-modules y) (use-modules z))
|
|
|
|
|
|
`(begin ,@(reverse! use-list)))))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(scm-error
|
|
|
|
|
|
'wrong-type-arg "require-extension"
|
|
|
|
|
|
"Not a recognized extension type: ~S" (list extension) #f)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-10-19 13:49:29 +00:00
|
|
|
|
;;; {Load emacs interface support if emacs option is given.}
|
2004-05-29 08:40:38 +00:00
|
|
|
|
;;;
|
1998-10-19 13:49:29 +00:00
|
|
|
|
|
2001-02-13 01:07:45 +00:00
|
|
|
|
(define (named-module-use! user usee)
|
2001-06-04 22:14:16 +00:00
|
|
|
|
(module-use! (resolve-module user) (resolve-interface usee)))
|
2001-02-13 01:07:45 +00:00
|
|
|
|
|
1998-10-19 13:49:29 +00:00
|
|
|
|
(define (load-emacs-interface)
|
2001-05-10 22:00:22 +00:00
|
|
|
|
(and (provided? 'debug-extensions)
|
|
|
|
|
|
(debug-enable 'backtrace))
|
2001-02-13 01:07:45 +00:00
|
|
|
|
(named-module-use! '(guile-user) '(ice-9 emacs)))
|
1998-10-19 13:49:29 +00:00
|
|
|
|
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
1999-09-11 18:27:52 +00:00
|
|
|
|
(define using-readline?
|
|
|
|
|
|
(let ((using-readline? (make-fluid)))
|
|
|
|
|
|
(make-procedure-with-setter
|
|
|
|
|
|
(lambda () (fluid-ref using-readline?))
|
|
|
|
|
|
(lambda (v) (fluid-set! using-readline? v)))))
|
|
|
|
|
|
|
2001-04-28 19:07:38 +00:00
|
|
|
|
(define (top-repl)
|
2001-06-01 14:01:27 +00:00
|
|
|
|
(let ((guile-user-module (resolve-module '(guile-user))))
|
|
|
|
|
|
|
|
|
|
|
|
;; Load emacs interface support if emacs option is given.
|
2002-10-20 21:51:16 +00:00
|
|
|
|
(if (and (module-defined? guile-user-module 'use-emacs-interface)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(module-ref guile-user-module 'use-emacs-interface))
|
|
|
|
|
|
(load-emacs-interface))
|
2001-06-01 14:01:27 +00:00
|
|
|
|
|
|
|
|
|
|
;; Use some convenient modules (in reverse order)
|
2001-08-30 23:25:34 +00:00
|
|
|
|
|
2007-01-15 23:22:36 +00:00
|
|
|
|
(set-current-module guile-user-module)
|
|
|
|
|
|
(process-use-modules
|
|
|
|
|
|
(append
|
|
|
|
|
|
'(((ice-9 r5rs))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
((ice-9 session))
|
|
|
|
|
|
((ice-9 debug)))
|
2007-01-15 23:22:36 +00:00
|
|
|
|
(if (provided? 'regex)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
'(((ice-9 regex)))
|
|
|
|
|
|
'())
|
2007-01-15 23:22:36 +00:00
|
|
|
|
(if (provided? 'threads)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
'(((ice-9 threads)))
|
|
|
|
|
|
'())))
|
2001-06-01 14:01:27 +00:00
|
|
|
|
;; load debugger on demand
|
2007-05-05 20:38:57 +00:00
|
|
|
|
(module-autoload! guile-user-module '(ice-9 debugger) '(debug))
|
2001-06-01 14:01:27 +00:00
|
|
|
|
|
2007-01-15 23:22:36 +00:00
|
|
|
|
;; Note: SIGFPE, SIGSEGV and SIGBUS are actually "query-only" (see
|
|
|
|
|
|
;; scmsigs.c scm_sigaction_for_thread), so the handlers setup here have
|
|
|
|
|
|
;; no effect.
|
2001-06-01 14:01:27 +00:00
|
|
|
|
(let ((old-handlers #f)
|
2008-09-09 08:23:10 +02:00
|
|
|
|
(start-repl (module-ref (resolve-interface '(system repl repl))
|
|
|
|
|
|
'start-repl))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(signals (if (provided? 'posix)
|
|
|
|
|
|
`((,SIGINT . "User interrupt")
|
|
|
|
|
|
(,SIGFPE . "Arithmetic error")
|
|
|
|
|
|
(,SIGSEGV
|
|
|
|
|
|
. "Bad memory access (Segmentation violation)"))
|
|
|
|
|
|
'())))
|
2007-01-15 23:22:36 +00:00
|
|
|
|
;; no SIGBUS on mingw
|
|
|
|
|
|
(if (defined? 'SIGBUS)
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(set! signals (acons SIGBUS "Bad memory access (bus error)"
|
|
|
|
|
|
signals)))
|
2001-06-01 14:01:27 +00:00
|
|
|
|
|
|
|
|
|
|
(dynamic-wind
|
|
|
|
|
|
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;; call at entry
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(let ((make-handler (lambda (msg)
|
|
|
|
|
|
(lambda (sig)
|
|
|
|
|
|
;; Make a backup copy of the stack
|
|
|
|
|
|
(fluid-set! before-signal-stack
|
|
|
|
|
|
(fluid-ref the-last-stack))
|
|
|
|
|
|
(save-stack 2)
|
|
|
|
|
|
(scm-error 'signal
|
|
|
|
|
|
#f
|
|
|
|
|
|
msg
|
|
|
|
|
|
#f
|
|
|
|
|
|
(list sig))))))
|
|
|
|
|
|
(set! old-handlers
|
|
|
|
|
|
(map (lambda (sig-msg)
|
|
|
|
|
|
(sigaction (car sig-msg)
|
|
|
|
|
|
(make-handler (cdr sig-msg))))
|
|
|
|
|
|
signals))))
|
|
|
|
|
|
|
|
|
|
|
|
;; the protected thunk.
|
|
|
|
|
|
(lambda ()
|
2008-09-09 08:23:10 +02:00
|
|
|
|
(let ((status (start-repl 'scheme)))
|
2009-12-22 00:58:12 +01:00
|
|
|
|
(run-hook exit-hook)
|
|
|
|
|
|
status))
|
|
|
|
|
|
|
|
|
|
|
|
;; call at exit.
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(map (lambda (sig-msg old-handler)
|
|
|
|
|
|
(if (not (car old-handler))
|
|
|
|
|
|
;; restore original C handler.
|
|
|
|
|
|
(sigaction (car sig-msg) #f)
|
|
|
|
|
|
;; restore Scheme handler, SIG_IGN or SIG_DFL.
|
|
|
|
|
|
(sigaction (car sig-msg)
|
|
|
|
|
|
(car old-handler)
|
|
|
|
|
|
(cdr old-handler))))
|
|
|
|
|
|
signals old-handlers))))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
1998-10-31 16:46:55 +00:00
|
|
|
|
;;; This hook is run at the very end of an interactive session.
|
|
|
|
|
|
;;;
|
* boot-9.scm (beautify-user-module!): Beautify also if public
interface is set to the module itself. In this way we can use
beautify-user-module! to beautify a module prepared for object
code.
(process-define-module): Special case: Try to load object code as
well if a module does :use-module on itself.
* boot-9.scm: Bugfix: Since boot-9.scm is now loaded from
invoke_main_func, we can no longer be sure that all modules have
been registered when boot-9.scm is loaded.
(register-modules): New function: Register and tag modules
registered by scm_register_module_xxx since last call to this
function. Modules are tagged with the dynamic object passed as
argument. (Already linked modules should be tagged with #f.)
(init-dynamic-module, link-dynamic-module): Call register-modules
first to register linked modules.
* boot-9.scm (init-dynamic-module): Remove module from
registered-modules as soon as possible in case we are recursively
invoked; Set public interface before doing the dynamic-call.
* boot-9.scm (map-in-order): Removed (replaced by scm_serial_map).
(abort-hook, before-error-hook, after-error-hook,
before-backtrace-hook, after-backtrace-hook, before-read-hook,
after-read-hook, exit-hook): Make hooks with `make-hook'.
* boot-9.scm: Make hooks first class citizens and make them easier
to use from C:
(make-hook, add-hook!, remove-hook!, run-hooks): Moved to
libguile/feature.c.
* boot-9.scm: Added warnings about bindings used in
libguile/modules.c: the-module, set-current-module,
make-modules-in, beautify-user-module!, module-eval-closure.
1998-11-23 02:36:43 +00:00
|
|
|
|
(define exit-hook (make-hook))
|
1998-10-31 16:46:55 +00:00
|
|
|
|
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Deprecated stuff}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(begin-deprecated
|
2010-01-11 00:23:12 +01:00
|
|
|
|
(module-use! the-scm-module (resolve-interface '(ice-9 deprecated))))
|
2004-05-29 08:40:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Place the user in the guile-user module.
|
|
|
|
|
|
;;;
|
2001-06-10 20:44:45 +00:00
|
|
|
|
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
;;; FIXME: annotate ?
|
|
|
|
|
|
;; (define (syncase exp)
|
|
|
|
|
|
;; (with-fluids ((expansion-eval-closure
|
2009-12-22 00:58:12 +01:00
|
|
|
|
;; (module-eval-closure (current-module))))
|
syncase early in boot-9, defmacros in terms of syntax-case -- halfway working
* module/ice-9/boot-9.scm
(eval-when): Remove, as syncase is going to handle this one for us.
(sc-expand, sc-expand3, sc-chi, install-global-transformer)
(syntax-dispatch, syntax-error, annotation?, bound-identifier=?)
(datum->syntax-object, free-identifier=?, generate-temporaries)
(identifier?, syntax-object->datum, void, andmap): Oh, ugly of uglies:
add these exciting definitions to the main environment. Hopefully we
can pull them back out soon.
(make-module-ref, resolve-module): Stub these out, as a replacement for
expand-support.
(%pre-modules-transformer): Define to sc-expand, so that we are using
syncase from the very start.
(defmacro, define-macro): Define in terms of syntax-case.
(macroexpand, macroexpand-1): Remove, there should be a different way
to get at this -- though perhaps with the same name.
(make-module): Make sc-expand the default module-transformer.
(process-define-module): Issue a deprecation warning when using ice-9
syncase.
(primitive-macro?): Remove, no meaning...
(use-syntax): Deprecate.
(define-private, define-public, defmacro-public): Rework in terms of
syntax-rules.
* module/ice-9/syncase.scm: Gut, as syncase is provided by core now.
2009-04-24 13:54:38 +02:00
|
|
|
|
;; (deannotate/source-properties (sc-expand (annotate exp)))))
|
|
|
|
|
|
|
reimplement srfi-4 vectors on top of bytevectors
* libguile/srfi-4.h:
* libguile/srfi-4.c (scm_make_srfi_4_vector): New function, exported by
(srfi srfi-4 gnu).
* libguile/srfi-4.i.c: Removed.
* module/srfi/srfi-4.scm:
* module/srfi/srfi-4/gnu.scm: Reimplement srfi-4 vectors on top of
bytevectors. The implementation is mostly in Scheme now.
* test-suite/tests/unif.test: Update to use (srfi srfi-4 gnu).
* libguile/bytevectors.c (bytevector_ref_c32, bytevector_ref_c64)
(bytevector_set_c32, bytevector_set_c64): Fix some embarrassing bugs.
Still need to do an upper bounds check.
* libguile/deprecated.h: Remove deprecated array functions:
scm_i_arrayp, scm_i_array_ndim, scm_i_array_mem, scm_i_array_v,
scm_i_array_base, scm_i_array_dims, and the deprecated macros:
SCM_ARRAYP, SCM_ARRAY_NDIM, SCM_ARRAY_CONTP, SCM_ARRAY_MEM,
SCM_ARRAY_V, SCM_ARRAY_BASE, SCM_ARRAY_DIMS.
* libguile/deprecated.c (scm_uniform_vector_read_x)
(scm_uniform_vector_write, scm_uniform_array_read_x)
(scm_uniform_array_write): Newly deprecated functions.
* libguile/generalized-arrays.c (scm_array_type): Remove the bytevector
hack.
* libguile/objcodes.c (scm_bytecode_to_objcode, scm_objcode_to_bytecode):
Rework to operate on bytevectors, as scm_make_u8vector now causes a
module lookup, which can't be done e.g. when loading the VM boot
program for psyntax-pp.go on a fresh bootstrap.
* libguile/objcodes.h (SCM_F_OBJCODE_IS_BYTEVECTOR):
(SCM_OBJCODE_IS_BYTEVECTOR): s/U8VECTOR/BYTEVECTOR/.
* module/ice-9/boot-9.scm (the-scm-module): A terrible hack to pull in
(srfi srfi-4), as the bindings are primarily there now. We'll worry
about this later.
2009-07-19 15:35:33 +02:00
|
|
|
|
;; FIXME:
|
|
|
|
|
|
(module-use! the-scm-module (resolve-interface '(srfi srfi-4)))
|
|
|
|
|
|
|
2009-05-20 17:41:21 +02:00
|
|
|
|
(define-module (guile-user)
|
|
|
|
|
|
#:autoload (system base compile) (compile))
|
2001-01-24 21:45:09 +00:00
|
|
|
|
|
2010-01-10 23:58:48 +01:00
|
|
|
|
;; Remain in the `(guile)' module at compilation-time so that the
|
|
|
|
|
|
;; `-Wunused-toplevel' warning works as expected.
|
|
|
|
|
|
(eval-when (compile) (set-current-module the-root-module))
|
|
|
|
|
|
|
2001-04-28 19:07:38 +00:00
|
|
|
|
;;; boot-9.scm ends here
|