mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-30 06:50:31 +02:00
attempted microoptimization in eval.scm.
* module/ice-9/eval.scm (primitive-eval): Try using list-ref instead of cdring in the vm. We'll check the hydra build times to see if this has any actual merit. Surely the best solution is another representation of environments, though.
This commit is contained in:
parent
2a8a127bbe
commit
bb0c815741
1 changed files with 14 additions and 17 deletions
|
@ -46,6 +46,9 @@
|
||||||
(eval-when (compile)
|
(eval-when (compile)
|
||||||
(define-syntax capture-env
|
(define-syntax capture-env
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
|
((_ (exp ...))
|
||||||
|
(let ((env (exp ...)))
|
||||||
|
(capture-env env)))
|
||||||
((_ env)
|
((_ env)
|
||||||
(if (null? env)
|
(if (null? env)
|
||||||
(current-module)
|
(current-module)
|
||||||
|
@ -340,10 +343,7 @@
|
||||||
(define (eval exp env)
|
(define (eval exp env)
|
||||||
(memoized-expression-case exp
|
(memoized-expression-case exp
|
||||||
(('lexical-ref n)
|
(('lexical-ref n)
|
||||||
(let lp ((n n) (env env))
|
(list-ref env n))
|
||||||
(if (zero? n)
|
|
||||||
(car env)
|
|
||||||
(lp (1- n) (cdr env)))))
|
|
||||||
|
|
||||||
(('call (f nargs . args))
|
(('call (f nargs . args))
|
||||||
(let ((proc (eval f env)))
|
(let ((proc (eval f env)))
|
||||||
|
@ -353,10 +353,10 @@
|
||||||
(variable-ref
|
(variable-ref
|
||||||
(if (variable? var-or-sym)
|
(if (variable? var-or-sym)
|
||||||
var-or-sym
|
var-or-sym
|
||||||
(let lp ((env env))
|
(memoize-variable-access! exp
|
||||||
(if (pair? env)
|
(capture-env (if (pair? env)
|
||||||
(lp (cdr env))
|
(cdr (last-pair env))
|
||||||
(memoize-variable-access! exp (capture-env env)))))))
|
env))))))
|
||||||
|
|
||||||
(('if (test consequent . alternate))
|
(('if (test consequent . alternate))
|
||||||
(if (eval test env)
|
(if (eval test env)
|
||||||
|
@ -391,10 +391,7 @@
|
||||||
|
|
||||||
(('lexical-set! (n . x))
|
(('lexical-set! (n . x))
|
||||||
(let ((val (eval x env)))
|
(let ((val (eval x env)))
|
||||||
(let lp ((n n) (env env))
|
(list-set! env n val)))
|
||||||
(if (zero? n)
|
|
||||||
(set-car! env val)
|
|
||||||
(lp (1- n) (cdr env))))))
|
|
||||||
|
|
||||||
(('call-with-values (producer . consumer))
|
(('call-with-values (producer . consumer))
|
||||||
(call-with-values (eval producer env)
|
(call-with-values (eval producer env)
|
||||||
|
@ -416,10 +413,10 @@
|
||||||
(variable-set!
|
(variable-set!
|
||||||
(if (variable? var-or-sym)
|
(if (variable? var-or-sym)
|
||||||
var-or-sym
|
var-or-sym
|
||||||
(let lp ((env env))
|
(memoize-variable-access! exp
|
||||||
(if (pair? env)
|
(capture-env (if (pair? env)
|
||||||
(lp (cdr env))
|
(cdr (last-pair env))
|
||||||
(memoize-variable-access! exp (capture-env env)))))
|
env))))
|
||||||
(eval x env)))
|
(eval x env)))
|
||||||
|
|
||||||
(('dynwind (in exp . out))
|
(('dynwind (in exp . out))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue