Merge remote-tracking branch 'origin/master' into j2/progress

This commit is contained in:
Tyler Wilding
2022-09-27 23:00:22 -04:00
170 changed files with 57997 additions and 18336 deletions
+19 -10
View File
@@ -160,12 +160,18 @@ goos::Object decompile_at_label_guess_type(const DecompilerLabel& label,
}
goos::Object decompile_function_at_label(const DecompilerLabel& label,
const LinkedObjectFile* file) {
const LinkedObjectFile* file,
bool in_static_pair) {
if (file) {
auto other_func = file->try_get_function_at_label(label);
if (other_func && other_func->ir2.env.has_local_vars() && other_func->ir2.top_form &&
other_func->ir2.expressions_succeeded) {
return final_output_lambda(*other_func);
auto out = final_output_lambda(*other_func);
if (in_static_pair) {
return pretty_print::build_list("unquote", out);
} else {
return out;
}
}
}
return pretty_print::to_symbol(fmt::format("<lambda at {}>", label.name));
@@ -180,13 +186,14 @@ goos::Object decompile_at_label(const TypeSpec& type,
const std::vector<DecompilerLabel>& labels,
const std::vector<std::vector<LinkedWord>>& words,
const TypeSystem& ts,
const LinkedObjectFile* file) {
const LinkedObjectFile* file,
bool in_static_pair) {
if (type == TypeSpec("string")) {
return decompile_string_at_label(label, words);
}
if (ts.tc(TypeSpec("function"), type)) {
return decompile_function_at_label(label, file);
return decompile_function_at_label(label, file, in_static_pair);
}
if (ts.tc(TypeSpec("array"), type)) {
@@ -721,6 +728,7 @@ goos::Object decompile_sound_spec(const TypeSpec& type,
// volume is fixed point, and floats should round towards zero, so we convert specific ints
// to better-looking floats that end up being the same value.
// there should be a more automated way to do this, but i am a bit lazy.
// TODO try fixed point print i made some time ago
switch (volume) {
case 0x2cc:
volf = 70;
@@ -1534,13 +1542,13 @@ goos::Object decompile_pair_elt(const LinkedWord& word,
return decompile_pair(label, labels, words, ts, false, file);
}
return decompile_at_label(*guessed_type, label, labels, words, ts, file);
return decompile_at_label(*guessed_type, label, labels, words, ts, file, true);
} else if (word.kind() == LinkedWord::PLAIN_DATA && word.data == 0) {
// do nothing, the default is zero?
return pretty_print::to_symbol("0");
} else if (word.kind() == LinkedWord::SYM_PTR) {
// never quote symbols in a list.
return pretty_print::to_symbol(fmt::format("{}", word.symbol_name()));
return pretty_print::to_symbol(word.symbol_name());
} else if (word.kind() == LinkedWord::EMPTY_PTR) {
return pretty_print::to_symbol("'()");
} else if (word.kind() == LinkedWord::PLAIN_DATA && (word.data & 0b111) == 0) {
@@ -1562,13 +1570,14 @@ goos::Object decompile_pair(const DecompilerLabel& label,
const LinkedObjectFile* file) {
if ((label.offset % 8) != 2) {
if ((label.offset % 4) != 0) {
throw std::runtime_error(fmt::format("Invalid alignment for pair {}\n", label.offset % 16));
throw std::runtime_error(
fmt::format("Invalid alignment for pair {} at {}\n", label.offset % 16, label.name));
} else {
auto& word = words.at(label.target_segment).at(label.offset / 4);
if (word.kind() != LinkedWord::EMPTY_PTR) {
throw std::runtime_error(fmt::format(
"Based on alignment, expected to get empty list for pair, but didn't. Label - {}",
label.name));
throw std::runtime_error(
fmt::format("Based on alignment, expected to get empty list for pair at {}, but didn't",
label.name));
}
return pretty_print::to_symbol("'()");
}