passed the argument list which the program requires. Similarly type
analysis is a bit more interesting at this level.
+###### ast functions
+
+ static struct variable *declare_function(struct parse_context *c,
+ struct variable *name,
+ struct binode *args,
+ struct exec *code)
+ {
+ struct text funcname = {" func", 5};
+ if (name) {
+ struct value fn = {.function = code};
+ name->type = add_type(c, funcname, &function_prototype);
+ name->type->function.params = reorder_bilist(args);
+ global_alloc(c, name->type, name, &fn);
+ var_block_close(c, CloseSequential, code);
+ } else
+ var_block_close(c, CloseSequential, NULL);
+ return name;
+ }
+
###### top level grammar
$*variable
- DeclareFunction -> func FuncName ( OpenScope Args ) Block Newlines ${ {
- struct text funcname = { " func", 5};
- $0 = $<FN;
- if ($0) {
- struct value fn = {.function = $<Bl};
- $0->type = add_type(c, funcname, &function_prototype);
- $0->type->function.params = reorder_bilist($<Ar);
- global_alloc(c, $0->type, $0, &fn);
- var_block_close(c, CloseSequential, fn.function);
- } else
- var_block_close(c, CloseSequential, NULL);
- } }$
- | func FuncName IN OpenScope OptNL Args OUT OptNL do Block Newlines ${ {
- struct text funcname = { " func", 5};
- $0 = $<FN;
- if ($0) {
- struct value fn = {.function = $<Bl};
- $0->type = add_type(c, funcname, &function_prototype);
- $0->type->function.params = reorder_bilist($<Ar);
- global_alloc(c, $0->type, $0, &fn);
- var_block_close(c, CloseSequential, fn.function);
- } else
- var_block_close(c, CloseSequential, NULL);
- } }$
- | func FuncName NEWLINE OpenScope OptNL do Block Newlines ${ {
- struct text funcname = { " func", 5};
- $0 = $<FN;
- if ($0) {
- struct value fn = {.function = $<Bl};
- $0->type = add_type(c, funcname, &function_prototype);
- $0->type->function.params = NULL;
- global_alloc(c, $0->type, $0, &fn);
- var_block_close(c, CloseSequential, fn.function);
- } else
- var_block_close(c, CloseSequential, NULL);
- } }$
+ DeclareFunction -> func FuncName ( OpenScope Args ) Block Newlines ${
+ $0 = declare_function(c, $<FN, $<Ar, $<Bl);
+ }$
+ | func FuncName IN OpenScope OptNL Args OUT OptNL do Block Newlines ${
+ $0 = declare_function(c, $<FN, $<Ar, $<Bl);
+ }$
+ | func FuncName NEWLINE OpenScope OptNL do Block Newlines ${
+ $0 = declare_function(c, $<FN, NULL, $<Bl);
+ }$
###### print func decls
{