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

163 lines
5.0 KiB
Common Lisp
Vendored
Generated

;;-*-Lisp-*-
(in-package goal)
;; definition of type dma-packet
(deftype dma-packet (structure)
((dma dma-tag)
(vif0 vif-tag)
(vif1 vif-tag)
(quad uint128 :overlay-at dma)
)
)
;; definition for method 3 of type dma-packet
;; INFO: Used lq/sq
(defmethod inspect ((this dma-packet))
(format #t "[~8x] ~A~%" this 'dma-packet)
(format #t "~Tdma: #x~X~%" (-> this dma))
(format #t "~Tvif0: #x~X~%" (-> this vif0))
(format #t "~Tvif1: #x~X~%" (-> this vif1))
(format #t "~Tquad: ~D~%" (-> this quad))
this
)
;; definition of type dma-packet-array
(deftype dma-packet-array (inline-array-class)
()
)
;; definition for method 3 of type dma-packet-array
(defmethod inspect ((this dma-packet-array))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tlength: ~D~%" (-> this length))
(format #t "~Tallocated-length: ~D~%" (-> this allocated-length))
(format #t "~Tdata[0] @ #x~X~%" (-> this _data))
this
)
;; failed to figure out what this is:
(set! (-> dma-packet-array heap-base) (the-as uint 16))
;; definition of type dma-gif-packet
(deftype dma-gif-packet (structure)
((dma-vif dma-packet :inline)
(gif uint64 2)
(gif0 uint64 :overlay-at (-> gif 0))
(gif1 uint64 :overlay-at (-> gif 1))
(quad uint128 2 :overlay-at (-> dma-vif dma))
)
)
;; definition for method 3 of type dma-gif-packet
(defmethod inspect ((this dma-gif-packet))
(format #t "[~8x] ~A~%" this 'dma-gif-packet)
(format #t "~Tdma-vif: #<dma-packet @ #x~X>~%" (-> this dma-vif))
(format #t "~Tgif[2] @ #x~X~%" (&-> this gif0))
(format #t "~Tquad[2] @ #x~X~%" (-> this dma-vif))
this
)
;; definition of type dma-buffer
(deftype dma-buffer (basic)
((allocated-length int32)
(base pointer)
(end pointer)
(data uint64 1)
(data-buffer uint8 :dynamic :overlay-at (-> data 0))
)
(:methods
(new (symbol type int) _type_)
)
)
;; definition for method 3 of type dma-buffer
(defmethod inspect ((this dma-buffer))
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tallocated-length: ~D~%" (-> this allocated-length))
(format #t "~Tbase: #x~X~%" (-> this base))
(format #t "~Tend: #x~X~%" (-> this end))
(format #t "~Tdata[1] @ #x~X~%" (-> this data))
this
)
;; definition for method 0 of type dma-buffer
(defmethod new dma-buffer ((allocation symbol) (type-to-make type) (arg0 int))
(let ((v0-0 (object-new allocation type-to-make (+ arg0 -4 (-> type-to-make size)))))
(set! (-> v0-0 base) (-> v0-0 data))
(set! (-> v0-0 allocated-length) arg0)
v0-0
)
)
;; definition for function dma-buffer-inplace-new
(defun dma-buffer-inplace-new ((arg0 dma-buffer) (arg1 int))
(set! (-> arg0 base) (-> arg0 data))
(set! (-> arg0 allocated-length) arg1)
arg0
)
;; definition for method 4 of type dma-buffer
(defmethod length ((this dma-buffer))
(-> this allocated-length)
)
;; definition for method 5 of type dma-buffer
(defmethod asize-of ((this dma-buffer))
(+ (-> this allocated-length) -4 (-> dma-buffer size))
)
;; definition for function dma-buffer-length
(defun dma-buffer-length ((arg0 dma-buffer))
(shr (+ (&- (-> arg0 base) (the-as uint (-> arg0 data))) 15) 4)
)
;; definition for function dma-buffer-free
(defun dma-buffer-free ((arg0 dma-buffer))
(shr (+ (&- (-> arg0 end) (the-as uint (-> arg0 base))) 15) 4)
)
;; definition for function dma-buffer-add-vu-function
(defun dma-buffer-add-vu-function ((dma-buf dma-buffer) (vu-func vu-function) (arg2 int))
(let ((func-ptr (the-as object (+ (the-as uint vu-func) 16)))
(qlen (-> vu-func qlength))
(origin (-> vu-func origin))
)
(while (> qlen 0)
(let ((qwc-now (min 127 qlen)))
(let* ((dma-buf-2 dma-buf)
(buf-ptr (the-as dma-packet (-> dma-buf-2 base)))
)
(set! (-> buf-ptr dma) (new 'static 'dma-tag :id (dma-tag-id ref) :addr (the-as int func-ptr) :qwc qwc-now))
(set! (-> buf-ptr vif0) (new 'static 'vif-tag :cmd (if (zero? arg2) 16 19)))
(set! (-> buf-ptr vif1) (new 'static 'vif-tag :cmd (vif-cmd mpg) :num (* qwc-now 2) :imm origin))
(set! (-> dma-buf-2 base) (&+ (the-as pointer buf-ptr) 16))
)
(set! func-ptr (+ (the-as uint func-ptr) (* qwc-now 16)))
(set! qlen (- qlen qwc-now))
(+! origin (* qwc-now 2))
)
)
)
#f
)
;; definition for function dma-buffer-send
(defun dma-buffer-send ((arg0 dma-bank) (arg1 dma-buffer))
(when (< (-> arg1 allocated-length) (&- (-> arg1 base) (the-as uint (-> arg1 data))))
(crash!)
0
)
(dma-send arg0 (the-as uint (-> arg1 data)) (the-as uint (dma-buffer-length arg1)))
(none)
)
;; definition for function dma-buffer-send-chain
(defun dma-buffer-send-chain ((arg0 dma-bank-source) (arg1 dma-buffer))
(when (< (-> arg1 allocated-length) (&- (-> arg1 base) (the-as uint (-> arg1 data))))
(crash!)
0
)
(dma-send-chain arg0 (the-as uint (-> arg1 data)))
(none)
)