| 1 | import wasm |
| 2 | |
| 3 | fn main() { |
| 4 | mut m := wasm.Module{} |
| 5 | mut pyth := m.new_function('pythagoras', [.f32_t, .f32_t], [ |
| 6 | .f32_t, |
| 7 | ]) |
| 8 | { |
| 9 | pyth.local_get(0) |
| 10 | pyth.local_get(0) |
| 11 | pyth.mul(.f32_t) |
| 12 | pyth.local_get(1) |
| 13 | pyth.local_get(1) |
| 14 | pyth.mul(.f32_t) |
| 15 | pyth.add(.f32_t) |
| 16 | pyth.sqrt(.f32_t) |
| 17 | pyth.cast(.f32_t, true, .f64_t) |
| 18 | } |
| 19 | m.commit(pyth, true) |
| 20 | mut test := m.new_function('test', [.f32_t], [.f64_t]) |
| 21 | { |
| 22 | test.local_get(0) |
| 23 | test.f32_const(10.0) |
| 24 | test.call('pythagoras') |
| 25 | test.cast(.f32_t, true, .f64_t) |
| 26 | } |
| 27 | m.commit(test, true) |
| 28 | print(m.compile().bytestr()) |
| 29 | } |
| 30 | |