From 06d6b434de57771d7d67d455883eaaa123e9846d Mon Sep 17 00:00:00 2001 From: John Lorentzson Date: Wed, 9 Jul 2025 16:06:56 +0200 Subject: [PATCH] Remove unused "NEXT" slots from syntax tree nodes (and related code) --- wip-duuqnd/user-side-compiler/high-level.lisp | 29 +------------------ wip-duuqnd/user-side-compiler/parser.lisp | 27 ++--------------- 2 files changed, 4 insertions(+), 52 deletions(-) diff --git a/wip-duuqnd/user-side-compiler/high-level.lisp b/wip-duuqnd/user-side-compiler/high-level.lisp index a794c2c..78b1446 100644 --- a/wip-duuqnd/user-side-compiler/high-level.lisp +++ b/wip-duuqnd/user-side-compiler/high-level.lisp @@ -3,17 +3,11 @@ ;;; Base node (defclass node () - ((%next :accessor next :accessor normal-next :initform nil - :initarg :next) - (%source :accessor source :initarg :source :initform nil) - (%comment :accessor comment :initarg :comment :initform nil))) + ((%source :accessor source :initarg :source :initform nil))) (defun nodep (obj) (typep obj 'node)) -(defmethod node-nexts ((node node)) - (list (normal-next node))) - ;;; Basic nodes (defclass node-nop (node) ()) @@ -36,9 +30,6 @@ (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) ((%dst-variable :accessor dst-variable :initarg :variable) (%value :accessor value :initarg :value))) @@ -48,11 +39,6 @@ (setf (operands instance) (list (dst-variable 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) ()) (defmacro define-standard-expr-node (name) @@ -60,10 +46,6 @@ (defclass ,name (node-standard-expr) ()) (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-minus) (define-standard-expr-node node-expr-multiply) @@ -90,12 +72,6 @@ (%then :accessor then-node :initarg :then) (%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) ((%stop-ref :accessor stop-ref :initarg :stop-ref :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.") (%loopee-node :accessor loopee-node :initarg :loopee-node))) -(defmethod node-nexts ((node node-dotimes)) - (append (list (loopee-node node)) - (call-next-method))) diff --git a/wip-duuqnd/user-side-compiler/parser.lisp b/wip-duuqnd/user-side-compiler/parser.lisp index 201c206..76fa93b 100644 --- a/wip-duuqnd/user-side-compiler/parser.lisp +++ b/wip-duuqnd/user-side-compiler/parser.lisp @@ -228,8 +228,7 @@ comma ',' is required to separate arguments."))) (defun wire-up-statements (statements) (loop :for statement :in statements :for rest := (rest statements) :then (rest rest) - :for next := (first rest) - :do (setf (normal-next statement) next)) + :for next := (first rest)) statements) (define-syntax-matcher block (statements) @@ -244,8 +243,7 @@ comma ',' is required to separate arguments."))) (setf statements (wire-up-statements (nreverse statements))) (make-instance 'node-block :source *syntax-source* - :statements statements - :next (first statements))) + :statements statements)) (defmacro match-syntax-pattern (syntax-list error-messages) (append @@ -287,12 +285,6 @@ comma ',' is required to separate arguments."))) :stop-ref (transform n 'reference) :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) (match-syntax-pattern ((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))) (make-instance 'node-program :source *syntax-source* - :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)))) + :statements statements))