diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2022-03-06 02:18:01 +0100 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2022-06-27 21:13:31 +0200 |
commit | 26bc4f9904b014c9949489e8ae28366da473e85d (patch) | |
tree | 71b89917bb301831e8c77d4a1a8496a9ce84de9c /filter/config.Y | |
parent | fb1d8f65136aa6190b527b691f24abe16a461471 (diff) |
Filter: Implement direct recursion
Direct recursion almost worked, just crashed on function signature check.
Split function parsing such that function signature is saved before
function body is processed. Recursive calls are marked so they can be
avoided during f_same() and similar code walking.
Also, include tower of hanoi solver as a test case.
Diffstat (limited to 'filter/config.Y')
-rw-r--r-- | filter/config.Y | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/filter/config.Y b/filter/config.Y index a4e82c7d..82a072ab 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -460,25 +460,28 @@ function_body: conf: function_def ; function_def: - FUNCTION symbol { DBG( "Beginning of function %s\n", $2->name ); + FUNCTION symbol { + DBG( "Beginning of function %s\n", $2->name ); $2 = cf_define_symbol($2, SYM_FUNCTION, function, NULL); cf_push_scope($2); - } function_args function_body - { - $5->arg_list = NULL; - $5->args = 0; + } function_args { + /* Make dummy f_line for storing function prototype */ + struct f_line *dummy = cfg_allocz(sizeof(struct f_line)); + $2->function = dummy; /* Revert the args */ while ($4) { struct f_arg *tmp = $4; $4 = $4->next; - tmp->next = $5->arg_list; - $5->arg_list = tmp; - $5->args++; + tmp->next = dummy->arg_list; + dummy->arg_list = tmp; + dummy->args++; } - - $2->function = $5; + } function_body { + $6->args = $2->function->args; + $6->arg_list = $2->function->arg_list; + $2->function = $6; cf_pop_scope(); } ; |