Files
jak-project/goal_src/jak1/engine/util/glist.gc
T
Tyler Wilding c162c66118 g/j1: Cleanup all main issues in the formatter and format all of goal_src/jak1 (#3535)
This PR does two main things:
1. Work through the main low-hanging fruit issues in the formatter
keeping it from feeling mature and usable
2. Iterate and prove that point by formatting all of the Jak 1 code
base. **This has removed around 100K lines in total.**
- The decompiler will now format it's results for jak 1 to keep things
from drifting back to where they were. This is controlled by a new
config flag `format_code`.

How am I confident this hasn't broken anything?:
- I compiled the entire project and stored it's `out/jak1/obj` files
separately
- I then recompiled the project after formatting and wrote a script that
md5's each file and compares it (`compare-compilation-outputs.py`
- The results (eventually) were the same:

![Screenshot 2024-05-25
132900](https://github.com/open-goal/jak-project/assets/13153231/015e6f20-8d19-49b7-9951-97fa88ddc6c2)
> This proves that the only difference before and after is non-critical
whitespace for all code/macros that is actually in use.

I'm still aware of improvements that could be made to the formatter, as
well as general optimization of it's performance. But in general these
are for rare or non-critical situations in my opinion and I'll work
through them before doing Jak 2. The vast majority looks great and is
working properly at this point. Those known issues are the following if
you are curious:

![image](https://github.com/open-goal/jak-project/assets/13153231/0edfaba1-6d36-40f5-ab23-0642209867c4)
2024-06-05 22:17:31 -04:00

107 lines
4.1 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/util/glist-h.gc")
(require "kernel/gstring.gc")
;; THIS FILE IS REALLY WEIRD PLEASE JUST LOOK AWAY
(declare-file (debug))
(defun-debug glst-num-elements ((list glst-list))
"Return the number of elements on the list"
(-> list numelem))
(defun-debug glst-remove ((list glst-list) (node glst-node))
"Remove the node from the list"
(let ((prev (glst-prev node))
(next (glst-next node)))
(set! (-> prev next) next)
(set! (-> next prev) prev))
(+! (-> list numelem) -1)
node)
(defun-debug glst-remove-tail ((list glst-list))
"Remove the last node from the list, if it is not also the first.
Returns the deleted node, or #f otherwise"
(let ((tail (glst-tail list))) (if (not (glst-start-of-list? (-> tail prev))) (glst-remove list tail))))
(defun-debug glst-remove-head ((list glst-list))
"Remove the first node from the list, if it is not also the last.
Returns the deleted node, or #f otherwise"
(let ((head (glst-head list))) (if (not (glst-end-of-list? (-> head next))) (glst-remove list head))))
(defun-debug glst-insert-before ((list glst-list) (node glst-node) (new-node glst-node))
"Insert a new node before node in the list.
Returns the new node."
(let ((prev (glst-prev node)))
(set! (-> new-node prev) prev)
(set! (-> new-node next) node)
(set! (-> prev next) new-node)
(set! (-> node prev) new-node))
(+! (-> list numelem) 1)
new-node)
(defun-debug glst-insert-after ((list glst-list) (node glst-node) (new-node glst-node))
"Insert a new node after node in the list.
Returns the new node."
(let ((next (glst-next node)))
(set! (-> new-node next) next)
(set! (-> new-node prev) node)
(set! (-> next prev) new-node)
(set! (-> node next) new-node))
(+! (-> list numelem) 1)
new-node)
(defun-debug glst-add-tail ((list glst-list) (node glst-node))
"Add a node to the end of the list"
(glst-insert-before list (the-as glst-node (&-> list tail)) node))
(defun-debug glst-add-head ((list glst-list) (node glst-node))
"Add a node to the start of the list"
(glst-insert-after list (the-as glst-node (&-> list head)) node))
(defun-debug glst-init-list! ((list glst-list))
"Init the list"
(set! (-> list head) (the-as glst-node (&-> list tail)))
(set! (-> list tail) #f)
(set! (-> list tailpred) (the-as glst-node (&-> list head)))
(set! (-> list numelem) 0)
list)
(defmacro glst-iterate-list (list node &rest body)
"Iterate through the list using node as the current node variable"
`(let ((,node (glst-head ,list))) (while (not (glst-end-of-list? (-> ,node next))) ,@body (set! ,node (glst-next ,node)))))
(defmacro glst-iterate-named-list (list node &rest body)
"Iterate through the named node list using node as the current node variable"
`(let ((,node (the glst-named-node (glst-head ,list))))
(while (not (glst-end-of-list? (-> ,node next)))
,@body
(set! ,node (the glst-named-node (glst-next ,node))))))
(defun-debug glst-find-node-by-name ((list glst-list) (name string))
"Find the node in the list with the given name and return it. If it is not found, #f is returned instead"
(glst-iterate-named-list list node (if (name= (-> node privname) name) (return node)))
(the-as glst-node #f))
(defun-debug glst-get-node-by-index ((list glst-list) (n int))
"Return the n-th node in the list, beginning at zero"
(if (and (< n (glst-num-elements list)) (>= n 0))
(let ((node (glst-head list)))
(dotimes (index n)
;; (nop!) x4
(set! node (glst-next node)))
(return node)))
(the-as glst-node #f))
(defun-debug glst-length-of-longest-name ((list glst-list))
"Returns the length of longest name in a list of named nodes"
(let ((max-len 0))
(glst-iterate-named-list list node (let ((len (length (-> node privname)))) (when (< max-len len) (set! max-len len))))
max-len))
(defun-debug glst-get-node-index ((list glst-list) (node glst-node))
"Returns the index of the node in the list. If the node is not found on the list, returns -1"
(let ((index 0)) (glst-iterate-list list current-node (if (= current-node node) (return index)) (+! index 1)) -1))