struct text name;
struct type *next;
struct value (*init)(struct type *type);
+ struct value (*prepare)(struct type *type);
struct value (*parse)(struct type *type, char *str);
void (*print)(struct value val);
int (*cmp_order)(struct value v1, struct value v2);
v.type->free(v);
}
+ static struct value val_prepare(struct type *type)
+ {
+ struct value rv;
+
+ if (type)
+ return type->prepare(type);
+ rv.type = type;
+ return rv;
+ }
+
static struct value val_init(struct type *type)
{
struct value rv;
###### value functions
+ static struct value _val_prepare(struct type *type)
+ {
+ struct value rv;
+
+ rv.type = type;
+ switch(type->vtype) {
+ case Vnone:
+ break;
+ case Vnum:
+ memset(&rv.num, 0, sizeof(rv.num));
+ break;
+ case Vstr:
+ rv.str.txt = NULL;
+ rv.str.len = 0;
+ break;
+ case Vbool:
+ rv.bool = 0;
+ break;
+ case Vlabel:
+ rv.label = NULL;
+ break;
+ }
+ return rv;
+ }
+
static struct value _val_init(struct type *type)
{
struct value rv;
static struct type base_prototype = {
.init = _val_init,
+ .prepare = _val_prepare,
.parse = _parse_value,
.print = _print_value,
.cmp_order = _value_cmp,
v->scope = InScope;
v->in_scope = c->in_scope;
c->in_scope = v;
- v->val = val_init(NULL);
+ v->val = val_prepare(NULL);
return v;
}
if (v) {
v->where_decl = $0;
v->where_set = $0;
- v->val = val_init($<3);
+ v->val = val_prepare($<3);
} else {
v = var_ref(config2context(config), $1.txt);
$0->var = v;
if (v) {
v->where_decl = $0;
v->where_set = $0;
- v->val = val_init($<3);
+ v->val = val_prepare($<3);
v->constant = 1;
} else {
v = var_ref(config2context(config), $1.txt);
/* This might be a label - allocate a var just in case */
v = var_decl(config2context(config), $1.txt);
if (v) {
- v->val = val_init(Tlabel);
+ v->val = val_prepare(Tlabel);
v->val.label = &v->val;
v->where_set = $0;
}
v = v->merged;
if (v->val.type == NULL) {
if (type && *ok != 0) {
- v->val = val_init(type);
+ v->val = val_prepare(type);
v->where_set = prog;
*ok = 2;
}
struct var *v = cast(var, b->left);
if (!v->var->val.type) {
v->var->where_set = b;
- v->var->val = val_init(Tstr);
+ v->var->val = val_prepare(Tstr);
}
}
b = cast(binode, prog);