not filling the binary with thousands of unnecessary zeros
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 27 Jul 2020 15:50:17 +0000 (10:50 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 27 Jul 2020 15:50:17 +0000 (10:50 -0500)
onyx
progs/ez.onyx
progs/ufc.onyx
src/onyxwasm.c

diff --git a/onyx b/onyx
index b644cefb58ce9252f1d5024eb18fb005de3190c5..cbe7e0ba7aaa9e05cc1ea80521cf270b7a02437b 100755 (executable)
Binary files a/onyx and b/onyx differ
index 947baca2f2f0d51c751c7ffe0be394275719c17e..e4f056cb5116e640fd6238e6353a7be1d9945091 100644 (file)
@@ -13,10 +13,15 @@ Foo :: struct {
     st : SomeType;
 }
 
-foo_sum :: proc (use foo: ^Foo) -> i32 {
+foo_sum :: proc (use this: ^Foo) -> i32 {
+    this.foo_other();
     return x + y;
 }
 
+foo_other :: proc (use this: ^Foo) {
+    print(st as i32);
+}
+
 asdf :: proc (pa: PrintableArray) {
     for i: 0, pa.len print(pa.data[i] as i32);
 }
@@ -32,18 +37,18 @@ print_st :: proc (st: SomeType, other: i32) {
     print(st as i32);
 }
 
-single_int : u8
+single_int : u32
 
-array : [N] Foo
 N :: 1024
+array : [N] Foo
 
 proc #export "main" {
     print("Hello World! this is slightly longer\n");
 
     print(__heap_start as i32);
 
-    single_int = 10 as u8;
-    print(single_int as i32);
+    single_int = 10;
+    print(single_int);
 
     array[4].y = 1234;
     print(array[4].y);
index 50cd18c16ae529fb0ec626dff56631c4bf032e2e..fb88f6ac43767bd19473fb0dd2cdbf1b72111d56 100644 (file)
@@ -64,10 +64,6 @@ dot :: proc (v: Vec2, u: Vec2) -> f32 {
        return v.x * u.x + v.y * u.y;
 }
 
-asdf :: proc (use v: ^Vec2, use u: ^Vec2) -> f32 {
-       return x + x;
-}
-
 
 // SomeType :: enum (u32) { Value1, Value2 }
 
index aa03c2d7b9c30de052c4d1b80cb3ba51a67fb8f8..409fb1d0cded0fab91c4875772ea88f7559d87c8 100644 (file)
@@ -1358,19 +1358,16 @@ static void compile_memory_reservation(OnyxWasmModule* mod, AstMemRes* memres) {
         offset += alignment - (offset % alignment);
     }
 
-    ptr data = bh_alloc_array(global_heap_allocator, i8, size);
-    memset(data, 0, size);
-
-    WasmDatum datum = {
-        .offset = offset,
-        .length = size,
-        .data = data
-    };
+    // WasmDatum datum = {
+    //     .offset = offset,
+    //     .length = size,
+    //     .data = NULL
+    // };
 
     memres->addr = offset;
     mod->next_datum_offset = offset + size;
 
-    bh_arr_push(mod->data, datum);
+    // bh_arr_push(mod->data, datum);
 }
 
 OnyxWasmModule onyx_wasm_module_create(bh_allocator alloc) {
@@ -1948,6 +1945,8 @@ static i32 output_datasection(OnyxWasmModule* module, bh_buffer* buff) {
     bh_buffer_append(&vec_buff, leb, leb_len);
 
     bh_arr_each(WasmDatum, datum, module->data) {
+        if (datum->data == NULL) continue;
+
         // NOTE: 0x00 memory index
         bh_buffer_write_byte(&vec_buff, 0x00);