Re: gsoc: grabbing clisp environment info, cltl2
Bruno Haible <[email protected]> Tue, 22 May 2018 02:06:48 +0200
| Newsgroups | gmane.lisp.clisp.devel |
|---|---|
| Message-ID | <12518836.K1TjDN1RiC@omega> |
Hi Charles,
> 'front-end' compilation needs to take place in a lexical environment
> in order to get variable, function, optimize information etc as well
> as to hook into macroexpanders. However, I have found that CLISP does
> not adhere to the CLtL2 environment interface.
The environment interface is not available as a "modern", "abstract"
interface, only as a data structure with accessors:
- The concepts of these environments are described in lispbibl.d
around line 14000.
- These environments mix lexical and dynamic information; if you
want to ignore the dynamic information, do so carefully.
- The variables environment has Lisp code that accesses it in:
venv-assoc (init.lisp), venv-search (compiler.lisp).
- The functions/macros environment has Lisp code that accesses it in:
fenv-assoc (init.lisp), fenv-search (compiler.lisp).
- The block environment has Lisp code that accesses it in:
benv-search (compiler.lisp).
- The tagbody/go environment has Lisp code that accesses it in:
genv-search (compiler.lisp).
- The declarations environment has Lisp code that accesses it in:
declared-notinline, declared-constant-notinline, declared-declaration,
declared-optimize (all compiler.lisp).
Note: These environment structures are also accessed from the interpreter
(C code in eval.d and control.d). This means that if you extend these
structures to accommodate objects built by SICL, the C code may need an
update as well. This is because the compiler has to access interpreter
environments, as in
(let ((x 5))
(declare (special x)) ; This declaration has an effect on the function!
(locally (declare (compile))
(lambda () (incf x))))
With the '(declare (special x))':
0 (GETVALUE&PUSH 0) ; X
2 (CALLS2 177) ; 1+
4 (SETVALUE 0) ; X
6 (SKIP&RET 1)
Without the '(declare (special x))':
0 (CONST&PUSH 0) ; #(X 5 NIL)
1 (CONST 1) ; 1
2 (SVREF)
3 (PUSH)
4 (CALLS2&PUSH 177) ; 1+
6 (CONST&PUSH 0) ; #(X 5 NIL)
7 (CONST 1) ; 1
8 (SVSET)
9 (SKIP&RET 1)
> Additionally,
> (ext:the-environment) does not seem to give compile time lexical
> environment information, only runtime environment information.
Yes, (ext:the-environment) has the same mix between lexical and dynamic
information.
> I couldn't find any interface to tell whether
> symbols were declared special with defvar.
There is SYS::SPECIAL-VARIABLE-P, defined in eval.d, and
CONSTANTP, defined in control.d. Both of these access special bits in
the symbol (cf. constant_var_p, special_var_p in lispbibl.d).
> Any way of getting CLtL2-esque information here? Maybe buried in a codewalker?
It is surely possible to implement the functions from
https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node102.html
- except for augment-environment - in a straightforward manner.
augment-environment, however, is not so adapted for clisp, because it would
be consing more than is desirable.
Note that this interface did not make it into ANSI CL, see
http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Issues/iss343.html
Bruno
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
clisp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-devel