change analyze_args API
This commit is contained in:
parent
801c04788f
commit
66a7e653ba
|
@ -37,9 +37,10 @@ new_irep(pic_state *pic)
|
||||||
return irep;
|
return irep;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static pic_sym *
|
||||||
analyze_args(pic_state *pic, pic_value args, struct xhash *x, bool *varg, size_t *argc, size_t *localc)
|
analyze_args(pic_state *pic, pic_value args, bool *varg, size_t *argc, size_t *localc)
|
||||||
{
|
{
|
||||||
|
pic_sym *syms = pic_alloc(pic, sizeof(pic_sym));
|
||||||
size_t i = 1, l = 0;
|
size_t i = 1, l = 0;
|
||||||
pic_value v;
|
pic_value v;
|
||||||
|
|
||||||
|
@ -48,10 +49,12 @@ analyze_args(pic_state *pic, pic_value args, struct xhash *x, bool *varg, size_t
|
||||||
pic_value sym;
|
pic_value sym;
|
||||||
|
|
||||||
sym = pic_car(pic, v);
|
sym = pic_car(pic, v);
|
||||||
if (! pic_symbol_p(sym))
|
if (! pic_symbol_p(sym)) {
|
||||||
return false;
|
pic_free(pic, syms);
|
||||||
if (x)
|
return NULL;
|
||||||
xh_put(x, pic_symbol_name(pic, pic_sym(sym)), i);
|
}
|
||||||
|
syms = pic_realloc(pic, syms, sizeof(pic_sym) * (i + 1));
|
||||||
|
syms[i] = pic_sym(sym);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (pic_nil_p(v)) {
|
if (pic_nil_p(v)) {
|
||||||
|
@ -59,17 +62,18 @@ analyze_args(pic_state *pic, pic_value args, struct xhash *x, bool *varg, size_t
|
||||||
}
|
}
|
||||||
else if (pic_symbol_p(v)) {
|
else if (pic_symbol_p(v)) {
|
||||||
*varg = true;
|
*varg = true;
|
||||||
if (x)
|
syms = pic_realloc(pic, syms, sizeof(pic_sym) * (i + 1));
|
||||||
xh_put(x, pic_symbol_name(pic, pic_sym(v)), i + l);
|
syms[i] = pic_sym(v);
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
pic_free(pic, syms);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
*argc = i;
|
*argc = i;
|
||||||
*localc = l;
|
*localc = l;
|
||||||
|
|
||||||
return true;
|
return syms;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -77,8 +81,16 @@ valid_formal(pic_state *pic, pic_value formal)
|
||||||
{
|
{
|
||||||
bool varg;
|
bool varg;
|
||||||
size_t argc, localc;
|
size_t argc, localc;
|
||||||
|
pic_sym *syms;
|
||||||
|
|
||||||
return analyze_args(pic, formal, NULL, &varg, &argc, &localc);
|
syms = analyze_args(pic, formal, &varg, &argc, &localc);
|
||||||
|
if (syms == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pic_free(pic, syms);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct analyze_scope {
|
typedef struct analyze_scope {
|
||||||
|
|
Loading…
Reference in New Issue