diff --git a/backend_wat.go b/backend_wat.go index 9817357..9431d9a 100644 --- a/backend_wat.go +++ b/backend_wat.go @@ -894,13 +894,10 @@ func (c *Compiler) compileFunctionWAT(function *ParsedFunction) (string, error) } func (c *Compiler) compile() (string, error) { - module := "(module (memory 0)\n" + module := "(module (memory $memory 0) (export \"memory\" (memory $memory))\n" module += "(func $__builtin_panic\n" - module += "i32.const 0\n" - module += "i32.const 0\n" - module += "i32.div_u\n" - module += "drop\n" + module += "unreachable\n" module += ")\n" for _, file := range c.Files { diff --git a/example/array.ely b/example/array.ely index 1a24359..ba48a97 100644 --- a/example/array.ely +++ b/example/array.ely @@ -3,7 +3,7 @@ u64 array() { __builtin_memory_grow(1u64); } - raw(u32, 0x0u64) = 1u32; + raw(u32, 0x0u64) = 2u32; raw(u64, 0x04u64) = 69u64; u64[] array = raw(u64[], 0x0u64); @@ -18,6 +18,11 @@ void array2() { array[0] = 1u64; } +void outOfBounds() { + u64[] array = raw(u64[], 0x0u64); + array[100] = 69u64; +} + u64[] arrayReturn() { if(__builtin_memory_size() == 0u64) { __builtin_memory_grow(1u64);