abcl icon indicating copy to clipboard operation
abcl copied to clipboard

CLtL2 environment support

Open ghost opened this issue 7 years ago • 11 comments

Ticket 137 in Trac

While trying to implement a Cleavir environment as referenced in #62, I found there's only compiler-let in lisp:.

ghost avatar May 04 '18 06:05 ghost

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

ghost avatar May 04 '18 06:05 ghost

Not necessary with synthetic, or hostile, environment in cleavir.

ghost avatar May 05 '18 08:05 ghost

This is an active target for anyone who has a couple days to throw at the problem.

See https://abcl.org/trac/ticket/137.

easye avatar Nov 02 '19 16:11 easye

I would like this as well, specifically for define-declaration.

Shinmera avatar Nov 22 '19 12:11 Shinmera

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

Slids avatar Apr 12 '21 02:04 Slids

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.

easye avatar Apr 12 '21 04:04 easye

CL-ENVIRONMENTS https://github.com/alex-gutev/cl-environments seems to provide a portable implementation that seems to work on ABCL.

easye avatar Jul 14 '23 08:07 easye

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.

alanruttenberg avatar Jul 14 '23 16:07 alanruttenberg

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.

easye avatar Jul 15 '23 04:07 easye

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)))))))))

alanruttenberg avatar Jul 16 '23 21:07 alanruttenberg

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.

easye avatar Jul 17 '23 05:07 easye