wasm_valkind_t kind;
};
-struct wasm_functype_t {
+struct wasm_functype_inner_t {
wasm_valtype_vec_t params;
wasm_valtype_vec_t results;
};
-struct wasm_globaltype_t {
+struct wasm_globaltype_inner_t {
wasm_valtype_t *content;
wasm_mutability_t mutability;
};
-struct wasm_tabletype_t {
+struct wasm_tabletype_inner_t {
wasm_valtype_t *element;
wasm_limits_t limits;
};
-struct wasm_memorytype_t {
+struct wasm_memorytype_inner_t {
wasm_limits_t limits;
};
struct wasm_externtype_t {
wasm_externkind_t kind;
union {
- wasm_functype_t *func;
- wasm_globaltype_t *global;
- wasm_tabletype_t *table;
- wasm_memorytype_t *memory;
+ struct wasm_functype_inner_t func;
+ struct wasm_globaltype_inner_t global;
+ struct wasm_tabletype_inner_t table;
+ struct wasm_memorytype_inner_t memory;
};
};
+struct wasm_functype_t { wasm_externtype_t type; };
+struct wasm_globaltype_t { wasm_externtype_t type; };
+struct wasm_tabletype_t { wasm_externtype_t type; };
+struct wasm_memorytype_t { wasm_externtype_t type; };
+
struct wasm_importtype_t {
wasm_name_t *module_name;
wasm_name_t *import_name;
};
struct wasm_func_t {
+ wasm_instance_t *instance;
+ ovm_func_t *func;
};
struct wasm_global_t {
+ wasm_instance_t *instance;
+ int register_index;
+
+ wasm_globaltype_t *type;
};
struct wasm_table_t {
+ wasm_tabletype_t *type;
};
struct wasm_memory_t {
+ wasm_memorytype_t *type;
};
struct wasm_extern_t {
+ wasm_externtype_t *type;
+ union {
+ wasm_func_t *func;
+ wasm_global_t *global;
+ wasm_table_t *table;
+ wasm_memory_t *memory;
+ };
};
struct wasm_instance_t {
ovm_state_t *state;
};
+
+#define WASM_DECLARE_VEC_IMPL(type, ptr_or_none) \
+ void wasm_##type##_vec_new_empty(wasm_##type##_vec_t *out) { \
+ out->size = 0; \
+ out->data = NULL; \
+ } \
+ \
+ void wasm_##type##_vec_new_uninitialized(wasm_##type##_vec_t *out, size_t size) { \
+ out->data = malloc(sizeof(wasm_##type##_t) * size); \
+ out->size = size; \
+ } \
+ \
+ void wasm_##type##_vec_new(wasm_##type##_vec_t *out, size_t size, wasm_##type##_t ptr_or_none const data[]) { \
+ out->data = malloc(sizeof(wasm_##type##_t) * size); \
+ out->size = size; \
+ \
+ fori (i, 0, (i32) size) { \
+ out->data[i] = data[i]; \
+ } \
+ } \
+ \
+ void wasm_##type##_vec_copy(wasm_##type##_vec_t *out, const wasm_##type##_vec_t *in) { \
+ wasm_##type##_vec_new(out, in->size, in->data); \
+ } \
+ \
+ void wasm_##type##_vec_delete(wasm_##type##_vec_t *vec) { \
+ if (vec->data) free(vec->data); \
+ }
+
#endif
// wasm_byte_t
//
-void wasm_byte_vec_new_empty(wasm_byte_vec_t *out) {
- out->size = 0;
- out->data = NULL;
-}
-
-void wasm_byte_vec_new_uninitialized(wasm_byte_vec_t *out, size_t size) {
- out->data = malloc(sizeof(wasm_byte_t) * size);
- out->size = size;
-}
-
-void wasm_byte_vec_new(wasm_byte_vec_t *out, size_t size, const wasm_byte_t data[]) {
- out->data = malloc(sizeof(wasm_byte_t) * size);
- out->size = size;
-
- fori (i, 0, (i32) size) {
- out->data[i] = data[i];
- }
-}
-
-void wasm_byte_vec_copy(wasm_byte_vec_t *out, const wasm_byte_vec_t *in) {
- wasm_byte_vec_new(out, in->size, in->data);
-}
-
-void wasm_byte_vec_delete(wasm_byte_vec_t *vec) {
- if (vec->data) free(vec->data);
-}
+WASM_DECLARE_VEC_IMPL(byte, )
//
// wasm_valtype_t
return type->kind;
}
-
-void wasm_valtype_vec_new_empty(wasm_valtype_vec_t *out) {
- out->size = 0;
- out->data = NULL;
-}
-
-void wasm_valtype_vec_new_uninitialized(wasm_valtype_vec_t *out, size_t size) {
- out->data = malloc(sizeof(wasm_valtype_t) * size);
- out->size = size;
-}
-
-void wasm_valtype_vec_new(wasm_valtype_vec_t *out, size_t size, wasm_valtype_t* const data[]) {
- out->data = malloc(sizeof(wasm_valtype_t) * size);
- out->size = size;
-
- fori (i, 0, (i32) size) {
- out->data[i] = data[i];
- }
-}
-
-void wasm_valtype_vec_copy(wasm_valtype_vec_t *out, const wasm_valtype_vec_t *in) {
- wasm_valtype_vec_new(out, in->size, in->data);
-}
-
-void wasm_valtype_vec_delete(wasm_valtype_vec_t *vec) {
- if (vec->data) free(vec->data);
-}
-
+WASM_DECLARE_VEC_IMPL(valtype, *)
// wasm_functype_t
wasm_functype_t *wasm_functype_new(wasm_valtype_vec_t *params, wasm_valtype_vec_t *results) {
wasm_functype_t *functype = malloc(sizeof(*functype));
- functype->params = *params;
- functype->results = *results;
+ functype->type.kind = WASM_EXTERN_FUNC;
+ functype->type.func.params = *params;
+ functype->type.func.results = *results;
return functype;
}
}
const wasm_valtype_vec_t* wasm_functype_params(const wasm_functype_t *functype) {
- return &functype->params;
+ return &functype->type.func.params;
}
const wasm_valtype_vec_t* wasm_functype_results(const wasm_functype_t *functype) {
- return &functype->results;
-}
-
-
-void wasm_functype_vec_new_empty(wasm_functype_vec_t *out) {
- out->size = 0;
- out->data = NULL;
-}
-
-void wasm_functype_vec_new_uninitialized(wasm_functype_vec_t *out, size_t size) {
- out->data = malloc(sizeof(wasm_functype_t) * size);
- out->size = size;
-}
-
-void wasm_functype_vec_new(wasm_functype_vec_t *out, size_t size, wasm_functype_t* const data[]) {
- out->data = malloc(sizeof(wasm_functype_t) * size);
- out->size = size;
-
- fori (i, 0, (i32) size) {
- out->data[i] = data[i];
- }
-}
-
-void wasm_functype_vec_copy(wasm_functype_vec_t *out, const wasm_functype_vec_t *in) {
- wasm_functype_vec_new(out, in->size, in->data);
-}
-
-void wasm_functype_vec_delete(wasm_functype_vec_t *vec) {
- if (vec->data) free(vec->data);
+ return &functype->type.func.results;
}
+WASM_DECLARE_VEC_IMPL(functype, *)
// wasm_globaltype_t
wasm_globaltype_t *wasm_globaltype_new(wasm_valtype_t *valtype, wasm_mutability_t mut) {
wasm_globaltype_t *globaltype = malloc(sizeof(*globaltype));
- globaltype->content = valtype;
- globaltype->mutability = mut;
+ globaltype->type.kind = WASM_EXTERN_GLOBAL;
+ globaltype->type.global.content = valtype;
+ globaltype->type.global.mutability = mut;
return globaltype;
}
}
const wasm_valtype_t* wasm_globaltype_content(const wasm_globaltype_t *globaltype) {
- return globaltype->content;
+ return globaltype->type.global.content;
}
wasm_mutability_t wasm_globaltype_mutability(const wasm_globaltype_t *globaltype) {
- return globaltype->mutability;
+ return globaltype->type.global.mutability;
}
-
-void wasm_globaltype_vec_new_empty(wasm_globaltype_vec_t *out) {
- out->size = 0;
- out->data = NULL;
-}
-
-void wasm_globaltype_vec_new_uninitialized(wasm_globaltype_vec_t *out, size_t size) {
- out->data = malloc(sizeof(wasm_globaltype_t) * size);
- out->size = size;
-}
-
-void wasm_globaltype_vec_new(wasm_globaltype_vec_t *out, size_t size, wasm_globaltype_t* const data[]) {
- out->data = malloc(sizeof(wasm_globaltype_t) * size);
- out->size = size;
-
- fori (i, 0, (i32) size) {
- out->data[i] = data[i];
- }
-}
-
-void wasm_globaltype_vec_copy(wasm_globaltype_vec_t *out, const wasm_globaltype_vec_t *in) {
- wasm_globaltype_vec_new(out, in->size, in->data);
-}
-
-void wasm_globaltype_vec_delete(wasm_globaltype_vec_t *vec) {
- if (vec->data) free(vec->data);
-}
+WASM_DECLARE_VEC_IMPL(globaltype, *)
// wasm_tabletype_t
wasm_tabletype_t *wasm_tabletype_new(wasm_valtype_t *valtype, const wasm_limits_t *limits) {
wasm_tabletype_t *tabletype = malloc(sizeof(*tabletype));
- tabletype->element = valtype;
- tabletype->limits = *limits;
+ tabletype->type.kind = WASM_EXTERN_TABLE;
+ tabletype->type.table.element = valtype;
+ tabletype->type.table.limits = *limits;
return tabletype;
}
}
const wasm_valtype_t* wasm_tabletype_element(const wasm_tabletype_t *tabletype) {
- return tabletype->element;
+ return tabletype->type.table.element;
}
const wasm_limits_t* wasm_tabletype_limits(const wasm_tabletype_t *tabletype) {
- return &tabletype->limits;
+ return &tabletype->type.table.limits;
}
+WASM_DECLARE_VEC_IMPL(tabletype, *)
-void wasm_tabletype_vec_new_empty(wasm_tabletype_vec_t *out) {
- out->size = 0;
- out->data = NULL;
-}
+// wasm_memorytype_t
-void wasm_tabletype_vec_new_uninitialized(wasm_tabletype_vec_t *out, size_t size) {
- out->data = malloc(sizeof(wasm_tabletype_t) * size);
- out->size = size;
-}
+wasm_memorytype_t *wasm_memorytype_new(const wasm_limits_t *limits) {
+ wasm_memorytype_t *memorytype = malloc(sizeof(*memorytype));
+ memorytype->type.kind = WASM_EXTERN_TABLE;
+ memorytype->type.memory.limits = *limits;
-void wasm_tabletype_vec_new(wasm_tabletype_vec_t *out, size_t size, wasm_tabletype_t* const data[]) {
- out->data = malloc(sizeof(wasm_tabletype_t) * size);
- out->size = size;
+ return memorytype;
+}
- fori (i, 0, (i32) size) {
- out->data[i] = data[i];
- }
+void wasm_memorytype_delete(wasm_memorytype_t *memorytype) {
+ if (memorytype) free(memorytype);
}
-void wasm_tabletype_vec_copy(wasm_tabletype_vec_t *out, const wasm_tabletype_vec_t *in) {
- wasm_tabletype_vec_new(out, in->size, in->data);
+const wasm_limits_t* wasm_memorytype_limits(const wasm_memorytype_t *memorytype) {
+ return &memorytype->type.memory.limits;
}
-void wasm_tabletype_vec_delete(wasm_tabletype_vec_t *vec) {
- if (vec->data) free(vec->data);
+WASM_DECLARE_VEC_IMPL(memorytype, *)
+
+// wasm_externtype_t
+
+const wasm_externkind_t wasm_externtype_kind(const wasm_externtype_t *externtype) {
+ return externtype->kind;
}
+WASM_DECLARE_VEC_IMPL(externtype, *)
-// wasm_memorytype_t
+wasm_externtype_t* wasm_functype_as_externtype(wasm_functype_t* ext) { return (wasm_externtype_t *) ext; }
+wasm_externtype_t* wasm_globaltype_as_externtype(wasm_globaltype_t* ext) { return (wasm_externtype_t *) ext; }
+wasm_externtype_t* wasm_tabletype_as_externtype(wasm_tabletype_t* ext) { return (wasm_externtype_t *) ext; }
+wasm_externtype_t* wasm_memorytype_as_externtype(wasm_memorytype_t* ext) { return (wasm_externtype_t *) ext; }
-wasm_memorytype_t *wasm_memorytype_new(const wasm_limits_t *limits) {
- wasm_memorytype_t *memorytype = malloc(sizeof(*memorytype));
- memorytype->limits = *limits;
+wasm_functype_t* wasm_externtype_as_functype(wasm_externtype_t* ext) { return ext->kind == WASM_EXTERN_FUNC ? (wasm_functype_t *) ext : NULL; }
+wasm_globaltype_t* wasm_externtype_as_globaltype(wasm_externtype_t* ext) { return ext->kind == WASM_EXTERN_GLOBAL ? (wasm_globaltype_t *) ext : NULL; }
+wasm_tabletype_t* wasm_externtype_as_tabletype(wasm_externtype_t* ext) { return ext->kind == WASM_EXTERN_TABLE ? (wasm_tabletype_t *) ext : NULL; }
+wasm_memorytype_t* wasm_externtype_as_memorytype(wasm_externtype_t* ext) { return ext->kind == WASM_EXTERN_MEMORY ? (wasm_memorytype_t *) ext : NULL; }
- return memorytype;
-}
+const wasm_externtype_t* wasm_functype_as_externtype_const(const wasm_functype_t* ext) { return (const wasm_externtype_t *) ext; }
+const wasm_externtype_t* wasm_globaltype_as_externtype_const(const wasm_globaltype_t* ext) { return (const wasm_externtype_t *) ext; }
+const wasm_externtype_t* wasm_tabletype_as_externtype_const(const wasm_tabletype_t* ext) { return (const wasm_externtype_t *) ext; }
+const wasm_externtype_t* wasm_memorytype_as_externtype_const(const wasm_memorytype_t* ext) { return (const wasm_externtype_t *) ext; }
-void wasm_memorytype_delete(wasm_memorytype_t *memorytype) {
- if (memorytype) free(memorytype);
+const wasm_functype_t* wasm_externtype_as_functype_const(const wasm_externtype_t* ext) { return ext->kind == WASM_EXTERN_FUNC ? (const wasm_functype_t *) ext : NULL; }
+const wasm_globaltype_t* wasm_externtype_as_globaltype_const(const wasm_externtype_t* ext) { return ext->kind == WASM_EXTERN_GLOBAL ? (const wasm_globaltype_t *) ext : NULL; }
+const wasm_tabletype_t* wasm_externtype_as_tabletype_const(const wasm_externtype_t* ext) { return ext->kind == WASM_EXTERN_TABLE ? (const wasm_tabletype_t *) ext : NULL; }
+const wasm_memorytype_t* wasm_externtype_as_memorytype_const(const wasm_externtype_t* ext) { return ext->kind == WASM_EXTERN_MEMORY ? (const wasm_memorytype_t *) ext : NULL; }
+
+
+
+// wasm_importtype_t
+
+wasm_importtype_t *wasm_importtype_new(wasm_name_t *module, wasm_name_t* name, wasm_externtype_t *ext) {
+ wasm_importtype_t *importtype = malloc(sizeof(*importtype));
+ importtype->module_name = module;
+ importtype->import_name = name;
+ importtype->type = ext;
+
+ return importtype;
}
-const wasm_limits_t* wasm_memorytype_limits(const wasm_memorytype_t *memorytype) {
- return &memorytype->limits;
+void wasm_importtype_delete(wasm_importtype_t *importtype) {
+ if (importtype) free(importtype);
}
+const wasm_name_t* wasm_importtype_module(const wasm_importtype_t* importtype) {
+ return importtype->module_name;
+}
-void wasm_memorytype_vec_new_empty(wasm_memorytype_vec_t *out) {
- out->size = 0;
- out->data = NULL;
+const wasm_name_t* wasm_importtype_name(const wasm_importtype_t* importtype) {
+ return importtype->import_name;
}
-void wasm_memorytype_vec_new_uninitialized(wasm_memorytype_vec_t *out, size_t size) {
- out->data = malloc(sizeof(wasm_memorytype_t) * size);
- out->size = size;
+const wasm_externtype_t* wasm_importtype_type(const wasm_importtype_t* importtype) {
+ return importtype->type;
}
-void wasm_memorytype_vec_new(wasm_memorytype_vec_t *out, size_t size, wasm_memorytype_t* const data[]) {
- out->data = malloc(sizeof(wasm_memorytype_t) * size);
- out->size = size;
+WASM_DECLARE_VEC_IMPL(importtype, *)
- fori (i, 0, (i32) size) {
- out->data[i] = data[i];
- }
-}
+// wasm_exporttype_t
+
+wasm_exporttype_t *wasm_exporttype_new(wasm_name_t* name, wasm_externtype_t *ext) {
+ wasm_exporttype_t *exporttype = malloc(sizeof(*exporttype));
+ exporttype->name = name;
+ exporttype->type = ext;
-void wasm_memorytype_vec_copy(wasm_memorytype_vec_t *out, const wasm_memorytype_vec_t *in) {
- wasm_memorytype_vec_new(out, in->size, in->data);
+ return exporttype;
}
-void wasm_memorytype_vec_delete(wasm_memorytype_vec_t *vec) {
- if (vec->data) free(vec->data);
+void wasm_exporttype_delete(wasm_exporttype_t *exporttype) {
+ if (exporttype) free(exporttype);
}
+const wasm_name_t* wasm_exporttype_name(const wasm_exporttype_t* exporttype) {
+ return exporttype->name;
+}
-// wasm_externtype_t
+const wasm_externtype_t* wasm_exporttype_type(const wasm_exporttype_t* exporttype) {
+ return exporttype->type;
+}
+WASM_DECLARE_VEC_IMPL(exporttype, *)