From: Brendan Hansen Date: Wed, 22 Jun 2022 03:49:20 +0000 (-0500) Subject: bugfixing and testing X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=2fcd94b0a1b3963d39f1a85b27644160cb48af90;p=onyx-embedder.git bugfixing and testing --- diff --git a/include/onyx_wasm.h b/include/onyx_wasm.h index b93dc65..b42b8ba 100644 --- a/include/onyx_wasm.h +++ b/include/onyx_wasm.h @@ -73,7 +73,7 @@ struct wasm_importtype_t { }; struct wasm_exporttype_t { - wasm_name_t *name; + wasm_name_t name; wasm_externtype_t *type; int index; }; diff --git a/src/wasm/module.c b/src/wasm/module.c index 84c6f70..452497e 100644 --- a/src/wasm/module.c +++ b/src/wasm/module.c @@ -302,18 +302,17 @@ static void parse_data_section(build_context *ctx) { ctx->module->data_entries = malloc(sizeof(struct wasm_data_t) * data_count); fori (i, 0, (int) data_count) { - char data_type = CONSUME_BYTE(ctx); - assert(data_type == 0x00 || data_type == 0x01); - struct wasm_data_t data_entry; data_entry.data = NULL; data_entry.offset = 0; data_entry.length = 0; data_entry.passive = true; + char data_type = CONSUME_BYTE(ctx); if (data_type == 0x00) { assert(CONSUME_BYTE(ctx) == 0x41); data_entry.offset = uleb128_to_uint(ctx->binary.data, &ctx->offset); + data_entry.passive = false; assert(CONSUME_BYTE(ctx) == 0x0B); } diff --git a/src/wasm/type.c b/src/wasm/type.c index eddf1d0..37fa859 100644 --- a/src/wasm/type.c +++ b/src/wasm/type.c @@ -124,7 +124,7 @@ WASM_DECLARE_VEC_IMPL(tabletype, *) 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.kind = WASM_EXTERN_MEMORY; memorytype->type.memory.limits = *limits; return memorytype; @@ -203,7 +203,7 @@ WASM_DECLARE_VEC_IMPL(importtype, *) 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->name = *name; exporttype->type = ext; return exporttype; @@ -214,7 +214,7 @@ void wasm_exporttype_delete(wasm_exporttype_t *exporttype) { } const wasm_name_t* wasm_exporttype_name(const wasm_exporttype_t* exporttype) { - return exporttype->name; + return &exporttype->name; } const wasm_externtype_t* wasm_exporttype_type(const wasm_exporttype_t* exporttype) { diff --git a/src/wasm_cli_test.c b/src/wasm_cli_test.c index 8d2337d..b72caec 100644 --- a/src/wasm_cli_test.c +++ b/src/wasm_cli_test.c @@ -19,5 +19,23 @@ int main(int argc, char *argv[]) { wasm_module_t *module = wasm_module_new(store, &wasm_bytes); assert(module); + + wasm_importtype_vec_t imports; + wasm_module_imports(module, &imports); + + fori (i, 0, (int) imports.size) { + const wasm_name_t *module_name = wasm_importtype_module(imports.data[i]); + const wasm_name_t *import_name = wasm_importtype_name(imports.data[i]); + bh_printf("imports: %b.%b\n", module_name->data, module_name->size, import_name->data, import_name->size); + } + + + wasm_exporttype_vec_t exports; + wasm_module_exports(module, &exports); + + fori (i, 0, (int) exports.size) { + const wasm_name_t *export_name = wasm_exporttype_name(exports.data[i]); + bh_printf("exports: %b %d\n", export_name->data, export_name->size, wasm_externtype_kind(wasm_exporttype_type(exports.data[i]))); + } } diff --git a/tests/wasm/out.wasm b/tests/wasm/out.wasm index 2678395..9992ca7 100644 Binary files a/tests/wasm/out.wasm and b/tests/wasm/out.wasm differ diff --git a/tests/wasm/tiny.onyx b/tests/wasm/tiny.onyx index 4b8d6ce..bd99d3a 100644 --- a/tests/wasm/tiny.onyx +++ b/tests/wasm/tiny.onyx @@ -12,4 +12,8 @@ g :: (x) => x + 1; z: (i32) -> i32 = g; z(10); -} \ No newline at end of file + + foo(); +} + +foo :: () -> void #foreign "test" "asdfasdf" ---