mirror of
https://github.com/open-goal/jak-project
synced 2026-08-13 20:25:20 -04:00
decompiler fixes
This commit is contained in:
@@ -54,7 +54,8 @@ void append_body_to_function_definition(goos::Object* top_form,
|
||||
const std::vector<goos::Object>& inline_body,
|
||||
const FunctionVariableDefinitions& var_dec,
|
||||
const TypeSpec& ts,
|
||||
GameVersion version) {
|
||||
GameVersion version,
|
||||
const Env& env) {
|
||||
// Some forms like docstrings and local-vars we _always_ want to be at the top level and first (in
|
||||
// the order added)
|
||||
std::vector<goos::Object> initial_top_level_forms;
|
||||
@@ -77,19 +78,32 @@ void append_body_to_function_definition(goos::Object* top_form,
|
||||
for (const auto& elem : initial_top_level_forms) {
|
||||
final_body.push_back(elem);
|
||||
}
|
||||
std::vector<goos::Object> scoped_body;
|
||||
|
||||
// If the form contains the ppointer and isn't a behavior, we need to wrap the body in `with-pp`
|
||||
if (var_dec.had_pp && !ts.try_get_tag("behavior")) {
|
||||
std::vector<goos::Object> body_with_pp;
|
||||
body_with_pp.push_back(pretty_print::to_symbol("with-pp"));
|
||||
body_with_pp.insert(body_with_pp.end(), body_elements.begin(), body_elements.end());
|
||||
final_body.push_back(pretty_print::build_list(body_with_pp));
|
||||
scoped_body.push_back(pretty_print::build_list(body_with_pp));
|
||||
} else {
|
||||
// otherwise, just construct the form from the body
|
||||
for (const auto& elem : body_elements) {
|
||||
final_body.push_back(elem);
|
||||
scoped_body.push_back(elem);
|
||||
}
|
||||
}
|
||||
|
||||
if (env.uses_scratchpad()) {
|
||||
ASSERT(env.scratchpad_type());
|
||||
std::vector<goos::Object> scratchpad_body;
|
||||
scratchpad_body.push_back(pretty_print::to_symbol("slet"));
|
||||
scratchpad_body.push_back(pretty_print::build_list("spad", env.scratchpad_type()->print()));
|
||||
scratchpad_body.insert(scratchpad_body.end(), scoped_body.begin(), scoped_body.end());
|
||||
final_body.push_back(pretty_print::build_list(scratchpad_body));
|
||||
} else {
|
||||
final_body.insert(final_body.end(), scoped_body.begin(), scoped_body.end());
|
||||
}
|
||||
|
||||
pretty_print::append(*top_form, pretty_print::build_list(final_body));
|
||||
}
|
||||
} // namespace
|
||||
@@ -103,11 +117,13 @@ goos::Object final_output_lambda(const Function& func, GameVersion version) {
|
||||
if (behavior) {
|
||||
auto result = pretty_print::build_list(fmt::format("lambda :behavior {}", *behavior),
|
||||
get_arg_list_for_function(func, func.ir2.env));
|
||||
append_body_to_function_definition(&result, inline_body, var_dec, func.type, version);
|
||||
append_body_to_function_definition(&result, inline_body, var_dec, func.type, version,
|
||||
func.ir2.env);
|
||||
return result;
|
||||
} else {
|
||||
auto result = pretty_print::build_list("lambda", get_arg_list_for_function(func, func.ir2.env));
|
||||
append_body_to_function_definition(&result, inline_body, var_dec, func.type, version);
|
||||
append_body_to_function_definition(&result, inline_body, var_dec, func.type, version,
|
||||
func.ir2.env);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -134,8 +150,7 @@ goos::Object final_output_defstate_anonymous_behavior(const Function& func,
|
||||
} else if (func.guessed_name.kind == FunctionName::FunctionKind::NV_STATE) {
|
||||
if (dts.state_metadata.count(state_name) != 0 &&
|
||||
dts.state_metadata.at(state_name).count(handler_name) != 0) {
|
||||
metadata_docstring =
|
||||
dts.state_metadata.at(state_name).at(handler_name).docstring.value();
|
||||
metadata_docstring = dts.state_metadata.at(state_name).at(handler_name).docstring.value();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +161,8 @@ goos::Object final_output_defstate_anonymous_behavior(const Function& func,
|
||||
auto var_dec = func.ir2.env.local_var_type_list(func.ir2.top_form, func.type.arg_count() - 1);
|
||||
|
||||
auto result = pretty_print::build_list("behavior", get_arg_list_for_function(func, func.ir2.env));
|
||||
append_body_to_function_definition(&result, inline_body, var_dec, func.type, dts.version());
|
||||
append_body_to_function_definition(&result, inline_body, var_dec, func.type, dts.version(),
|
||||
func.ir2.env);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -198,7 +214,8 @@ std::string final_defun_out(const Function& func,
|
||||
}
|
||||
}
|
||||
|
||||
append_body_to_function_definition(&top_form, inline_body, var_dec, func.type, dts.version());
|
||||
append_body_to_function_definition(&top_form, inline_body, var_dec, func.type, dts.version(),
|
||||
env);
|
||||
return pretty_print::to_string(top_form);
|
||||
}
|
||||
|
||||
@@ -219,7 +236,7 @@ std::string final_defun_out(const Function& func,
|
||||
set_metadata_docstring(&inline_body, method_info.docstring.value());
|
||||
}
|
||||
append_body_to_function_definition(&top_form, inline_body, var_dec, method_info.type,
|
||||
dts.version());
|
||||
dts.version(), env);
|
||||
return pretty_print::to_string(top_form);
|
||||
}
|
||||
|
||||
@@ -230,7 +247,8 @@ std::string final_defun_out(const Function& func,
|
||||
top.push_back(arguments);
|
||||
auto top_form = pretty_print::build_list(top);
|
||||
|
||||
append_body_to_function_definition(&top_form, inline_body, var_dec, func.type, dts.version());
|
||||
append_body_to_function_definition(&top_form, inline_body, var_dec, func.type, dts.version(),
|
||||
env);
|
||||
return pretty_print::to_string(top_form);
|
||||
}
|
||||
|
||||
@@ -243,7 +261,8 @@ std::string final_defun_out(const Function& func,
|
||||
top.push_back(arguments);
|
||||
auto top_form = pretty_print::build_list(top);
|
||||
|
||||
append_body_to_function_definition(&top_form, inline_body, var_dec, func.type, dts.version());
|
||||
append_body_to_function_definition(&top_form, inline_body, var_dec, func.type, dts.version(),
|
||||
env);
|
||||
return pretty_print::to_string(top_form);
|
||||
}
|
||||
|
||||
@@ -257,7 +276,8 @@ std::string final_defun_out(const Function& func,
|
||||
top.push_back(arguments);
|
||||
auto top_form = pretty_print::build_list(top);
|
||||
|
||||
append_body_to_function_definition(&top_form, inline_body, var_dec, func.type, dts.version());
|
||||
append_body_to_function_definition(&top_form, inline_body, var_dec, func.type, dts.version(),
|
||||
env);
|
||||
return pretty_print::to_string(top_form);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user