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
+66 -88
View File
@@ -3,28 +3,25 @@
;; definition of type joint-exploder-tuning
(deftype joint-exploder-tuning (structure)
((explosion uint64 :offset-assert 0)
(duration time-frame :offset-assert 8)
(gravity float :offset-assert 16)
(rot-speed float :offset-assert 20)
(fountain-rand-transv-lo vector :inline :offset-assert 32)
(fountain-rand-transv-hi vector :inline :offset-assert 48)
(away-from-focal-pt vector :inline :offset 32)
(away-from-rand-transv-xz-lo float :offset 48)
(away-from-rand-transv-xz-hi float :offset 52)
(away-from-rand-transv-y-lo float :offset 56)
(away-from-rand-transv-y-hi float :offset 60)
((explosion uint64)
(duration time-frame)
(gravity float)
(rot-speed float)
(fountain-rand-transv-lo vector :inline)
(fountain-rand-transv-hi vector :inline)
(away-from-focal-pt vector :inline :overlay-at fountain-rand-transv-lo)
(away-from-rand-transv-xz-lo float :overlay-at (-> fountain-rand-transv-hi x))
(away-from-rand-transv-xz-hi float :overlay-at (-> fountain-rand-transv-hi y))
(away-from-rand-transv-y-lo float :overlay-at (-> fountain-rand-transv-hi z))
(away-from-rand-transv-y-hi float :overlay-at (-> fountain-rand-transv-hi w))
)
:method-count-assert 9
:size-assert #x40
:flag-assert #x900000040
(:methods
(new (symbol type int) _type_ 0)
(new (symbol type int) _type_)
)
)
;; definition for method 3 of type joint-exploder-tuning
(defmethod inspect joint-exploder-tuning ((this joint-exploder-tuning))
(defmethod inspect ((this joint-exploder-tuning))
(format #t "[~8x] ~A~%" this 'joint-exploder-tuning)
(format #t "~Texplosion: ~D~%" (-> this explosion))
(format #t "~Tduration: ~D~%" (-> this duration))
@@ -42,16 +39,13 @@
;; definition of type joint-exploder-static-joint-params
(deftype joint-exploder-static-joint-params (structure)
((joint-index int16 :offset-assert 0)
(parent-joint-index int16 :offset-assert 2)
((joint-index int16)
(parent-joint-index int16)
)
:method-count-assert 9
:size-assert #x4
:flag-assert #x900000004
)
;; definition for method 3 of type joint-exploder-static-joint-params
(defmethod inspect joint-exploder-static-joint-params ((this joint-exploder-static-joint-params))
(defmethod inspect ((this joint-exploder-static-joint-params))
(format #t "[~8x] ~A~%" this 'joint-exploder-static-joint-params)
(format #t "~Tjoint-index: ~D~%" (-> this joint-index))
(format #t "~Tparent-joint-index: ~D~%" (-> this parent-joint-index))
@@ -60,15 +54,12 @@
;; definition of type joint-exploder-static-params
(deftype joint-exploder-static-params (basic)
((joints (array joint-exploder-static-joint-params) :offset-assert 4)
((joints (array joint-exploder-static-joint-params))
)
:method-count-assert 9
:size-assert #x8
:flag-assert #x900000008
)
;; definition for method 3 of type joint-exploder-static-params
(defmethod inspect joint-exploder-static-params ((this joint-exploder-static-params))
(defmethod inspect ((this joint-exploder-static-params))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tjoints: ~A~%" (-> this joints))
this
@@ -76,22 +67,19 @@
;; definition of type joint-exploder-joint
(deftype joint-exploder-joint (structure)
((next int16 :offset-assert 0)
(prev int16 :offset-assert 2)
(joint-index int16 :offset-assert 4)
(rspeed float :offset-assert 8)
(mat matrix :inline :offset-assert 16)
(rmat matrix :inline :offset-assert 80)
(transv vector :inline :offset-assert 144)
(prev-pos vector :inline :offset-assert 160)
((next int16)
(prev int16)
(joint-index int16)
(rspeed float)
(mat matrix :inline)
(rmat matrix :inline)
(transv vector :inline)
(prev-pos vector :inline)
)
:method-count-assert 9
:size-assert #xb0
:flag-assert #x9000000b0
)
;; definition for method 3 of type joint-exploder-joint
(defmethod inspect joint-exploder-joint ((this joint-exploder-joint))
(defmethod inspect ((this joint-exploder-joint))
(format #t "[~8x] ~A~%" this 'joint-exploder-joint)
(format #t "~Tnext: ~D~%" (-> this next))
(format #t "~Tprev: ~D~%" (-> this prev))
@@ -106,19 +94,16 @@
;; definition of type joint-exploder-joints
(deftype joint-exploder-joints (basic)
((num-joints int32 :offset-assert 4)
(joint joint-exploder-joint :inline :dynamic :offset 16)
((num-joints int32)
(joint joint-exploder-joint :inline :dynamic :offset 16)
)
:method-count-assert 9
:size-assert #x10
:flag-assert #x900000010
(:methods
(new (symbol type joint-exploder-static-params) _type_ 0)
(new (symbol type joint-exploder-static-params) _type_)
)
)
;; definition for method 3 of type joint-exploder-joints
(defmethod inspect joint-exploder-joints ((this joint-exploder-joints))
(defmethod inspect ((this joint-exploder-joints))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tnum-joints: ~D~%" (-> this num-joints))
(format #t "~Tjoint[0] @ #x~X~%" (-> this joint))
@@ -127,18 +112,15 @@
;; definition of type joint-exploder-list
(deftype joint-exploder-list (structure)
((head int32 :offset-assert 0)
(pre-moved? symbol :offset-assert 4)
(bbox-valid? symbol :offset-assert 8)
(bbox bounding-box :inline :offset-assert 16)
((head int32)
(pre-moved? symbol)
(bbox-valid? symbol)
(bbox bounding-box :inline)
)
:method-count-assert 9
:size-assert #x30
:flag-assert #x900000030
)
;; definition for method 3 of type joint-exploder-list
(defmethod inspect joint-exploder-list ((this joint-exploder-list))
(defmethod inspect ((this joint-exploder-list))
(format #t "[~8x] ~A~%" this 'joint-exploder-list)
(format #t "~Thead: ~D~%" (-> this head))
(format #t "~Tpre-moved?: ~A~%" (-> this pre-moved?))
@@ -149,30 +131,26 @@
;; definition of type joint-exploder
(deftype joint-exploder (process-drawable)
((parent-override (pointer process-drawable) :offset 12)
(die-if-below-y float :offset-assert 176)
(die-if-beyond-xz-dist-sqrd float :offset-assert 180)
(joints joint-exploder-joints :offset-assert 184)
(static-params joint-exploder-static-params :offset-assert 188)
(anim art-joint-anim :offset-assert 192)
(scale-vector vector :inline :offset-assert 208)
(tuning joint-exploder-tuning :inline :offset-assert 224)
(lists joint-exploder-list 5 :inline :offset-assert 288)
((parent-override (pointer process-drawable) :overlay-at parent)
(die-if-below-y float)
(die-if-beyond-xz-dist-sqrd float)
(joints joint-exploder-joints)
(static-params joint-exploder-static-params)
(anim art-joint-anim)
(scale-vector vector :inline)
(tuning joint-exploder-tuning :inline)
(lists joint-exploder-list 5 :inline)
)
:heap-base #x1a0
:method-count-assert 29
:size-assert #x210
:flag-assert #x1d01a00210
(:methods
(joint-exploder-method-20 (_type_ joint-exploder-list int) int 20)
(joint-exploder-method-21 (_type_ joint-exploder-list joint-exploder-joint) none 21)
(joint-exploder-method-22 (_type_ joint-exploder-list) symbol 22)
(joint-exploder-method-23 (_type_) symbol 23)
(joint-exploder-method-24 (_type_ joint-exploder-list int) int 24)
(joint-exploder-method-25 (_type_ joint-exploder-list) symbol 25)
(joint-exploder-method-26 (_type_ joint-exploder-list int) int 26)
(joint-exploder-method-27 (_type_ joint-exploder-list int) joint-exploder-list 27)
(joint-exploder-method-28 (_type_ joint-exploder-list) none 28)
(joint-exploder-method-20 (_type_ joint-exploder-list int) int)
(joint-exploder-method-21 (_type_ joint-exploder-list joint-exploder-joint) none)
(joint-exploder-method-22 (_type_ joint-exploder-list) symbol)
(joint-exploder-method-23 (_type_) symbol)
(joint-exploder-method-24 (_type_ joint-exploder-list int) int)
(joint-exploder-method-25 (_type_ joint-exploder-list) symbol)
(joint-exploder-method-26 (_type_ joint-exploder-list int) int)
(joint-exploder-method-27 (_type_ joint-exploder-list int) joint-exploder-list)
(joint-exploder-method-28 (_type_ joint-exploder-list) none)
)
(:states
joint-exploder-shatter
@@ -180,7 +158,7 @@
)
;; definition for method 3 of type joint-exploder
(defmethod inspect joint-exploder ((this joint-exploder))
(defmethod inspect ((this joint-exploder))
(let ((t9-0 (method-of-type process-drawable inspect)))
(t9-0 this)
)
@@ -197,7 +175,7 @@
;; definition for method 5 of type joint-exploder-joints
;; INFO: Return type mismatch uint vs int.
(defmethod asize-of joint-exploder-joints ((this joint-exploder-joints))
(defmethod asize-of ((this joint-exploder-joints))
(the-as int (+ (-> this type size) (* 176 (-> this num-joints))))
)
@@ -238,7 +216,7 @@
;; definition for method 24 of type joint-exploder
;; INFO: Used lq/sq
(defmethod joint-exploder-method-24 joint-exploder ((this joint-exploder) (arg0 joint-exploder-list) (arg1 int))
(defmethod joint-exploder-method-24 ((this joint-exploder) (arg0 joint-exploder-list) (arg1 int))
(let ((v0-0 (joint-exploder-method-26 this arg0 arg1)))
(let* ((v1-1 (-> this joints))
(v1-2 (-> v1-1 joint arg1))
@@ -253,7 +231,7 @@
)
;; definition for method 26 of type joint-exploder
(defmethod joint-exploder-method-26 joint-exploder ((this joint-exploder) (arg0 joint-exploder-list) (arg1 int))
(defmethod joint-exploder-method-26 ((this joint-exploder) (arg0 joint-exploder-list) (arg1 int))
(let* ((v1-0 (-> this joints))
(a2-1 (-> v1-0 joint arg1))
(a0-4 (-> a2-1 prev))
@@ -285,7 +263,7 @@
)
;; definition for method 20 of type joint-exploder
(defmethod joint-exploder-method-20 joint-exploder ((this joint-exploder) (arg0 joint-exploder-list) (arg1 int))
(defmethod joint-exploder-method-20 ((this joint-exploder) (arg0 joint-exploder-list) (arg1 int))
(let* ((v1-0 (-> this joints))
(a3-0 (-> v1-0 joint arg1))
(a0-4 (-> arg0 head))
@@ -303,7 +281,7 @@
;; definition for method 21 of type joint-exploder
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defmethod joint-exploder-method-21 joint-exploder ((this joint-exploder) (arg0 joint-exploder-list) (arg1 joint-exploder-joint))
(defmethod joint-exploder-method-21 ((this joint-exploder) (arg0 joint-exploder-list) (arg1 joint-exploder-joint))
(let ((a1-1 (-> arg1 mat vector 3)))
(cond
((-> arg0 bbox-valid?)
@@ -322,7 +300,7 @@
;; definition for method 27 of type joint-exploder
;; INFO: Used lq/sq
(defmethod joint-exploder-method-27 joint-exploder ((this joint-exploder) (arg0 joint-exploder-list) (arg1 int))
(defmethod joint-exploder-method-27 ((this joint-exploder) (arg0 joint-exploder-list) (arg1 int))
(local-vars (sv-16 int) (sv-32 int) (sv-48 int))
(let ((s4-0 (the-as joint-exploder-list #f)))
(let ((v1-0 1))
@@ -420,7 +398,7 @@
)
;; definition for method 28 of type joint-exploder
(defmethod joint-exploder-method-28 joint-exploder ((this joint-exploder) (arg0 joint-exploder-list))
(defmethod joint-exploder-method-28 ((this joint-exploder) (arg0 joint-exploder-list))
(when (and (-> arg0 bbox-valid?) (>= (-> arg0 head) 0))
(cond
((< 20480.0 (- (-> arg0 bbox max x) (-> arg0 bbox min x)))
@@ -454,7 +432,7 @@
;; definition for method 25 of type joint-exploder
;; INFO: Used lq/sq
(defmethod joint-exploder-method-25 joint-exploder ((this joint-exploder) (arg0 joint-exploder-list))
(defmethod joint-exploder-method-25 ((this joint-exploder) (arg0 joint-exploder-list))
(set! (-> arg0 bbox-valid?) #f)
(set! (-> arg0 pre-moved?) #t)
(let ((s4-0 (-> this joints))
@@ -499,7 +477,7 @@
;; definition for method 22 of type joint-exploder
;; INFO: Used lq/sq
(defmethod joint-exploder-method-22 joint-exploder ((this joint-exploder) (arg0 joint-exploder-list))
(defmethod joint-exploder-method-22 ((this joint-exploder) (arg0 joint-exploder-list))
(fill-using-bounding-box
*collide-cache*
(-> arg0 bbox)
@@ -622,7 +600,7 @@
;; definition for method 23 of type joint-exploder
;; INFO: Used lq/sq
(defmethod joint-exploder-method-23 joint-exploder ((this joint-exploder))
(defmethod joint-exploder-method-23 ((this joint-exploder))
(let ((gp-0 (-> this joints)))
(dotimes (s4-0 (-> gp-0 num-joints))
(let ((v1-2 (-> this static-params joints s4-0))
@@ -720,7 +698,7 @@
;; definition for method 7 of type joint-exploder
;; INFO: Return type mismatch process-drawable vs joint-exploder.
(defmethod relocate joint-exploder ((this joint-exploder) (arg0 int))
(defmethod relocate ((this joint-exploder) (arg0 int))
(if (nonzero? (-> this joints))
(&+! (-> this joints) arg0)
)