mirror of
https://github.com/open-goal/jak-project
synced 2026-09-10 12:25:21 -04:00
fix labmda defs (#670)
This commit is contained in:
@@ -21,7 +21,8 @@ bool convert_to_expressions(
|
||||
|
||||
// set argument names to some reasonable defaults. these will be used if the user doesn't
|
||||
// give us anything more specific.
|
||||
if (f.guessed_name.kind == FunctionName::FunctionKind::GLOBAL) {
|
||||
if (f.guessed_name.kind == FunctionName::FunctionKind::GLOBAL ||
|
||||
f.guessed_name.kind == FunctionName::FunctionKind::UNIDENTIFIED) {
|
||||
f.ir2.env.set_remap_for_function(f.type.arg_count() - 1);
|
||||
} else if (f.guessed_name.kind == FunctionName::FunctionKind::METHOD) {
|
||||
if (f.guessed_name.method_id == GOAL_NEW_METHOD) {
|
||||
|
||||
@@ -24,9 +24,9 @@ goos::Object get_arg_list_for_function(const Function& func, const Env& env) {
|
||||
}
|
||||
|
||||
namespace {
|
||||
void append_to_body(goos::Object* top_form,
|
||||
const std::vector<goos::Object>& inline_body,
|
||||
const FunctionVariableDefinitions& var_dec) {
|
||||
void append_body_to_function_definition(goos::Object* top_form,
|
||||
const std::vector<goos::Object>& inline_body,
|
||||
const FunctionVariableDefinitions& var_dec) {
|
||||
if (var_dec.local_vars) {
|
||||
pretty_print::append(*top_form, pretty_print::build_list(*var_dec.local_vars));
|
||||
}
|
||||
@@ -43,6 +43,15 @@ void append_to_body(goos::Object* top_form,
|
||||
}
|
||||
} // namespace
|
||||
|
||||
goos::Object final_output_lambda(const Function& func) {
|
||||
std::vector<goos::Object> inline_body;
|
||||
func.ir2.top_form->inline_forms(inline_body, func.ir2.env);
|
||||
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("lambda", get_arg_list_for_function(func, func.ir2.env));
|
||||
append_body_to_function_definition(&result, inline_body, var_dec);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string final_defun_out(const Function& func,
|
||||
const Env& env,
|
||||
const DecompilerTypeSystem& dts,
|
||||
@@ -72,7 +81,7 @@ std::string final_defun_out(const Function& func,
|
||||
top.push_back(arguments);
|
||||
auto top_form = pretty_print::build_list(top);
|
||||
|
||||
append_to_body(&top_form, inline_body, var_dec);
|
||||
append_body_to_function_definition(&top_form, inline_body, var_dec);
|
||||
return pretty_print::to_string(top_form);
|
||||
}
|
||||
|
||||
@@ -87,7 +96,7 @@ std::string final_defun_out(const Function& func,
|
||||
top.push_back(arguments);
|
||||
auto top_form = pretty_print::build_list(top);
|
||||
|
||||
append_to_body(&top_form, inline_body, var_dec);
|
||||
append_body_to_function_definition(&top_form, inline_body, var_dec);
|
||||
return pretty_print::to_string(top_form);
|
||||
}
|
||||
|
||||
@@ -98,7 +107,7 @@ std::string final_defun_out(const Function& func,
|
||||
top.push_back(arguments);
|
||||
auto top_form = pretty_print::build_list(top);
|
||||
|
||||
append_to_body(&top_form, inline_body, var_dec);
|
||||
append_body_to_function_definition(&top_form, inline_body, var_dec);
|
||||
return pretty_print::to_string(top_form);
|
||||
}
|
||||
|
||||
@@ -111,7 +120,7 @@ std::string final_defun_out(const Function& func,
|
||||
top.push_back(arguments);
|
||||
auto top_form = pretty_print::build_list(top);
|
||||
|
||||
append_to_body(&top_form, inline_body, var_dec);
|
||||
append_body_to_function_definition(&top_form, inline_body, var_dec);
|
||||
return pretty_print::to_string(top_form);
|
||||
}
|
||||
return "nyi";
|
||||
|
||||
@@ -16,4 +16,5 @@ std::string write_from_top_level(const Function& top_level,
|
||||
const std::unordered_set<std::string>& skip_functions = {});
|
||||
|
||||
goos::Object get_arg_list_for_function(const Function& func, const Env& env);
|
||||
goos::Object final_output_lambda(const Function& function);
|
||||
} // namespace decompiler
|
||||
|
||||
@@ -21,12 +21,7 @@ int insert_static_refs(Form* top_level_form,
|
||||
auto& file = env.file;
|
||||
auto other_func = file->try_get_function_at_label(atom->label());
|
||||
if (other_func) {
|
||||
std::vector<goos::Object> inline_body;
|
||||
other_func->ir2.top_form->inline_forms(inline_body, other_func->ir2.env);
|
||||
auto result = pretty_print::build_list(
|
||||
"lambda", get_arg_list_for_function(*other_func, other_func->ir2.env));
|
||||
pretty_print::append(result, pretty_print::build_list(inline_body));
|
||||
|
||||
auto result = final_output_lambda(*other_func);
|
||||
f->clear();
|
||||
f->push_back(pool.alloc_element<LambdaDefinitionElement>(result));
|
||||
replaced++;
|
||||
|
||||
@@ -139,12 +139,7 @@ goos::Object decompile_function_at_label(const DecompilerLabel& label,
|
||||
if (file) {
|
||||
auto other_func = file->try_get_function_at_label(label);
|
||||
if (other_func) {
|
||||
std::vector<goos::Object> inline_body;
|
||||
other_func->ir2.top_form->inline_forms(inline_body, other_func->ir2.env);
|
||||
auto result = pretty_print::build_list(
|
||||
"lambda", get_arg_list_for_function(*other_func, other_func->ir2.env));
|
||||
pretty_print::append(result, pretty_print::build_list(inline_body));
|
||||
return result;
|
||||
return final_output_lambda(*other_func);
|
||||
}
|
||||
}
|
||||
return pretty_print::to_symbol(fmt::format("<lambda at {}>", label.name));
|
||||
|
||||
Reference in New Issue
Block a user