Skip to content

Instantly share code, notes, and snippets.

@leroycep
Created July 4, 2020 18:02
Show Gist options
  • Save leroycep/b47dade18e892211e6b2d08e21501846 to your computer and use it in GitHub Desktop.
Save leroycep/b47dade18e892211e6b2d08e21501846 to your computer and use it in GitHub Desktop.
2020-07-04 zig table not exported
(module
(type (;0;) (func (param i32)))
(type (;1;) (func (param i32 i32)))
(type (;2;) (func))
(type (;3;) (func (param i32) (result i32)))
(import "env" "register" (func $register (type 0)))
(func $std.builtin.default_panic (type 1) (param i32 i32)
(local i32 i32 i32)
global.get 0
local.set 2
i32.const 16
local.set 3
local.get 2
local.get 3
i32.sub
local.set 4
local.get 4
local.get 1
i32.store offset=12
loop ;; label = @1
unreachable
br 0 (;@1;)
end)
(func $hello (type 2)
(local i32)
i32.const 1
local.set 0
local.get 0
call $register
return)
(func $add_one (type 3) (param i32) (result i32)
(local i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)
global.get 0
local.set 1
i32.const 16
local.set 2
local.get 1
local.get 2
i32.sub
local.set 3
local.get 3
global.set 0
local.get 3
local.get 0
i32.store offset=8
local.get 3
i32.load offset=8
local.set 4
i32.const 1
local.set 5
local.get 4
local.get 5
i32.add
local.set 6
local.get 6
local.get 4
i32.lt_s
local.set 7
i32.const 1
local.set 8
local.get 7
local.get 8
i32.and
local.set 9
block ;; label = @1
local.get 9
i32.eqz
br_if 0 (;@1;)
i32.const 1044
local.set 10
i32.const 0
local.set 11
local.get 10
local.get 11
call $std.builtin.default_panic
unreachable
end
local.get 3
local.get 6
i32.store offset=12
local.get 3
i32.load offset=12
local.set 12
i32.const 16
local.set 13
local.get 3
local.get 13
i32.add
local.set 14
local.get 14
global.set 0
local.get 12
return)
(table (;0;) 2 2 funcref)
(memory (;0;) 2)
(global (;0;) (mut i32) (i32.const 66592))
(export "memory" (memory 0))
(export "hello" (func $hello))
(elem (;0;) (i32.const 1) func $add_one)
(data (;0;) (i32.const 1024) "integer overflow\00\00\00\00\00\04\00\00\10\00\00\00"))
export fn hello() void {
register(add_one);
}
fn add_one(a: i32) callconv(.C) i32 {
return a + 1;
}
extern fn register(callback: fn (i32) callconv(.C) i32) void;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment