Remove unused "NEXT" slots from syntax tree nodes (and related code)

This commit is contained in:
John Lorentzson 2025-07-09 16:06:56 +02:00
parent d25f3795f5
commit 06d6b434de
2 changed files with 4 additions and 52 deletions

View file

@ -3,17 +3,11 @@
;;; Base node ;;; Base node
(defclass node () (defclass node ()
((%next :accessor next :accessor normal-next :initform nil ((%source :accessor source :initarg :source :initform nil)))
:initarg :next)
(%source :accessor source :initarg :source :initform nil)
(%comment :accessor comment :initarg :comment :initform nil)))
(defun nodep (obj) (defun nodep (obj)
(typep obj 'node)) (typep obj 'node))
(defmethod node-nexts ((node node))
(list (normal-next node)))
;;; Basic nodes ;;; Basic nodes
(defclass node-nop (node) ()) (defclass node-nop (node) ())
@ -36,9 +30,6 @@
(define-transformation (node (node-expr-grouping node-expr)) node) (define-transformation (node (node-expr-grouping node-expr)) node)
(defmethod node-nexts ((node node-expr-grouping))
(append (list (expression node)) (call-next-method)))
(defclass node-assignment (node-expr) (defclass node-assignment (node-expr)
((%dst-variable :accessor dst-variable :initarg :variable) ((%dst-variable :accessor dst-variable :initarg :variable)
(%value :accessor value :initarg :value))) (%value :accessor value :initarg :value)))
@ -48,11 +39,6 @@
(setf (operands instance) (list (dst-variable instance) (setf (operands instance) (list (dst-variable instance)
(value instance)))) (value instance))))
(defmethod node-nexts ((node node-assignment))
(append (when (nodep (value node))
(list (value node)))
(call-next-method)))
(defclass node-standard-expr (node-expr) ()) (defclass node-standard-expr (node-expr) ())
(defmacro define-standard-expr-node (name) (defmacro define-standard-expr-node (name)
@ -60,10 +46,6 @@
(defclass ,name (node-standard-expr) ()) (defclass ,name (node-standard-expr) ())
(define-transformation (node (,name node-expr)) node))) (define-transformation (node (,name node-expr)) node)))
(defmethod node-nexts ((node node-standard-expr))
(append (remove-if-not #'nodep (operands node))
(call-next-method)))
(define-standard-expr-node node-expr-plus) (define-standard-expr-node node-expr-plus)
(define-standard-expr-node node-expr-minus) (define-standard-expr-node node-expr-minus)
(define-standard-expr-node node-expr-multiply) (define-standard-expr-node node-expr-multiply)
@ -90,12 +72,6 @@
(%then :accessor then-node :initarg :then) (%then :accessor then-node :initarg :then)
(%else :accessor else-node :initarg :else :initform nil))) (%else :accessor else-node :initarg :else :initform nil)))
(defclass node-branch (node)
((%branch-next :accessor branch-next :initarg :branch-next)))
(defmethod node-nexts ((node node-branch))
(list (normal-next node) (branch-next node)))
(defclass node-dotimes (node) (defclass node-dotimes (node)
((%stop-ref :accessor stop-ref :initarg :stop-ref ((%stop-ref :accessor stop-ref :initarg :stop-ref
:documentation "A reference giving a value of how many times to run the loop.") :documentation "A reference giving a value of how many times to run the loop.")
@ -103,6 +79,3 @@
:documentation "A reference to a variable being set to the loop index.") :documentation "A reference to a variable being set to the loop index.")
(%loopee-node :accessor loopee-node :initarg :loopee-node))) (%loopee-node :accessor loopee-node :initarg :loopee-node)))
(defmethod node-nexts ((node node-dotimes))
(append (list (loopee-node node))
(call-next-method)))

View file

@ -228,8 +228,7 @@ comma ',' is required to separate arguments.")))
(defun wire-up-statements (statements) (defun wire-up-statements (statements)
(loop :for statement :in statements (loop :for statement :in statements
:for rest := (rest statements) :then (rest rest) :for rest := (rest statements) :then (rest rest)
:for next := (first rest) :for next := (first rest))
:do (setf (normal-next statement) next))
statements) statements)
(define-syntax-matcher block (statements) (define-syntax-matcher block (statements)
@ -244,8 +243,7 @@ comma ',' is required to separate arguments.")))
(setf statements (wire-up-statements (nreverse statements))) (setf statements (wire-up-statements (nreverse statements)))
(make-instance 'node-block (make-instance 'node-block
:source *syntax-source* :source *syntax-source*
:statements statements :statements statements))
:next (first statements)))
(defmacro match-syntax-pattern (syntax-list error-messages) (defmacro match-syntax-pattern (syntax-list error-messages)
(append (append
@ -287,12 +285,6 @@ comma ',' is required to separate arguments.")))
:stop-ref (transform n 'reference) :stop-ref (transform n 'reference)
:loopee-node (transform code 'node))) :loopee-node (transform code 'node)))
(defmethod node-nexts ((node node-conditional))
(append (list (test-node node) (then-node node))
(unless (null (else-node node))
(list (else-node node)))
(call-next-method)))
(define-syntax-matcher if (test then else) (define-syntax-matcher if (test then else)
(match-syntax-pattern (match-syntax-pattern
((test expression) :then token-end-of-statement (then block)) ((test expression) :then token-end-of-statement (then block))
@ -319,17 +311,4 @@ comma ',' is required to separate arguments.")))
(setf statements (wire-up-statements (nreverse statements))) (setf statements (wire-up-statements (nreverse statements)))
(make-instance 'node-program (make-instance 'node-program
:source *syntax-source* :source *syntax-source*
:statements statements :statements statements))
:next (first statements)))
;;; Testing jigs
(defmacro do-node-tree ((node start-node) &body body)
(let ((stack (gensym))
(current (gensym)))
`(loop :with ,stack := (list (normal-next ,start-node))
:for ,current := (pop ,stack)
:until (null ,current)
:do (setf ,stack (append (remove nil (node-nexts ,current)) ,stack))
:do (let ((,node ,current))
,@body))))