deftype and defmethod syntax major changes (#3094)

Major change to how `deftype` shows up in our code:
- the decompiler will no longer emit the `offset-assert`,
`method-count-assert`, `size-assert` and `flag-assert` parameters. There
are extremely few cases where having this in the decompiled code is
helpful, as the types there come from `all-types` which already has
those parameters. This also doesn't break type consistency because:
  - the asserts aren't compared.
- the first step of the test uses `all-types`, which has the asserts,
which will throw an error if they're bad.
- the decompiler won't emit the `heap-base` parameter unless necessary
now.
- the decompiler will try its hardest to turn a fixed-offset field into
an `overlay-at` field. It falls back to the old offset if all else
fails.
- `overlay-at` now supports field "dereferencing" to specify the offset
that's within a field that's a structure, e.g.:
```lisp
(deftype foobar (structure)
  ((vec    vector  :inline)
   (flags  int32   :overlay-at (-> vec w))
   )
  )
```
in this structure, the offset of `flags` will be 12 because that is the
final offset of `vec`'s `w` field within this structure.
- **removed ID from all method declarations.** IDs are only ever
automatically assigned now. Fixes #3068.
- added an `:overlay` parameter to method declarations, in order to
declare a new method that goes on top of a previously-defined method.
Syntax is `:overlay <method-name>`. Please do not ever use this.
- added `state-methods` list parameter. This lets you quickly specify a
list of states to be put in the method table. Same syntax as the
`states` list parameter. The decompiler will try to put as many states
in this as it can without messing with the method ID order.

Also changes `defmethod` to make the first type definition (before the
arguments) optional. The type can now be inferred from the first
argument. Fixes #3093.

---------

Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com>
This commit is contained in:
ManDude
2023-10-30 03:20:02 +00:00
committed by GitHub
parent 09536c68ac
commit cd68cb671e
2079 changed files with 94384 additions and 117066 deletions
+153 -219
View File
@@ -3,17 +3,14 @@
;; definition of type joint-anim
(deftype joint-anim (basic)
((name string :offset-assert 4)
(number int16 :offset-assert 8)
(length int16 :offset-assert 10)
((name string)
(number int16)
(length int16)
)
:method-count-assert 9
:size-assert #xc
:flag-assert #x90000000c
)
;; definition for method 3 of type joint-anim
(defmethod inspect joint-anim ((this joint-anim))
(defmethod inspect ((this joint-anim))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -28,24 +25,18 @@
;; definition of type joint-anim-matrix
(deftype joint-anim-matrix (joint-anim)
((data matrix :inline :dynamic :offset 16)
((data matrix :inline :dynamic :offset 16)
)
:method-count-assert 9
:size-assert #x10
:flag-assert #x900000010
)
;; definition of type joint-anim-transformq
(deftype joint-anim-transformq (joint-anim)
((data transformq :inline :dynamic :offset 16)
((data transformq :inline :dynamic :offset 16)
)
:method-count-assert 9
:size-assert #x10
:flag-assert #x900000010
)
;; definition for method 3 of type joint-anim-transformq
(defmethod inspect joint-anim-transformq ((this joint-anim-transformq))
(defmethod inspect ((this joint-anim-transformq))
(when (not this)
(set! this this)
(goto cfg-7)
@@ -64,15 +55,12 @@
;; definition of type joint-anim-drawable
(deftype joint-anim-drawable (joint-anim)
((data drawable :dynamic :offset-assert 12)
((data drawable :dynamic)
)
:method-count-assert 9
:size-assert #xc
:flag-assert #x90000000c
)
;; definition for method 3 of type joint-anim-drawable
(defmethod inspect joint-anim-drawable ((this joint-anim-drawable))
(defmethod inspect ((this joint-anim-drawable))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -88,19 +76,16 @@
;; definition of type joint-anim-frame
(deftype joint-anim-frame (structure)
((matrices matrix 2 :inline :offset-assert 0)
(data transformq :inline :dynamic :offset-assert 128)
((matrices matrix 2 :inline)
(data transformq :inline :dynamic)
)
:method-count-assert 9
:size-assert #x80
:flag-assert #x900000080
(:methods
(new (symbol type int) _type_ 0)
(new (symbol type int) _type_)
)
)
;; definition for method 3 of type joint-anim-frame
(defmethod inspect joint-anim-frame ((this joint-anim-frame))
(defmethod inspect ((this joint-anim-frame))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -125,17 +110,14 @@
;; definition of type joint-anim-compressed-hdr
(deftype joint-anim-compressed-hdr (structure)
((control-bits uint32 14 :offset-assert 0)
(num-joints uint32 :offset-assert 56)
(matrix-bits uint32 :offset-assert 60)
((control-bits uint32 14)
(num-joints uint32)
(matrix-bits uint32)
)
:method-count-assert 9
:size-assert #x40
:flag-assert #x900000040
)
;; definition for method 3 of type joint-anim-compressed-hdr
(defmethod inspect joint-anim-compressed-hdr ((this joint-anim-compressed-hdr))
(defmethod inspect ((this joint-anim-compressed-hdr))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -150,20 +132,17 @@
;; definition of type joint-anim-compressed-fixed
(deftype joint-anim-compressed-fixed (structure)
((hdr joint-anim-compressed-hdr :inline :offset-assert 0)
(offset-64 uint32 :offset-assert 64)
(offset-32 uint32 :offset-assert 68)
(offset-16 uint32 :offset-assert 72)
(reserved uint32 :offset-assert 76)
(data vector 133 :inline :offset-assert 80)
((hdr joint-anim-compressed-hdr :inline)
(offset-64 uint32)
(offset-32 uint32)
(offset-16 uint32)
(reserved uint32)
(data vector 133 :inline)
)
:method-count-assert 9
:size-assert #x8a0
:flag-assert #x9000008a0
)
;; definition for method 3 of type joint-anim-compressed-fixed
(defmethod inspect joint-anim-compressed-fixed ((this joint-anim-compressed-fixed))
(defmethod inspect ((this joint-anim-compressed-fixed))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -181,19 +160,16 @@
;; definition of type joint-anim-compressed-frame
(deftype joint-anim-compressed-frame (structure)
((offset-64 uint32 :offset-assert 0)
(offset-32 uint32 :offset-assert 4)
(offset-16 uint32 :offset-assert 8)
(reserved uint32 :offset-assert 12)
(data vector 133 :inline :offset-assert 16)
((offset-64 uint32)
(offset-32 uint32)
(offset-16 uint32)
(reserved uint32)
(data vector 133 :inline)
)
:method-count-assert 9
:size-assert #x860
:flag-assert #x900000860
)
;; definition for method 3 of type joint-anim-compressed-frame
(defmethod inspect joint-anim-compressed-frame ((this joint-anim-compressed-frame))
(defmethod inspect ((this joint-anim-compressed-frame))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -210,20 +186,17 @@
;; definition of type joint-anim-compressed-control
(deftype joint-anim-compressed-control (structure)
((num-frames uint16 :offset-assert 0)
(flags uint16 :offset-assert 2)
(fixed-qwc uint32 :offset-assert 4)
(frame-qwc uint32 :offset-assert 8)
(fixed joint-anim-compressed-fixed :offset-assert 12)
(data joint-anim-compressed-frame :dynamic :offset-assert 16)
((num-frames uint16)
(flags uint16)
(fixed-qwc uint32)
(frame-qwc uint32)
(fixed joint-anim-compressed-fixed)
(data joint-anim-compressed-frame :dynamic)
)
:method-count-assert 9
:size-assert #x10
:flag-assert #x900000010
)
;; definition for method 3 of type joint-anim-compressed-control
(defmethod inspect joint-anim-compressed-control ((this joint-anim-compressed-control))
(defmethod inspect ((this joint-anim-compressed-control))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -241,23 +214,20 @@
;; definition of type art
(deftype art (basic)
((name string :offset 8)
(length int32 :offset-assert 12)
(extra res-lump :offset-assert 16)
((name string :offset 8)
(length int32)
(extra res-lump)
)
:method-count-assert 13
:size-assert #x14
:flag-assert #xd00000014
(:methods
(login (_type_) _type_ 9)
(get-art-by-name-method (_type_ string type) basic 10)
(get-art-idx-by-name-method (_type_ string type) int 11)
(needs-link? (_type_) symbol 12)
(login (_type_) _type_)
(get-art-by-name-method (_type_ string type) basic)
(get-art-idx-by-name-method (_type_ string type) int)
(needs-link? (_type_) symbol)
)
)
;; definition for method 3 of type art
(defmethod inspect art ((this art))
(defmethod inspect ((this art))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -272,15 +242,12 @@
;; definition of type art-element
(deftype art-element (art)
((pad uint8 12 :offset-assert 20)
((pad uint8 12)
)
:method-count-assert 13
:size-assert #x20
:flag-assert #xd00000020
)
;; definition for method 3 of type art-element
(defmethod inspect art-element ((this art-element))
(defmethod inspect ((this art-element))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -295,31 +262,25 @@
;; definition of type art-mesh-anim
(deftype art-mesh-anim (art-element)
((data basic :dynamic :offset-assert 32)
((data basic :dynamic)
)
:method-count-assert 13
:size-assert #x20
:flag-assert #xd00000020
)
;; definition of type art-joint-anim
(deftype art-joint-anim (art-element)
((speed float :offset 20)
(artist-base float :offset 24)
(artist-step float :offset 28)
(eye-anim merc-eye-anim-block :offset 4)
(master-art-group-name string :offset-assert 32)
(master-art-group-index int32 :offset-assert 36)
(blend-shape-anim (pointer int8) :offset-assert 40)
(frames joint-anim-compressed-control :offset-assert 44)
((speed float :overlay-at (-> pad 0))
(artist-base float :overlay-at (-> pad 4))
(artist-step float :overlay-at (-> pad 8))
(eye-anim merc-eye-anim-block :offset 4)
(master-art-group-name string)
(master-art-group-index int32)
(blend-shape-anim (pointer int8))
(frames joint-anim-compressed-control)
)
:method-count-assert 13
:size-assert #x30
:flag-assert #xd00000030
)
;; definition for method 3 of type art-joint-anim
(defmethod inspect art-joint-anim ((this art-joint-anim))
(defmethod inspect ((this art-joint-anim))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -342,50 +303,38 @@
;; definition of type art-group
(deftype art-group (art)
((info file-info :offset 4)
(data art-element :dynamic :offset 32)
((info file-info :offset 4)
(data art-element :dynamic :offset 32)
)
:method-count-assert 15
:size-assert #x20
:flag-assert #xf00000020
(:methods
(relocate (_type_ kheap (pointer uint8)) none :replace 7)
(link-art! (_type_) art-group 13)
(unlink-art! (_type_) int 14)
(relocate (_type_ kheap (pointer uint8)) none :replace)
(link-art! (_type_) art-group)
(unlink-art! (_type_) int)
)
)
;; definition of type art-mesh-geo
(deftype art-mesh-geo (art-element)
((data basic :dynamic :offset-assert 32)
((data basic :dynamic)
)
:method-count-assert 13
:size-assert #x20
:flag-assert #xd00000020
)
;; definition of type art-joint-geo
(deftype art-joint-geo (art-element)
((data joint :dynamic :offset-assert 32)
((data joint :dynamic)
)
:method-count-assert 13
:size-assert #x20
:flag-assert #xd00000020
)
;; definition of type art-joint-anim-manager-slot
(deftype art-joint-anim-manager-slot (structure)
((anim art-joint-anim :offset-assert 0)
(comp-data uint32 :offset-assert 4)
(time-stamp uint64 :offset-assert 8)
((anim art-joint-anim)
(comp-data uint32)
(time-stamp uint64)
)
:method-count-assert 9
:size-assert #x10
:flag-assert #x900000010
)
;; definition for method 3 of type art-joint-anim-manager-slot
(defmethod inspect art-joint-anim-manager-slot ((this art-joint-anim-manager-slot))
(defmethod inspect ((this art-joint-anim-manager-slot))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -400,25 +349,22 @@
;; definition of type art-joint-anim-manager
(deftype art-joint-anim-manager (basic)
((kheap kheap :inline :offset-assert 16)
(free-index int32 :offset-assert 32)
(slot art-joint-anim-manager-slot 64 :inline :offset-assert 48)
((kheap kheap :inline)
(free-index int32)
(slot art-joint-anim-manager-slot 64 :inline)
)
:method-count-assert 14
:size-assert #x430
:flag-assert #xe00000430
(:methods
(new (symbol type int) _type_ 0)
(decompress (_type_ art-joint-anim) art-joint-anim 9)
(update-time-stamp (_type_ art-joint-anim) art-joint-anim 10)
(unload-from-slot (_type_ int) art-joint-anim 11)
(used-bytes-for-slot (_type_ int) int 12)
(unload-from-level (_type_ level) none 13)
(new (symbol type int) _type_)
(decompress (_type_ art-joint-anim) art-joint-anim)
(update-time-stamp (_type_ art-joint-anim) art-joint-anim)
(unload-from-slot (_type_ int) art-joint-anim)
(used-bytes-for-slot (_type_ int) int)
(unload-from-level (_type_ level) none)
)
)
;; definition for method 3 of type art-joint-anim-manager
(defmethod inspect art-joint-anim-manager ((this art-joint-anim-manager))
(defmethod inspect ((this art-joint-anim-manager))
(when (not this)
(set! this this)
(goto cfg-7)
@@ -453,34 +399,31 @@
;; definition of type skeleton-group
(deftype skeleton-group (art-group)
((art-group-name string :offset-assert 32)
(jgeo int32 :offset-assert 36)
(janim int32 :offset-assert 40)
(bounds vector :inline :offset-assert 48)
(radius meters :offset 60)
(mgeo int16 6 :offset-assert 64)
(max-lod int32 :offset-assert 76)
(lod-dist float 6 :offset-assert 80)
(longest-edge meters :offset-assert 104)
(texture-level int8 :offset-assert 108)
(version int8 :offset-assert 109)
(shadow int8 :offset-assert 110)
(sort int8 :offset-assert 111)
(origin-joint-index int8 :offset-assert 112)
(shadow-joint-index int8 :offset-assert 113)
(light-index uint8 :offset-assert 114)
(pad uint8 :offset-assert 115)
((art-group-name string)
(jgeo int32)
(janim int32)
(bounds vector :inline)
(radius meters :overlay-at (-> bounds data 3))
(mgeo int16 6)
(max-lod int32)
(lod-dist float 6)
(longest-edge meters)
(texture-level int8)
(version int8)
(shadow int8)
(sort int8)
(origin-joint-index int8)
(shadow-joint-index int8)
(light-index uint8)
(pad uint8)
)
:method-count-assert 16
:size-assert #x74
:flag-assert #x1000000074
(:methods
(add-to-loading-level (_type_) skeleton-group 15)
(add-to-loading-level (_type_) skeleton-group)
)
)
;; definition for method 3 of type skeleton-group
(defmethod inspect skeleton-group ((this skeleton-group))
(defmethod inspect ((this skeleton-group))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -513,17 +456,14 @@
;; definition of type lod-group
(deftype lod-group (structure)
((geo merc-ctrl :offset-assert 0)
(dist meters :offset-assert 4)
((geo merc-ctrl)
(dist meters)
)
:pack-me
:method-count-assert 9
:size-assert #x8
:flag-assert #x900000008
)
;; definition for method 3 of type lod-group
(defmethod inspect lod-group ((this lod-group))
(defmethod inspect ((this lod-group))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -537,19 +477,16 @@
;; definition of type lod-set
(deftype lod-set (structure)
((lod lod-group 6 :inline :offset-assert 0)
(max-lod int8 :offset-assert 48)
((lod lod-group 6 :inline)
(max-lod int8)
)
:method-count-assert 10
:size-assert #x31
:flag-assert #xa00000031
(:methods
(setup-lods! (_type_ skeleton-group art-group entity) _type_ 9)
(setup-lods! (_type_ skeleton-group art-group entity) _type_)
)
)
;; definition for method 3 of type lod-set
(defmethod inspect lod-set ((this lod-set))
(defmethod inspect ((this lod-set))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -563,63 +500,60 @@
;; definition of type draw-control
(deftype draw-control (basic)
((process process-drawable :offset-assert 4)
(status draw-control-status :offset-assert 8)
(data-format draw-control-data-format :offset-assert 10)
(global-effect draw-control-global-effect :offset-assert 11)
(art-group art-group :offset-assert 12)
(jgeo art-joint-geo :offset-assert 16)
(mgeo merc-ctrl :offset-assert 20)
(dma-add-func (function process-drawable draw-control symbol object none) :offset-assert 24)
(skeleton skeleton :offset-assert 28)
(lod-set lod-set :inline :offset-assert 32)
(max-lod int8 :offset 80)
(force-lod int8 :offset-assert 81)
(cur-lod int8 :offset-assert 82)
(desired-lod int8 :offset-assert 83)
(ripple ripple-control :offset-assert 84)
(longest-edge meters :offset-assert 88)
(longest-edge? uint32 :offset 88)
(light-index uint8 :offset-assert 92)
(shadow-mask uint8 :offset-assert 93)
(level-index uint8 :offset-assert 94)
(death-draw-overlap uint8 :offset-assert 95)
(death-timer uint8 :offset-assert 96)
(death-timer-org uint8 :offset-assert 97)
(death-vertex-skip uint16 :offset-assert 98)
(death-effect uint32 :offset-assert 100)
(shadow shadow-geo :offset-assert 104)
(shadow-ctrl shadow-control :offset-assert 108)
(distance meters :offset-assert 112)
(origin vector :inline :offset-assert 128)
(bounds vector :inline :offset-assert 144)
(radius meters :offset 156)
(color-mult rgbaf :inline :offset-assert 160)
(color-emissive rgbaf :inline :offset-assert 176)
(effect-mask uint64 :offset-assert 192)
(seg-mask uint64 :offset-assert 200)
(origin-joint-index uint8 :offset-assert 208)
(shadow-joint-index uint8 :offset-assert 209)
(force-fade uint8 :offset-assert 210)
(default-texture-page uint8 :offset-assert 211)
(shadow-values uint32 :offset-assert 212)
((process process-drawable)
(status draw-control-status)
(data-format draw-control-data-format)
(global-effect draw-control-global-effect)
(art-group art-group)
(jgeo art-joint-geo)
(mgeo merc-ctrl)
(dma-add-func (function process-drawable draw-control symbol object none))
(skeleton skeleton)
(lod-set lod-set :inline)
(max-lod int8 :overlay-at (-> lod-set max-lod))
(force-lod int8)
(cur-lod int8)
(desired-lod int8)
(ripple ripple-control)
(longest-edge meters)
(longest-edge? uint32 :overlay-at longest-edge)
(light-index uint8)
(shadow-mask uint8)
(level-index uint8)
(death-draw-overlap uint8)
(death-timer uint8)
(death-timer-org uint8)
(death-vertex-skip uint16)
(death-effect uint32)
(shadow shadow-geo)
(shadow-ctrl shadow-control)
(distance meters)
(origin vector :inline)
(bounds vector :inline)
(radius meters :overlay-at (-> bounds data 3))
(color-mult rgbaf :inline)
(color-emissive rgbaf :inline)
(effect-mask uint64)
(seg-mask uint64)
(origin-joint-index uint8)
(shadow-joint-index uint8)
(force-fade uint8)
(default-texture-page uint8)
(shadow-values uint32)
)
:method-count-assert 15
:size-assert #xd8
:flag-assert #xf000000d8
(:methods
(new (symbol type process symbol) _type_ 0)
(get-skeleton-origin (_type_) vector 9)
(lod-set! (_type_ int) none 10)
(lods-assign! (_type_ lod-set) none 11)
(setup-masks (_type_ int int) none 12)
(setup-cspace-and-add (_type_ art-joint-geo symbol) cspace-array 13)
(do-joint-math (_type_ cspace-array joint-control) none 14)
(new (symbol type process symbol) _type_)
(get-skeleton-origin (_type_) vector)
(lod-set! (_type_ int) none)
(lods-assign! (_type_ lod-set) none)
(setup-masks (_type_ int int) none)
(setup-cspace-and-add (_type_ art-joint-geo symbol) cspace-array)
(do-joint-math (_type_ cspace-array joint-control) none)
)
)
;; definition for method 3 of type draw-control
(defmethod inspect draw-control ((this draw-control))
(defmethod inspect ((this draw-control))
(when (not this)
(set! this this)
(goto cfg-47)
@@ -752,7 +686,7 @@
)
;; definition for method 9 of type draw-control
(defmethod get-skeleton-origin draw-control ((this draw-control))
(defmethod get-skeleton-origin ((this draw-control))
(-> this skeleton bones 0 transform trans)
)