| 1 | module main |
| 2 | |
| 3 | import wasm |
| 4 | |
| 5 | fn test_patch() { |
| 6 | mut m := wasm.Module{} |
| 7 | vsp := m.new_global('__vsp', false, .i32_t, true, wasm.constexpr_value(10)) |
| 8 | mut at := m.new_function('add', [], []) |
| 9 | { |
| 10 | pp := at.patch_pos() |
| 11 | at.drop() |
| 12 | at.i32_const(10) |
| 13 | at.i32_const(10) |
| 14 | at.i32_const(10) |
| 15 | at.drop() |
| 16 | at.drop() |
| 17 | at.drop() |
| 18 | pps := at.patch_pos() |
| 19 | { |
| 20 | at.i32_const(10) |
| 21 | at.i32_const(10) |
| 22 | at.global_set(vsp) |
| 23 | at.i32_const(10) |
| 24 | at.global_set(vsp) |
| 25 | } |
| 26 | at.patch(pp, pps) // move to start |
| 27 | } |
| 28 | m.commit(at, true) |
| 29 | validate(m.compile()) or { panic(err) } |
| 30 | } |
| 31 | |