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
+89 -113
View File
@@ -6,25 +6,22 @@
;; 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 none) :offset-assert 48)
(joypad-item basic :offset-assert 52)
(font font-context :offset-assert 56)
(is-hidden symbol :offset-assert 60)
((is-active symbol)
(sel-length int32)
(sel-menu debug-menu 8)
(root-menu debug-menu)
(joypad-func (function basic none))
(joypad-item basic)
(font font-context)
(is-hidden symbol)
)
:method-count-assert 9
:size-assert #x40
:flag-assert #x900000040
(: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))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tis-active: ~A~%" (-> this is-active))
(format #t "~Tsel-length: ~D~%" (-> this sel-length))
@@ -55,18 +52,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))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tparent: ~A~%" (-> this parent))
@@ -76,29 +70,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))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tparent: ~A~%" (-> this parent))
@@ -126,15 +117,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))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tparent: ~A~%" (-> this parent))
@@ -146,18 +134,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))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tparent: ~A~%" (-> this parent))
@@ -183,19 +168,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))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tparent: ~A~%" (-> this parent))
@@ -223,19 +205,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))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tparent: ~A~%" (-> this parent))
@@ -268,43 +247,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))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tname: ~A~%" (-> this name))
(format #t "~Tparent: ~A~%" (-> this parent))
@@ -477,14 +453,14 @@
)
;; definition for function debug-menu-context-grab-joypad
(defun debug-menu-context-grab-joypad ((menu debug-menu-context) (callback-arg basic) (callback-func (function basic none)))
(defun debug-menu-context-grab-joypad ((ctxt debug-menu-context) (callback-arg basic) (callback-func (function basic none)))
(cond
((-> menu joypad-func)
((-> ctxt joypad-func)
#f
)
(else
(set! (-> menu joypad-func) callback-func)
(set! (-> menu joypad-item) callback-arg)
(set! (-> ctxt joypad-func) callback-func)
(set! (-> ctxt joypad-item) callback-arg)
#t
)
)
@@ -1058,32 +1034,32 @@
)
;; definition for function debug-menu-item-render
(defun debug-menu-item-render ((arg0 debug-menu-item) (arg1 int) (arg2 int) (arg3 int) (arg4 symbol))
(when (> (-> arg0 refresh-delay) 0)
(+! (-> arg0 refresh-ctr) -1)
(when (<= (-> arg0 refresh-ctr) 0)
(set! (-> arg0 refresh-ctr) (-> arg0 refresh-delay))
(debug-menu-item-send-msg arg0 (debug-menu-msg update))
(defun debug-menu-item-render ((item debug-menu-item) (x int) (y int) (submenus int) (selected symbol))
(when (> (-> item refresh-delay) 0)
(+! (-> item refresh-ctr) -1)
(when (<= (-> item refresh-ctr) 0)
(set! (-> item refresh-ctr) (-> item refresh-delay))
(debug-menu-item-send-msg item (debug-menu-msg update))
)
)
(cond
((= (-> arg0 type) debug-menu-item-submenu)
(debug-menu-item-submenu-render (the-as debug-menu-item-submenu arg0) arg1 arg2 arg3 arg4)
((= (-> item type) debug-menu-item-submenu)
(debug-menu-item-submenu-render (the-as debug-menu-item-submenu item) x y submenus selected)
)
((= (-> arg0 type) debug-menu-item-function)
(debug-menu-item-function-render (the-as debug-menu-item-function arg0) arg1 arg2 arg3 arg4)
((= (-> item type) debug-menu-item-function)
(debug-menu-item-function-render (the-as debug-menu-item-function item) x y submenus selected)
)
((= (-> arg0 type) debug-menu-item-flag)
(debug-menu-item-flag-render (the-as debug-menu-item-flag arg0) arg1 arg2 arg3 arg4)
((= (-> item type) debug-menu-item-flag)
(debug-menu-item-flag-render (the-as debug-menu-item-flag item) x y submenus selected)
)
((= (-> arg0 type) debug-menu-item-var)
(debug-menu-item-var-render (the-as debug-menu-item-var arg0) arg1 arg2 arg3 arg4)
((= (-> item type) debug-menu-item-var)
(debug-menu-item-var-render (the-as debug-menu-item-var item) x y submenus selected)
)
(else
(format 0 "ERROR: Found unknown item type!~%")
)
)
arg0
item
)
;; definition for function debug-menu-render
@@ -1175,13 +1151,13 @@
;; definition for function debug-menu-context-render
(defun debug-menu-context-render ((arg0 debug-menu-context))
(let ((s4-0 6))
(dotimes (s5-0 (-> arg0 sel-length))
(let ((s3-0 (-> arg0 sel-menu s5-0)))
(let ((a3-0 (-> s3-0 selected-item)))
(debug-menu-render s3-0 s4-0 28 a3-0 (+ (- -1 s5-0) (-> arg0 sel-length)))
(let ((x-pos 6))
(dotimes (stack-idx (-> arg0 sel-length))
(let ((menu (-> arg0 sel-menu stack-idx)))
(let ((selection (-> menu selected-item)))
(debug-menu-render menu x-pos 28 selection (+ (- -1 stack-idx) (-> arg0 sel-length)))
)
(set! s4-0 (+ s4-0 3 (-> s3-0 pix-width)))
(set! x-pos (+ x-pos 3 (-> menu pix-width)))
)
)
)