CLtL2 environment support
While trying to implement a Cleavir environment as referenced in #62, I found there's only compiler-let in lisp:.
Would this be a relatively easy task to undertake for a novice such as myself? Probably not, but fortune favors the bold; I would appreciate a few pointers for where to start looking at :)
Regards
Not necessary with synthetic, or hostile, environment in cleavir.
This is an active target for anyone who has a couple days to throw at the problem.
I would like this as well, specifically for define-declaration.
What's the status of this? It's been years and the ticket tracker is... old... Trying to get ace.core working with abcl and it requires function-information and variable-information
What's the status of this? Unfortunately, there is no news on implementation of CLtL2 environment support. There is 80% of a portable implementation in the work Marco has pointed out, but I have never found the time to push this forward.
CL-ENVIRONMENTS https://github.com/alex-gutev/cl-environments seems to provide a portable implementation that seems to work on ABCL.
ABCL passes NIL as the environment parameter to compiler macro functions thus there is no way to obtain any information about the lexical environment in which the form appears. The environment information functions: VARIABLE-INFORMATION, FUNCTION-INFORMATION and DECLARATION-INFORMATION can only return information about global bindings/declarations when called from inside a compiler macro.
We might be able to fix some of this by using native functions to access the internal state. I have some environment inspection code - not sure if it is part of abcl-introspect but it could be added.
We might be able to fix some of this by using native functions to access the internal state. I have some environment inspection code - not sure if it is part of abcl-introspect but it could be added.
@alanruttenberg Please share with a pull request (or just Signal/mail me yer code) when you can: I've been interested in implementing this for "forever", so having something to start from would apparently be of great help.
The environment code is already in abcl-introspect.lisp, called environment-parts.
You can see how I get the set of bindings in collapse-locals or better in find-locals in my branch stage-merge-2022-02. I rewrote frame-locals as my old method using collapse-locals was buggy.
There isn't only a single environment object, even for a single function call . The environment is a stack and you have to traverse it and account for shadowed bindings. Below is a function for the slime inspector so they can be inspected.
(defmethod emacs-inspect ((o system::environment))
(let ((parts (sys::environment-parts o)))
(let ((lexicals (mapcar 'cdr (remove :lexical-variable parts :test-not 'eq :key 'car)))
(specials (mapcar 'cdr (remove :special parts :test-not 'eq :key 'car)))
(functions (mapcar 'cdr (remove :lexical-function parts :test-not 'eq :key 'car))))
`(,@(if lexicals
(list* '(:label "Lexicals:") '(:newline)
(loop for (var value) in lexicals
append `(" " (:label ,(format nil "~s" var)) ": " (:value ,value) (:newline)))))
,@(if functions
(list* '(:label "Functions:") '(:newline)
(loop for (var value) in functions
append `(" "(:label ,(format nil "~s" var)) ": " (:value ,value) (:newline)))))
,@(if specials
(list* '(:label "Specials:") '(:newline)
(loop for (var value) in specials
append `(" " (:label ,(format nil "~s" var)) ": " (:value ,value) (:newline)))))))))
Below is a function for the slime inspector so they can be inspected.
This is already part of the currently shipping SLIME https://github.com/slime/slime/blob/ba3d0794e7b2eb7b539fedd8109904b1fb4512a8/swank/abcl.lisp#L1213.
I suspect that the ABCL-INTROSPECT changes from https://github.com/alanruttenberg/abcl/tree/stage-merge-2022-02 are also present, but will double check.