mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 11:50:28 +02:00
(Best-ability ChangeLog annotation added by Christopher Allan Webber.) * module/language/elisp/bindings.scm (get-lexical-binding) (get-function-binding): Use cadr instead of fluid-ref on slot. (with-fluids**): New procedure. (with-symbol-bindings, with-function-bindings): Use with-fluids**. Also stop using "make-fluid", use "(list #f #f)" instead as default lexical-bindings hashtable value. (with-lexical-bindings): Drop the error checking for invalid targets. * module/language/elisp/boot.el (defun, save-excursion) (save-current-buffer, save-restriction, track-mouse, setq-default) (catch, condition-case): New macros. (omega, eval, gensym, interactive, autoload-do-load, fset, prin1) (backtrace-frame, backtrace, %set-eager-macroexpansion-mode): New functions. (null, consp, listp, car, cdr, make-symbol, signal): Wrap in eval-and-compile. (prog1, cond, or, while): Update to make use of gensym. (unwind-protect): Switch from funcall to %funcall. (%functionp): Rename from functionp. (%indirect-function): Update to use %functionp instead of functionp. Add check for if object is null, signaling void-function. Instead of calling symbol-function directly, call via %funcall from the module "(language elisp runtime)". (fset): Significant additions and refactoring. (gload): Renamed from fload. (defvaralias, nthcdr, nth, eq): Move functions to a different location. (eq): Also stop using null. (dolist): Remove quasiquoting, build list manually. (random): Fix indentation. (progn, eval-when-compile, if, defconst, defvar, setq, let, flet) (labels, let*, function, defmacro, quote): Protect as special operators by raising error if invoked as a function. * module/language/elisp/compile-tree-il.scm: Import "(ice-9 format)". Export compile-%function. (lexical-binding, handle-var-def, defun, valid-symbol-list-arg?) (process-options!): Remove. (reference-variable): Adjust functions passed to access-variable. (global?): Drop module parameter, use value-slot instead. (ensure-globals!, set-variable!, parse-body-1, parse-lambda-list) (compile-lambda, defconst, defvar, let, let*, compile-pair): Refactor. (reference-function): Use '(elisp-functions) instead of function-slot. (bind-lexically?): Drop module parameter, simplify. (make-dynlet): Switch from using make-primcall to make-call. (find-operator): Switch from using resolve-interface/resolve-module to using function-slot. (if, defconst, defvar, let, let*, flet, labels, guile-ref) (guile-private-ref, guile-primitive, defmacro, `, quote, %funcall) (%set-lexical-binding-mode): Add error checking. (setq): Pass in args to report-error. (function): Simplified, now calling %function. (%function): New function, based on prior "function". Refactor, including adding support for matching against a closure. (%set-lexical-binding-mode): Switch from using fluid-set! to set-lexical-binding-mode. (special-operators): New variable. Build from following for-each statement. (compile-tree-il): Drop call to "process-options!" * module/language/elisp/lexer.scm: Import "(language elisp runtime)". (lex): Switch from using "list->string" to "make-lisp-string". * module/language/elisp/runtime.scm: Use modules "(ice-9 format)", "(system base compile)". Remove from export list list, removing ensure-fluid!, symbol-fluid!, set-symbol-fluid!. Add to export list ensure-dynamic!, symbol-name, symbol-plist, set-symbol-plist!, bind-symbol, symbol-desc, proclaim-symbol! special? emacs! unbound, lexical-binding?, set-lexical-binding-mode, log!, eval-elisp, local-eval-elisp, make-lisp-string, lisp-string? (make-list-string, lisp-string?) New function aliases. (value-slot-module, function-slot-module): Adjust module resolution. (nil_, t_): New variables. (ensure-fluid!, symbol-fluid, set-symbol-fluid!): Removed. (lexical-binding, unbound): New variables. (lexical-binding?, set-lexical-binding-mode, unbound, dynamic?) (make-dynamic, dynamic-ref, dynamic-set!, dynamic-unset!) (dynamic-bound?, dynamic-bind, ensure-present!, ensure-desc!) (schemify, symbol-name, symbol-desc, ensure-dynamic!, symbol-dynamic) (set-symbol-plist!, special?, proclaim-special!, emacs!, eval-elisp) (make-string): New procedures. (symbol-value): Use dynamic-ref! instead of fluid-ref!. (set-symbol-value!): Use dynamic-set! instead of fluid-set!. (symbol-function, set-symbol-function!, symbol-bound?) (symbol-fbound?, makunbound!, fmakunbound!): Refactor, including adjusting how module resolution is being done. * module/language/elisp/spec.scm: Import module "(system vm vm)". Setup elisp-symbols, elisp-functions, elisp-plists. Use "set-default-vm-engine!" and "set-vm-engine!" to be set to 'debug. (elisp): Comment out joiner.
114 lines
4 KiB
Scheme
114 lines
4 KiB
Scheme
;;; Guile Emacs Lisp
|
|
|
|
;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
|
|
;;;
|
|
;;; 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
|
|
;;; version 3 of the License, or (at your option) any later version.
|
|
;;;
|
|
;;; This library is distributed in the hope that it will be useful,
|
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;;; 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
|
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
;;; Code:
|
|
|
|
(define-module (language elisp bindings)
|
|
#:use-module (srfi srfi-1)
|
|
#:use-module (srfi srfi-8)
|
|
#:use-module (srfi srfi-9)
|
|
#:use-module (srfi srfi-26)
|
|
#:export (make-bindings
|
|
with-lexical-bindings
|
|
with-dynamic-bindings
|
|
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
|
|
;;; symbols, for which globals need to be created, or mark certain
|
|
;;; symbols as lexically bound.
|
|
;;;
|
|
;;; The lexical bindings of symbols are stored in a hash-table that
|
|
;;; associates symbols to fluids; those fluids are used in the
|
|
;;; with-lexical-binding and with-dynamic-binding routines to associate
|
|
;;; symbols to different bindings over a dynamic extent.
|
|
|
|
;;; Record type used to hold the data necessary.
|
|
|
|
(define-record-type bindings
|
|
(%make-bindings lexical-bindings function-bindings)
|
|
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-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.
|
|
|
|
(define (get-lexical-binding bindings sym)
|
|
(let* ((lex (lexical-bindings bindings))
|
|
(slot (hash-ref lex sym #f)))
|
|
(if slot
|
|
(cadr slot)
|
|
#f)))
|
|
|
|
(define (get-function-binding bindings symbol)
|
|
(and=> (hash-ref (function-bindings bindings) symbol)
|
|
cadr))
|
|
|
|
(define (with-fluids** fls vals proc)
|
|
(dynamic-wind
|
|
(lambda ()
|
|
(for-each (lambda (f v) (set-cdr! f (cons v (cdr f))))
|
|
fls vals))
|
|
proc
|
|
(lambda ()
|
|
(for-each (lambda (f) (set-cdr! f (cdr (cdr f))))
|
|
fls))))
|
|
|
|
;;; Establish a binding or mark a symbol as dynamically bound for the
|
|
;;; extent of calling proc.
|
|
|
|
(define (with-symbol-bindings bindings syms targets proc)
|
|
(if (or (not (list? syms))
|
|
(not (and-map symbol? syms)))
|
|
(error "can't bind non-symbols" syms))
|
|
(let ((lex (lexical-bindings bindings)))
|
|
(for-each (lambda (sym)
|
|
(if (not (hash-ref lex sym))
|
|
(hash-set! lex sym (list #f #f))))
|
|
syms)
|
|
(with-fluids** (map (lambda (sym) (hash-ref lex sym)) syms)
|
|
targets
|
|
proc)))
|
|
|
|
(define (with-lexical-bindings bindings syms targets proc)
|
|
(with-symbol-bindings bindings syms targets proc))
|
|
|
|
(define (with-dynamic-bindings bindings syms proc)
|
|
(with-symbol-bindings bindings
|
|
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 (list #f #f))))
|
|
symbols)
|
|
(with-fluids** (map (cut hash-ref fb <>) symbols)
|
|
gensyms
|
|
thunk)))
|