From 2fcd94b0a1b3963d39f1a85b27644160cb48af90 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 21 Jun 2022 22:49:20 -0500 Subject: [PATCH] bugfixing and testing --- include/onyx_wasm.h | 2 +- src/wasm/module.c | 5 ++--- src/wasm/type.c | 6 +++--- src/wasm_cli_test.c | 18 ++++++++++++++++++ tests/wasm/out.wasm | Bin 713 -> 755 bytes tests/wasm/tiny.onyx | 6 +++++- 6 files changed, 29 insertions(+), 8 deletions(-) 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 2678395df54988164c2d451d83cc0906651b17cb..9992ca76868a8212443e542d9b2e0a9968c2bd19 100644 GIT binary patch delta 257 zcmX@f`k9rFA+b1@k%57MQH?Eufng%IoC0G#V?C1~BTGqYaS2CaaY`BpGcYi7uro3- zGqNyDw6WG;<78)KaAe?SWanXI;+o0G&ceu8&n?EtRIdOOR$x+K29k_|%oFE}X)-hL z167JZ0Cc+v5XS&(;_E;x0Q8g>5Zh$t7UUO| Yq^2l5S|wjEwc%VvJ1n3P526CIx07$tcJ)alM!(69Yd`r3gfh(GemKlw*+M z<^k$b04mG^sW6`SPEwRbkr`xy854semjZ(Z6N4ZtgVba>Mq7h_OhWPbd6gCMX{C9| p@%d?K#i=F5GC-HQ0C6r5PXprpK>P!UjTjjw%Q7i%KE|la2mtLjB8mV2 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" --- -- 2.25.1