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
+46 -63
View File
@@ -3,7 +3,7 @@
;; definition for method 52 of type process-taskable
;; INFO: Return type mismatch int vs none.
(defmethod process-taskable-method-52 process-taskable ((this process-taskable))
(defmethod process-taskable-method-52 ((this process-taskable))
(let ((v1-1 (-> this draw shadow-ctrl)))
(when v1-1
(let ((a0-1 v1-1))
@@ -19,7 +19,7 @@
;; definition for method 9 of type gui-query
;; INFO: Return type mismatch int vs none.
(defmethod init! gui-query ((this gui-query) (arg0 string) (arg1 int) (arg2 int) (arg3 int) (arg4 symbol) (arg5 string))
(defmethod init! ((this gui-query) (arg0 string) (arg1 int) (arg2 int) (arg3 int) (arg4 symbol) (arg5 string))
(set! (-> this x-position) arg1)
(set! (-> this y-position) arg2)
(set! (-> this message-space) arg3)
@@ -32,7 +32,7 @@
)
;; definition for method 10 of type gui-query
(defmethod get-response gui-query ((this gui-query))
(defmethod get-response ((this gui-query))
(kill-current-level-hint '() '(sidekick voicebox stinger) 'exit)
(level-hint-surpress!)
(hide-hud)
@@ -145,20 +145,17 @@
;; definition for method 7 of type process-taskable
;; INFO: Return type mismatch process-drawable vs process-taskable.
(defmethod relocate process-taskable ((this process-taskable) (arg0 int))
(defmethod relocate ((this process-taskable) (arg0 int))
(the-as process-taskable ((method-of-type process-drawable relocate) this arg0))
)
;; definition for method 46 of type process-taskable
;; INFO: Return type mismatch int vs none.
(defmethod process-taskable-method-46 process-taskable ((this process-taskable))
(defmethod process-taskable-method-46 ((this process-taskable))
(when (nonzero? (-> this sound-flava))
(let ((s5-1 (vector-!
(new 'stack-no-clear 'vector)
(target-pos 0)
(the-as vector (-> this root-override root-prim prim-core))
)
)
(let ((s5-1
(vector-! (new 'stack-no-clear 'vector) (target-pos 0) (the-as vector (-> this root root-prim prim-core)))
)
)
(set! (-> s5-1 y) (* 4.0 (-> s5-1 y)))
(cond
@@ -176,12 +173,9 @@
)
)
(when (-> this music)
(let ((s5-3 (vector-!
(new 'stack-no-clear 'vector)
(target-pos 0)
(the-as vector (-> this root-override root-prim prim-core))
)
)
(let ((s5-3
(vector-! (new 'stack-no-clear 'vector) (target-pos 0) (the-as vector (-> this root root-prim prim-core)))
)
)
(set! (-> s5-3 y) (* 4.0 (-> s5-3 y)))
(cond
@@ -204,7 +198,7 @@
;; definition for method 31 of type process-taskable
;; INFO: Return type mismatch art-joint-anim vs art-element.
(defmethod get-art-elem process-taskable ((this process-taskable))
(defmethod get-art-elem ((this process-taskable))
(the-as art-element (if (> (-> this skel active-channels) 0)
(-> this skel root-channel 0 frame-group)
)
@@ -213,13 +207,13 @@
;; definition for method 32 of type process-taskable
;; INFO: Return type mismatch symbol vs basic.
(defmethod play-anim! process-taskable ((this process-taskable) (arg0 symbol))
(defmethod play-anim! ((this process-taskable) (arg0 symbol))
(the-as basic #f)
)
;; definition for method 33 of type process-taskable
;; INFO: Return type mismatch int vs none.
(defmethod process-taskable-method-33 process-taskable ((this process-taskable))
(defmethod process-taskable-method-33 ((this process-taskable))
(let ((s5-0 (play-anim! this #f)))
(if (type-type? (-> s5-0 type) spool-anim)
(spool-push *art-control* (-> (the-as spool-anim s5-0) name) 0 this -99.0)
@@ -230,7 +224,7 @@
)
;; definition for method 51 of type process-taskable
(defmethod close-anim-file! process-taskable ((this process-taskable))
(defmethod close-anim-file! ((this process-taskable))
(let* ((gp-0 (play-anim! this #f))
(v1-2 (if (and (nonzero? gp-0) (type-type? (-> gp-0 type) spool-anim))
gp-0
@@ -245,13 +239,13 @@
;; definition for method 34 of type process-taskable
;; INFO: Return type mismatch symbol vs spool-anim.
(defmethod get-accept-anim process-taskable ((this process-taskable) (arg0 symbol))
(defmethod get-accept-anim ((this process-taskable) (arg0 symbol))
(the-as spool-anim #f)
)
;; definition for method 35 of type process-taskable
;; INFO: Return type mismatch int vs none.
(defmethod push-accept-anim process-taskable ((this process-taskable))
(defmethod push-accept-anim ((this process-taskable))
(let ((s5-0 (get-accept-anim this #f)))
(if (type-type? (-> s5-0 type) spool-anim)
(spool-push *art-control* (-> s5-0 name) 0 this -99.0)
@@ -263,13 +257,13 @@
;; definition for method 36 of type process-taskable
;; INFO: Return type mismatch symbol vs spool-anim.
(defmethod get-reject-anim process-taskable ((this process-taskable) (arg0 symbol))
(defmethod get-reject-anim ((this process-taskable) (arg0 symbol))
(the-as spool-anim #f)
)
;; definition for method 37 of type process-taskable
;; INFO: Return type mismatch int vs none.
(defmethod push-reject-anim process-taskable ((this process-taskable))
(defmethod push-reject-anim ((this process-taskable))
(let ((s5-0 (get-reject-anim this #f)))
(if (type-type? (-> s5-0 type) spool-anim)
(spool-push *art-control* (-> s5-0 name) 0 this -99.0)
@@ -281,7 +275,7 @@
;; definition for method 38 of type process-taskable
;; INFO: Return type mismatch object vs none.
(defmethod process-taskable-method-38 process-taskable ((this process-taskable))
(defmethod process-taskable-method-38 ((this process-taskable))
(if (nonzero? (-> this cell-for-task))
(go (method-of-object this give-cell))
)
@@ -365,9 +359,7 @@
)
:trans (behavior ()
(if (and (time-elapsed? (-> self state-time) (seconds 5))
(or (not *target*)
(< 20480.0 (vector-vector-distance (-> self root-override trans) (-> *target* control trans)))
)
(or (not *target*) (< 20480.0 (vector-vector-distance (-> self root trans) (-> *target* control trans))))
)
(go-virtual idle)
)
@@ -651,7 +643,7 @@
)
;; definition for method 39 of type process-taskable
(defmethod should-display? process-taskable ((this process-taskable))
(defmethod should-display? ((this process-taskable))
#t
)
@@ -681,7 +673,7 @@
)
0
(process-taskable-clean-up-after-talking)
(clear-collide-with-as (-> self root-override))
(clear-collide-with-as (-> self root))
(ja-channel-set! 0)
(the-as int (ja-post))
)
@@ -696,7 +688,7 @@
(else
(ja-channel-set! 1)
(ja :group! (get-art-elem self))
(restore-collide-with-as (-> self root-override))
(restore-collide-with-as (-> self root))
(process-entity-status! self (entity-perm-status bit-3) #t)
(let ((v1-7 (-> self draw shadow-ctrl)))
(logclear! (-> v1-7 settings flags) (shadow-flags disable-draw))
@@ -728,13 +720,11 @@
;; definition for method 50 of type process-taskable
;; WARN: disable def twice: 4. This may happen when a cond (no else) is nested inside of another conditional, but it should be rare.
(defmethod process-taskable-method-50 process-taskable ((this process-taskable))
(defmethod process-taskable-method-50 ((this process-taskable))
(if *target*
(or (not *target*)
(< 245760.0 (vector-vector-distance (-> this root-override trans) (-> *target* control trans)))
)
(or (not *target*) (< 245760.0 (vector-vector-distance (-> this root trans) (-> *target* control trans))))
(< 60397978000.0
(vector-vector-distance-squared (the-as vector (-> this root-override root-prim prim-core)) (camera-pos))
(vector-vector-distance-squared (the-as vector (-> this root root-prim prim-core)) (camera-pos))
)
)
)
@@ -816,7 +806,7 @@
(logior! (-> self mask) (process-mask actor-pause))
(let ((v1-6 (-> self entity extra trans)))
(if v1-6
(set! (-> self root-override trans quad) (-> v1-6 quad))
(set! (-> self root trans quad) (-> v1-6 quad))
)
)
(ja-channel-set! 0)
@@ -833,7 +823,7 @@
)
;; definition for method 47 of type process-taskable
(defmethod target-above-threshold? process-taskable ((this process-taskable))
(defmethod target-above-threshold? ((this process-taskable))
#t
)
@@ -856,15 +846,10 @@
)
)
(('touch)
(the-as symbol (send-shove-back
(-> self root-override)
proc
(the-as touching-shapes-entry (-> block param 0))
0.7
6144.0
16384.0
)
)
(the-as
symbol
(send-shove-back (-> self root) proc (the-as touching-shapes-entry (-> block param 0)) 0.7 6144.0 16384.0)
)
)
(('clone)
(the-as symbol (go-virtual be-clone (the-as handle (-> block param 0))))
@@ -921,10 +906,8 @@
(not (logtest? (-> *target* control status) (cshape-moving-flags onsurf)))
)
)
(< (-> (target-pos 0) y) (+ 8192.0 (-> self root-override root-prim prim-core world-sphere y)))
(< (vector-vector-distance (target-pos 0) (the-as vector (-> self root-override root-prim prim-core)))
32768.0
)
(< (-> (target-pos 0) y) (+ 8192.0 (-> self root root-prim prim-core world-sphere y)))
(< (vector-vector-distance (target-pos 0) (the-as vector (-> self root root-prim prim-core))) 32768.0)
(= (-> *level* loading-level) (-> *level* level-default))
(not (movie?))
(not (level-hint-displayed?))
@@ -1007,7 +990,7 @@
;; definition for method 41 of type process-taskable
;; INFO: Return type mismatch int vs none.
(defmethod initialize-collision process-taskable ((this process-taskable) (arg0 int) (arg1 vector))
(defmethod initialize-collision ((this process-taskable) (arg0 int) (arg1 vector))
(let ((s5-0 (new 'process 'collide-shape this (collide-list-enum hit-by-player))))
(let ((s4-0 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
(set! (-> s4-0 prim-core collide-as) (collide-kind enemy))
@@ -1020,7 +1003,7 @@
)
(set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
(backup-collide-with-as s5-0)
(set! (-> this root-override) s5-0)
(set! (-> this root) s5-0)
)
0
(none)
@@ -1028,14 +1011,14 @@
;; definition for method 40 of type process-taskable
;; INFO: Return type mismatch int vs none.
(defmethod process-taskable-method-40 process-taskable ((this process-taskable) (arg0 object) (arg1 skeleton-group) (arg2 int) (arg3 int) (arg4 vector) (arg5 int))
(defmethod process-taskable-method-40 ((this process-taskable) (arg0 object) (arg1 skeleton-group) (arg2 int) (arg3 int) (arg4 vector) (arg5 int))
(stack-size-set! (-> this main-thread) 512)
(initialize-collision this arg2 arg4)
(process-drawable-from-entity! this (the-as entity-actor arg0))
(initialize-skeleton this arg1 '())
(set! (-> this shadow-backup) (-> this draw shadow))
(logior! (-> this skel status) (janim-status eye))
(set! (-> this root-override pause-adjust-distance) -122880.0)
(set! (-> this root pause-adjust-distance) -122880.0)
(set! (-> this fuel-cell-anim) (fuel-cell-pick-anim this))
(set! (-> this draw origin-joint-index) (the-as uint arg2))
(set! (-> this draw shadow-joint-index) (the-as uint arg2))
@@ -1065,7 +1048,7 @@
;; definition for method 42 of type process-taskable
;; INFO: Return type mismatch object vs none.
(defmethod process-taskable-method-42 process-taskable ((this process-taskable))
(defmethod process-taskable-method-42 ((this process-taskable))
(cond
((not (should-display? this))
(go (method-of-object this hidden))
@@ -1082,20 +1065,20 @@
;; definition for method 43 of type process-taskable
;; INFO: Return type mismatch int vs symbol.
(defmethod process-taskable-method-43 process-taskable ((this process-taskable))
(defmethod process-taskable-method-43 ((this process-taskable))
(the-as symbol 0)
)
;; definition for method 9 of type ambient-control
;; INFO: Return type mismatch int vs none.
(defmethod ambient-control-method-9 ambient-control ((this ambient-control))
(defmethod ambient-control-method-9 ((this ambient-control))
(set! (-> this last-ambient-time) (-> *display* game-frame-counter))
0
(none)
)
;; definition for method 10 of type ambient-control
(defmethod ambient-control-method-10 ambient-control ((this ambient-control) (arg0 vector) (arg1 time-frame) (arg2 float) (arg3 process-drawable))
(defmethod ambient-control-method-10 ((this ambient-control) (arg0 vector) (arg1 time-frame) (arg2 float) (arg3 process-drawable))
(when (< (- (-> *display* game-frame-counter) (-> this last-ambient-time)) arg1)
(set! arg0 (the-as vector #f))
(goto cfg-6)
@@ -1110,7 +1093,7 @@
)
;; definition for method 11 of type ambient-control
(defmethod play-ambient ambient-control ((this ambient-control) (arg0 string) (arg1 symbol) (arg2 vector))
(defmethod play-ambient ((this ambient-control) (arg0 string) (arg1 symbol) (arg2 vector))
(when (and (not (string= arg0 (-> this last-ambient)))
(or arg1 (can-hint-be-played? (text-id one) (the-as entity #f) (the-as string #f)))
(= (-> *level* loading-level) (-> *level* level-default))
@@ -1220,7 +1203,7 @@
(format #t "ERROR<GMJ>: othercam parent invalid~%")
(deactivate self)
)
(set! (-> *camera-other-root* quad) (-> (the-as process-taskable s2-0) root-override trans quad))
(set! (-> *camera-other-root* quad) (-> (the-as process-taskable s2-0) root trans quad))
(let ((s4-0 (-> (the-as process-taskable s2-0) node-list data (-> self cam-joint-index) bone transform))
(s3-0 (-> (the-as process-taskable s2-0) node-list data (-> self cam-joint-index) bone scale))
(gp-0 (new 'stack-no-clear 'vector))
@@ -1304,7 +1287,7 @@
;; definition for method 48 of type process-taskable
;; INFO: Return type mismatch object vs none.
(defmethod draw-npc-shadow process-taskable ((this process-taskable))
(defmethod draw-npc-shadow ((this process-taskable))
(let ((gp-0 (-> this draw shadow-ctrl)))
(cond
((and (-> this draw shadow)