More array special cases (#1913)

also make jak 1 and jak 2 behave the same way, to reduce confusion. It
wasn't too bad to update jak 1.
This commit is contained in:
water111 2022-09-24 16:10:13 -04:00 committed by GitHub
parent 332f0b2f2b
commit 6227c6d6a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 64 additions and 56 deletions

View File

@ -76,7 +76,7 @@ TP_Type SimpleAtom::get_type(const TypeState& input,
if (m_string == "#f") {
return TP_Type::make_false();
} else {
return TP_Type::make_from_ts("symbol");
return TP_Type::make_symbol(m_string);
}
case Kind::SYMBOL_VAL: {
if (m_string == "#f") {
@ -1424,6 +1424,20 @@ TypeState CallOp::propagate_types_internal(const TypeState& input,
end_types.get(Register(Reg::GPR, Reg::V0)) = TP_Type::make_from_ts(in_type.last_arg());
if (in_tp.kind == TP_Type::Kind::NON_OBJECT_NEW_METHOD &&
in_type.last_arg() == TypeSpec("array")) {
// array new:
auto& a2 = input.get(Register(Reg::GPR, arg_regs[2])); // elt type
auto& a1 = input.get(Register(Reg::GPR, arg_regs[1])); // array
auto& a0 = input.get(Register(Reg::GPR, arg_regs[0])); // allocation
if (a2.kind == TP_Type::Kind::TYPE_OF_TYPE_NO_VIRTUAL &&
in_tp.method_from_type() == TypeSpec("array") && a0.is_symbol()) {
end_types.get(Register(Reg::GPR, Reg::V0)) =
TP_Type::make_from_ts(TypeSpec("array", {a2.get_type_objects_typespec()}));
}
}
// we can also update register usage here.
m_read_regs.clear();
m_arg_vars.clear();

View File

@ -184,7 +184,7 @@ TP_Type get_type_symbol_ptr(const std::string& name) {
if (name == "#f") {
return TP_Type::make_false();
} else {
return TP_Type::make_from_ts("symbol");
return TP_Type::make_symbol(name);
}
}
@ -2478,14 +2478,15 @@ void CallOp::propagate_types2(types2::Instruction& instr,
out_types[Register(Reg::GPR, Reg::V0)]->type = TP_Type::make_from_ts(in_type.last_arg());
if (in_tp.kind == TP_Type::Kind::NON_OBJECT_NEW_METHOD &&
in_type.last_arg() == TypeSpec("array") && input_types[Register(Reg::GPR, arg_regs[2])]) {
in_tp.method_from_type() == TypeSpec("array") &&
input_types[Register(Reg::GPR, arg_regs[2])]) {
// array new:
auto& a2 = input_types[Register(Reg::GPR, arg_regs[2])];
auto& a1 = input_types[Register(Reg::GPR, arg_regs[1])];
auto& a0 = input_types[Register(Reg::GPR, arg_regs[0])];
// the is_symbol() check here makes sure it's a symbol known at compile time.
if (a2->type && a2->type->kind == TP_Type::Kind::TYPE_OF_TYPE_NO_VIRTUAL && a1->type &&
a1->type->is_symbol()) {
if (a0->type && a0->type->is_symbol() && a2->type &&
a2->type->kind == TP_Type::Kind::TYPE_OF_TYPE_NO_VIRTUAL && a1->type) {
out_types[Register(Reg::GPR, Reg::V0)]->type = TP_Type::make_from_ts(TypeSpec(
"array",
{input_types[Register(Reg::GPR, arg_regs[2])]->type->get_type_objects_typespec()}));

View File

@ -318,6 +318,9 @@ TP_Type DecompilerTypeSystem::tp_lca(const TP_Type& existing,
case TP_Type::Kind::LABEL_ADDR:
*changed = false;
return existing;
case TP_Type::Kind::SYMBOL:
*changed = true;
return TP_Type::make_from_ts("symbol");
case TP_Type::Kind::FALSE_AS_NULL:
case TP_Type::Kind::UNINITIALIZED:

View File

@ -71,7 +71,7 @@
(defun store-image ((oddeven int))
"Store an image to image.raw"
(local-vars (ptr-1 (pointer uint8)) (y-idx int) (y-idx-2 int))
(local-vars (ptr-1 (pointer uint128)) (y-idx int) (y-idx-2 int))
(let ((width 512)
(height (-> *video-parms* screen-sy))
(file (new 'debug 'file-stream "image.raw" 'write))

View File

@ -59,7 +59,7 @@
;;
;; Each element is populated on demand from calling add-debug-sphere-from-table and as such this table
;; shouldn't be used directly.
(define *debug-sphere-table* (the-as (array vector-array) (new 'debug 'boxed-array vector-array 10)))
(define *debug-sphere-table* (new 'debug 'boxed-array vector-array 10))
)
(defun add-debug-sphere-from-table ((bucket bucket-id) (position vector) (radius meters) (color rgba) (table-idx int))

View File

@ -11,7 +11,7 @@
(define *background-draw-engine* (new 'global 'engine 'draw 10 connection))
(define *matrix-engine* (the-as (array handle) (new 'global 'boxed-array handle 1024)))
(define *matrix-engine* (new 'global 'boxed-array handle 1024))
(set! (-> *matrix-engine* length) 0)
(define *part-engine* (new 'global 'engine 'sparticle-launcher 256 connection))

View File

@ -387,10 +387,10 @@
(set! gp-0 (when (or (not *game-info*) (zero? *game-info*))
(set! gp-0 (new 'static 'game-info :mode 'debug :current-continue #f :last-continue #f))
(set! (-> gp-0 unknown-array1) (the-as (array uint64) (new 'global 'boxed-array uint64 110)))
(set! (-> gp-0 unknown-array4) (the-as (array uint64) (new 'global 'boxed-array uint64 110)))
(set! (-> gp-0 unknown-array2) (the-as (array uint64) (new 'global 'boxed-array uint64 32)))
(set! (-> gp-0 unknown-array3) (the-as (array uint64) (new 'global 'boxed-array uint64 32)))
(set! (-> gp-0 unknown-array1) (new 'global 'boxed-array uint64 110))
(set! (-> gp-0 unknown-array4) (new 'global 'boxed-array uint64 110))
(set! (-> gp-0 unknown-array2) (new 'global 'boxed-array uint64 32))
(set! (-> gp-0 unknown-array3) (new 'global 'boxed-array uint64 32))
(set! *game-info* gp-0)
gp-0
)

View File

@ -27,13 +27,9 @@
(kmemopen global "part-tables")
(define *part-id-table*
(the-as (array sparticle-launcher) (new 'global 'boxed-array sparticle-launcher 5760))
)
(define *part-id-table* (new 'global 'boxed-array sparticle-launcher 5760))
(define *part-group-id-table*
(the-as (array sparticle-launch-group) (new 'global 'boxed-array sparticle-launch-group 1408))
)
(define *part-group-id-table* (new 'global 'boxed-array sparticle-launch-group 1408))
(define *sp-temp* 0)

View File

@ -180,7 +180,7 @@
(set! (-> gp-0 spool-lock) (the-as handle #f))
(set! (-> gp-0 reserve-buffer) #f)
(set! (-> gp-0 active-stream) #f)
(set! (-> gp-0 queue-stream) (the-as (array spool-anim) (new 'global 'boxed-array spool-anim 4)))
(set! (-> gp-0 queue-stream) (new 'global 'boxed-array spool-anim 4))
(dotimes (s5-1 (-> gp-0 queue-stream allocated-length))
(set! (-> gp-0 queue-stream s5-1) (new 'global 'spool-anim))
)

View File

@ -3420,7 +3420,7 @@
(set! (-> obj game) *game-info*)
(collide-shape-method-29 (-> obj control) (-> arg0 trans))
(set! (-> obj control unknown-vector15 quad) (-> arg0 trans quad))
(set! (-> obj focus-search) (the-as (array collide-shape) (new 'process 'boxed-array collide-shape 128)))
(set! (-> obj focus-search) (new 'process 'boxed-array collide-shape 128))
(set! (-> obj focus-search length) 0)
(set! (-> obj control unknown-cpad-info00) (-> *cpad-list* cpads 0))
(set! (-> obj control unknown-surface01) (new 'process 'surface))

View File

@ -727,7 +727,15 @@ Val* Compiler::compile_deref(const goos::Object& form, const goos::Object& _rest
// deref thing is one of the field names. Otherwise, array.
if (field_name == "content-type" || field_name == "length" ||
field_name == "allocated-length" || field_name == "type" || field_name == "data") {
result = get_field_of_structure(struct_type, result, field_name, env);
// if accessing data, give the more specific pointer type.
if (field_name == "data" && result->type().has_single_arg()) {
auto elt_type = m_ts.make_pointer_typespec(result->type().get_single_arg());
result = get_field_of_structure(struct_type, result, field_name, env);
result->set_type(elt_type);
} else {
// otherwise, deref as normal
result = get_field_of_structure(struct_type, result, field_name, env);
}
continue;
}
} else {

View File

@ -5,7 +5,7 @@
(define *background-draw-engine* (new 'global 'engine 'draw 10))
;; definition for symbol *matrix-engine*, type (array handle)
(define *matrix-engine* (the-as (array handle) (new 'global 'boxed-array handle 1024)))
(define *matrix-engine* (new 'global 'boxed-array handle 1024))
;; failed to figure out what this is:
(set! (-> *matrix-engine* length) 0)

View File

@ -82,13 +82,13 @@
;; definition for function store-image
;; INFO: Used lq/sq
(defun store-image ((oddeven int))
(local-vars (ptr-1 (pointer uint8)) (y-idx int) (y-idx-2 int))
(local-vars (ptr-1 (pointer uint128)) (y-idx int) (y-idx-2 int))
(let ((width 512)
(height (-> *video-parms* screen-sy))
(file (new 'debug 'file-stream "image.raw" 'write))
)
(let ((buff0 (new 'debug 'boxed-array uint128 (/ (* width height) 4))))
(let ((buff1 (new 'debug 'boxed-array uint128 (/ (* width height) 4))))
(let ((buff0 (the-as (array uint128) (new 'debug 'boxed-array uint128 (/ (* width height) 4)))))
(let ((buff1 (the-as (array uint128) (new 'debug 'boxed-array uint128 (/ (* width height) 4)))))
(let ((packet (new 'static 'gs-store-image-packet)))
(gs-set-default-store-image packet #x2800 (/ width 64) 0 0 0 width height)
(flush-cache 0)

View File

@ -273,14 +273,10 @@
)
;; definition for symbol *part-id-table*, type (array sparticle-launcher)
(define *part-id-table*
(the-as (array sparticle-launcher) (new 'global 'boxed-array sparticle-launcher 3584))
)
(define *part-id-table* (new 'global 'boxed-array sparticle-launcher 3584))
;; definition for symbol *part-group-id-table*, type (array sparticle-launch-group)
(define *part-group-id-table*
(the-as (array sparticle-launch-group) (new 'global 'boxed-array sparticle-launch-group 1024))
)
(define *part-group-id-table* (new 'global 'boxed-array sparticle-launch-group 1024))
;; definition for function lookup-part-group-by-name
;; INFO: Return type mismatch sparticle-launch-group vs basic.

View File

@ -837,9 +837,7 @@
(let ((s5-1 (res-lump-data arg0 'delay pointer :tag-ptr (& sv-16))))
(cond
(s5-1
(set! (-> obj spawn-array)
(the-as (array int64) (new 'process 'boxed-array time-frame (the-as int (-> sv-16 elt-count))))
)
(set! (-> obj spawn-array) (new 'process 'boxed-array time-frame (the-as int (-> sv-16 elt-count))))
(dotimes (v1-12 (the-as int (-> sv-16 elt-count)))
(set! (-> obj spawn-array v1-12)
(the int (* (fabs (-> obj speed)) (-> (the-as (pointer float) (&+ s5-1 (* v1-12 4))))))
@ -847,7 +845,7 @@
)
)
(else
(set! (-> obj spawn-array) (the-as (array int64) (new 'process 'boxed-array time-frame 4)))
(set! (-> obj spawn-array) (new 'process 'boxed-array time-frame 4))
(set! (-> obj spawn-array 0) (the int (* 45056.0 (fabs (-> obj speed)))))
(set! (-> obj spawn-array 1) (the int (* 90112.0 (fabs (-> obj speed)))))
(set! (-> obj spawn-array 2) (the int (* 45056.0 (fabs (-> obj speed)))))

View File

@ -370,7 +370,7 @@
(set! (-> obj path) (new 'process 'path-control obj 'path 0.0))
(logior! (-> obj path flags) (path-control-flag display draw-line draw-point draw-text))
(let ((s4-1 (entity-actor-count arg0 'alt-actor)))
(set! (-> obj alt-actors) (the-as (array entity-actor) (new 'process 'boxed-array entity-actor s4-1)))
(set! (-> obj alt-actors) (new 'process 'boxed-array entity-actor s4-1))
(dotimes (s3-1 s4-1)
(set! (-> obj alt-actors s3-1) (entity-actor-lookup arg0 'alt-actor s3-1))
)

View File

@ -763,7 +763,7 @@
(set! (-> obj end-y) (+ 851968.0 (-> obj start-y)))
(set-vector! (-> obj root scale) 1.0 0.8 1.0 1.0)
(let ((s4-0 (entity-actor-count arg0 'alt-actor)))
(set! (-> obj alt-actors) (the-as (array entity-actor) (new 'process 'boxed-array entity-actor s4-0)))
(set! (-> obj alt-actors) (new 'process 'boxed-array entity-actor s4-0))
(dotimes (s3-0 s4-0)
(set! (-> obj alt-actors s3-0) (entity-actor-lookup arg0 'alt-actor s3-0))
)

View File

@ -46,7 +46,7 @@
;; this part is debug only
(when *debug-segment*
;; definition for symbol *debug-sphere-table*, type (array vector-array)
(define *debug-sphere-table* (the-as (array vector-array) (new 'debug 'boxed-array vector-array 10)))
(define *debug-sphere-table* (new 'debug 'boxed-array vector-array 10))
)
;; definition for function add-debug-sphere-from-table

View File

@ -8,7 +8,7 @@
(define *background-draw-engine* (new 'global 'engine 'draw 10 connection))
;; definition for symbol *matrix-engine*, type (array handle)
(define *matrix-engine* (the-as (array handle) (new 'global 'boxed-array handle 1024)))
(define *matrix-engine* (new 'global 'boxed-array handle 1024))
;; failed to figure out what this is:
(set! (-> *matrix-engine* length) 0)
@ -39,7 +39,3 @@
;; failed to figure out what this is:
(kmemclose)

View File

@ -456,10 +456,10 @@
;; failed to figure out what this is:
(set! gp-0 (when (or (not *game-info*) (zero? *game-info*))
(set! gp-0 (new 'static 'game-info :mode 'debug :current-continue #f :last-continue #f))
(set! (-> gp-0 unknown-array1) (the-as (array uint64) (new 'global 'boxed-array uint64 110)))
(set! (-> gp-0 unknown-array4) (the-as (array uint64) (new 'global 'boxed-array uint64 110)))
(set! (-> gp-0 unknown-array2) (the-as (array uint64) (new 'global 'boxed-array uint64 32)))
(set! (-> gp-0 unknown-array3) (the-as (array uint64) (new 'global 'boxed-array uint64 32)))
(set! (-> gp-0 unknown-array1) (new 'global 'boxed-array uint64 110))
(set! (-> gp-0 unknown-array4) (new 'global 'boxed-array uint64 110))
(set! (-> gp-0 unknown-array2) (new 'global 'boxed-array uint64 32))
(set! (-> gp-0 unknown-array3) (new 'global 'boxed-array uint64 32))
(set! *game-info* gp-0)
gp-0
)

View File

@ -256,14 +256,10 @@
(kmemopen global "part-tables")
;; definition for symbol *part-id-table*, type (array sparticle-launcher)
(define *part-id-table*
(the-as (array sparticle-launcher) (new 'global 'boxed-array sparticle-launcher 5760))
)
(define *part-id-table* (new 'global 'boxed-array sparticle-launcher 5760))
;; definition for symbol *part-group-id-table*, type (array sparticle-launch-group)
(define *part-group-id-table*
(the-as (array sparticle-launch-group) (new 'global 'boxed-array sparticle-launch-group 1408))
)
(define *part-group-id-table* (new 'global 'boxed-array sparticle-launch-group 1408))
;; definition for symbol *sp-temp*, type int
(define *sp-temp* 0)

View File

@ -244,7 +244,7 @@
(set! (-> gp-0 spool-lock) (the-as handle #f))
(set! (-> gp-0 reserve-buffer) #f)
(set! (-> gp-0 active-stream) #f)
(set! (-> gp-0 queue-stream) (the-as (array spool-anim) (new 'global 'boxed-array spool-anim 4)))
(set! (-> gp-0 queue-stream) (new 'global 'boxed-array spool-anim 4))
(dotimes (s5-1 (-> gp-0 queue-stream allocated-length))
(set! (-> gp-0 queue-stream s5-1) (new 'global 'spool-anim))
)

View File

@ -3391,7 +3391,7 @@
(set! (-> obj game) *game-info*)
(collide-shape-method-29 (-> obj control) (-> arg0 trans))
(set! (-> obj control unknown-vector15 quad) (-> arg0 trans quad))
(set! (-> obj focus-search) (the-as (array collide-shape) (new 'process 'boxed-array collide-shape 128)))
(set! (-> obj focus-search) (new 'process 'boxed-array collide-shape 128))
(set! (-> obj focus-search length) 0)
(set! (-> obj control unknown-cpad-info00) (-> *cpad-list* cpads 0))
(set! (-> obj control unknown-surface01) (new 'process 'surface))