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

368 lines
9.8 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: actor-link-h.gc
;; name in dgo: actor-link-h
;; dgos: ENGINE, GAME
(define-extern entity-by-name (function string entity))
(define-extern entity-by-type (function type entity-actor))
(define-extern entity-by-aid (function uint entity))
;; DECOMP BEGINS
;; WARN: Return type mismatch entity vs entity-actor.
(defun entity-actor-lookup ((arg0 res-lump) (arg1 symbol) (arg2 int))
(local-vars (sv-16 res-tag))
(set! sv-16 (new 'static 'res-tag))
(let ((v1-1 (res-lump-data arg0 arg1 pointer :tag-ptr (& sv-16))))
(the-as
entity-actor
(when (and v1-1 (< arg2 (the-as int (-> sv-16 elt-count))))
(if (= (-> sv-16 elt-type) string)
(entity-by-name (the-as string (-> (the-as (pointer uint32) (&+ v1-1 (* arg2 4))))))
(entity-by-aid (-> (the-as (pointer uint32) (&+ v1-1 (* arg2 4)))))
)
)
)
)
)
;; WARN: Check prologue - tricky store of r0
(defun entity-actor-count ((arg0 res-lump) (arg1 symbol))
(local-vars (sv-16 res-tag))
(set! sv-16 (new 'static 'res-tag))
(if (res-lump-data arg0 arg1 pointer :tag-ptr (& sv-16))
(the-as int (-> sv-16 elt-count))
0
)
)
(deftype actor-link-info (basic)
((process process)
(next entity-actor)
(prev entity-actor)
)
(:methods
(new (symbol type process symbol) _type_)
(get-matching-actor-type-mask (_type_ type) int)
(actor-count-before (_type_) int)
(link-to-next-and-prev-actor (_type_) actor-link-info)
(get-next (_type_) entity-actor)
(get-prev (_type_) entity-actor)
(get-next-process (_type_) process)
(get-prev-process (_type_) process)
(apply-function-forward (_type_ (function entity-actor object object) object) int)
(apply-function-reverse (_type_ (function entity-actor object object) object) int)
(apply-all (_type_ (function entity-actor object object) object) int)
(send-to-all (_type_ symbol) none)
(send-to-all-after (_type_ symbol) object)
(send-to-all-before (_type_ symbol) object)
(send-to-next-and-prev (_type_ symbol) none)
(send-to-next (_type_ symbol) none)
(send-to-prev (_type_ symbol) none)
(actor-count (_type_) int)
)
)
(defmethod next-actor ((this entity-actor))
(entity-actor-lookup this 'next-actor 0)
)
(defmethod prev-actor ((this entity-actor))
(entity-actor-lookup this 'prev-actor 0)
)
(defmethod new actor-link-info ((allocation symbol) (type-to-make type) (arg0 process) (arg1 symbol))
(let* ((a0-1 (-> arg0 entity))
(s4-0 (entity-actor-lookup a0-1 'next-actor 0))
(a0-2 (-> arg0 entity))
(s3-0 (entity-actor-lookup a0-2 'prev-actor 0))
)
(when (or (not arg1) s4-0 s3-0)
(let ((v0-2 (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(set! (-> v0-2 process) arg0)
(set! (-> v0-2 next) s4-0)
(set! (-> v0-2 prev) s3-0)
v0-2
)
)
)
)
(defmethod get-next ((this actor-link-info))
(-> this next)
)
(defmethod get-prev ((this actor-link-info))
(-> this prev)
)
;; WARN: Return type mismatch basic vs process.
(defmethod get-next-process ((this actor-link-info))
(the-as process (and (-> this next) (-> this next extra process)))
)
;; WARN: Return type mismatch basic vs process.
(defmethod get-prev-process ((this actor-link-info))
(the-as process (and (-> this prev) (-> this prev extra process)))
)
(defmethod link-to-next-and-prev-actor ((this actor-link-info))
(let ((a0-1 (-> this process entity)))
(set! (-> this next) (entity-actor-lookup a0-1 'next-actor 0))
)
(let ((a0-2 (-> this process entity)))
(set! (-> this prev) (entity-actor-lookup a0-2 'prev-actor 0))
)
this
)
(defmethod apply-function-forward ((this actor-link-info) (arg0 (function entity-actor object object)) (arg1 object))
(let ((s3-0 (-> this next)))
(while s3-0
(if (arg0 s3-0 arg1)
(return (the-as int #f))
)
(set! s3-0 (entity-actor-lookup s3-0 'next-actor 0))
)
)
0
)
(defmethod apply-function-reverse ((this actor-link-info) (arg0 (function entity-actor object object)) (arg1 object))
(let ((s3-0 (-> this prev)))
(while s3-0
(if (arg0 s3-0 arg1)
(return (the-as int #f))
)
(set! s3-0 (entity-actor-lookup s3-0 'prev-actor 0))
)
)
0
)
(defmethod apply-all ((this actor-link-info) (arg0 (function entity-actor object object)) (arg1 object))
(let ((s4-0 (-> this process entity)))
(while (let ((a0-2 s4-0))
(entity-actor-lookup a0-2 'prev-actor 0)
)
(set! s4-0 (entity-actor-lookup s4-0 'prev-actor 0))
)
(while s4-0
(if (arg0 s4-0 arg1)
(return (the-as int #f))
)
(let ((a0-4 s4-0))
(set! s4-0 (entity-actor-lookup a0-4 'next-actor 0))
)
)
)
0
)
(defmethod send-to-all-after ((this actor-link-info) (arg0 symbol))
(with-pp
(let ((s4-0 (-> this next))
(s5-0 (the-as object #f))
)
(while s4-0
(let ((a0-1 (-> s4-0 extra process)))
(when a0-1
(let ((a1-1 (new 'stack-no-clear 'event-message-block)))
(set! (-> a1-1 from) (process->ppointer pp))
(set! (-> a1-1 num-params) 0)
(set! (-> a1-1 message) arg0)
(set! s5-0 (or (send-event-function a0-1 a1-1) s5-0))
)
)
)
(set! s4-0 (entity-actor-lookup s4-0 'next-actor 0))
)
s5-0
)
)
)
(defmethod send-to-all-before ((this actor-link-info) (arg0 symbol))
(with-pp
(let ((s4-0 (-> this prev))
(s5-0 (the-as object #f))
)
(while s4-0
(let ((a0-1 (-> s4-0 extra process)))
(when a0-1
(let ((a1-1 (new 'stack-no-clear 'event-message-block)))
(set! (-> a1-1 from) (process->ppointer pp))
(set! (-> a1-1 num-params) 0)
(set! (-> a1-1 message) arg0)
(set! s5-0 (or (send-event-function a0-1 a1-1) s5-0))
)
)
)
(set! s4-0 (entity-actor-lookup s4-0 'prev-actor 0))
)
s5-0
)
)
)
;; WARN: Return type mismatch symbol vs none.
(defmethod send-to-next ((this actor-link-info) (arg0 symbol))
(let ((a0-1 (-> this next)))
(when a0-1
(let ((a0-2 (-> a0-1 extra process)))
(if a0-2
(send-event a0-2 arg0)
)
)
)
)
(none)
)
;; WARN: Return type mismatch symbol vs none.
(defmethod send-to-prev ((this actor-link-info) (arg0 symbol))
(let ((a0-1 (-> this prev)))
(when a0-1
(let ((a0-2 (-> a0-1 extra process)))
(if a0-2
(send-event a0-2 arg0)
)
)
)
)
(none)
)
;; WARN: Return type mismatch symbol vs none.
(defmethod send-to-next-and-prev ((this actor-link-info) (arg0 symbol))
(send-to-next this arg0)
(send-to-prev this arg0)
(none)
)
;; WARN: Return type mismatch symbol vs none.
(defmethod send-to-all ((this actor-link-info) (arg0 symbol))
(send-to-all-after this arg0)
(send-to-all-before this arg0)
(none)
)
(defmethod actor-count ((this actor-link-info))
(let ((s5-0 (-> this process entity))
(gp-0 0)
)
(while (let ((a0-2 s5-0))
(entity-actor-lookup a0-2 'prev-actor 0)
)
(set! s5-0 (entity-actor-lookup s5-0 'prev-actor 0))
)
(while s5-0
(+! gp-0 1)
(let ((a0-3 s5-0))
(set! s5-0 (entity-actor-lookup a0-3 'next-actor 0))
)
)
gp-0
)
)
(defmethod get-matching-actor-type-mask ((this actor-link-info) (arg0 type))
(let ((s3-0 (-> this process entity))
(s5-0 0)
)
(let ((s4-0 1))
(while (let ((a0-2 s3-0))
(entity-actor-lookup a0-2 'prev-actor 0)
)
(set! s3-0 (entity-actor-lookup s3-0 'prev-actor 0))
)
(while s3-0
(if (= (-> s3-0 etype) arg0)
(set! s5-0 (logior s5-0 s4-0))
)
(let ((a0-3 s3-0))
(set! s3-0 (entity-actor-lookup a0-3 'next-actor 0))
)
(set! s4-0 (* s4-0 2))
)
)
s5-0
)
)
(defmethod actor-count-before ((this actor-link-info))
(let* ((s5-0 (-> this process entity))
(s4-0 s5-0)
(gp-0 0)
)
(while (let ((a0-2 s4-0))
(entity-actor-lookup a0-2 'prev-actor 0)
)
(set! s4-0 (entity-actor-lookup s4-0 'prev-actor 0))
)
(while (!= s4-0 s5-0)
(+! gp-0 1)
(let ((a0-3 s4-0))
(set! s4-0 (entity-actor-lookup a0-3 'next-actor 0))
)
)
gp-0
)
)
(defun actor-link-subtask-complete-hook ((arg0 entity-actor) (arg1 (pointer symbol)))
(cond
((logtest? (-> arg0 extra perm status) (entity-perm-status subtask-complete))
(set! (-> arg1 0) #t)
#f
)
(else
(set! (-> arg1 0) #f)
#t
)
)
)
(defun actor-link-subtask-incomplete-count-hook ((arg0 entity-actor) (arg1 (pointer uint64)))
(cond
((logtest? (-> arg0 extra perm status) (entity-perm-status subtask-complete))
#f
)
(else
(+! (-> arg1 0) 1)
#f
)
)
)
(defun actor-link-dead-hook ((arg0 entity-actor) (arg1 (pointer symbol)))
(cond
((logtest? (-> arg0 extra perm status) (entity-perm-status dead))
(set! (-> arg1 0) #t)
#f
)
(else
(set! (-> arg1 0) #f)
#t
)
)
)
(defun alt-actor-list-subtask-incomplete-count ((arg0 process-drawable))
(let ((s4-0 (entity-actor-count (-> arg0 entity) 'alt-actor))
(gp-0 0)
)
(dotimes (s3-0 s4-0)
(let ((a0-3 (entity-actor-lookup (-> arg0 entity) 'alt-actor s3-0)))
(if (or (not a0-3) (not (logtest? (-> a0-3 extra perm status) (entity-perm-status subtask-complete))))
(+! gp-0 1)
)
)
)
gp-0
)
)