From ddde60b3af966391d3a5525e0643aa20dce70ec9 Mon Sep 17 00:00:00 2001 From: cxxxr Date: Thu, 30 Nov 2023 02:15:15 +0900 Subject: [PATCH] split files --- contrib/walker/utils.lisp | 48 ++++++++++++++++++++++++++++++++++++++ contrib/walker/walker.lisp | 28 ++++------------------ micros.asd | 1 + 3 files changed, 53 insertions(+), 24 deletions(-) create mode 100644 contrib/walker/utils.lisp diff --git a/contrib/walker/utils.lisp b/contrib/walker/utils.lisp new file mode 100644 index 0000000..4b87201 --- /dev/null +++ b/contrib/walker/utils.lisp @@ -0,0 +1,48 @@ +(in-package :micros/walker) + +(defun string-prefix-p (prefix string) + (and (<= (length prefix) (length string)) + (string= prefix string :end2 (length prefix)))) + +;;; copy from alexandria +(deftype string-designator () + "A string designator type. A string designator is either a string, a symbol, +or a character." + `(or symbol string character)) + +(defmacro with-gensyms (names &body forms) + "Binds a set of variables to gensyms and evaluates the implicit progn FORMS. + +Each element within NAMES is either a symbol SYMBOL or a pair (SYMBOL +STRING-DESIGNATOR). Bare symbols are equivalent to the pair (SYMBOL SYMBOL). + +Each pair (SYMBOL STRING-DESIGNATOR) specifies that the variable named by SYMBOL +should be bound to a symbol constructed using GENSYM with the string designated +by STRING-DESIGNATOR being its first argument." + `(let ,(mapcar (lambda (name) + (multiple-value-bind (symbol string) + (etypecase name + (symbol + (values name (symbol-name name))) + ((cons symbol (cons string-designator null)) + (values (first name) (string (second name))))) + `(,symbol (gensym ,string)))) + names) + ,@forms)) + +(defun parse-body (body &key documentation whole) + (let ((doc nil) + (decls nil) + (current nil)) + (tagbody + :declarations + (setf current (car body)) + (when (and documentation (stringp current) (cdr body)) + (if doc + (error "Too many documentation strings in ~S." (or whole body)) + (setf doc (pop body))) + (go :declarations)) + (when (and (listp current) (eql (first current) 'declare)) + (push (pop body) decls) + (go :declarations))) + (values body (nreverse decls) doc))) diff --git a/contrib/walker/walker.lisp b/contrib/walker/walker.lisp index ad1c904..0566ad5 100644 --- a/contrib/walker/walker.lisp +++ b/contrib/walker/walker.lisp @@ -1,4 +1,4 @@ -(in-package #:micros/walker) +(in-package :micros/walker) (define-condition unimplemented () ((context :initarg :context @@ -8,28 +8,6 @@ (cerror "continue" 'unimplemented :context context) (make-instance 'unknown-form :form form :path path)) -;; copy from alexandria:parse-body -(defun parse-body (body &key documentation whole) - (let ((doc nil) - (decls nil) - (current nil)) - (tagbody - :declarations - (setf current (car body)) - (when (and documentation (stringp current) (cdr body)) - (if doc - (error "Too many documentation strings in ~S." (or whole body)) - (setf doc (pop body))) - (go :declarations)) - (when (and (listp current) (eql (first current) 'declare)) - (push (pop body) decls) - (go :declarations))) - (values body (nreverse decls) doc))) - -(defun string-prefix-p (prefix string) - (and (<= (length prefix) (length string)) - (string= prefix string :end2 (length prefix)))) - (defmacro walker-assert (predicate) `(assert ,predicate)) @@ -1007,4 +985,6 @@ (:no-error (paths) (list :ok paths)) (unimplemented (c) - (list :error (format nil "unimplemented: ~A" (unimplemented-context c)))))))) + (list :error (format nil "unimplemented: ~A" (unimplemented-context c)))) + (error (c) + (list :error (format nil "ERROR: ~A" c))))))) diff --git a/micros.asd b/micros.asd index 144c20a..9abe2d0 100644 --- a/micros.asd +++ b/micros.asd @@ -50,6 +50,7 @@ ;; (:file "sprof") (:module "walker" :components ((:file "package") + (:file "utils") (:file "types") (:file "walker") (:file "defun-form")