From: David Vázquez Date: Wed, 24 Apr 2013 18:33:39 +0000 (+0100) Subject: Define lexenv with def!struct X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=a492f6e21f55974a21f2f8ec5ccf105fb3f1a832;p=jscl.git Define lexenv with def!struct --- diff --git a/ecmalisp.lisp b/ecmalisp.lisp index bcf192a..9fd5cba 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -1364,31 +1364,32 @@ value declarations) -(defun make-lexenv () - (list nil nil nil nil)) +(def!struct lexenv + variable + function + block + gotag) -(defun copy-lexenv (lexenv) - (copy-list lexenv)) +(defun lookup-in-lexenv (name lexenv namespace) + (find name (ecase namespace + (variable (lexenv-variable lexenv)) + (function (lexenv-function lexenv)) + (block (lexenv-block lexenv)) + (gotag (lexenv-gotag lexenv))) + :key #'binding-name)) (defun push-to-lexenv (binding lexenv namespace) (ecase namespace - (variable (rplaca lexenv (cons binding (car lexenv)))) - (function (rplaca (cdr lexenv) (cons binding (cadr lexenv)))) - (block (rplaca (cddr lexenv) (cons binding (caddr lexenv)))) - (gotag (rplaca (cdddr lexenv) (cons binding (cadddr lexenv)))))) + (variable (push binding (lexenv-variable lexenv))) + (function (push binding (lexenv-function lexenv))) + (block (push binding (lexenv-block lexenv))) + (gotag (push binding (lexenv-gotag lexenv))))) (defun extend-lexenv (bindings lexenv namespace) (let ((env (copy-lexenv lexenv))) (dolist (binding (reverse bindings) env) (push-to-lexenv binding env namespace)))) -(defun lookup-in-lexenv (name lexenv namespace) - (find name (ecase namespace - (variable (first lexenv)) - (function (second lexenv)) - (block (third lexenv)) - (gotag (fourth lexenv))) - :key #'binding-name)) (defvar *environment* (make-lexenv))