mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-09 21:40:33 +02:00
use srfi-9 for elisp bindings records
* module/language/elisp/bindings.scm: Use `(srfi srfi-9)'. (bindings-type): Remove low-level record type definition and replace with... (bindings): ...this, an SRFI-9 record type. All uses changed. (mark-global-needed!): Rename to... (mark-global!): ...this. All callers changed. (map-globals-needed): Rename to... (map-globals): ...this. All callers changed.
This commit is contained in:
parent
d5ac6923c3
commit
d5da7661c8
2 changed files with 47 additions and 50 deletions
|
@ -19,9 +19,10 @@
|
|||
;;; Code:
|
||||
|
||||
(define-module (language elisp bindings)
|
||||
#:use-module (srfi srfi-9)
|
||||
#:export (make-bindings
|
||||
mark-global-needed!
|
||||
map-globals-needed
|
||||
mark-global!
|
||||
map-globals
|
||||
with-lexical-bindings
|
||||
with-dynamic-bindings
|
||||
get-lexical-binding))
|
||||
|
@ -41,37 +42,35 @@
|
|||
|
||||
;;; Record type used to hold the data necessary.
|
||||
|
||||
(define bindings-type
|
||||
(make-record-type 'bindings '(needed-globals lexical-bindings)))
|
||||
(define-record-type bindings
|
||||
(%make-bindings globals lexical-bindings)
|
||||
bindings?
|
||||
(globals globals set-globals!)
|
||||
(lexical-bindings lexical-bindings set-lexical-bindings!))
|
||||
|
||||
;;; Construct an 'empty' instance of the bindings data structure to be
|
||||
;;; used at the start of a fresh compilation.
|
||||
|
||||
(define (make-bindings)
|
||||
((record-constructor bindings-type) '() (make-hash-table)))
|
||||
(%make-bindings '() (make-hash-table)))
|
||||
|
||||
;;; Mark that a given symbol is needed as global in the specified
|
||||
;;; slot-module.
|
||||
|
||||
(define (mark-global-needed! bindings sym module)
|
||||
(let* ((old-needed ((record-accessor bindings-type 'needed-globals)
|
||||
bindings))
|
||||
(old-in-module (or (assoc-ref old-needed module) '()))
|
||||
(define (mark-global! bindings sym module)
|
||||
(let* ((old-globals (globals bindings))
|
||||
(old-in-module (or (assoc-ref old-globals module) '()))
|
||||
(new-in-module (if (memq sym old-in-module)
|
||||
old-in-module
|
||||
(cons sym old-in-module)))
|
||||
(new-needed (assoc-set! old-needed module new-in-module)))
|
||||
((record-modifier bindings-type 'needed-globals)
|
||||
bindings
|
||||
new-needed)))
|
||||
(new-globals (assoc-set! old-globals module new-in-module)))
|
||||
(set-globals! bindings new-globals)))
|
||||
|
||||
;;; Cycle through all globals needed in order to generate the code for
|
||||
;;; their creation or some other analysis.
|
||||
|
||||
(define (map-globals-needed bindings proc)
|
||||
(let ((needed ((record-accessor bindings-type 'needed-globals)
|
||||
bindings)))
|
||||
(let iterate-modules ((mod-tail needed)
|
||||
(define (map-globals bindings proc)
|
||||
(let iterate-modules ((mod-tail (globals bindings))
|
||||
(mod-result '()))
|
||||
(if (null? mod-tail)
|
||||
mod-result
|
||||
|
@ -86,14 +85,13 @@
|
|||
sym-result
|
||||
(iterate-symbols (cdr sym-tail)
|
||||
(cons (proc module (car sym-tail))
|
||||
sym-result))))))))))
|
||||
sym-result)))))))))
|
||||
|
||||
;;; Get the current lexical binding (gensym it should refer to in the
|
||||
;;; current scope) for a symbol or #f if it is dynamically bound.
|
||||
|
||||
(define (get-lexical-binding bindings sym)
|
||||
(let* ((lex ((record-accessor bindings-type 'lexical-bindings)
|
||||
bindings))
|
||||
(let* ((lex (lexical-bindings bindings))
|
||||
(slot (hash-ref lex sym #f)))
|
||||
(if slot
|
||||
(fluid-ref slot)
|
||||
|
@ -106,8 +104,7 @@
|
|||
(if (or (not (list? syms))
|
||||
(not (and-map symbol? syms)))
|
||||
(error "can't bind non-symbols" syms))
|
||||
(let ((lex ((record-accessor bindings-type 'lexical-bindings)
|
||||
bindings)))
|
||||
(let ((lex (lexical-bindings bindings)))
|
||||
(for-each (lambda (sym)
|
||||
(if (not (hash-ref lex sym))
|
||||
(hash-set! lex sym (make-fluid))))
|
||||
|
|
|
@ -133,7 +133,7 @@
|
|||
(define (ensuring-globals loc bindings body)
|
||||
(make-sequence
|
||||
loc
|
||||
`(,@(map-globals-needed (fluid-ref bindings)
|
||||
`(,@(map-globals (fluid-ref bindings)
|
||||
(lambda (mod sym)
|
||||
(generate-ensure-global loc sym mod)))
|
||||
,body)))
|
||||
|
@ -185,7 +185,7 @@
|
|||
(lambda () (make-module-ref loc module sym #t))
|
||||
(lambda (lexical) (make-lexical-ref loc lexical lexical))
|
||||
(lambda ()
|
||||
(mark-global-needed! (fluid-ref bindings-data) sym module)
|
||||
(mark-global! (fluid-ref bindings-data) sym module)
|
||||
(call-primitive loc
|
||||
'fluid-ref
|
||||
(make-module-ref loc module sym #t)))))
|
||||
|
@ -206,7 +206,7 @@
|
|||
(list (make-const loc module) (make-const loc sym) value)))
|
||||
(lambda (lexical) (make-lexical-set loc lexical lexical value))
|
||||
(lambda ()
|
||||
(mark-global-needed! (fluid-ref bindings-data) sym module)
|
||||
(mark-global! (fluid-ref bindings-data) sym module)
|
||||
(call-primitive loc
|
||||
'fluid-set!
|
||||
(make-module-ref loc module sym #t)
|
||||
|
@ -276,7 +276,7 @@
|
|||
(lambda () (split-let-bindings bind module))
|
||||
(lambda (lexical dynamic)
|
||||
(for-each (lambda (sym)
|
||||
(mark-global-needed! (fluid-ref bindings-data)
|
||||
(mark-global! (fluid-ref bindings-data)
|
||||
sym
|
||||
module))
|
||||
(map car dynamic))
|
||||
|
@ -321,7 +321,7 @@
|
|||
(begin
|
||||
(for-each (lambda (sym)
|
||||
(if (not (bind-lexically? sym module))
|
||||
(mark-global-needed! (fluid-ref bindings-data)
|
||||
(mark-global! (fluid-ref bindings-data)
|
||||
sym
|
||||
module)))
|
||||
(map car bind))
|
||||
|
@ -470,7 +470,7 @@
|
|||
optional-dyn-pairs
|
||||
rest-dyn-pairs)))
|
||||
(for-each (lambda (sym)
|
||||
(mark-global-needed! (fluid-ref bindings-data)
|
||||
(mark-global! (fluid-ref bindings-data)
|
||||
sym
|
||||
value-slot))
|
||||
dynamic)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue