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

74 lines
2.1 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: script-h.gc
;; name in dgo: script-h
;; dgos: ENGINE, GAME
(define-extern *load-state* load-state)
;; NOTE - for editable-player
(declare-type script-context structure)
(define-extern *syntax-context* script-context)
(define-extern *script-context* script-context)
;; NOTE - for menu
(define-extern command-get-int (function object int int))
(define-extern command-get-float (function object float float))
(defmacro script-eval (script &key (key (process->ppointer PP)) &key (proc PP) &key (vector (the-as vector #f)))
`(eval! (new 'stack 'script-context ,key ,proc ,vector) ,script))
;; DECOMP BEGINS
(deftype script-form (structure)
((name symbol)
(spec pair)
(func (function script-context object))
)
:pack-me
(:methods
(script-form-method-9 () none)
)
)
(deftype script-context (structure)
((load-state load-state)
(key object)
(process process)
(trans vector)
(side-effect? symbol)
(got-error? symbol)
(expr pair)
(param-count int32)
(param object 16)
(param-type object 16)
)
(:methods
(new (symbol type object process vector) _type_)
(eval! (_type_ pair) object)
(script-context-method-10 (_type_ object pair) object)
(script-context-method-11 (_type_ pair pair symbol) symbol)
)
)
;; WARN: Return type mismatch structure vs script-context.
(defmethod new script-context ((allocation symbol) (type-to-make type) (arg0 object) (arg1 process) (arg2 vector))
(let ((t9-0 (method-of-type structure new))
(v1-1 type-to-make)
)
(-> type-to-make size)
(let ((v0-0 (t9-0 allocation v1-1)))
(set! (-> (the-as script-context v0-0) key) arg0)
(set! (-> (the-as script-context v0-0) process) arg1)
(set! (-> (the-as script-context v0-0) load-state) *load-state*)
(set! (-> (the-as script-context v0-0) side-effect?) #t)
(set! (-> (the-as script-context v0-0) got-error?) #f)
(set! (-> (the-as script-context v0-0) trans) arg2)
(the-as script-context v0-0)
)
)
)