Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[cl-backend] move stash handling into a seperate package
- Loading branch information
Showing
2 changed files
with
46 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| (defpackage niecza-stash (:export wrap-in-let to-stash-name) (:use :common-lisp)) | ||
| (in-package :niecza-stash) | ||
|
|
||
| (ql:quickload "fare-matcher") | ||
|
|
||
| (defun to-stash-name (name) (intern (format nil "~{~A~^-~}" name))) | ||
|
|
||
| (defun entry (prefix node) | ||
| (fare-matcher:match node | ||
| ((and (list name var Xref ChildNode) (when (equal var "var"))) | ||
| (cons (list (append prefix (list name)) Xref) (process (cons name prefix) ChildNode))))) | ||
|
|
||
|
|
||
| (defun process (prefix nodes) (apply 'append (mapcar #'(lambda (x) (entry prefix x)) nodes))) | ||
|
|
||
|
|
||
| (defun wrap-in-let (stash body) | ||
| (let ((processed (process '() stash))) | ||
| `(let | ||
| ,(mapcar (lambda (x) (list (to-stash-name (first x)) nil)) (hide-foreign processed)) | ||
| ,@body | ||
| ,@(set-stash processed)))) | ||
|
|
||
| (defun only-with-xrefs (stash) (remove-if (lambda (x) (not (second x))) stash)) | ||
|
|
||
| (defun set-stash (stash) | ||
| (mapcar (lambda (x) `(setf ,(to-stash-name (first x)) ,(niecza::xref-to-symbol (second x)))) (only-with-xrefs (hide-foreign stash)))) | ||
|
|
||
| (defun hide-foreign (stash) | ||
| (remove-if | ||
| (lambda (x) | ||
| (and (second x) (not (equal (first (second x)) "MAIN")))) | ||
| stash)) | ||
|
|