Files
ManDude cd68cb671e 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>
2023-10-30 03:20:02 +00:00

344 lines
11 KiB
Common Lisp
Vendored
Generated

;;-*-Lisp-*-
(in-package goal)
;; definition of type load-dgo-msg
(deftype load-dgo-msg (structure)
((rsvd uint16)
(result load-msg-result)
(b1 pointer)
(b2 pointer)
(bt pointer)
(name uint128)
(name-chars uint8 16 :overlay-at name)
(address uint32 :overlay-at b1)
)
)
;; definition for method 3 of type load-dgo-msg
;; INFO: Used lq/sq
(defmethod inspect ((this load-dgo-msg))
(format #t "[~8x] ~A~%" this 'load-dgo-msg)
(format #t "~Trsvd: ~D~%" (-> this rsvd))
(format #t "~Tresult: ~D~%" (-> this result))
(format #t "~Tb1: #x~X~%" (-> this b1))
(format #t "~Tb2: #x~X~%" (-> this b2))
(format #t "~Tbt: #x~X~%" (-> this bt))
(format #t "~Tname: ~D~%" (-> this name))
(format #t "~Taddress: ~D~%" (-> this b1))
this
)
;; definition of type load-chunk-msg
(deftype load-chunk-msg (structure)
((rsvd uint16)
(result load-msg-result)
(address pointer)
(section uint32)
(maxlen uint32)
(id uint32 :overlay-at address)
(basename uint8 48)
)
)
;; definition for method 3 of type load-chunk-msg
(defmethod inspect ((this load-chunk-msg))
(format #t "[~8x] ~A~%" this 'load-chunk-msg)
(format #t "~Trsvd: ~D~%" (-> this rsvd))
(format #t "~Tresult: ~D~%" (-> this result))
(format #t "~Taddress: ~D~%" (-> this address))
(format #t "~Tsection: ~D~%" (-> this section))
(format #t "~Tmaxlen: ~D~%" (-> this maxlen))
(format #t "~Tid: ~D~%" (-> this address))
(format #t "~Tbasename[48] @ #x~X~%" (-> this basename))
this
)
;; definition of type dgo-header
(deftype dgo-header (structure)
((length uint32)
(rootname uint8 60)
(data uint8 :dynamic)
)
)
;; definition for method 3 of type dgo-header
(defmethod inspect ((this dgo-header))
(format #t "[~8x] ~A~%" this 'dgo-header)
(format #t "~Tlength: ~D~%" (-> this length))
(format #t "~Trootname[60] @ #x~X~%" (-> this rootname))
this
)
;; failed to figure out what this is:
(when (zero? *load-dgo-rpc*)
(set! *load-dgo-rpc* (new 'global 'rpc-buffer-pair (the-as uint 32) (the-as uint 1) 3))
(set! *load-str-rpc* (new 'global 'rpc-buffer-pair (the-as uint 64) (the-as uint 1) 4))
(set! *play-str-rpc* (new 'global 'rpc-buffer-pair (the-as uint 64) (the-as uint 2) 5))
(set! *load-str-lock* #f)
(set! *que-str-lock* #f)
(set! *dgo-name* (new 'global 'string 64 (the-as string #f)))
)
;; definition for function str-load
(defun str-load ((name string) (chunk-id int) (address pointer) (len int))
(if (or (check-busy *load-str-rpc*) *load-str-lock*)
(return #f)
)
(let ((cmd (the-as load-chunk-msg (add-element *load-str-rpc*))))
(set! (-> cmd result) (load-msg-result invalid))
(set! (-> cmd address) address)
(set! (-> cmd section) (the-as uint chunk-id))
(set! (-> cmd maxlen) (the-as uint len))
(charp<-string (-> cmd basename) name)
(call *load-str-rpc* (the-as uint 0) (the-as pointer cmd) (the-as uint 32))
)
(set! *load-str-lock* #t)
(set! *que-str-lock* #t)
#t
)
;; definition for function str-load-status
(defun str-load-status ((length-out (pointer int32)))
(if (check-busy *load-str-rpc*)
(return 'busy)
)
(set! *load-str-lock* #f)
(set! *que-str-lock* #t)
(let ((response (the-as load-chunk-msg (pop-last-received *load-str-rpc*))))
(if (= (-> response result) (load-msg-result error))
(return 'error)
)
(set! (-> length-out 0) (the-as int (-> response maxlen)))
)
'complete
)
;; definition for function str-load-cancel
;; INFO: Return type mismatch int vs none.
(defun str-load-cancel ()
(set! *load-str-lock* #f)
(set! *que-str-lock* #t)
0
(none)
)
;; definition for function str-play-async
;; INFO: Return type mismatch int vs none.
(defun str-play-async ((name string) (addr sound-id))
(set! *que-str-lock* #t)
(let ((cmd (the-as load-chunk-msg (add-element *play-str-rpc*))))
(charp<-string (-> cmd basename) name)
(set! (-> cmd address) (the-as pointer addr))
(set! (-> cmd result) (load-msg-result done))
)
0
0
(none)
)
;; definition for function str-play-stop
;; INFO: Return type mismatch int vs none.
(defun str-play-stop ((name string))
(set! *que-str-lock* #t)
(let ((cmd (the-as load-chunk-msg (add-element *play-str-rpc*))))
(charp<-string (-> cmd basename) name)
(set! (-> cmd result) (load-msg-result error))
)
0
(none)
)
;; definition for function str-play-queue
;; INFO: Return type mismatch int vs none.
(defun str-play-queue ((name string))
(when (and (not (check-busy *play-str-rpc*)) (not *load-str-lock*) (not *que-str-lock*))
(let ((cmd (the-as load-chunk-msg (add-element *play-str-rpc*))))
(charp<-string (-> cmd basename) name)
(set! (-> cmd result) (load-msg-result more))
)
)
(set! *que-str-lock* #f)
0
(none)
)
;; definition for function str-ambient-play
;; INFO: Return type mismatch int vs none.
(defun str-ambient-play ((name string))
(set! *que-str-lock* #t)
(let ((cmd (the-as load-chunk-msg (add-element *play-str-rpc*))))
(set! (-> cmd basename 0) (the-as uint 36))
(charp<-string (&-> cmd basename 1) name)
(set! (-> cmd result) (load-msg-result done))
)
0
0
(none)
)
;; definition for function str-ambient-stop
;; INFO: Return type mismatch int vs none.
(defun str-ambient-stop ((name string))
(set! *que-str-lock* #t)
(let ((cmd (the-as load-chunk-msg (add-element *play-str-rpc*))))
(set! (-> cmd basename 0) (the-as uint 36))
(charp<-string (&-> cmd basename 1) name)
(set! (-> cmd result) (load-msg-result error))
)
0
(none)
)
;; definition for function str-play-kick
;; INFO: Return type mismatch int vs none.
(defun str-play-kick ()
(cond
((check-busy *play-str-rpc*)
)
(else
(call *play-str-rpc* (the-as uint 0) (the-as pointer 0) (the-as uint 0))
)
)
0
(none)
)
;; definition for symbol *dgo-time*, type time-frame
(define *dgo-time* (the-as time-frame 0))
;; definition for function dgo-load-begin
;; INFO: Used lq/sq
(defun dgo-load-begin ((name string) (buffer1 pointer) (buffer2 pointer) (current-heap pointer))
(set! *dgo-time* (-> *display* real-integral-frame-counter))
(format 0 "Starting level load clock~%")
(sync *load-dgo-rpc* #t)
(let ((cmd (the-as load-dgo-msg (add-element *load-dgo-rpc*))))
(set! (-> cmd result) (load-msg-result invalid))
(set! (-> cmd b1) buffer1)
(set! (-> cmd b2) buffer2)
(set! (-> cmd bt) current-heap)
(set! (-> cmd name) (string->sound-name name))
(call *load-dgo-rpc* (the-as uint 0) (the-as pointer cmd) (the-as uint 32))
cmd
)
)
;; definition for function dgo-load-get-next
(defun dgo-load-get-next ((last-object (pointer symbol)))
(set! (-> last-object 0) #t)
(let ((load-location (the-as pointer #f)))
(when (not (check-busy *load-dgo-rpc*))
(let ((response (the-as load-dgo-msg (pop-last-received *load-dgo-rpc*))))
(when response
(if (or (= (-> response result) (load-msg-result done)) (= (-> response result) (load-msg-result more)))
(set! load-location (-> response b1))
)
(if (= (-> response result) (load-msg-result more))
(set! (-> last-object 0) #f)
)
(if (= (-> response result) (load-msg-result done))
(format
0
"Elapsed time for level = ~Fs~%"
(* 0.016666668 (the float (- (-> *display* real-integral-frame-counter) *dgo-time*)))
)
)
)
)
)
load-location
)
)
;; definition for function dgo-load-continue
;; INFO: Used lq/sq
;; INFO: Return type mismatch load-dgo-msg vs int.
(defun dgo-load-continue ((current-heap pointer))
(let ((cmd (the-as load-dgo-msg (add-element *load-dgo-rpc*))))
(set! (-> cmd result) (load-msg-result invalid))
(set! (-> cmd b1) (the-as pointer 0))
(set! (-> cmd b2) (the-as pointer 0))
(set! (-> cmd bt) current-heap)
(set! (-> cmd name) (the-as uint128 0))
(call *load-dgo-rpc* (the-as uint 1) (the-as pointer cmd) (the-as uint 32))
(the-as int cmd)
)
)
;; definition for function dgo-load-cancel
;; INFO: Return type mismatch int vs none.
(defun dgo-load-cancel ()
(sync *load-dgo-rpc* #t)
(let ((cmd (add-element *load-dgo-rpc*)))
(call *load-dgo-rpc* (the-as uint 2) cmd (the-as uint 32))
)
0
(none)
)
;; definition for function find-temp-buffer
(defun find-temp-buffer ((size int))
(let ((qwc (+ (/ size 16) 2)))
(cond
((< (the-as uint qwc)
(the-as uint (dma-buffer-free (-> *display* frames (-> *display* on-screen) frame global-buf)))
)
(logand -16 (&+ (-> *display* frames (-> *display* on-screen) frame global-buf base) 15))
)
((< (the-as uint qwc)
(the-as uint (dma-buffer-free (-> *display* frames (-> *display* on-screen) frame global-buf)))
)
(logand -16 (&+ (-> *display* frames (-> *display* on-screen) frame global-buf base) 15))
)
)
)
)
;; definition for function dgo-load-link
(defun dgo-load-link ((obj-file dgo-header) (heap kheap) (print-login symbol) (last-object symbol))
(let ((obj-data (-> obj-file data)))
(if (>= (the-as int (&+ obj-data (-> obj-file length))) (the-as int (-> heap top-base)))
(format
0
"ERROR: -----> dgo file header #x~X has overrun heap #x~X by ~D bytes. This is very bad!~%"
obj-file
heap
(&- (&+ obj-data (-> obj-file length)) (the-as uint (-> heap top-base)))
)
)
(if last-object
(format
0
"NOTICE: loaded ~g, ~D bytes (~f K) at top ~D~%"
(-> obj-file rootname)
(-> obj-file length)
(* 0.0009765625 (the float (-> obj-file length)))
(&- (&+ obj-data (-> obj-file length)) (the-as uint (-> heap base)))
)
)
(string<-charp (clear *dgo-name*) (-> obj-file rootname))
(nonzero? (link-begin
obj-data
(-> *dgo-name* data)
(the-as int (-> obj-file length))
heap
(if print-login
(link-flag output-load-msg output-load-true-msg execute-login print-login fast-link)
(link-flag output-load-msg output-load-true-msg execute-login fast-link)
)
)
)
)
)
;; definition for function destroy-mem
;; INFO: Return type mismatch int vs none.
(defun destroy-mem ((arg0 (pointer uint32)) (arg1 (pointer uint32)))
(while (< (the-as int arg0) (the-as int arg1))
(set! (-> arg0 0) (the-as uint #xffffffff))
(set! arg0 (&-> arg0 1))
)
0
(none)
)