From: Charles Z. <ka...@be...> - 2018-05-14 03:48:46
|
Hello clisp, Everything is building under git, working with SLIME, quicklisp, etc. I've been trying to create Cleavir flow graphs with CLISP. Such '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. Additionally, (ext:the-environment) does not seem to give compile time lexical environment information, only runtime environment information. This makes it hard to discover information about local variables or local functions. Even then, I couldn't find any interface to tell whether symbols were declared special with defvar. So, for the time being, I've been able to only get approximate information environment information by evaluating (boundp ...) and testing whether PROGV and LET yield the same information. This is enough to get basic forms like (lambda (x) x) compiling to HIR (the Cleavir flow graph representation) in clisp. However, in order to do more complicated stuff it seems like I'll need some way of getting at optimize, variable and function info at runtime. Any way of getting CLtL2-esque information here? Maybe buried in a codewalker? Charles |
From: Sam S. <sd...@gn...> - 2018-05-14 18:57:03
|
Hi Charles, > * Charles Zhang <xneybf@orexryrl.rqh> [2018-05-13 23:48:35 -0400]: > > I couldn't find any interface to tell whether > symbols were declared special with defvar. see eval.d:SYS::SPECIAL-VARIABLE-P -- Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.1561 http://childpsy.net http://calmchildstories.com http://steingoldpsychology.com http://camera.org http://www.memritv.org https://jihadwatch.org Lisp: Serious empowerment. |
From: Bruno H. <br...@cl...> - 2018-05-22 00:07:06
|
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 |