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
+79 -82
View File
@@ -2,7 +2,7 @@
(in-package goal)
;; definition for method 8 of type subtitle-range
(defmethod mem-usage subtitle-range ((this subtitle-range) (arg0 memory-usage-block) (arg1 int))
(defmethod mem-usage ((this subtitle-range) (arg0 memory-usage-block) (arg1 int))
(set! (-> arg0 length) (max 73 (-> arg0 length)))
(set! (-> arg0 data 72 name) "subtitle")
(+! (-> arg0 data 72 count) 1)
@@ -15,7 +15,7 @@
;; definition for method 3 of type load-dir
;; INFO: Used lq/sq
(defmethod inspect load-dir ((this load-dir))
(defmethod inspect ((this load-dir))
(local-vars (sv-16 basic))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tlevel: ~A~%" (-> this lev))
@@ -39,7 +39,7 @@
;; definition for method 8 of type load-dir
;; WARN: Return type mismatch symbol vs load-dir.
(defmethod mem-usage load-dir ((this load-dir) (arg0 memory-usage-block) (arg1 int))
(defmethod mem-usage ((this load-dir) (arg0 memory-usage-block) (arg1 int))
(set! (-> arg0 length) (max 85 (-> arg0 length)))
(set! (-> arg0 data 84 name) "array")
(+! (-> arg0 data 84 count) 1)
@@ -68,7 +68,7 @@
)
;; definition for method 9 of type load-dir-art-group
(defmethod load-to-heap-by-name load-dir-art-group ((this load-dir-art-group) (arg0 string) (arg1 symbol) (arg2 kheap) (arg3 int))
(defmethod load-to-heap-by-name ((this load-dir-art-group) (arg0 string) (arg1 symbol) (arg2 kheap) (arg3 int))
(let ((s5-0 (-> this string-array)))
(dotimes (s3-0 (-> s5-0 length))
(when (string= arg0 (-> s5-0 s3-0))
@@ -95,7 +95,7 @@
)
;; definition for method 10 of type load-dir-art-group
(defmethod set-loaded-art load-dir-art-group ((this load-dir-art-group) (arg0 art-group))
(defmethod set-loaded-art ((this load-dir-art-group) (arg0 art-group))
(let ((s4-0 (-> this string-array)))
(dotimes (s3-0 (-> s4-0 length))
(when (string= (-> arg0 name) (-> s4-0 s3-0))
@@ -179,7 +179,7 @@
)
;; definition for method 2 of type external-art-buffer
(defmethod print external-art-buffer ((this external-art-buffer))
(defmethod print ((this external-art-buffer))
(format
#t
"#<~A ~S ~D ~A @ #x~X>"
@@ -204,7 +204,7 @@
)
;; definition for method 9 of type external-art-buffer
(defmethod set-pending-file external-art-buffer ((this external-art-buffer) (arg0 string) (arg1 int) (arg2 handle) (arg3 float))
(defmethod set-pending-file ((this external-art-buffer) (arg0 string) (arg1 int) (arg2 handle) (arg3 float))
(set! (-> this pending-load-file) arg0)
(set! (-> this pending-load-file-part) arg1)
(set! (-> this pending-load-file-owner) arg2)
@@ -213,18 +213,18 @@
)
;; definition for method 15 of type external-art-buffer
(defmethod unlock! external-art-buffer ((this external-art-buffer))
(defmethod unlock! ((this external-art-buffer))
(set! (-> this locked?) #f)
0
)
;; definition for method 11 of type external-art-buffer
(defmethod inactive? external-art-buffer ((this external-art-buffer))
(defmethod inactive? ((this external-art-buffer))
(!= (-> this status) 'active)
)
;; definition for method 12 of type external-art-buffer
(defmethod file-status external-art-buffer ((this external-art-buffer) (arg0 string) (arg1 int))
(defmethod file-status ((this external-art-buffer) (arg0 string) (arg1 int))
(when (and (name= (-> this pending-load-file) arg0) (= (-> this pending-load-file-part) arg1))
(if (and (name= (-> this load-file) arg0) (= (-> this load-file-part) arg1))
(-> this status)
@@ -234,7 +234,7 @@
)
;; definition for method 13 of type art-group
(defmethod link-art! art-group ((this art-group))
(defmethod link-art! ((this art-group))
(when this
(countdown (s5-0 (-> this length))
(let* ((s3-0 (-> this data s5-0))
@@ -287,7 +287,7 @@
)
;; definition for method 14 of type art-group
(defmethod unlink-art! art-group ((this art-group))
(defmethod unlink-art! ((this art-group))
(when this
(countdown (s5-0 (-> this length))
(let* ((s3-0 (-> this data s5-0))
@@ -325,7 +325,7 @@
)
;; definition for method 13 of type external-art-buffer
(defmethod link-file external-art-buffer ((this external-art-buffer) (arg0 art-group))
(defmethod link-file ((this external-art-buffer) (arg0 art-group))
(when arg0
(link-art! arg0)
(set! (-> this art-group) arg0)
@@ -334,7 +334,7 @@
)
;; definition for method 14 of type external-art-buffer
(defmethod unlink-file external-art-buffer ((this external-art-buffer) (arg0 art-group))
(defmethod unlink-file ((this external-art-buffer) (arg0 art-group))
(when arg0
(unlink-art! arg0)
(set! (-> this art-group) #f)
@@ -344,7 +344,7 @@
;; definition for method 10 of type external-art-buffer
;; WARN: Found some very strange gotos. Check result carefully, this is not well tested.
(defmethod update external-art-buffer ((this external-art-buffer))
(defmethod update ((this external-art-buffer))
(when (or (not (name= (-> this pending-load-file) (-> this load-file)))
(!= (-> this pending-load-file-part) (-> this load-file-part))
)
@@ -530,7 +530,7 @@
(define *preload-spool-anims* #t)
;; definition for method 12 of type external-art-control
(defmethod file-status external-art-control ((this external-art-control) (arg0 string) (arg1 int))
(defmethod file-status ((this external-art-control) (arg0 string) (arg1 int))
(dotimes (s3-0 2)
(let ((v1-3 (file-status (-> this buffer s3-0) arg0 arg1)))
(if v1-3
@@ -542,7 +542,7 @@
)
;; definition for method 9 of type external-art-control
(defmethod update external-art-control ((this external-art-control) (arg0 symbol))
(defmethod update ((this external-art-control) (arg0 symbol))
(if (nonzero? (-> this reserve-buffer-count))
(spool-push this "reserved" 0 *dproc* (if (-> this reserve-buffer)
-110.0
@@ -667,12 +667,12 @@
)
;; definition for method 15 of type external-art-control
(defmethod none-reserved? external-art-control ((this external-art-control))
(defmethod none-reserved? ((this external-art-control))
(zero? (-> this reserve-buffer-count))
)
;; definition for method 13 of type external-art-control
(defmethod reserve-alloc external-art-control ((this external-art-control))
(defmethod reserve-alloc ((this external-art-control))
(cond
((or (nonzero? (-> this dma-reserve-buffer-count)) (= *master-mode* 'progress))
(set! (-> this dma-reserve-buffer-count) 1)
@@ -697,7 +697,7 @@
)
;; definition for method 14 of type external-art-control
(defmethod reserve-free external-art-control ((this external-art-control) (arg0 kheap))
(defmethod reserve-free ((this external-art-control) (arg0 kheap))
(cond
((nonzero? (-> this dma-reserve-buffer-count))
(set! (-> this dma-reserve-buffer-count) 0)
@@ -726,7 +726,7 @@
)
;; definition for method 10 of type external-art-control
(defmethod clear-rec external-art-control ((this external-art-control))
(defmethod clear-rec ((this external-art-control))
(dotimes (v1-0 3)
(set! (-> this rec v1-0 type) spool-anim)
(set! (-> this rec v1-0 name) #f)
@@ -738,7 +738,7 @@
)
;; definition for method 11 of type external-art-control
(defmethod spool-push external-art-control ((this external-art-control) (arg0 string) (arg1 int) (arg2 process) (arg3 float))
(defmethod spool-push ((this external-art-control) (arg0 string) (arg1 int) (arg2 process) (arg3 float))
(when (and (= arg3 -99.0) arg2)
(let ((a0-2 (target-pos 0)))
(set! arg3 (vector-vector-distance a0-2 (-> (the-as process-drawable arg2) root trans)))
@@ -798,31 +798,28 @@
;; definition of type spooler-block
(deftype spooler-block (basic)
((anim spool-anim :offset-assert 4)
(idle art-joint-anim :offset-assert 8)
(exit art-joint-anim :offset-assert 12)
(break-func (function process-drawable object) :offset-assert 16)
(part int32 :offset-assert 20)
(part-audio-start float :offset-assert 24)
(old-status uint16 :offset-assert 28)
(old-pos int32 :offset-assert 32)
(good-time time-frame :offset-assert 40)
(old-time time-frame :offset-assert 48)
(good-count int32 :offset-assert 56)
(sid sound-id :offset-assert 60)
(real-start-time time-frame :offset-assert 64)
(paused? symbol :offset-assert 72)
((anim spool-anim)
(idle art-joint-anim)
(exit art-joint-anim)
(break-func (function process-drawable object))
(part int32)
(part-audio-start float)
(old-status uint16)
(old-pos int32)
(good-time time-frame)
(old-time time-frame)
(good-count int32)
(sid sound-id)
(real-start-time time-frame)
(paused? symbol)
)
:method-count-assert 9
:size-assert #x4c
:flag-assert #x90000004c
(:methods
(new (symbol type art-joint-anim (function process-drawable symbol)) _type_ 0)
(new (symbol type art-joint-anim (function process-drawable symbol)) _type_)
)
)
;; definition for method 3 of type spooler-block
(defmethod inspect spooler-block ((this spooler-block))
(defmethod inspect ((this spooler-block))
(when (not this)
(set! this this)
(goto cfg-4)
@@ -1211,7 +1208,7 @@
)
;; definition for method 3 of type gui-control
(defmethod inspect gui-control ((this gui-control))
(defmethod inspect ((this gui-control))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tengine: ~A~%" (-> this engine))
(let ((a2-2 (-> this engine alive-list next0)))
@@ -1229,7 +1226,7 @@
)
;; definition for method 2 of type gui-connection
(defmethod print gui-connection ((this gui-connection))
(defmethod print ((this gui-connection))
(let* ((t9-0 format)
(a0-1 #t)
(a1-0 "#<gc ~12S ~2D ~6D ~6,,0f ~7S ~8S ")
@@ -1456,13 +1453,13 @@
)
;; definition for method 24 of type gui-control
(defmethod channel-id-set! gui-control ((this gui-control) (arg0 gui-connection) (arg1 sound-id))
(defmethod channel-id-set! ((this gui-control) (arg0 gui-connection) (arg1 sound-id))
(set! (-> this ids (-> arg0 channel)) arg1)
0
)
;; definition for method 15 of type gui-control
(defmethod lookup-gui-connection gui-control ((this gui-control) (arg0 process) (arg1 gui-channel) (arg2 string) (arg3 sound-id))
(defmethod lookup-gui-connection ((this gui-control) (arg0 process) (arg1 gui-channel) (arg2 string) (arg3 sound-id))
(let ((s1-0 (the-as gui-connection (-> this engine alive-list next0))))
(-> this engine)
(let ((s0-0 (-> s1-0 next0)))
@@ -1498,7 +1495,7 @@
;; definition for method 14 of type gui-control
;; WARN: Return type mismatch int vs sound-id.
(defmethod lookup-gui-connection-id gui-control ((this gui-control) (arg0 string) (arg1 gui-channel) (arg2 gui-action))
(defmethod lookup-gui-connection-id ((this gui-control) (arg0 string) (arg1 gui-channel) (arg2 gui-action))
(let ((s2-0 (the-as gui-connection (-> this engine alive-list next0))))
(-> this engine)
(let ((s1-0 (-> s2-0 next0)))
@@ -1530,7 +1527,7 @@
)
;; definition for method 20 of type gui-control
(defmethod set-falloff! gui-control ((this gui-control) (arg0 sound-id) (arg1 symbol) (arg2 int) (arg3 int) (arg4 int))
(defmethod set-falloff! ((this gui-control) (arg0 sound-id) (arg1 symbol) (arg2 int) (arg3 int) (arg4 int))
(when (nonzero? arg0)
(let ((v1-2 (lookup-gui-connection *gui-control* (the-as process #f) (gui-channel none) (the-as string #f) arg0)))
(when v1-2
@@ -1558,7 +1555,7 @@
;; definition for method 18 of type gui-control
;; WARN: Return type mismatch object vs symbol.
;; WARN: disable def twice: 34. This may happen when a cond (no else) is nested inside of another conditional, but it should be rare.
(defmethod gui-control-method-18 gui-control ((this gui-control) (arg0 gui-channel))
(defmethod gui-control-method-18 ((this gui-control) (arg0 gui-channel))
(let ((v1-0 arg0))
(the-as
symbol
@@ -1580,7 +1577,7 @@
)
;; definition for method 23 of type gui-control
(defmethod handle-command gui-control ((this gui-control) (arg0 gui-channel) (arg1 gui-channel) (arg2 symbol) (arg3 gui-connection))
(defmethod handle-command ((this gui-control) (arg0 gui-channel) (arg1 gui-channel) (arg2 symbol) (arg3 gui-connection))
(let ((s5-0 (-> this ids arg1)))
(cond
((nonzero? s5-0)
@@ -1652,7 +1649,7 @@
;; definition for method 19 of type gui-control
;; INFO: Used lq/sq
(defmethod handle-command-list gui-control ((this gui-control) (arg0 gui-channel) (arg1 gui-connection))
(defmethod handle-command-list ((this gui-control) (arg0 gui-channel) (arg1 gui-connection))
(local-vars (sv-16 int) (sv-32 int) (sv-48 int))
(let ((gp-0 #t))
(cond
@@ -1720,7 +1717,7 @@
;; definition for method 17 of type gui-control
;; WARN: Return type mismatch int vs gui-status.
(defmethod get-status gui-control ((this gui-control) (arg0 sound-id))
(defmethod get-status ((this gui-control) (arg0 sound-id))
(let ((gp-0 (the-as gui-connection #f)))
(if (zero? arg0)
(return (gui-status unknown))
@@ -1854,15 +1851,15 @@
)
;; definition for method 16 of type gui-control
(defmethod set-action! gui-control ((this gui-control)
(arg0 gui-action)
(arg1 sound-id)
(arg2 gui-channel)
(arg3 gui-action)
(arg4 string)
(arg5 (function gui-connection symbol))
(arg6 process)
)
(defmethod set-action! ((this gui-control)
(arg0 gui-action)
(arg1 sound-id)
(arg2 gui-channel)
(arg3 gui-action)
(arg4 string)
(arg5 (function gui-connection symbol))
(arg6 process)
)
(local-vars (sv-16 gui-action) (sv-17 gui-action) (sv-20 string) (sv-24 (function gui-connection symbol)))
(set! sv-16 arg0)
(set! sv-17 arg3)
@@ -1905,14 +1902,14 @@
;; definition for method 9 of type gui-control
;; INFO: Used lq/sq
;; WARN: Return type mismatch int vs sound-id.
(defmethod add-process gui-control ((this gui-control)
(arg0 process)
(arg1 gui-channel)
(arg2 gui-action)
(arg3 string)
(arg4 float)
(arg5 time-frame)
)
(defmethod add-process ((this gui-control)
(arg0 process)
(arg1 gui-channel)
(arg2 gui-action)
(arg3 string)
(arg4 float)
(arg5 time-frame)
)
(local-vars
(sv-16 int)
(sv-20 gui-connection)
@@ -1979,7 +1976,7 @@
;; definition for method 10 of type gui-control
;; WARN: Return type mismatch int vs none.
(defmethod remove-process gui-control ((this gui-control) (arg0 process) (arg1 gui-channel))
(defmethod remove-process ((this gui-control) (arg0 process) (arg1 gui-channel))
(let ((s3-0 (the-as gui-connection (-> this engine alive-list next0))))
(-> this engine)
(let ((s2-0 (-> s3-0 next0)))
@@ -2000,15 +1997,15 @@
;; definition for method 12 of type gui-control
;; INFO: Used lq/sq
;; WARN: Return type mismatch int vs sound-id.
(defmethod gui-control-method-12 gui-control ((this gui-control)
(arg0 process)
(arg1 gui-channel)
(arg2 gui-action)
(arg3 string)
(arg4 int)
(arg5 float)
(arg6 sound-id)
)
(defmethod gui-control-method-12 ((this gui-control)
(arg0 process)
(arg1 gui-channel)
(arg2 gui-action)
(arg3 string)
(arg4 int)
(arg5 float)
(arg6 sound-id)
)
(local-vars
(sv-16 gui-connection)
(sv-20 int)
@@ -2101,7 +2098,7 @@
)
;; definition for method 21 of type gui-control
(defmethod gui-control-method-21 gui-control ((this gui-control) (arg0 gui-connection) (arg1 vector))
(defmethod gui-control-method-21 ((this gui-control) (arg0 gui-connection) (arg1 vector))
(case (shr (the-as int (-> arg0 channel)) 4)
((1 2)
(let ((s5-0 (-> this spool-connections)))
@@ -2173,7 +2170,7 @@
)
;; definition for method 11 of type gui-control
(defmethod stop-str gui-control ((this gui-control) (arg0 gui-connection))
(defmethod stop-str ((this gui-control) (arg0 gui-connection))
(case (shr (the-as int (-> arg0 channel)) 4)
((1 2)
(if (= (get-status this (-> arg0 id)) (gui-status active))
@@ -2189,7 +2186,7 @@
;; definition for method 22 of type gui-control
;; WARN: Return type mismatch int vs none.
(defmethod gui-control-method-22 gui-control ((this gui-control) (arg0 gui-connection) (arg1 process) (arg2 symbol))
(defmethod gui-control-method-22 ((this gui-control) (arg0 gui-connection) (arg1 process) (arg2 symbol))
(local-vars (v1-66 symbol) (v1-143 symbol))
(with-pp
(when (and (>= (the-as uint (-> arg0 channel)) (the-as uint 16))
@@ -2408,7 +2405,7 @@
)
;; definition for method 13 of type gui-control
(defmethod update gui-control ((this gui-control) (arg0 symbol))
(defmethod update ((this gui-control) (arg0 symbol))
(set! (-> this ids 65)
(the-as sound-id (if (and (>= (-> *display* base-clock frame-counter) (-> *game-info* blackout-time))
(= (-> *setting-control* user-current bg-a) 0.0)