fix labmda defs (#670)

This commit is contained in:
water111
2021-07-02 12:27:46 -04:00
committed by GitHub
parent fc124dd940
commit b96d865e2b
6 changed files with 45 additions and 44 deletions
+2 -1
View File
@@ -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) {
+16 -7
View File
@@ -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";
+1
View File
@@ -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
+1 -6
View File
@@ -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++;
+1 -6
View File
@@ -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));
+24 -24
View File
@@ -1136,7 +1136,7 @@
process
(search-process-tree
arg1
(lambda ((a0-0 process)) (name= (-> a0-0 name) *global-search-name*))
(lambda ((arg0 process)) (name= (-> arg0 name) *global-search-name*))
)
)
)
@@ -1149,7 +1149,7 @@
process
(search-process-tree
arg1
(lambda ((a0-0 process)) (not (name= (-> a0-0 name) *global-search-name*)))
(lambda ((arg0 process)) (not (name= (-> arg0 name) *global-search-name*)))
)
)
)
@@ -1160,7 +1160,7 @@
(iterate-process-tree
arg0
(lambda
((a0-0 process))
((arg0 process))
(set! *global-search-count* (+ *global-search-count* 1))
#t
)
@@ -1190,7 +1190,7 @@
a0-1
(search-process-tree
arg1
(lambda ((a0-0 process)) (= (-> a0-0 type) *global-search-name*))
(lambda ((arg0 process)) (= (-> arg0 type) *global-search-name*))
)
)
a0-1
@@ -1221,7 +1221,7 @@
a0-1
(search-process-tree
arg1
(lambda ((a0-0 process)) (!= (-> a0-0 type) *global-search-name*))
(lambda ((arg0 process)) (!= (-> arg0 type) *global-search-name*))
)
)
a0-1
@@ -1343,15 +1343,15 @@
)
(execute-process-tree
*active-pool*
(lambda ((a0-0 process)) (let ((s5-0 *kernel-context*)
(v1-0 (-> a0-0 status))
(lambda ((arg0 process)) (let ((s5-0 *kernel-context*)
(v1-0 (-> arg0 status))
)
(cond
((or (= v1-0 'waiting-to-run) (= v1-0 'suspended))
(set! (-> s5-0 current-process) a0-0)
(set! (-> s5-0 current-process) arg0)
(cond
((nonzero?
(logand (-> a0-0 mask) (process-mask pause))
(logand (-> arg0 mask) (process-mask pause))
)
(set! *stdcon* *stdcon1*)
(set! *debug-draw-pauseable* #t)
@@ -1361,23 +1361,23 @@
(set! *debug-draw-pauseable* #f)
)
)
(when (-> a0-0 trans-hook)
(when (-> arg0 trans-hook)
(let
((s4-0
(new
'process
'cpu-thread
a0-0
arg0
'trans
256
(-> a0-0 main-thread stack-top)
(-> arg0 main-thread stack-top)
)
)
)
(reset-and-call s4-0 (-> a0-0 trans-hook))
(reset-and-call s4-0 (-> arg0 trans-hook))
(delete s4-0)
)
(when (= (-> a0-0 status) 'dead)
(when (= (-> arg0 status) 'dead)
(set! (-> s5-0 current-process) #f)
(return 'dead)
)
@@ -1385,42 +1385,42 @@
(if
(nonzero?
(logand
(-> a0-0 mask)
(-> arg0 mask)
(process-mask sleep-code)
)
)
(set! (-> a0-0 status) 'suspended)
((-> a0-0 main-thread resume-hook)
(-> a0-0 main-thread)
(set! (-> arg0 status) 'suspended)
((-> arg0 main-thread resume-hook)
(-> arg0 main-thread)
)
)
(cond
((= (-> a0-0 status) 'dead)
((= (-> arg0 status) 'dead)
(set! (-> s5-0 current-process) #f)
'dead
)
(else
(when (-> a0-0 post-hook)
(when (-> arg0 post-hook)
(let
((s4-1
(new
'process
'cpu-thread
a0-0
arg0
'post
256
(&-> *dram-stack* 14336)
)
)
)
(reset-and-call s4-1 (-> a0-0 post-hook))
(reset-and-call s4-1 (-> arg0 post-hook))
(delete s4-1)
)
(when (= (-> a0-0 status) 'dead)
(when (= (-> arg0 status) 'dead)
(set! (-> s5-0 current-process) #f)
(return 'dead)
)
(set! (-> a0-0 status) 'suspended)
(set! (-> arg0 status) 'suspended)
)
(set! (-> s5-0 current-process) #f)
#f