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
+97 -104
View File
@@ -8,57 +8,54 @@
;; DECOMP BEGINS
(deftype progress-global-state (basic)
((aspect-ratio-choice symbol :offset-assert 4)
(video-mode-choice symbol :offset-assert 8)
(yes-no-choice symbol :offset-assert 12)
(on-off-choice symbol :offset-assert 16)
(which-slot int32 :offset-assert 20)
(starting-state symbol :offset-assert 24)
(last-slot-saved int32 :offset-assert 28)
(slider-backup float :offset-assert 32)
(language-backup language-enum :offset-assert 40)
(center-x-backup int32 :offset-assert 48)
(center-y-backup int32 :offset-assert 52)
(aspect-ratio-backup symbol :offset-assert 56)
(last-slider-sound time-frame :offset-assert 64)
(video-mode-timeout time-frame :offset-assert 72)
(progressive-mode-timeout time-frame :offset-assert 80)
(current-task-index int32 :offset-assert 88)
(current-line-index int32 :offset-assert 92)
(first-closed-line-index int32 :offset-assert 96)
(extra-text-state int32 :offset-assert 100)
(current-task uint8 :offset-assert 104)
(num-open-tasks-found int32 :offset-assert 108)
(num-closed-tasks-found int32 :offset-assert 112)
(color-flash-counter int32 :offset-assert 116)
(num-unlocked-secrets int32 :offset-assert 120)
(game-options-item-selected int32 :offset-assert 124)
(game-options-item-picked basic :offset-assert 128)
(game-options-last-move time-frame :offset-assert 136)
(game-options-vibrations symbol :offset-assert 144)
(game-options-subtitles symbol :offset-assert 148)
(game-options-language-index int32 :offset-assert 152)
(game-options-subtitle-language-index int32 :offset-assert 156)
(graphic-options-item-selected int32 :offset-assert 160)
(graphic-options-item-picked symbol :offset-assert 164)
(graphic-options-last-move time-frame :offset-assert 168)
(graphic-options-aspect-ratio symbol :offset-assert 176)
(graphic-options-progressive-scan symbol :offset-assert 180)
(qr-options-item-selected int32 :offset-assert 184)
(qr-options-item-picked basic :offset-assert 188)
(qr-options-last-move time-frame :offset-assert 192)
(qr-options-restart basic :offset-assert 200)
(qr-options-quit basic :offset-assert 204)
(total-num-tasks int32 :offset-assert 208)
(scene-player-act int32 :offset-assert 212)
(stereo-mode-backup int32 :offset-assert 216)
(secrets-unlocked symbol :offset-assert 220)
(missions-total-spacing float :offset-assert 224)
(clear-screen symbol :offset-assert 228)
((aspect-ratio-choice symbol)
(video-mode-choice symbol)
(yes-no-choice symbol)
(on-off-choice symbol)
(which-slot int32)
(starting-state symbol)
(last-slot-saved int32)
(slider-backup float)
(language-backup language-enum)
(center-x-backup int32)
(center-y-backup int32)
(aspect-ratio-backup symbol)
(last-slider-sound time-frame)
(video-mode-timeout time-frame)
(progressive-mode-timeout time-frame)
(current-task-index int32)
(current-line-index int32)
(first-closed-line-index int32)
(extra-text-state int32)
(current-task uint8)
(num-open-tasks-found int32)
(num-closed-tasks-found int32)
(color-flash-counter int32)
(num-unlocked-secrets int32)
(game-options-item-selected int32)
(game-options-item-picked basic)
(game-options-last-move time-frame)
(game-options-vibrations symbol)
(game-options-subtitles symbol)
(game-options-language-index int32)
(game-options-subtitle-language-index int32)
(graphic-options-item-selected int32)
(graphic-options-item-picked symbol)
(graphic-options-last-move time-frame)
(graphic-options-aspect-ratio symbol)
(graphic-options-progressive-scan symbol)
(qr-options-item-selected int32)
(qr-options-item-picked basic)
(qr-options-last-move time-frame)
(qr-options-restart basic)
(qr-options-quit basic)
(total-num-tasks int32)
(scene-player-act int32)
(stereo-mode-backup int32)
(secrets-unlocked symbol)
(missions-total-spacing float)
(clear-screen symbol)
)
:method-count-assert 9
:size-assert #xe8
:flag-assert #x9000000e8
)
@@ -103,7 +100,7 @@
(set-master-mode 'game)
0)
(defmethod init-defaults progress ((this progress))
(defmethod init-defaults ((this progress))
"Initialize default menu settings."
(set! (-> *progress-state* aspect-ratio-choice) (get-aspect-ratio))
(set! (-> *progress-state* video-mode-choice) (get-video-mode))
@@ -174,16 +171,12 @@
(deftype hud-ring-cell (process-drawable)
((parent (pointer progress) :override)
(joint-idx int32 :offset-assert 200)
(init-angle degrees :offset-assert 204)
(graphic-index int32 :offset-assert 208)
(joint-idx int32)
(init-angle degrees)
(graphic-index int32)
)
:heap-base #x60
:method-count-assert 21
:size-assert #xd4
:flag-assert #x15006000d4
(:methods
(idle () _type_ :state 20)
(:state-methods
idle
)
)
@@ -462,7 +455,7 @@
(none)
)
(defmethod deactivate progress ((this progress))
(defmethod deactivate ((this progress))
(remove-setting-by-arg0 *setting-control* 'extra-bank)
(disable-drawing *bigmap*)
(set! (-> *blit-displays-work* menu-mode) #f)
@@ -490,7 +483,7 @@
(none)
)
(defmethod gone? progress ((this progress))
(defmethod gone? ((this progress))
(and *progress-process*
(-> *progress-process* 0 next-state)
(= (-> *progress-process* 0 next-state name) 'gone)
@@ -522,7 +515,7 @@
)
)
(defmethod can-go-back? progress ((this progress))
(defmethod can-go-back? ((this progress))
(and (= (-> this menu-transition) 0.0)
(not (-> this selected-option))
(!= (-> this current) 'loading)
@@ -580,7 +573,7 @@
(none)
)
(defmethod get-state-check-card progress ((this progress) (arg0 symbol))
(defmethod get-state-check-card ((this progress) (arg0 symbol))
(let ((v1-0 *progress-save-info*)
(v0-0 arg0)
)
@@ -677,7 +670,7 @@
)
)
(defmethod push-state progress ((this progress))
(defmethod push-state ((this progress))
(let ((v1-0 (-> this state-pos)))
(cond
((< v1-0 5)
@@ -693,7 +686,7 @@
0
)
(defmethod pop-state progress ((this progress))
(defmethod pop-state ((this progress))
(let ((v1-0 (-> this state-pos)))
(cond
((> v1-0 0)
@@ -716,7 +709,7 @@
0
)
(defmethod set-next-state progress ((this progress) (arg0 symbol) (arg1 int))
(defmethod set-next-state ((this progress) (arg0 symbol) (arg1 int))
"Set the next menu state specified by arg0 at the index specified by arg1."
(set! (-> *progress-state* clear-screen) #f)
(when (!= arg0 (-> this current))
@@ -762,7 +755,7 @@
0
)
(defmethod set-menu-options progress ((this progress) (arg0 symbol))
(defmethod set-menu-options ((this progress) (arg0 symbol))
"Set the menu options for the menu state specified by arg0."
(set! (-> this current-options) #f)
(case arg0
@@ -969,7 +962,7 @@
0
)
(defmethod respond-to-cpad progress ((this progress))
(defmethod respond-to-cpad ((this progress))
(mc-get-slot-info 0 *progress-save-info*)
(when (-> this current-options)
(let ((option-array (-> this current-options options)))
@@ -1715,12 +1708,12 @@
)
)
(defmethod respond-progress menu-option ((this menu-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
0
)
(defmethod respond-progress menu-on-off-option ((this menu-on-off-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-on-off-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(let ((v1-1 (&-> *progress-state* on-off-choice))
(gp-0 #f)
@@ -1770,7 +1763,7 @@
0
)
(defmethod respond-progress menu-yes-no-option ((this menu-yes-no-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-yes-no-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(let ((v1-1 (&-> *progress-state* yes-no-choice))
(gp-0 #f)
@@ -1811,7 +1804,7 @@
0
)
(defmethod respond-progress menu-slider-option ((this menu-slider-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-slider-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(when (-> *bigmap* progress-minimap)
(let ((gp-0 (-> this value-to-modify))
@@ -1893,7 +1886,7 @@
0
)
(defmethod respond-progress menu-stereo-mode-sound-option ((this menu-stereo-mode-sound-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-stereo-mode-sound-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(when (-> *bigmap* progress-minimap)
(let ((a0-1 (-> *setting-control* user-default stereo-mode))
@@ -1931,7 +1924,7 @@
0
)
(defmethod respond-progress menu-main-menu-option ((this menu-main-menu-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-main-menu-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(cond
((cpad-pressed? 0 start)
@@ -2026,7 +2019,7 @@
0
)
(defmethod respond-progress menu-sub-menu-option ((this menu-sub-menu-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-sub-menu-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(when (and (-> *progress-state* secrets-unlocked)
(not (memcard-unlocked-secrets? #f))
@@ -2086,7 +2079,7 @@
0
)
(defmethod respond-progress menu-unlocked-menu-option ((this menu-unlocked-menu-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-unlocked-menu-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(let ((s4-0 (memcard-unlocked-secrets? #t)))
(logclear! (-> *game-info* purchase-secrets) (game-secrets hero-mode))
@@ -2223,7 +2216,7 @@
0
)
(defmethod respond-progress menu-memcard-slot-option ((this menu-memcard-slot-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-memcard-slot-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(memcard-unlocked-secrets? #t)
(let ((a1-2 (get-state-check-card arg0 (-> arg0 current))))
@@ -2268,7 +2261,7 @@
0
)
(defmethod respond-progress menu-already-exists-option ((this menu-already-exists-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-already-exists-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(let ((s4-0 (&-> *progress-state* yes-no-choice))
(a1-2 (get-state-check-card arg0 'select-save))
@@ -2310,7 +2303,7 @@
0
)
(defmethod respond-progress menu-create-game-option ((this menu-create-game-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-create-game-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(let ((s4-0 (&-> *progress-state* yes-no-choice))
(gp-0 #f)
@@ -2355,7 +2348,7 @@
0
)
(defmethod respond-progress menu-insufficient-space-option ((this menu-insufficient-space-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-insufficient-space-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(let ((s5-0 (&-> *progress-state* yes-no-choice))
(s3-0 (get-state-check-card arg0 'select-save))
@@ -2450,7 +2443,7 @@
0
)
(defmethod respond-progress menu-secrets-insufficient-space-option ((this menu-secrets-insufficient-space-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-secrets-insufficient-space-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(&-> *progress-state* yes-no-choice)
(cond
@@ -2468,7 +2461,7 @@
0
)
(defmethod respond-progress menu-video-mode-warning-option ((this menu-video-mode-warning-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-video-mode-warning-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(let ((v1-1 (&-> *progress-state* yes-no-choice))
(gp-0 #f)
@@ -2506,7 +2499,7 @@
0
)
(defmethod respond-progress menu-video-mode-ok-option ((this menu-video-mode-ok-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-video-mode-ok-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(let ((v1-1 (&-> *progress-state* yes-no-choice))
(s5-0 #f)
@@ -2552,7 +2545,7 @@
0
)
(defmethod respond-progress menu-progressive-mode-warning-option ((this menu-progressive-mode-warning-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-progressive-mode-warning-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(let ((v1-1 (&-> *progress-state* yes-no-choice))
(gp-0 #f)
@@ -2597,7 +2590,7 @@
0
)
(defmethod respond-progress menu-progressive-mode-ok-option ((this menu-progressive-mode-ok-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-progressive-mode-ok-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(let ((v1-1 (&-> *progress-state* yes-no-choice))
(s5-0 #f)
@@ -2645,7 +2638,7 @@
0
)
(defmethod respond-progress menu-card-removed-option ((this menu-card-removed-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-card-removed-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(when (cpad-pressed? 0 confirm)
(logclear! (-> *cpad-list* cpads 0 button0-abs 0) (pad-buttons confirm))
@@ -2656,7 +2649,7 @@
0
)
(defmethod respond-progress menu-insert-card-option ((this menu-insert-card-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-insert-card-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
*progress-save-info*
(cond
@@ -2673,7 +2666,7 @@
0
)
(defmethod respond-progress menu-error-loading-option ((this menu-error-loading-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-error-loading-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(when (cpad-pressed? 0 confirm)
(logclear! (-> *cpad-list* cpads 0 button0-abs 0) (pad-buttons confirm))
@@ -2684,7 +2677,7 @@
0
)
(defmethod respond-progress menu-error-auto-saving-option ((this menu-error-auto-saving-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-error-auto-saving-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(when (cpad-pressed? 0 confirm)
(logclear! (-> *cpad-list* cpads 0 button0-abs 0) (pad-buttons confirm))
@@ -2695,7 +2688,7 @@
0
)
(defmethod respond-progress menu-error-disc-removed-option ((this menu-error-disc-removed-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-error-disc-removed-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(when (cpad-pressed? 0 confirm)
(logclear! (-> *cpad-list* cpads 0 button0-abs 0) (pad-buttons confirm))
@@ -2708,7 +2701,7 @@
0
)
(defmethod respond-progress menu-error-reading-option ((this menu-error-reading-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-error-reading-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(when (cpad-pressed? 0 confirm)
(logclear! (-> *cpad-list* cpads 0 button0-abs 0) (pad-buttons confirm))
@@ -2719,7 +2712,7 @@
0
)
(defmethod respond-progress menu-icon-info-option ((this menu-icon-info-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-icon-info-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(when (cpad-pressed? 0 confirm)
(logclear! (-> *cpad-list* cpads 0 button0-abs 0) (pad-buttons confirm))
@@ -2730,7 +2723,7 @@
0
)
(defmethod respond-progress menu-quit-option ((this menu-quit-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-quit-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(let ((v1-1 (&-> *progress-state* yes-no-choice))
(gp-0 #f)
@@ -2774,7 +2767,7 @@
0
)
(defmethod respond-progress menu-format-card-option ((this menu-format-card-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-format-card-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(let ((s4-0 (&-> *progress-state* yes-no-choice))
(gp-0 #f)
@@ -2819,7 +2812,7 @@
)
;; WARN: disable def twice: 110. This may happen when a cond (no else) is nested inside of another conditional, but it should be rare.
(defmethod respond-progress menu-select-start-option ((this menu-select-start-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-select-start-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(set! (-> arg0 sliding-height) (seek-ease
(-> arg0 sliding-height)
@@ -2950,7 +2943,7 @@
0
)
(defmethod respond-progress menu-select-scene-option ((this menu-select-scene-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-select-scene-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(set! (-> arg0 sliding-height) (seek-ease
(-> arg0 sliding-height)
@@ -3025,7 +3018,7 @@
0
)
(defmethod respond-progress menu-bigmap-option ((this menu-bigmap-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-bigmap-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(handle-cpad-inputs *bigmap*)
(logclear! (-> *cpad-list* cpads 0 button0-abs 0) (pad-buttons confirm))
@@ -3033,7 +3026,7 @@
0
)
(defmethod respond-progress menu-missions-option ((this menu-missions-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-missions-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(set! (-> arg0 sliding-height) (seek-ease
(-> arg0 sliding-height)
@@ -3082,7 +3075,7 @@
0
)
(defmethod respond-progress menu-highscores-option ((this menu-highscores-option) (progress progress) (selected? symbol))
(defmethod respond-progress ((this menu-highscores-option) (progress progress) (selected? symbol))
"Handle progress menu navigation logic."
(set! (-> progress sliding) (seek-ease
(-> progress sliding)
@@ -3149,7 +3142,7 @@
0
)
(defmethod respond-progress menu-secret-option ((this menu-secret-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-secret-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(let* ((s5-1 (logtest? (-> *game-info* secrets) (game-secrets hero-mode)))
(s3-0 (if (not s5-1)
@@ -3267,7 +3260,7 @@
0
)
(defmethod respond-progress menu-game-option ((this menu-game-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-game-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(-> *progress-state* game-options-vibrations)
(-> *progress-state* game-options-subtitles)
@@ -3488,7 +3481,7 @@
0
)
(defmethod respond-progress menu-graphic-option ((this menu-graphic-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-graphic-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(-> *progress-state* graphic-options-aspect-ratio)
(-> *progress-state* graphic-options-progressive-scan)
@@ -3700,7 +3693,7 @@
0
)
(defmethod respond-progress menu-qr-option ((this menu-qr-option) (arg0 progress) (arg1 symbol))
(defmethod respond-progress ((this menu-qr-option) (arg0 progress) (arg1 symbol))
"Handle progress menu navigation logic."
(-> *progress-state* qr-options-restart)
(-> *progress-state* qr-options-quit)