+typedef struct PSI_Data {
+ decl_typedefs *defs;
+ decls *decls;
+ impls *impls;
+ char *lib;
+ char *fn;
+} PSI_Data;
+
+static inline void PSI_DataExchange(PSI_Data *dest, PSI_Data *src) {
+ memcpy(dest, src, sizeof(*dest));
+ memset(src, 0, sizeof(*src));
+}
+
+struct decl_typedef;
typedef struct decl_type {
- text *name;
+ char *name;
token_t type;
+ struct decl_type *real;
} decl_type;
-static inline decl_type *init_decl_type(token_t type, text *name) {
+static inline decl_type *init_decl_type(token_t type, char *name) {
decl_type *t = malloc(sizeof(*t));
t->type = type;
- t->name = (text *) strdup((const char *) name);
+ t->name = strdup(name);
return t;
}
free(type);
}
+typedef struct decl_typedef {
+ char *alias;
+ decl_type *type;
+} decl_typedef;
+
+static inline decl_typedef *init_decl_typedef(char *name, decl_type *type) {
+ decl_typedef *t = malloc(sizeof(*t));
+ t->alias = strdup(name);
+ t->type = type;
+ return t;
+}
+
+static inline void free_decl_typedef(decl_typedef *t) {
+ free(t->alias);
+ free_decl_type(t->type);
+ free(t);
+}
+
+typedef struct decl_typedefs {
+ size_t count;
+ decl_typedef **list;
+} decl_typedefs;
+
+static decl_typedefs *add_decl_typedef(decl_typedefs *defs, decl_typedef *def) {
+ if (!defs) {
+ defs = calloc(1, sizeof(*defs));
+ }
+ defs->list = realloc(defs->list, ++defs->count * sizeof(*defs->list));
+ defs->list[defs->count-1] = def;
+ return defs;
+}
+
+static void free_decl_typedefs(decl_typedefs *defs) {
+ size_t i;
+
+ for (i = 0; i < defs->count; ++i) {
+ free_decl_typedef(defs->list[i]);
+ }
+ free(defs->list);
+ free(defs);
+}
+
typedef struct decl_var {
- text *name;
+ char *name;
unsigned pointer_level;
} decl_var;
-static inline decl_var *init_decl_var(text *name, unsigned pl) {
+static inline decl_var *init_decl_var(char *name, unsigned pl) {
decl_var *v = malloc(sizeof(*v));
- v->name = (text *) strdup((const char *) name);
+ v->name = (char *) strdup((const char *) name);
v->pointer_level = pl;
return v;
}
free(args);
}
+typedef struct decl_abi {
+ char *convention;
+} decl_abi;
+
+static inline decl_abi *init_decl_abi(char *convention) {
+ decl_abi *abi = malloc(sizeof(*abi));
+ abi->convention = strdup(convention);
+ return abi;
+}
+
+static inline void free_decl_abi(decl_abi *abi) {
+ free(abi->convention);
+ free(abi);
+}
+
typedef struct decl {
+ decl_abi *abi;
decl_arg *func;
decl_args *args;
+ void *dlptr;
} decl;
-static inline decl* init_decl(decl_arg *func, decl_args *args) {
+static inline decl* init_decl(decl_abi *abi, decl_arg *func, decl_args *args) {
decl *d = malloc(sizeof(*d));
+ d->abi = abi;
d->func = func;
d->args = args;
return d;
}
static inline void free_decl(decl *d) {
+ free_decl_abi(d->abi);
free_decl_arg(d->func);
free_decl_args(d->args);
free(d);
}
+typedef struct decls {
+ size_t count;
+ decl **list;
+} decls;
+
+static inline decls *add_decl(decls *decls, decl *decl) {
+ if (!decls) {
+ decls = calloc(1, sizeof(*decls));
+ }
+ decls->list = realloc(decls->list, ++decls->count * sizeof(*decls->list));
+ decls->list[decls->count-1] = decl;
+ return decls;
+}
+
+static inline void free_decls(decls *decls) {
+ size_t i;
+
+ for (i = 0; i < decls->count; ++i) {
+ free_decl(decls->list[i]);
+ }
+ free(decls->list);
+ free(decls);
+}
+
typedef struct impl_type {
- text *name;
+ char *name;
token_t type;
} impl_type;
-static inline impl_type *init_impl_type(token_t type, text *name) {
+static inline impl_type *init_impl_type(token_t type, char *name) {
impl_type *t = malloc(sizeof(*t));
t->type = type;
- t->name = (text *) strdup((const char *) name);
+ t->name = (char *) strdup((const char *) name);
return t;
}
}
typedef struct impl_var {
- text *name;
+ char *name;
unsigned reference:1;
} impl_var;
-static inline impl_var *init_impl_var(text *name, int is_reference) {
+static inline impl_var *init_impl_var(char *name, int is_reference) {
impl_var *var = malloc(sizeof(*var));
- var->name = (text *) strdup((const char *) name);
+ var->name = (char *) strdup((const char *) name);
var->reference = is_reference;
return var;
}
static inline impl_args *init_impl_args(impl_arg *arg) {
impl_args *args = malloc(sizeof(*args));
- args->count = 1;
args->args = malloc(sizeof(*args->args));
- args->args[0] = arg;
+ if (arg) {
+ args->count = 1;
+ args->args[0] = arg;
+ } else {
+ args->count = 0;
+ args->args = NULL;
+ }
return args;
}
}
typedef struct impl_func {
- text *name;
+ char *name;
impl_args *args;
impl_type *return_type;
} impl_func;
-static inline impl_func *init_impl_func(text *name, impl_args *args, impl_type *type) {
+static inline impl_func *init_impl_func(char *name, impl_args *args, impl_type *type) {
impl_func *func = malloc(sizeof(*func));
- func->name = (text *) strdup((const char *) name);
- func->args = args;
+ func->name = strdup(name);
+ func->args = args ? args : init_impl_args(NULL);
func->return_type = type;
return func;
}
typedef struct let_func {
token_t type;
- text *name;
+ char *name;
} let_func;
-static inline let_func *init_let_func(token_t type, text *name) {
+static inline let_func *init_let_func(token_t type, char *name) {
let_func *func = malloc(sizeof(*func));
func->type = type;
- func->name = (text *) strdup((const char *) name);
+ func->name = (char *) strdup((const char *) name);
return func;
}
unsigned null_pointer_ref:1;
} let_value;
-static inline let_value *init_let_value(let_func *func, impl_var *var) {
+static inline let_value *init_let_value(let_func *func, impl_var *var, int null_pointer_ref) {
let_value *val = malloc(sizeof(*val));
-
- if (!func || !var) {
- val->null_pointer_ref = 1;
- } else {
- val->null_pointer_ref = 0;
- }
+ val->null_pointer_ref = null_pointer_ref;
val->func = func;
val->var = var;
-
return val;
}
typedef struct set_func {
token_t type;
- text *name;
+ char *name;
} set_func;
-static inline set_func *init_set_func(token_t type, text *name) {
+static inline set_func *init_set_func(token_t type, char *name) {
set_func *func = malloc(sizeof(*func));
func->type = type;
- func->name = (text *) strdup((const char *) name);
+ func->name = (char *) strdup((const char *) name);
return func;
}
free_impl_stmts(impl->stmts);
free(impl);
}
+
+typedef struct impls {
+ size_t count;
+ impl **list;
+} impls;
+
+static impls *add_impl(impls *impls, impl *impl) {
+ if (!impls) {
+ impls = calloc(1, sizeof(*impls));
+ }
+ impls->list = realloc(impls->list, ++impls->count * sizeof(*impls->list));
+ impls->list[impls->count-1] = impl;
+ return impls;
+}
+
+static void free_impls(impls *impls) {
+ size_t i;
+
+ for (i = 0; i < impls->count; ++i) {
+ free_impl(impls->list[i]);
+ }
+ free(impls->list);
+ free(impls);
+}