1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-18 06:59:43 +02:00

vector names can now be resolved at instantiation (partially implemented)

This commit is contained in:
Werner Almesberger 2011-10-25 16:46:26 -03:00
parent c8f5d29178
commit cb34a28826
5 changed files with 58 additions and 19 deletions

4
dump.c
View File

@ -296,8 +296,12 @@ static void generate_name(struct vec *base)
static const char *base_name(struct vec *base, const struct vec *next) static const char *base_name(struct vec *base, const struct vec *next)
{ {
const char *name = (const char *) base;
if (!base) if (!base)
return "@"; return "@";
if (*name)
return name;
if (next && base->next == next) if (next && base->next == next)
return "."; return ".";
if (!base->name) if (!base->name)

7
fpd.y
View File

@ -826,6 +826,7 @@ vec:
TOK_VEC base '(' expr ',' expr ')' TOK_VEC base '(' expr ',' expr ')'
{ {
$$ = alloc_type(struct vec); $$ = alloc_type(struct vec);
$$->nul_tag = 0;
$$->name = NULL; $$->name = NULL;
$$->base = $2; $$->base = $2;
$$->x = $4; $$->x = $4;
@ -854,10 +855,8 @@ base:
| ID | ID
{ {
$$ = find_vec(curr_frame, $1); $$ = find_vec(curr_frame, $1);
if (!$$) { if (!$$)
yyerrorf("unknown vector \"%s\"", $1); $$ = (struct vec *) $1;
YYABORT;
}
} }
; ;

View File

@ -1,8 +1,8 @@
/* /*
* gui_tool.c - GUI, tool bar * gui_tool.c - GUI, tool bar
* *
* Written 2009, 2010 by Werner Almesberger * Written 2009-2011 by Werner Almesberger
* Copyright 2009, 2010 by Werner Almesberger * Copyright 2009-2011 by Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -73,6 +73,7 @@ static struct vec *new_vec(struct inst *base)
struct vec *vec, **walk; struct vec *vec, **walk;
vec = alloc_type(struct vec); vec = alloc_type(struct vec);
vec->nul_tag = 0;
vec->name = NULL; vec->name = NULL;
vec->base = inst_get_vec(base); vec->base = inst_get_vec(base);
vec->next = NULL; vec->next = NULL;

56
obj.c
View File

@ -168,11 +168,39 @@ static struct num eval_unit_default(const struct expr *expr,
} }
static int resolve_vec(const struct vec *vec, struct coord base_pos, static int recurse_vec(const char *name, const struct frame *frame,
struct coord *res) struct coord *res)
{ {
*res = vec ? vec->pos : base_pos; const struct vec *v;
return 1;
if (!frame)
return 0;
for (v = frame->vecs; v; v = v->next)
if (v->name == name) {
*res = v->pos;
return 1;
}
return recurse_vec(name, frame->curr_parent, res);
}
static int resolve_vec(const struct vec *vec, struct coord base_pos,
const struct frame *frame, struct coord *res)
{
const char *name = (const char *) vec;
if (!vec) {
*res = base_pos;
return 1;
}
if (!*name) {
*res = vec->pos;
return 1;
}
if (recurse_vec(name, frame->curr_parent, res))
return 1;
fail("unknown vector \"%s\"", name);
return 0;
} }
@ -189,7 +217,7 @@ static int generate_vecs(struct frame *frame, struct coord base_pos)
y = eval_unit(vec->y, frame); y = eval_unit(vec->y, frame);
if (is_undef(y)) if (is_undef(y))
goto error; goto error;
if (!resolve_vec(vec->base, base_pos, &vec_base)) if (!resolve_vec(vec->base, base_pos, frame, &vec_base))
goto error; goto error;
vec->pos = vec_base; vec->pos = vec_base;
vec->pos.x += x.n; vec->pos.x += x.n;
@ -217,7 +245,7 @@ static int generate_objs(struct frame *frame, struct coord base_pos,
for (obj = frame->objs; obj; obj = obj->next) { for (obj = frame->objs; obj; obj = obj->next) {
if (obj->type != ot_meas) if (obj->type != ot_meas)
if (!resolve_vec(obj->base, base_pos, &base)) if (!resolve_vec(obj->base, base_pos, frame, &base))
goto error; goto error;
switch (obj->type) { switch (obj->type) {
case ot_frame: case ot_frame:
@ -226,7 +254,8 @@ static int generate_objs(struct frame *frame, struct coord base_pos,
return 0; return 0;
break; break;
case ot_line: case ot_line:
if (!resolve_vec(obj->u.line.other, base_pos, &other)) if (!resolve_vec(obj->u.line.other, base_pos, frame,
&other))
goto error; goto error;
width = eval_unit_default(obj->u.line.width, frame, width = eval_unit_default(obj->u.line.width, frame,
DEFAULT_SILK_WIDTH); DEFAULT_SILK_WIDTH);
@ -236,7 +265,8 @@ static int generate_objs(struct frame *frame, struct coord base_pos,
goto error; goto error;
break; break;
case ot_rect: case ot_rect:
if (!resolve_vec(obj->u.rect.other, base_pos, &other)) if (!resolve_vec(obj->u.rect.other, base_pos, frame,
&other))
goto error; goto error;
width = eval_unit_default(obj->u.rect.width, frame, width = eval_unit_default(obj->u.rect.width, frame,
DEFAULT_SILK_WIDTH); DEFAULT_SILK_WIDTH);
@ -246,7 +276,8 @@ static int generate_objs(struct frame *frame, struct coord base_pos,
goto error; goto error;
break; break;
case ot_pad: case ot_pad:
if (!resolve_vec(obj->u.pad.other, base_pos, &other)) if (!resolve_vec(obj->u.pad.other, base_pos, frame,
&other))
goto error; goto error;
name = expand(obj->u.pad.name, frame); name = expand(obj->u.pad.name, frame);
if (!name) if (!name)
@ -257,15 +288,18 @@ static int generate_objs(struct frame *frame, struct coord base_pos,
goto error; goto error;
break; break;
case ot_hole: case ot_hole:
if (!resolve_vec(obj->u.hole.other, base_pos, &other)) if (!resolve_vec(obj->u.hole.other, base_pos, frame,
&other))
goto error; goto error;
if (!inst_hole(obj, base, other)) if (!inst_hole(obj, base, other))
goto error; goto error;
break; break;
case ot_arc: case ot_arc:
if (!resolve_vec(obj->u.arc.start, base_pos, &start)) if (!resolve_vec(obj->u.arc.start, base_pos, frame,
&start))
goto error; goto error;
if (!resolve_vec(obj->u.arc.end, base_pos, &end)) if (!resolve_vec(obj->u.arc.end, base_pos, frame,
&end))
goto error; goto error;
width = eval_unit_default(obj->u.arc.width, frame, width = eval_unit_default(obj->u.arc.width, frame,
DEFAULT_SILK_WIDTH); DEFAULT_SILK_WIDTH);

5
obj.h
View File

@ -1,8 +1,8 @@
/* /*
* obj.h - Object definition model * obj.h - Object definition model
* *
* Written 2009, 2010 by Werner Almesberger * Written 2009-2011 by Werner Almesberger
* Copyright 2009, 2010 by Werner Almesberger * Copyright 2009-2011 by Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -125,6 +125,7 @@ struct loop {
struct sample; struct sample;
struct vec { struct vec {
char nul_tag; /* tag for identifying vectors */
const char *name; /* NULL if anonymous */ const char *name; /* NULL if anonymous */
struct expr *x; struct expr *x;
struct expr *y; struct expr *y;