mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
36 lines
757 B
V
36 lines
757 B
V
module main
|
|
|
|
import wasm
|
|
|
|
fn test_globals() {
|
|
mut m := wasm.Module{}
|
|
|
|
vsp := m.new_global('__vsp', .i32_t, true, wasm.constexpr_value(10))
|
|
mut func := m.new_function('vsp', [], [.i32_t])
|
|
{
|
|
func.global_get(vsp)
|
|
func.i32_const(20)
|
|
func.add(.i32_t)
|
|
func.global_set(vsp)
|
|
func.global_get(vsp)
|
|
}
|
|
m.commit(func, true)
|
|
|
|
fref := m.new_global('__ref', .funcref_t, true, wasm.constexpr_ref_null(.funcref_t))
|
|
mut func1 := m.new_function('ref', [], [])
|
|
{
|
|
func1.ref_func('vsp')
|
|
func1.global_set(fref)
|
|
}
|
|
m.commit(func1, true)
|
|
|
|
gimport := m.new_global_import('env', '__import', .f64_t, false)
|
|
mut func2 := m.new_function('import', [], [.f64_t])
|
|
{
|
|
func2.global_get(gimport)
|
|
}
|
|
m.commit(func2, true)
|
|
|
|
validate(m.compile()) or { panic(err) }
|
|
}
|