1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-20 18:50:21 +02:00

function binding fixes

* module/language/elisp/bindings.scm (bindings): Add `function-bindings'
  field.
  (make-bindings): Initialize the `function-bindings' field.
  (get-function-binding, with-function-bindings): New functions.

  (access-variable, reference-variable, set-variable!): Remove the
  `module' argument and only handle references to the value cell. All
  callers changed. Callers passing `function-slot' as the module changed
  to use the corresponding functions for the function cell instead.

  (access-function, reference-function, set-function!): New procedures.

  (compile-flet, compile-labels): Use `with-function-bindings' instead
  of `with-lexical-bindings'.
This commit is contained in:
BT Templeton 2011-08-16 23:49:56 -04:00
parent 5199c059e8
commit eaeda0d550
2 changed files with 78 additions and 62 deletions

View file

@ -26,7 +26,9 @@
#:export (make-bindings
with-lexical-bindings
with-dynamic-bindings
get-lexical-binding))
with-function-bindings
get-lexical-binding
get-function-binding))
;;; This module defines routines to handle analysis of symbol bindings
;;; used during elisp compilation. This data allows to collect the
@ -41,15 +43,16 @@
;;; Record type used to hold the data necessary.
(define-record-type bindings
(%make-bindings lexical-bindings)
(%make-bindings lexical-bindings function-bindings)
bindings?
(lexical-bindings lexical-bindings set-lexical-bindings!))
(lexical-bindings lexical-bindings)
(function-bindings function-bindings))
;;; Construct an 'empty' instance of the bindings data structure to be
;;; used at the start of a fresh compilation.
(define (make-bindings)
(%make-bindings (make-hash-table)))
(%make-bindings (make-hash-table) (make-hash-table)))
;;; Get the current lexical binding (gensym it should refer to in the
;;; current scope) for a symbol or #f if it is dynamically bound.
@ -61,6 +64,10 @@
(fluid-ref slot)
#f)))
(define (get-function-binding bindings symbol)
(and=> (hash-ref (function-bindings bindings) symbol)
fluid-ref))
;;; Establish a binding or mark a symbol as dynamically bound for the
;;; extent of calling proc.
@ -88,3 +95,13 @@
syms
(map (lambda (el) #f) syms)
proc))
(define (with-function-bindings bindings symbols gensyms thunk)
(let ((fb (function-bindings bindings)))
(for-each (lambda (symbol)
(if (not (hash-ref fb symbol))
(hash-set! fb symbol (make-fluid))))
symbols)
(with-fluids* (map (cut hash-ref fb <>) symbols)
gensyms
thunk)))