union {
struct proto_config *proto; /* For SYM_PROTO and SYM_TEMPLATE */
- const struct f_line *function; /* For SYM_FUNCTION */
+ const struct function *function; /* For SYM_FUNCTION */
const struct filter *filter; /* For SYM_FILTER */
struct rtable_config *table; /* For SYM_TABLE */
struct f_dynamic_attr *attribute; /* For SYM_ATTRIBUTE */
BT_TEST_SUITE '(' CF_SYM_KNOWN ',' text ')' {
cf_assert_symbol($3, SYM_FUNCTION);
struct f_bt_test_suite *t = cfg_allocz(sizeof(struct f_bt_test_suite));
- t->fn = $3->function;
+ t->fn = $3->function->body;
t->fn_name = $3->name;
t->dsc = $5;
cf_assert_symbol($3, SYM_FUNCTION);
cf_assert_symbol($5, SYM_FUNCTION);
struct f_bt_test_suite *t = cfg_allocz(sizeof(struct f_bt_test_suite));
- t->fn = $3->function;
- t->cmp = $5->function;
+ t->fn = $3->function->body;
+ t->cmp = $5->function->body;
t->result = $7;
t->fn_name = $3->name;
t->dsc = $5->name;
cf_push_scope($2);
} function_args function_body {
DBG("Definition of function %s with %u args and %u local vars.\n", $2->name, $4, $5->vars);
+ struct function *fn = cfg_alloc(sizeof(struct function));
+ *fn = (struct function) { .sym = $2, .body = $5 };
+ $2->function = fn;
$5->args = $4;
- $2->function = $5;
cf_pop_scope();
}
;
SYMBOL;
FID_NEW_BODY()
- if (whati->varcount != sym->function->args)
+ if (whati->varcount != sym->function->body->args)
cf_error("Function call '%s' got %u arguments, needs %u arguments",
- sym->name, whati->varcount, sym->function->args);
+ sym->name, whati->varcount, sym->function->body->args);
/* Add void slot for return value (requires [[NEVER_CONSTANT]]) */
struct f_inst *rv = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_VOID });
FID_INTERPRET_BODY()
/* Push the body on stack */
- LINEX(sym->function);
+ LINEX(sym->function->body);
curline.emask |= FE_RETURN;
/* Set new base for local variables */
fstk->vcnt += whati->varcount;
/* Storage for local variables */
- memset(&(fstk->vstk[fstk->vcnt]), 0, sizeof(struct f_val) * sym->function->vars);
- fstk->vcnt += sym->function->vars;
+ uint vars = sym->function->body->vars;
+ memset(&(fstk->vstk[fstk->vcnt]), 0, sizeof(struct f_val) * vars);
+ fstk->vcnt += vars;
}
INST(FI_DROP_RESULT, 1, 0) {
case SYM_FUNCTION:
if ((osym = cf_find_symbol(old, sym->name)) &&
(osym->class == SYM_FUNCTION) &&
- f_same(sym->function, osym->function))
+ f_same(sym->function->body, osym->function->body))
sym->flags |= SYM_FLAG_SAME;
else
sym->flags &= ~SYM_FLAG_SAME;
break;
case SYM_FUNCTION:
debug("Function %s:\n", sym->name);
- f_dump_line(sym->function, 1);
+ f_dump_line(sym->function->body, 1);
break;
case SYM_PROTO:
{
}
struct f_val;
+struct f_line;
/* The filter encapsulating structure to be pointed-to from outside */
-struct f_line;
struct filter {
struct symbol *sym;
const struct f_line *root;
};
+struct function {
+ struct symbol *sym;
+ const struct f_line *body;
+};
+
struct rte;
enum filter_return f_run(const struct filter *filter, struct rte **rte, struct linpool *tmp_pool, int flags);