| 1 | module main |
| 2 | |
| 3 | import wasm |
| 4 | |
| 5 | fn test_globals() { |
| 6 | mut m := wasm.Module{} |
| 7 | m.enable_debug('vlang') |
| 8 | |
| 9 | vsp := m.new_global('__vsp', false, .i32_t, true, wasm.constexpr_value(10)) |
| 10 | mut func := m.new_function('vsp', [], [.i32_t]) |
| 11 | { |
| 12 | func.global_get(vsp) |
| 13 | func.i32_const(20) |
| 14 | func.add(.i32_t) |
| 15 | func.global_set(vsp) |
| 16 | func.global_get(vsp) |
| 17 | } |
| 18 | m.commit(func, true) |
| 19 | |
| 20 | fref := m.new_global('__ref', true, .funcref_t, true, wasm.constexpr_ref_null(.funcref_t)) |
| 21 | mut func1 := m.new_function('ref', [], []) |
| 22 | { |
| 23 | func1.ref_func('vsp') |
| 24 | func1.global_set(fref) |
| 25 | } |
| 26 | m.commit(func1, true) |
| 27 | |
| 28 | gimport := m.new_global_import('env', '__import', .f64_t, false) |
| 29 | mut func2 := m.new_function('import', [], [.f64_t]) |
| 30 | { |
| 31 | func2.global_get(gimport) |
| 32 | } |
| 33 | m.commit(func2, true) |
| 34 | |
| 35 | validate(m.compile()) or { panic(err) } |
| 36 | } |
| 37 | |