bugfixing and testing
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 22 Jun 2022 03:49:20 +0000 (22:49 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 22 Jun 2022 03:49:20 +0000 (22:49 -0500)
include/onyx_wasm.h
src/wasm/module.c
src/wasm/type.c
src/wasm_cli_test.c
tests/wasm/out.wasm
tests/wasm/tiny.onyx

index b93dc65a83f2c866bc302e1e3c8637a5adc073fe..b42b8bae0de51dc4b84f613860075a5372fc33b1 100644 (file)
@@ -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;
 };
index 84c6f7084261f7e778a9b8a688d261642592a4e2..452497e97b9948b120de751d9ae1a0807b777df1 100644 (file)
@@ -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);
         }
 
index eddf1d06f0e32e6748e348d1a4b961730f935533..37fa859a484a96f368ce466d9be3a96f75faf643 100644 (file)
@@ -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) {
index 8d2337d989e79f879a6ce5e162ee76209e24f0b7..b72caec9a0f2ad92324443ffa35cb690dfd98404 100644 (file)
@@ -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])));
+    }
 }
 
index 2678395df54988164c2d451d83cc0906651b17cb..9992ca76868a8212443e542d9b2e0a9968c2bd19 100644 (file)
Binary files a/tests/wasm/out.wasm and b/tests/wasm/out.wasm differ
index 4b8d6ceb7a3951972a873333373363578a9866c0..bd99d3a05a03fadb7df55b75eec93d3ae0ad6bd9 100644 (file)
@@ -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" ---