[decomp] fix up gun decomp (#2067)

I did some manual modifications in a few places to work around some
truly mysterious control flow, and some unsupported stack array stuff.

Also fixes a bug in decompiling static improper lists.

As far as I can tell, guns work, other than some graphical issues and
the crazy particle spawning issue, but I strongly suspect these are
problems with the sparticle/graphics side.
This commit is contained in:
water111
2022-12-30 14:07:32 -05:00
committed by GitHub
parent 997c1ab60a
commit f6c5504f6f
16 changed files with 3587 additions and 56 deletions
+11 -16
View File
@@ -1600,6 +1600,14 @@ goos::Object decompile_pair_elt(const LinkedWord& word,
(int)word.kind(), word.data));
}
}
bool is_pointer_to_pair(const LinkedWord& word, const std::vector<DecompilerLabel>& labels) {
if (word.kind() != LinkedWord::PTR) {
return false;
}
auto& dest_label = labels.at(word.label_id());
return (dest_label.offset % 8) == 2;
}
} // namespace
goos::Object decompile_pair(const DecompilerLabel& label,
@@ -1649,7 +1657,7 @@ goos::Object decompile_pair(const DecompilerLabel& label,
}
}
// if pointer
if (cdr_word.kind() == LinkedWord::PTR) {
if (is_pointer_to_pair(cdr_word, labels)) {
to_print = labels.at(cdr_word.label_id());
continue;
}
@@ -1662,21 +1670,8 @@ goos::Object decompile_pair(const DecompilerLabel& label,
return pretty_print::build_list(list_tokens);
}
} else {
if ((to_print.offset % 4) != 0) {
throw std::runtime_error(
fmt::format("Invalid alignment for pair {}\n", to_print.offset % 16));
} else {
// improper
list_tokens.push_back(pretty_print::to_symbol("."));
list_tokens.push_back(
decompile_pair_elt(words.at(to_print.target_segment).at(to_print.offset / 4), labels,
words, ts, file, version));
if (add_quote) {
return pretty_print::build_list("quote", pretty_print::build_list(list_tokens));
} else {
return pretty_print::build_list(list_tokens);
}
}
throw std::runtime_error(
fmt::format("Invalid alignment for pair {}\n", to_print.offset % 16));
}
}
}