[decompiler] Better support for non-virtual methods (#543)

* fix up nonvirtual method calls and stack new method calls

* look at final in compiler too
This commit is contained in:
water111
2021-05-30 22:52:40 -04:00
committed by GitHub
parent b1a76b2291
commit c4f44e265f
18 changed files with 217 additions and 139 deletions
@@ -666,24 +666,11 @@
(set! (-> s5-0 vector 1 quad) (the-as uint128 0))
(set! (-> s5-0 vector 2 quad) (the-as uint128 0))
(set! (-> s5-0 vector 3 quad) (the-as uint128 0))
(let
((s4-0
((method-of-type vector4s-3 new)
(the-as symbol (new 'stack-no-clear 'vector4s-3))
vector4s-3
)
)
(s3-0 (new 'stack-no-clear 'vector))
)
(let ((s4-0 (new 'stack 'vector4s-3))
(s3-0 (new 'stack-no-clear 'vector))
)
(set! (-> s3-0 quad) (the-as uint128 0))
(let
((s2-0
((method-of-type vector4s-3 new)
(the-as symbol (new 'stack-no-clear 'vector4s-3))
vector4s-3
)
)
)
(let ((s2-0 (new 'stack 'vector4s-3)))
(matrix*! s5-0 arg0 (-> *math-camera* camera-temp))
(matrix-3x3-inverse-transpose! gp-0 arg0)
(let ((v1-3 s3-0))
@@ -757,7 +744,3 @@
(none)
)
)
@@ -95,7 +95,7 @@
;; definition for method 12 of type connection
(defmethod belongs-to-process? connection ((obj connection) (arg0 process))
(= arg0 ((method-of-type connection get-process) obj))
(= arg0 (get-process obj))
)
;; definition for method 2 of type connection
@@ -253,25 +253,25 @@
(format #t "~Talive-list:~%")
(let ((s5-0 *print-column*))
(set! *print-column* (+ *print-column* (the-as uint 64)))
((method-of-type connectable inspect) (-> obj alive-list))
(inspect (-> obj alive-list))
(set! *print-column* s5-0)
)
(format #t "~Talive-list-end:~%")
(let ((s5-1 *print-column*))
(set! *print-column* (+ *print-column* (the-as uint 64)))
((method-of-type connectable inspect) (-> obj alive-list-end))
(inspect (-> obj alive-list-end))
(set! *print-column* s5-1)
)
(format #t "~Tdead-list:~%")
(let ((s5-2 *print-column*))
(set! *print-column* (+ *print-column* (the-as uint 64)))
((method-of-type connectable inspect) (-> obj dead-list))
(inspect (-> obj dead-list))
(set! *print-column* s5-2)
)
(format #t "~Tdead-list-end:~%")
(let ((s5-3 *print-column*))
(set! *print-column* (+ *print-column* (the-as uint 64)))
((method-of-type connectable inspect) (-> obj dead-list-end))
(inspect (-> obj dead-list-end))
(set! *print-column* s5-3)
)
(format #t "~Tdata[~D]: @ #x~X~%" (-> obj allocated-length) (-> obj data))
@@ -427,7 +427,7 @@
;; definition for method 13 of type connection
(defmethod move-to-dead connection ((obj connection))
(let ((v1-1 ((method-of-type connection get-engine) obj)))
(let ((v1-1 (get-engine obj)))
(set! (-> obj prev0 next0) (-> obj next0))
(set! (-> obj next0 prev0) (-> obj prev0))
(set! (-> obj prev1 next1) (-> obj next1))
@@ -506,32 +506,21 @@
(defun
draw-sprite2d-xy
((buf dma-buffer) (x int) (y int) (w int) (h int) (color rgba))
(let*
((context
((method-of-type draw-context new)
(the-as symbol (new 'stack-no-clear 'draw-context))
draw-context
x
y
w
h
color
)
)
(draw-x (max 1792 (min 2304 (+ (-> context orgx) 1792))))
(draw-y
(max
(min
(+ (-> context orgy) (-> *video-parms* screen-miny))
(-> *video-parms* screen-maxy)
)
(-> *video-parms* screen-miny)
)
)
(draw-w (-> context width))
(draw-h (-> context height))
(end-dma (the-as dma-packet (-> buf base)))
)
(let* ((context (new 'stack 'draw-context x y w h color))
(draw-x (max 1792 (min 2304 (+ (-> context orgx) 1792))))
(draw-y
(max
(min
(+ (-> context orgy) (-> *video-parms* screen-miny))
(-> *video-parms* screen-maxy)
)
(-> *video-parms* screen-miny)
)
)
(draw-w (-> context width))
(draw-h (-> context height))
(end-dma (the-as dma-packet (-> buf base)))
)
(let* ((a2-2 buf)
(dma (the-as dma-packet (-> a2-2 base)))
)
@@ -742,19 +731,7 @@
(defun
screen-gradient
((arg0 dma-buffer) (arg1 rgba) (arg2 rgba) (arg3 rgba) (arg4 rgba))
(let
((a1-2
((method-of-type draw-context new)
(the-as symbol (new 'stack-no-clear 'draw-context))
draw-context
0
0
512
224
(new 'static 'rgba)
)
)
)
(let ((a1-2 (new 'stack 'draw-context 0 0 512 224 (new 'static 'rgba))))
(set! (-> a1-2 color 0) arg1)
(set! (-> a1-2 color 1) arg2)
(set! (-> a1-2 color 2) arg3)
@@ -76,7 +76,7 @@
trajectory
((obj trajectory) (arg0 vector) (arg1 vector) (arg2 float) (arg3 float))
(let ((f0-1 (/ (vector-vector-xz-distance arg1 arg0) arg2)))
((method-of-type trajectory TODO-RENAME-11) obj arg0 arg1 f0-1 arg3)
(TODO-RENAME-11 obj arg0 arg1 f0-1 arg3)
)
(let ((v0-1 0))
)
@@ -98,7 +98,7 @@
(set! f0-3 (fmax (/ (- (- arg2) f0-4) arg3) (/ (+ (- arg2) f0-4) arg3)))
)
)
((method-of-type trajectory TODO-RENAME-11) obj arg0 arg1 f0-3 arg3)
(TODO-RENAME-11 obj arg0 arg1 f0-3 arg3)
)
(let ((v0-1 0))
)
@@ -118,7 +118,7 @@
(if (< 0.0 f1-5)
(set! f0-3 (sqrtf f1-5))
)
((method-of-type trajectory TODO-RENAME-13) obj arg0 arg1 f0-3 arg3)
(TODO-RENAME-13 obj arg0 arg1 f0-3 arg3)
)
(let ((v0-1 0))
)
@@ -142,7 +142,7 @@
)
(let
((f0-1 (* (-> obj time) (/ (+ 1.0 (the float s2-0)) (the float s3-0)))))
((method-of-type trajectory TODO-RENAME-9) obj f0-1 s4-0)
(TODO-RENAME-9 obj f0-1 s4-0)
)
(add-debug-line #t 68 s5-0 s4-0 (new 'static 'rgba :r #xff :a #x80) #f -1)
)
@@ -151,7 +151,3 @@
)
(none)
)
@@ -69,11 +69,11 @@
(set! (-> obj period) (* (-> obj period) (-> obj damp-period)))
(set! (-> obj ticks) f30-0)
(if (< (-> obj damp-period) 0.0)
((method-of-type smush-control set-zero!) obj)
(set-zero! obj)
)
)
(if (>= f30-0 (-> obj duration))
((method-of-type smush-control set-zero!) obj)
(set-zero! obj)
)
(*
(sin (/ (* 65536.0 f28-0) (-> obj period)))
@@ -130,11 +130,7 @@
(arg4 float)
(arg5 float)
)
(when
(>=
(fabs (* 0.2 (-> obj amp)))
(fabs ((method-of-type smush-control get-no-update) obj))
)
(when (>= (fabs (* 0.2 (-> obj amp))) (fabs (get-no-update obj)))
(set! (-> obj amp) arg0)
(set! (-> obj period) (the float arg1))
(set! (-> obj duration) (the float arg2))
@@ -145,7 +141,3 @@
)
obj
)
@@ -196,7 +196,7 @@
;; definition for method 9 of type sync-info-paused
(defmethod dummy-9 sync-info-paused ((obj sync-info-paused) (arg0 float))
(* ((method-of-type sync-info-paused dummy-11) obj) arg0)
(* (dummy-11 obj) arg0)
)
;; definition for method 13 of type sync-info
@@ -337,12 +337,12 @@
;; definition for method 12 of type sync-info-eased
(defmethod dummy-12 sync-info-eased ((obj sync-info-eased) (arg0 float))
(* ((method-of-type sync-info-eased dummy-13) obj) arg0)
(* (dummy-13 obj) arg0)
)
;; definition for method 12 of type sync-info-paused
(defmethod dummy-12 sync-info-paused ((obj sync-info-paused) (arg0 float))
(* ((method-of-type sync-info-paused dummy-13) obj) arg0)
(* (dummy-13 obj) arg0)
)
;; definition for method 9 of type delayed-rand-float
@@ -427,7 +427,7 @@
(arg5 float)
(arg6 float)
)
((method-of-type oscillating-float dummy-9) (-> obj osc) arg0 arg4 arg5 arg6)
(dummy-9 (-> obj osc) arg0 arg4 arg5 arg6)
(set! (-> obj max-value) arg1)
(set! (-> obj min-value) arg2)
(set! (-> obj elasticity) arg3)
@@ -437,7 +437,7 @@
;; definition for method 10 of type bouncing-float
(defmethod dummy-10 bouncing-float ((obj bouncing-float) (arg0 float))
((method-of-type oscillating-float dummy-10) (-> obj osc) arg0)
(dummy-10 (-> obj osc) arg0)
(set! (-> obj state) 0)
(when (>= (-> obj osc value) (-> obj max-value))
(set! (-> obj osc value) (-> obj max-value))
@@ -510,7 +510,7 @@
(the-as int (- (-> *display* base-frame-counter) (-> obj start-time)))
(-> obj timer)
)
((method-of-type delayed-rand-vector dummy-10) obj)
(dummy-10 obj)
)
(-> obj value)
)
@@ -524,7 +524,7 @@
(the-as int (- (-> *display* base-frame-counter) (-> obj start-time)))
(-> obj timer)
)
((method-of-type delayed-rand-vector dummy-10) obj)
(dummy-10 obj)
(.svf (&-> (-> obj value) quad) vf0)
)
(-> obj value)
@@ -41,7 +41,7 @@
((allocation symbol) (type-to-make type) (arg0 int) (arg1 string))
(cond
(arg1
(let* ((s2-1 (max ((method-of-type string length) arg1) arg0))
(let* ((s2-1 (max (length arg1) arg0))
(a0-4
(object-new
allocation
@@ -277,11 +277,7 @@
;; definition for function string<?
(defun string<? ((a string) (b string))
(let
((len
(min ((method-of-type string length) a) ((method-of-type string length) b))
)
)
(let ((len (min (length a) (length b))))
(dotimes (i len)
(cond
((< (-> a data i) (-> b data i))
@@ -298,11 +294,7 @@
;; definition for function string>?
(defun string>? ((a string) (b string))
(let
((len
(min ((method-of-type string length) a) ((method-of-type string length) b))
)
)
(let ((len (min (length a) (length b))))
(dotimes (i len)
(cond
((< (-> a data i) (-> b data i))
@@ -319,11 +311,7 @@
;; definition for function string<=?
(defun string<=? ((a string) (b string))
(let
((len
(min ((method-of-type string length) a) ((method-of-type string length) b))
)
)
(let ((len (min (length a) (length b))))
(dotimes (i len)
(cond
((< (-> a data i) (-> b data i))
@@ -340,11 +328,7 @@
;; definition for function string>=?
(defun string>=? ((a string) (b string))
(let
((len
(min ((method-of-type string length) a) ((method-of-type string length) b))
)
)
(let ((len (min (length a) (length b))))
(dotimes (i len)
(cond
((< (-> a data i) (-> b data i))
@@ -437,8 +421,8 @@
;; definition for function string-strip-trailing-whitespace!
(defun string-strip-trailing-whitespace! ((str string))
(when (nonzero? ((method-of-type string length) str))
(let ((ptr (&+ (-> str data) (+ ((method-of-type string length) str) -1))))
(when (nonzero? (length str))
(let ((ptr (&+ (-> str data) (+ (length str) -1))))
(while
(and
(>= (the-as int ptr) (the-as int (-> str data)))
+10 -15
View File
@@ -2467,19 +2467,15 @@ TEST_F(FormRegressionTest, StringLt) {
std::string type = "(function string string symbol)";
std::string expected =
"(begin\n"
" (let\n"
" ((s4-1\n"
" (min\n"
" ((method-of-type string length) arg0)\n"
" ((method-of-type string length) arg1)\n"
" )\n"
" )\n"
" )\n"
" (dotimes\n"
" (v1-4 s4-1)\n"
" (let ((s4-1 (min (length arg0) (length arg1))))\n"
" (dotimes (v1-4 s4-1)\n"
" (cond\n"
" ((< (-> arg0 data v1-4) (-> arg1 data v1-4)) (return #t))\n"
" ((< (-> arg1 data v1-4) (-> arg0 data v1-4)) (return #f))\n"
" ((< (-> arg0 data v1-4) (-> arg1 data v1-4))\n"
" (return #t)\n"
" )\n"
" ((< (-> arg1 data v1-4) (-> arg0 data v1-4))\n"
" (return #f)\n"
" )\n"
" )\n"
" )\n"
" )\n"
@@ -2714,9 +2710,8 @@ TEST_F(FormRegressionTest, StripStripTrailingWhitespace) {
std::string type = "(function string symbol)";
std::string expected =
"(begin\n"
" (when (nonzero? ((method-of-type string length) arg0))\n"
" (let\n"
" ((v1-6 (&+ (-> arg0 data) (+ ((method-of-type string length) arg0) -1))))\n"
" (when (nonzero? (length arg0))\n"
" (let ((v1-6 (&+ (-> arg0 data) (+ (length arg0) -1))))\n"
" (while\n"
" (and\n"
" (>= (the-as int v1-6) (the-as int (-> arg0 data)))\n"