zend_fcall *cb;
} zend;
void *ptr;
- uint8_t _dbg[sizeof(void *)];
} impl_val;
typedef struct decl_type {
PSI_Token *token;
char *name;
token_t type;
- struct decl_type *real;
- struct decl_struct *strct;
- struct decl_union *unn;
- struct decl_enum *enm;
- struct decl *func;
+ union {
+ struct decl_arg *def;
+ struct decl_struct *strct;
+ struct decl_union *unn;
+ struct decl_enum *enm;
+ struct decl *func;
+ } real;
} decl_type;
static inline decl_type *init_decl_type(token_t type, const char *name) {
return t;
}
-static inline decl_type *real_decl_type(decl_type *type) {
- while (type->real) {
- type = type->real;
+static inline int weak_decl_type(decl_type *type) {
+ switch (type->type) {
+ case PSI_T_CHAR:
+ case PSI_T_SHORT:
+ case PSI_T_INT:
+ case PSI_T_LONG:
+ case PSI_T_NAME:
+ return type->type;
+ default:
+ return 0;
}
- return type;
}
static inline void free_decl(struct decl *decl);
free(type->token);
}
if (type->type == PSI_T_FUNCTION) {
- free_decl(type->func);
+ free_decl(type->real.func);
}
free(type->name);
free(type);
decl_type *type;
decl_var *var;
decl_struct_layout *layout;
- struct let_stmt *let;
impl_val val;
void *ptr;
+ void *let;
void *mem;
} decl_arg;
arg->var = var;
var->arg = arg;
arg->ptr = &arg->val;
+ arg->let = arg->ptr;
return arg;
}
free(arg);
}
+static inline decl_type *real_decl_type(decl_type *type) {
+ while (weak_decl_type(type)) {
+ type = type->real.def->type;
+ }
+ return type;
+}
+
typedef struct decl_typedefs {
size_t count;
decl_arg **list;
size_t argc;
void **args;
void **rval;
- struct {
- void *data;
- void (*dtor)(void *data);
- } closure;
} decl_callinfo;
typedef struct decl {
typedef struct impl_var {
PSI_Token *token;
char *name;
+ struct impl_arg *arg;
unsigned reference:1;
} impl_var;
impl_arg *arg = calloc(1, sizeof(*arg));
arg->type = type;
arg->var = var;
+ arg->var->arg = arg;
arg->def = def;
return arg;
}
typedef struct let_callback {
struct let_func *func;
struct set_values *args;
+ decl *decl;
} let_callback;
static inline void free_let_func(struct let_func *func);
free(cb);
}
+typedef impl_val *(*let_func_handler)(impl_val *tmp, decl_type *type, impl_arg *iarg, void **to_free);
+
typedef struct let_func {
token_t type;
char *name;
impl_var *var;
- impl_arg *arg;
- impl_val *(*handler)(impl_val *tmp, decl_type *type, void *val, void **to_free);
+ let_func_handler handler;
} let_func;
static inline let_func *init_let_func(token_t type, const char *name, impl_var *var) {
typedef struct let_stmt {
decl_var *var;
let_val *val;
-
- void *ptr;
} let_stmt;
static inline let_stmt *init_let_stmt(decl_var *var, let_val *val) {
val->vars = vars;
return val;
}
+
+static inline set_values *add_set_value(set_values *vals, set_value *val);
static inline set_value *add_inner_set_value(set_value *val, set_value *inner) {
- val->inner->vals = realloc(val->inner->vals, ++val->inner->count * sizeof(*val->inner->vals));
- val->inner->vals[val->inner->count-1] = inner;
+ val->inner = add_set_value(val->inner, inner);
inner->outer.set = val;
return val;
}
free_decl_vars(val->vars);
}
if (val->inner && (!val->outer.set || val->outer.set->inner != val->inner)) {
- size_t i;
- for (i = 0; i < val->inner->count; ++i) {
- free_set_value(val->inner->vals[i]);
- }
- free(val->inner->vals);
+ free_set_values(val->inner);
}
if (val->num) {
free_num_exp(val->num);
}
static inline set_values *add_set_value(set_values *vals, set_value *val) {
+ if (!vals) {
+ vals = calloc(1, sizeof(*vals));
+ }
vals->vals = realloc(vals->vals, ++vals->count * sizeof(val));
vals->vals[vals->count-1] = val;
return vals;
static inline void free_set_values(set_values *vals) {
if (vals->vals) {
+ size_t i;
+
+ for (i = 0; i < vals->count; ++i) {
+ free_set_value(vals->vals[i]);
+ }
free(vals->vals);
}
free(vals);