mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 19:50:24 +02:00
clarify comments in eval.scm
* module/ice-9/eval.scm: Add some more comments.
This commit is contained in:
parent
5f1611640a
commit
b2b554efd3
1 changed files with 24 additions and 4 deletions
|
@ -22,14 +22,27 @@
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
|
||||||
;;; Scheme eval, written in Scheme!
|
;;; Scheme eval, written in Scheme.
|
||||||
|
;;;
|
||||||
|
;;; Expressions are first expanded, by the syntax expander (i.e.
|
||||||
|
;;; psyntax), then memoized into internal forms. The evaluator itself
|
||||||
|
;;; only operates on the internal forms ("memoized expressions").
|
||||||
|
;;;
|
||||||
|
;;; Environments are represented as linked lists of the form (VAL ... .
|
||||||
|
;;; MOD). If MOD is #f, it means the environment was captured before
|
||||||
|
;;; modules were booted. If MOD is the literal value '(), we are
|
||||||
|
;;; evaluating at the top level, and so should track changes to the
|
||||||
|
;;; current module.
|
||||||
|
;;;
|
||||||
|
;;; Evaluate this in Emacs to make code indentation work right:
|
||||||
|
;;;
|
||||||
|
;;; (put 'memoized-expression-case 'scheme-indent-function 1)
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; (put 'memoized-expression-case 'scheme-indent-function 1)
|
|
||||||
(eval-when (compile)
|
(eval-when (compile)
|
||||||
(define-syntax capture-env
|
(define-syntax capture-env
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
|
@ -37,11 +50,13 @@
|
||||||
(if (null? env)
|
(if (null? env)
|
||||||
(current-module)
|
(current-module)
|
||||||
(if (not env)
|
(if (not env)
|
||||||
;; the and current-module checks that modules are booted
|
;; the and current-module checks that modules are booted,
|
||||||
|
;; and thus the-root-module is defined
|
||||||
(and (current-module) the-root-module)
|
(and (current-module) the-root-module)
|
||||||
env)))))
|
env)))))
|
||||||
|
|
||||||
;; could be more straightforward if we had better copy propagation
|
;; This macro could be more straightforward if the compiler had better
|
||||||
|
;; copy propagation. As it is we do some copy propagation by hand.
|
||||||
(define-syntax mx-bind
|
(define-syntax mx-bind
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(syntax-case x ()
|
(syntax-case x ()
|
||||||
|
@ -63,6 +78,8 @@
|
||||||
#'(let ((v data))
|
#'(let ((v data))
|
||||||
body)))))
|
body)))))
|
||||||
|
|
||||||
|
;; The resulting nested if statements will be an O(n) dispatch. Once
|
||||||
|
;; we compile `case' effectively, this situation will improve.
|
||||||
(define-syntax mx-match
|
(define-syntax mx-match
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(syntax-case x (quote)
|
(syntax-case x (quote)
|
||||||
|
@ -85,6 +102,7 @@
|
||||||
|
|
||||||
(define primitive-eval
|
(define primitive-eval
|
||||||
(let ()
|
(let ()
|
||||||
|
;; The "engine". EXP is a memoized expression.
|
||||||
(define (eval exp env)
|
(define (eval exp env)
|
||||||
(memoized-expression-case exp
|
(memoized-expression-case exp
|
||||||
(('begin (first . rest))
|
(('begin (first . rest))
|
||||||
|
@ -197,7 +215,9 @@
|
||||||
(memoize-variable-access! exp #f))
|
(memoize-variable-access! exp #f))
|
||||||
(eval x env)))))
|
(eval x env)))))
|
||||||
|
|
||||||
|
;; primitive-eval
|
||||||
(lambda (exp)
|
(lambda (exp)
|
||||||
|
"Evaluate @var{exp} in the current module."
|
||||||
(eval
|
(eval
|
||||||
(memoize-expression ((or (module-transformer (current-module))
|
(memoize-expression ((or (module-transformer (current-module))
|
||||||
(lambda (x) x))
|
(lambda (x) x))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue