Conf/Filters: Moved argument count to conf scope
This commit is contained in:
parent
a84b8b6ebb
commit
63e7620462
3 changed files with 13 additions and 12 deletions
|
@ -742,6 +742,7 @@ cf_push_scope(struct symbol *sym)
|
||||||
conf_this_scope = s;
|
conf_this_scope = s;
|
||||||
s->active = 1;
|
s->active = 1;
|
||||||
s->name = sym;
|
s->name = sym;
|
||||||
|
s->slots = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -126,6 +126,7 @@ struct symbol {
|
||||||
struct sym_scope {
|
struct sym_scope {
|
||||||
struct sym_scope *next; /* Next on scope stack */
|
struct sym_scope *next; /* Next on scope stack */
|
||||||
struct symbol *name; /* Name of this scope */
|
struct symbol *name; /* Name of this scope */
|
||||||
|
uint slots; /* Variable slots */
|
||||||
int active; /* Currently entered */
|
int active; /* Currently entered */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,6 @@ CF_HDR
|
||||||
|
|
||||||
CF_DEFINES
|
CF_DEFINES
|
||||||
|
|
||||||
static uint decls_count;
|
|
||||||
|
|
||||||
static inline u32 pair(u32 a, u32 b) { return (a << 16) | b; }
|
static inline u32 pair(u32 a, u32 b) { return (a << 16) | b; }
|
||||||
static inline u32 pair_a(u32 p) { return p >> 16; }
|
static inline u32 pair_a(u32 p) { return p >> 16; }
|
||||||
static inline u32 pair_b(u32 p) { return p & 0xFFFF; }
|
static inline u32 pair_b(u32 p) { return p & 0xFFFF; }
|
||||||
|
@ -455,7 +453,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
|
||||||
%type <f> filter where_filter
|
%type <f> filter where_filter
|
||||||
%type <fl> filter_body function_body
|
%type <fl> filter_body function_body
|
||||||
%type <flv> lvalue
|
%type <flv> lvalue
|
||||||
%type <i> type function_params
|
%type <i> type function_params declsn decls
|
||||||
%type <ecs> ec_kind
|
%type <ecs> ec_kind
|
||||||
%type <fret> break_command
|
%type <fret> break_command
|
||||||
%type <i32> cnum
|
%type <i32> cnum
|
||||||
|
@ -557,22 +555,24 @@ type:
|
||||||
|
|
||||||
/* Declarations with ';' at the end */
|
/* Declarations with ';' at the end */
|
||||||
decls:
|
decls:
|
||||||
/* EMPTY */
|
/* EMPTY */ { $$ = 0; }
|
||||||
| declsn ';'
|
| declsn ';' { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
/* Declarations that have no ';' at the end. */
|
/* Declarations that have no ';' at the end. */
|
||||||
declsn:
|
declsn:
|
||||||
type CF_SYM_VOID {
|
type CF_SYM_VOID {
|
||||||
cf_define_symbol($2, SYM_VARIABLE | $1, offset, decls_count++);
|
cf_define_symbol($2, SYM_VARIABLE | $1, offset, $2->scope->slots++);
|
||||||
|
$$ = $2->scope->slots;
|
||||||
}
|
}
|
||||||
| declsn ';' type CF_SYM_VOID {
|
| declsn ';' type CF_SYM_VOID {
|
||||||
if (decls_count >= 0xff) cf_error("Too many declarations, at most 255 allowed");
|
if ($4->scope->slots >= 0xff) cf_error("Too many declarations, at most 255 allowed");
|
||||||
cf_define_symbol($4, SYM_VARIABLE | $3, offset, decls_count++);
|
cf_define_symbol($4, SYM_VARIABLE | $3, offset, $4->scope->slots++);
|
||||||
|
$$ = $4->scope->slots;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
filter_body: { decls_count = 0; } function_body { $$ = $2; } ;
|
filter_body: function_body ;
|
||||||
|
|
||||||
filter:
|
filter:
|
||||||
CF_SYM_KNOWN {
|
CF_SYM_KNOWN {
|
||||||
|
@ -594,14 +594,14 @@ where_filter:
|
||||||
;
|
;
|
||||||
|
|
||||||
function_params:
|
function_params:
|
||||||
'(' declsn ')' { $$ = decls_count; }
|
'(' declsn ')' { $$ = $2; }
|
||||||
| '(' ')' { $$ = 0; }
|
| '(' ')' { $$ = 0; }
|
||||||
;
|
;
|
||||||
|
|
||||||
function_body:
|
function_body:
|
||||||
decls '{' cmds '}' {
|
decls '{' cmds '}' {
|
||||||
$$ = f_linearize($3);
|
$$ = f_linearize($3);
|
||||||
$$->vars = decls_count;
|
$$->vars = $1;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -610,7 +610,6 @@ function_def:
|
||||||
FUNCTION CF_SYM_VOID { DBG( "Beginning of function %s\n", $2->name );
|
FUNCTION CF_SYM_VOID { DBG( "Beginning of function %s\n", $2->name );
|
||||||
$2 = cf_define_symbol($2, SYM_FUNCTION, function, NULL);
|
$2 = cf_define_symbol($2, SYM_FUNCTION, function, NULL);
|
||||||
cf_push_scope($2);
|
cf_push_scope($2);
|
||||||
decls_count = 0;
|
|
||||||
} function_params function_body {
|
} function_params function_body {
|
||||||
$5->vars -= $4;
|
$5->vars -= $4;
|
||||||
$5->args = $4;
|
$5->args = $4;
|
||||||
|
|
Loading…
Reference in a new issue