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
@@ -2,7 +2,7 @@
(in-package goal)
;; definition for method 15 of type skeleton-group
(defmethod add-to-loading-level skeleton-group ((this skeleton-group))
(defmethod add-to-loading-level ((this skeleton-group))
(let ((v1-1 (-> *level* loading-level)))
(if v1-1
(set-loaded-art (-> v1-1 art-group) this)
@@ -195,7 +195,7 @@
;; definition for method 10 of type draw-control
;; WARN: Return type mismatch int vs none.
(defmethod lod-set! draw-control ((this draw-control) (arg0 int))
(defmethod lod-set! ((this draw-control) (arg0 int))
(let ((v1-1 (max 0 (min arg0 (-> this lod-set max-lod)))))
(set! (-> this desired-lod) v1-1)
(when (!= (-> this cur-lod) v1-1)
@@ -212,7 +212,7 @@
;; definition for method 11 of type draw-control
;; WARN: Return type mismatch int vs none.
(defmethod lods-assign! draw-control ((this draw-control) (arg0 lod-set))
(defmethod lods-assign! ((this draw-control) (arg0 lod-set))
(mem-copy! (the-as pointer (-> this lod-set)) (the-as pointer arg0) 49)
(let ((a1-2 (min (-> this cur-lod) (-> this lod-set max-lod))))
(set! (-> this cur-lod) -1)
@@ -224,7 +224,7 @@
;; definition for method 12 of type draw-control
;; WARN: Return type mismatch int vs none.
(defmethod setup-masks draw-control ((this draw-control) (arg0 int) (arg1 int))
(defmethod setup-masks ((this draw-control) (arg0 int) (arg1 int))
"TODO - use the enum types"
(local-vars (v1-4 int) (a2-1 (array uint64)))
(let ((a1-2 (logior (logclear (-> this seg-mask) arg0) arg1)))
@@ -254,7 +254,7 @@
;; definition for method 9 of type lod-set
;; INFO: Used lq/sq
(defmethod setup-lods! lod-set ((this lod-set) (arg0 skeleton-group) (arg1 art-group) (arg2 entity))
(defmethod setup-lods! ((this lod-set) (arg0 skeleton-group) (arg1 art-group) (arg2 entity))
(local-vars (sv-16 res-tag))
(let ((v1-0 (-> arg1 length))
(s3-0 (-> arg0 max-lod))
@@ -293,7 +293,7 @@
)
;; definition for method 13 of type draw-control
(defmethod setup-cspace-and-add draw-control ((this draw-control) (arg0 art-joint-geo) (arg1 symbol))
(defmethod setup-cspace-and-add ((this draw-control) (arg0 art-joint-geo) (arg1 symbol))
(let ((s5-0 ((method-of-type cspace-array new) arg1 cspace-array (+ (-> arg0 length) 1))))
(let ((v0-1 ((method-of-type skeleton new) arg1 skeleton (+ (-> arg0 length) 1))))
(set! (-> this skeleton) v0-1)
@@ -368,7 +368,7 @@
;; definition for method 14 of type draw-control
;; INFO: Used lq/sq
;; WARN: Return type mismatch int vs none.
(defmethod do-joint-math draw-control ((this draw-control) (arg0 cspace-array) (arg1 joint-control))
(defmethod do-joint-math ((this draw-control) (arg0 cspace-array) (arg1 joint-control))
(with-pp
(cond
((logtest? (-> this status) (draw-control-status no-draw no-draw-temp))
@@ -448,7 +448,7 @@
;; definition for method 17 of type process-drawable
;; WARN: Return type mismatch int vs none.
(defmethod cleanup-for-death process-drawable ((this process-drawable))
(defmethod cleanup-for-death ((this process-drawable))
(when (type? (-> this root) collide-shape)
(let ((v1-2 (-> (the-as collide-shape (-> this root)) root-prim)))
(set! (-> v1-2 prim-core collide-as) (collide-spec))
@@ -466,7 +466,7 @@
;; definition for method 18 of type process-drawable
;; WARN: Return type mismatch int vs none.
(defmethod relocate-nav process-drawable ((this process-drawable) (arg0 int))
(defmethod relocate-nav ((this process-drawable) (arg0 int))
(set! (-> this nav) (the-as nav-control (&+ (the-as pointer (-> this nav)) arg0)))
0
(none)
@@ -525,7 +525,7 @@
)
;; definition for method 10 of type process-drawable
(defmethod deactivate process-drawable ((this process-drawable))
(defmethod deactivate ((this process-drawable))
(if (nonzero? (-> this part))
(kill-and-free-particles (-> this part))
)
@@ -733,7 +733,7 @@
;; definition for method 14 of type process-drawable
;; INFO: Used lq/sq
(defmethod initialize-skeleton process-drawable ((this process-drawable) (arg0 skeleton-group) (arg1 pair))
(defmethod initialize-skeleton ((this process-drawable) (arg0 skeleton-group) (arg1 pair))
(local-vars (v1-14 art-element))
(if (not arg0)
(go process-drawable-art-error "skel-group")
@@ -805,7 +805,7 @@
)
;; definition for method 15 of type process-drawable
(defmethod initialize-skeleton-by-name process-drawable ((this process-drawable) (arg0 string))
(defmethod initialize-skeleton-by-name ((this process-drawable) (arg0 string))
(let* ((s4-0 *level*)
(s3-0 (method-of-object s4-0 art-group-get-by-name))
)
@@ -821,7 +821,7 @@
)
;; definition for method 16 of type process-drawable
(defmethod apply-alignment process-drawable ((this process-drawable) (arg0 align-opts) (arg1 transformq) (arg2 vector))
(defmethod apply-alignment ((this process-drawable) (arg0 align-opts) (arg1 transformq) (arg2 vector))
(with-pp
(when (logtest? arg0 (align-opts adjust-x-vel adjust-y-vel adjust-xz-vel))
(let* ((s3-0 (quaternion->matrix (new 'stack-no-clear 'matrix) (-> this root quat)))
@@ -1194,7 +1194,7 @@
;; WARN: Return type mismatch int vs none.
;; ERROR: Unsupported inline assembly instruction kind - [lw ra, return-from-thread(s7)]
;; ERROR: Unsupported inline assembly instruction kind - [jr ra]
(defmethod update-anim-data joint-control ((this joint-control))
(defmethod update-anim-data ((this joint-control))
(local-vars (s7-0 none) (ra-0 int))
(let ((s5-0 (+ (-> this active-channels) (-> this float-channels))))
(dotimes (s4-0 (the-as int s5-0))
@@ -1238,7 +1238,7 @@
;; WARN: Return type mismatch int vs none.
;; ERROR: Unsupported inline assembly instruction kind - [lw ra, return-from-thread(s7)]
;; ERROR: Unsupported inline assembly instruction kind - [jr ra]
(defmethod evaluate-joint-control process-drawable ((this process-drawable))
(defmethod evaluate-joint-control ((this process-drawable))
(local-vars (s1-0 joint-control-channel) (s2-0 int) (s4-0 uint) (s7-0 none) (ra-0 int))
(let ((gp-0 (-> this skel)))
(let ((a0-1 (-> gp-0 top-anim)))
@@ -1354,7 +1354,7 @@
)
;; definition for method 9 of type joint-control
(defmethod current-cycle-distance joint-control ((this joint-control))
(defmethod current-cycle-distance ((this joint-control))
(cond
((< (the-as int (-> this root-channel)) (the-as int (-> this channel (-> this active-channels))))
(let ((s4-0 (-> this root-channel (-> this root-channel 0 group-size)))
@@ -1402,7 +1402,7 @@
;; definition for method 9 of type top-anim-joint-control
;; WARN: Return type mismatch top-anim-joint-control vs none.
(defmethod reset top-anim-joint-control ((this top-anim-joint-control))
(defmethod reset ((this top-anim-joint-control))
(let ((v0-0 this))
(set! (-> v0-0 interp) 0.0)
(set! (-> v0-0 frame-targ) #f)
@@ -1421,7 +1421,7 @@
)
;; definition for method 11 of type top-anim-joint-control
(defmethod get-channel top-anim-joint-control ((this top-anim-joint-control) (arg0 int))
(defmethod get-channel ((this top-anim-joint-control) (arg0 int))
(case arg0
((1)
(case (-> this process 0 skel float-channels)
@@ -1451,15 +1451,15 @@
;; definition for method 12 of type top-anim-joint-control
;; WARN: Return type mismatch int vs none.
(defmethod push-anim-to-targ top-anim-joint-control ((this top-anim-joint-control)
(arg0 art-joint-anim)
(arg1 float)
(arg2 int)
(arg3 int)
(arg4 float)
(arg5 float)
(arg6 symbol)
)
(defmethod push-anim-to-targ ((this top-anim-joint-control)
(arg0 art-joint-anim)
(arg1 float)
(arg2 int)
(arg3 int)
(arg4 float)
(arg5 float)
(arg6 symbol)
)
(when (!= (-> this interp) 0.0)
(let ((v1-1 this))
(set! (-> v1-1 frame-targ) arg0)
@@ -1489,7 +1489,7 @@
;; definition for method 10 of type top-anim-joint-control
;; WARN: Return type mismatch int vs none.
(defmethod update top-anim-joint-control ((this top-anim-joint-control))
(defmethod update ((this top-anim-joint-control))
(with-pp
(let* ((v1-0 (-> this process))
(pp (if v1-0