diff options
author | Brian Templeton <bpt@hcoop.net> | 2010-08-16 03:20:55 -0400 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2010-12-07 13:21:03 +0100 |
commit | c6920dc8bae4546ffeb250570d7abc8ace9ce91c (patch) | |
tree | cfa2110a9d272b6ca1a1ca26ad372f6a4f006649 /module/language/elisp/compile-tree-il.scm | |
parent | 3f70b2dc5c33073b6f24078bc1fc1d6bdcd3b03f (diff) | |
download | guile-c6920dc8bae4546ffeb250570d7abc8ace9ce91c.tar.gz |
lexical function binding for elisp
* module/language/elisp/compile-tree-il.scm (access-variable)
(reference-variable, set-variable!): Handle globally-bound non-special
variables.
(bind-lexically?): Create lexical bindings for flet and flet*.
* module/language/elisp/runtime.scm (reference-variable, set-variable!):
Handle globally-bound non-special variables.
(built-in-func): Set the variable directly instead of storing the
function in a fluid.
* module/language/elisp/runtime/subrs.scm (funcall): Call apply
directly.
* test-suite/tests/elisp-compiler.test ("Function Definitions")["flet
and flet*"]:
Signed-off-by: Andy Wingo <wingo@pobox.com>
Diffstat (limited to 'module/language/elisp/compile-tree-il.scm')
-rw-r--r-- | module/language/elisp/compile-tree-il.scm | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/module/language/elisp/compile-tree-il.scm b/module/language/elisp/compile-tree-il.scm index ac3e185b1..0df21c7e6 100644 --- a/module/language/elisp/compile-tree-il.scm +++ b/module/language/elisp/compile-tree-il.scm @@ -165,11 +165,17 @@ ;;; on whether it is currently lexically or dynamically bound. lexical ;;; access is done only for references to the value-slot module! -(define (access-variable loc sym module handle-lexical handle-dynamic) +(define (access-variable loc + sym + module + handle-global + handle-lexical + handle-dynamic) (let ((lexical (get-lexical-binding (fluid-ref bindings-data) sym))) - (if (and lexical (equal? module value-slot)) - (handle-lexical lexical) - (handle-dynamic)))) + (cond + (lexical (handle-lexical lexical)) + ((equal? module function-slot) (handle-global)) + (else (handle-dynamic))))) ;;; Generate code to reference a variable. For references in the ;;; value-slot module, we may want to generate a lexical reference @@ -180,6 +186,7 @@ loc sym module + (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) @@ -196,6 +203,11 @@ loc sym module + (lambda () + (make-application + loc + (make-module-ref loc runtime 'set-variable! #t) + (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) @@ -227,10 +239,12 @@ ;;; dynamically. A symbol will be bound lexically if and only if: We're ;;; processing a lexical-let (i.e. module is 'lexical), OR we're ;;; processing a value-slot binding AND the symbol is already lexically -;;; bound or it is always lexical. +;;; bound or is always lexical, OR we're processing a function-slot +;;; binding. (define (bind-lexically? sym module) (or (eq? module 'lexical) + (eq? module function-slot) (and (equal? module value-slot) (let ((always (fluid-ref always-lexical))) (or (eq? always 'all) |