v2 / vlib / wasm / tests / arith_test.v
36 lines · 34 sloc · 675 bytes · bf749b35590b7624a2495924e449a640a34acfb0
Raw
1module main
2
3import wasm
4
5fn test_add() {
6 mut m := wasm.Module{}
7 mut a1 := m.new_function('add', [.i32_t, .i32_t], [.i32_t])
8 {
9 a1.local_get(0)
10 a1.local_get(1)
11 a1.add(.i32_t)
12 }
13 m.commit(a1, true)
14 mut a2 := m.new_function('sub', [.i32_t, .i32_t], [.i32_t])
15 {
16 a2.local_get(0)
17 a2.local_get(1)
18 a2.sub(.i32_t)
19 }
20 m.commit(a2, true)
21 mut a3 := m.new_function('mul', [.i32_t, .i32_t], [.i32_t])
22 {
23 a3.local_get(0)
24 a3.local_get(1)
25 a3.mul(.i32_t)
26 }
27 m.commit(a3, true)
28 mut a4 := m.new_function('div', [.i32_t, .i32_t], [.i32_t])
29 {
30 a4.local_get(0)
31 a4.local_get(1)
32 a4.div(.i32_t, true)
33 }
34 m.commit(a4, true)
35 validate(m.compile()) or { panic(err) }
36}
37