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
+132 -195
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))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tnumber: ~D~%" (-> this number))
@@ -23,33 +20,24 @@
;; 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 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))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tnumber: ~D~%" (-> this number))
@@ -60,15 +48,12 @@
;; definition of type joint-anim-compressed
(deftype joint-anim-compressed (joint-anim)
((data uint32 :dynamic :offset-assert 12)
((data uint32 :dynamic)
)
:method-count-assert 9
:size-assert #xc
:flag-assert #x90000000c
)
;; definition for method 3 of type joint-anim-compressed
(defmethod inspect joint-anim-compressed ((this joint-anim-compressed))
(defmethod inspect ((this joint-anim-compressed))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tnumber: ~D~%" (-> this number))
@@ -78,19 +63,16 @@
;; definition of type joint-anim-frame
(deftype joint-anim-frame (structure)
((matrices matrix 2 :inline :offset-assert 0)
(data matrix :inline :dynamic :offset-assert 128)
((matrices matrix 2 :inline)
(data matrix :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))
(format #t "[~8x] ~A~%" this 'joint-anim-frame)
(format #t "~Tmatrices[2] @ #x~X~%" (-> this matrices))
(format #t "~Tdata[0] @ #x~X~%" (-> this data))
@@ -110,17 +92,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))
(format #t "[~8x] ~A~%" this 'joint-anim-compressed-hdr)
(format #t "~Tcontrol-bits[14] @ #x~X~%" (-> this control-bits))
(format #t "~Tnum-joints: ~D~%" (-> this num-joints))
@@ -130,20 +109,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))
(format #t "[~8x] ~A~%" this 'joint-anim-compressed-fixed)
(format #t "~Thdr: #<joint-anim-compressed-hdr @ #x~X>~%" (-> this hdr))
(format #t "~Toffset-64: ~D~%" (-> this offset-64))
@@ -156,19 +132,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))
(format #t "[~8x] ~A~%" this 'joint-anim-compressed-frame)
(format #t "~Toffset-64: ~D~%" (-> this offset-64))
(format #t "~Toffset-32: ~D~%" (-> this offset-32))
@@ -180,19 +153,16 @@
;; definition of type joint-anim-compressed-control
(deftype joint-anim-compressed-control (structure)
((num-frames uint32 :offset-assert 0)
(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 1 :offset-assert 16)
((num-frames uint32)
(fixed-qwc uint32)
(frame-qwc uint32)
(fixed joint-anim-compressed-fixed)
(data joint-anim-compressed-frame 1)
)
:method-count-assert 9
:size-assert #x14
:flag-assert #x900000014
)
;; 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))
(format #t "[~8x] ~A~%" this 'joint-anim-compressed-control)
(format #t "~Tnum-frames: ~D~%" (-> this num-frames))
(format #t "~Tfixed-qwc: ~D~%" (-> this fixed-qwc))
@@ -204,23 +174,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)
(lookup-art (_type_ string type) joint 10)
(lookup-idx-of-art (_type_ string type) int 11)
(needs-link? (_type_) symbol 12)
(login (_type_) _type_)
(lookup-art (_type_ string type) joint)
(lookup-idx-of-art (_type_ string type) int)
(needs-link? (_type_) symbol)
)
)
;; definition for method 3 of type art
(defmethod inspect art ((this art))
(defmethod inspect ((this art))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tlength: ~D~%" (-> this length))
@@ -230,15 +197,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))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tlength: ~D~%" (-> this length))
@@ -248,87 +212,69 @@
;; 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)
((eye-anim-data merc-eye-anim-block :offset 4)
(speed float :offset 20)
(artist-base float :offset 24)
(artist-step float :offset 28)
(master-art-group-name string :offset 32)
(master-art-group-index int32 :offset 36)
(blerc-data (pointer uint8) :offset 40)
(frames joint-anim-compressed-control :offset 44)
(data joint-anim-compressed :dynamic :offset-assert 48)
((eye-anim-data merc-eye-anim-block :offset 4)
(speed float :overlay-at (-> pad 0))
(artist-base float :overlay-at (-> pad 4))
(artist-step float :overlay-at (-> pad 8))
(master-art-group-name string :offset 32)
(master-art-group-index int32 :offset 36)
(blerc-data (pointer uint8) :offset 40)
(frames joint-anim-compressed-control :offset 44)
(data joint-anim-compressed :dynamic)
)
:method-count-assert 13
:size-assert #x30
:flag-assert #xd00000030
)
;; 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 skeleton-group
(deftype skeleton-group (basic)
((art-group-name string :offset-assert 4)
(jgeo int32 :offset-assert 8)
(janim int32 :offset-assert 12)
(bounds vector :inline :offset-assert 16)
(radius meters :offset 28)
(mgeo int16 4 :offset-assert 32)
(max-lod int32 :offset-assert 40)
(lod-dist float 4 :offset-assert 44)
(longest-edge meters :offset-assert 60)
(texture-level int8 :offset-assert 64)
(version int8 :offset-assert 65)
(shadow int8 :offset-assert 66)
(sort int8 :offset-assert 67)
(_pad uint8 4 :offset-assert 68)
((art-group-name string)
(jgeo int32)
(janim int32)
(bounds vector :inline)
(radius meters :overlay-at (-> bounds w))
(mgeo int16 4)
(max-lod int32)
(lod-dist float 4)
(longest-edge meters)
(texture-level int8)
(version int8)
(shadow int8)
(sort int8)
(_pad uint8 4)
)
:method-count-assert 9
:size-assert #x48
:flag-assert #x900000048
)
;; definition for method 3 of type skeleton-group
(defmethod inspect skeleton-group ((this skeleton-group))
(defmethod inspect ((this skeleton-group))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tart-group-name: ~A~%" (-> this art-group-name))
(format #t "~Tjgeo: ~D~%" (-> this jgeo))
@@ -348,17 +294,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))
(format #t "[~8x] ~A~%" this 'lod-group)
(format #t "~Tgeo: ~A~%" (-> this geo))
(format #t "~Tdist: (meters ~m)~%" (-> this dist))
@@ -367,20 +310,17 @@
;; definition of type lod-set
(deftype lod-set (structure)
((lod lod-group 4 :inline :offset-assert 0)
(max-lod int8 :offset-assert 32)
((lod lod-group 4 :inline)
(max-lod int8)
)
:pack-me
:method-count-assert 10
:size-assert #x21
:flag-assert #xa00000021
(: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))
(format #t "[~8x] ~A~%" this 'lod-set)
(format #t "~Tlod[4] @ #x~X~%" (-> this lod))
(format #t "~Tmax-lod: ~D~%" (-> this max-lod))
@@ -389,60 +329,57 @@
;; definition of type draw-control
(deftype draw-control (basic)
((status draw-status :offset-assert 4)
(matrix-type uint8 :offset-assert 5)
(data-format uint8 :offset-assert 6)
(global-effect draw-effect :offset-assert 7)
(art-group art-group :offset-assert 8)
(jgeo art-joint-geo :offset-assert 12)
(mgeo merc-ctrl :offset-assert 16)
(dma-add-func (function process-drawable draw-control symbol object none) :offset-assert 20)
(skeleton skeleton :offset-assert 24)
(lod-set lod-set :inline :offset-assert 28)
(lod lod-group 4 :inline :offset 28)
(max-lod int8 :offset 60)
(force-lod int8 :offset-assert 61)
(cur-lod int8 :offset-assert 62)
(desired-lod int8 :offset-assert 63)
(ripple ripple-control :offset-assert 64)
(longest-edge meters :offset-assert 68)
(longest-edge? uint32 :offset 68)
(light-index uint8 :offset-assert 72)
(dummy uint8 2 :offset-assert 73)
(death-draw-overlap uint8 :offset-assert 75)
(death-timer uint8 :offset-assert 76)
(death-timer-org uint8 :offset-assert 77)
(death-vertex-skip uint16 :offset-assert 78)
(death-effect uint32 :offset-assert 80)
(sink-group dma-foreground-sink-group :offset-assert 84)
(process process :offset-assert 88)
(shadow shadow-geo :offset-assert 92)
(shadow-ctrl shadow-control :offset-assert 96)
(origin vector :inline :offset-assert 112)
(bounds vector :inline :offset-assert 128)
(radius meters :offset 140)
(color-mult rgbaf :inline :offset-assert 144)
(color-emissive rgbaf :inline :offset-assert 160)
(secondary-interp float :offset-assert 176)
(current-secondary-interp float :offset-assert 180)
(shadow-mask uint8 :offset-assert 184)
(level-index uint8 :offset-assert 185)
(origin-joint-index uint8 :offset-assert 186)
(shadow-joint-index uint8 :offset-assert 187)
((status draw-status)
(matrix-type uint8)
(data-format uint8)
(global-effect draw-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)
(lod lod-group 4 :inline :overlay-at (-> lod-set lod 0))
(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)
(dummy uint8 2)
(death-draw-overlap uint8)
(death-timer uint8)
(death-timer-org uint8)
(death-vertex-skip uint16)
(death-effect uint32)
(sink-group dma-foreground-sink-group)
(process process)
(shadow shadow-geo)
(shadow-ctrl shadow-control)
(origin vector :inline)
(bounds vector :inline)
(radius meters :overlay-at (-> bounds w))
(color-mult rgbaf :inline)
(color-emissive rgbaf :inline)
(secondary-interp float)
(current-secondary-interp float)
(shadow-mask uint8)
(level-index uint8)
(origin-joint-index uint8)
(shadow-joint-index uint8)
)
:method-count-assert 12
:size-assert #xbc
:flag-assert #xc000000bc
(:methods
(new (symbol type process art-joint-geo) _type_ 0)
(get-skeleton-origin (_type_) vector 9)
(lod-set! (_type_ int) none 10)
(lods-assign! (_type_ lod-set) none 11)
(new (symbol type process art-joint-geo) _type_)
(get-skeleton-origin (_type_) vector)
(lod-set! (_type_ int) none)
(lods-assign! (_type_ lod-set) none)
)
)
;; definition for method 3 of type draw-control
(defmethod inspect draw-control ((this draw-control))
(defmethod inspect ((this draw-control))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tstatus: ~D~%" (-> this status))
(format #t "~Tmatrix-type: ~D~%" (-> this matrix-type))
@@ -488,7 +425,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 vector 3)
)