jak-project/goal_src/engine/util/glist-h.gc
ManDude d952475c77
[glist/glist-h] Decompile this stupidity (#286)
* [glist/glist-h] Decompile this stupidity

* [glist] fix macros

* [glist] fix return types
2021-02-26 08:59:28 -05:00

110 lines
2.3 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: glist-h.gc
;; name in dgo: glist-h
;; dgos: GAME, ENGINE
;; This whole linked list system is hellspawn! Whoever made this is insane and a danger to society
(when *debug-segment*
(deftype glst-node (structure)
((next glst-node :offset-assert 0)
(prev glst-node :offset-assert 4)
)
:method-count-assert 9
:size-assert #x8
:flag-assert #x900000008
)
(deftype glst-named-node (glst-node)
((privname string :offset-assert 8)
)
:method-count-assert 9
:size-assert #xc
:flag-assert #x90000000c
)
(deftype glst-list (structure)
((head glst-node :offset-assert 0)
(tail glst-node :offset-assert 4)
(tailpred glst-node :offset-assert 8)
(numelem int32 :offset-assert 12)
)
:method-count-assert 9
:size-assert #x10
:flag-assert #x900000010
)
;; FUN FACT! The "defun" macro only checks if the first item in the function body is a
;; string (the docstring), but because these functions were marked as inline (or debug)
;; BEFORE the docstring, they end up being considered part of the body and the compiled output!
;; This amusing mistake is reproduced here.
(defun-debug glst-next ((node glst-node))
(declare (inline))
"return the next node in the list"
(-> node next)
)
(defun-debug glst-prev ((node glst-node))
(declare (inline))
"return the previous node in the list"
(-> node prev)
)
(defun-debug glst-head ((list glst-list))
(declare (inline))
"return the start of the list"
(-> list head)
)
(defun-debug glst-tail ((list glst-list))
(declare (inline))
"return the tail of the list"
(-> list tailpred)
)
(defun-debug glst-end-of-list? ((node glst-node))
(declare (inline))
"is this node the end of the list. #t = end"
(not (-> node next))
)
(defun-debug glst-start-of-list? ((node glst-node))
(declare (inline))
"is this node the start of the list. #t = start"
(not (-> node prev))
)
(defun-debug glst-empty? ((list glst-list))
(declare (inline))
"is the list empty, #t = empty"
(= (-> list tailpred) (&-> list head))
)
(defun-debug glst-node-name ((node glst-named-node))
"Return the name of the node"
(-> node privname)
)
(defun-debug glst-set-name! ((node glst-named-node) (name string))
"Set the name of the node"
(set! (-> node privname) name)
)
)