From 940d413efee062eabca10a5705c390460c720df9 Mon Sep 17 00:00:00 2001 From: cxxxr Date: Sat, 2 Dec 2023 15:45:43 +0900 Subject: [PATCH] micros/walker: add check-type --- contrib/walker/TODO | 2 +- contrib/walker/data-and-control-flow.lisp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/contrib/walker/TODO b/contrib/walker/TODO index 8b42bde..86e25e5 100644 --- a/contrib/walker/TODO +++ b/contrib/walker/TODO @@ -1,7 +1,7 @@ - [ ] DEFINE-MODIFY-MACRO - [X] LOOP - [X] NTH-VALUE -- [ ] CHECK-TYPE +- [X] CHECK-TYPE - [ ] COND - [X] WITH-INPUT-FROM-STRING: with-single-binding-form - [ ] DEFCONSTANT diff --git a/contrib/walker/data-and-control-flow.lisp b/contrib/walker/data-and-control-flow.lisp index 43151fc..251f382 100644 --- a/contrib/walker/data-and-control-flow.lisp +++ b/contrib/walker/data-and-control-flow.lisp @@ -38,3 +38,22 @@ (def-simple-walker or-form or n form) (def-simple-walker incf-form incf n form) (def-simple-walker decf-form decf n form) + +;; check-type +(defclass check-type-form (ast) + ((place :initarg :place :reader ast-place) + (type :initarg :type :reader ast-type) + (type-string :initarg :type-string :reader ast-type-string))) + +(defmethod walk-form ((walker walker) (name (eql 'check-type)) form env path) + (with-walker-bindings (place type &optional type-string) (rest form) + (let ((place (walk walker place env (cons 1 path))) + (type-string (walk walker type-string env (cons 3 path)))) + (make-instance 'check-type-form + :place place + :type type + :type-string type-string)))) + +(defmethod visit (visitor (ast check-type-form)) + (visit visitor (ast-place ast)) + (visit visitor (ast-type-string ast)))