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
+65 -89
View File
@@ -6,26 +6,23 @@
;; definition of type debug-menu-context
(deftype debug-menu-context (basic)
((is-active symbol :offset-assert 4)
(sel-length int32 :offset-assert 8)
(sel-menu debug-menu 8 :offset-assert 12)
(root-menu debug-menu :offset-assert 44)
(joypad-func (function basic int none) :offset-assert 48)
(joypad-item basic :offset-assert 52)
(font font-context :offset-assert 56)
(is-hidden symbol :offset-assert 60)
(joypad-number int32 :offset-assert 64)
((is-active symbol)
(sel-length int32)
(sel-menu debug-menu 8)
(root-menu debug-menu)
(joypad-func (function basic int none))
(joypad-item basic)
(font font-context)
(is-hidden symbol)
(joypad-number int32)
)
:method-count-assert 9
:size-assert #x44
:flag-assert #x900000044
(:methods
(new (symbol type) _type_ 0)
(new (symbol type) _type_)
)
)
;; definition for method 3 of type debug-menu-context
(defmethod inspect debug-menu-context ((this debug-menu-context))
(defmethod inspect ((this debug-menu-context))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -63,18 +60,15 @@
;; definition of type debug-menu-node
(deftype debug-menu-node (basic)
((name string :offset-assert 4)
(parent debug-menu :offset-assert 8)
(refresh-delay int32 :offset-assert 12)
(refresh-ctr int32 :offset-assert 16)
((name string)
(parent debug-menu)
(refresh-delay int32)
(refresh-ctr int32)
)
:method-count-assert 9
:size-assert #x14
:flag-assert #x900000014
)
;; definition for method 3 of type debug-menu-node
(defmethod inspect debug-menu-node ((this debug-menu-node))
(defmethod inspect ((this debug-menu-node))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -89,29 +83,26 @@
)
;; definition for method 2 of type debug-menu-node
(defmethod print debug-menu-node ((this debug-menu-node))
(defmethod print ((this debug-menu-node))
(format #t "#<~A ~A @ #x~X>" (-> this type) (-> this name) this)
this
)
;; definition of type debug-menu
(deftype debug-menu (debug-menu-node)
((context debug-menu-context :offset-assert 20)
(selected-item debug-menu-item :offset-assert 24)
(pix-width int32 :offset-assert 28)
(pix-height int32 :offset-assert 32)
(items pair :offset-assert 36)
((context debug-menu-context)
(selected-item debug-menu-item)
(pix-width int32)
(pix-height int32)
(items pair)
)
:method-count-assert 9
:size-assert #x28
:flag-assert #x900000028
(:methods
(new (symbol type debug-menu-context string) _type_ 0)
(new (symbol type debug-menu-context string) _type_)
)
)
;; definition for method 3 of type debug-menu
(defmethod inspect debug-menu ((this debug-menu))
(defmethod inspect ((this debug-menu))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -144,15 +135,12 @@
;; definition of type debug-menu-item
(deftype debug-menu-item (debug-menu-node)
((id int32 :offset-assert 20)
((id int32)
)
:method-count-assert 9
:size-assert #x18
:flag-assert #x900000018
)
;; definition for method 3 of type debug-menu-item
(defmethod inspect debug-menu-item ((this debug-menu-item))
(defmethod inspect ((this debug-menu-item))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -169,18 +157,15 @@
;; definition of type debug-menu-item-submenu
(deftype debug-menu-item-submenu (debug-menu-item)
((submenu debug-menu :offset-assert 24)
((submenu debug-menu)
)
:method-count-assert 9
:size-assert #x1c
:flag-assert #x90000001c
(:methods
(new (symbol type string debug-menu) _type_ 0)
(new (symbol type string debug-menu) _type_)
)
)
;; definition for method 3 of type debug-menu-item-submenu
(defmethod inspect debug-menu-item-submenu ((this debug-menu-item-submenu))
(defmethod inspect ((this debug-menu-item-submenu))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -211,19 +196,16 @@
;; definition of type debug-menu-item-function
(deftype debug-menu-item-function (debug-menu-item)
((activate-func (function object object) :offset-assert 24)
(hilite-timer int8 :offset-assert 28)
((activate-func (function object object))
(hilite-timer int8)
)
:method-count-assert 9
:size-assert #x1d
:flag-assert #x90000001d
(:methods
(new (symbol type string object (function object object)) _type_ 0)
(new (symbol type string object (function object object)) _type_)
)
)
;; definition for method 3 of type debug-menu-item-function
(defmethod inspect debug-menu-item-function ((this debug-menu-item-function))
(defmethod inspect ((this debug-menu-item-function))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -256,19 +238,16 @@
;; definition of type debug-menu-item-flag
(deftype debug-menu-item-flag (debug-menu-item)
((activate-func (function object debug-menu-msg object) :offset-assert 24)
(is-on object :offset-assert 28)
((activate-func (function object debug-menu-msg object))
(is-on object)
)
:method-count-assert 9
:size-assert #x20
:flag-assert #x900000020
(:methods
(new (symbol type string object (function object debug-menu-msg object)) _type_ 0)
(new (symbol type string object (function object debug-menu-msg object)) _type_)
)
)
;; definition for method 3 of type debug-menu-item-flag
(defmethod inspect debug-menu-item-flag ((this debug-menu-item-flag))
(defmethod inspect ((this debug-menu-item-flag))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -306,43 +285,40 @@
;; definition of type debug-menu-item-var
(deftype debug-menu-item-var (debug-menu-item)
((display-str string :offset-assert 24)
(grabbed-joypad-p symbol :offset-assert 28)
(float-p symbol :offset-assert 32)
(range-p symbol :offset-assert 36)
(show-len int32 :offset-assert 40)
(inc-delay int32 :offset-assert 44)
(inc-delay-ctr int32 :offset-assert 48)
(step-delay-ctr int32 :offset-assert 52)
(inc-dir int32 :offset-assert 56)
(fval float :offset-assert 60)
(fundo-val float :offset-assert 64)
(frange-min float :offset-assert 68)
(frange-max float :offset-assert 72)
(fstart-inc float :offset-assert 76)
(fstep float :offset-assert 80)
(fprecision int32 :offset-assert 84)
(factivate-func (function int debug-menu-msg float float float) :offset-assert 88)
(ival int32 :offset 60)
(iundo-val int32 :offset 64)
(irange-min int32 :offset 68)
(irange-max int32 :offset 72)
(istart-inc int32 :offset 76)
(istep int32 :offset 80)
(ihex-p symbol :offset-assert 92)
(iactivate-func (function int debug-menu-msg int int int) :offset 88)
(ifloat-p symbol :offset-assert 96)
((display-str string)
(grabbed-joypad-p symbol)
(float-p symbol)
(range-p symbol)
(show-len int32)
(inc-delay int32)
(inc-delay-ctr int32)
(step-delay-ctr int32)
(inc-dir int32)
(fval float)
(fundo-val float)
(frange-min float)
(frange-max float)
(fstart-inc float)
(fstep float)
(fprecision int32)
(factivate-func (function int debug-menu-msg float float float))
(ival int32 :overlay-at fval)
(iundo-val int32 :overlay-at fundo-val)
(irange-min int32 :overlay-at frange-min)
(irange-max int32 :overlay-at frange-max)
(istart-inc int32 :overlay-at fstart-inc)
(istep int32 :overlay-at fstep)
(ihex-p symbol)
(iactivate-func (function int debug-menu-msg int int int) :overlay-at factivate-func)
(ifloat-p symbol)
)
:method-count-assert 9
:size-assert #x64
:flag-assert #x900000064
(:methods
(new (symbol type string int int) _type_ 0)
(new (symbol type string int int) _type_)
)
)
;; definition for method 3 of type debug-menu-item-var
(defmethod inspect debug-menu-item-var ((this debug-menu-item-var))
(defmethod inspect ((this debug-menu-item-var))
(when (not this)
(set! this this)
(goto cfg-4)