mirror of
https://github.com/vlang/v.git
synced 2025-09-15 15:32:27 +03:00
vlib: add a wasm module, implementing a pure V webassembly seralisation library (#17909)
This commit is contained in:
parent
9658d20f03
commit
d2f69472b2
14 changed files with 1966 additions and 0 deletions
29
examples/wasm_codegen/functions.v
Normal file
29
examples/wasm_codegen/functions.v
Normal file
|
@ -0,0 +1,29 @@
|
|||
import wasm
|
||||
|
||||
fn main() {
|
||||
mut m := wasm.Module{}
|
||||
mut pyth := m.new_function('pythagoras', [.f32_t, .f32_t], [
|
||||
.f32_t,
|
||||
])
|
||||
{
|
||||
pyth.local_get(0)
|
||||
pyth.local_get(0)
|
||||
pyth.mul(.f32_t)
|
||||
pyth.local_get(1)
|
||||
pyth.local_get(1)
|
||||
pyth.mul(.f32_t)
|
||||
pyth.add(.f32_t)
|
||||
pyth.sqrt(.f32_t)
|
||||
pyth.cast(.f32_t, true, .f64_t)
|
||||
}
|
||||
m.commit(pyth, true)
|
||||
mut test := m.new_function('test', [.f32_t], [.f64_t])
|
||||
{
|
||||
test.local_get(0)
|
||||
test.f32_const(10.0)
|
||||
test.call('pythagoras')
|
||||
test.cast(.f32_t, true, .f64_t)
|
||||
}
|
||||
m.commit(test, true)
|
||||
print(m.compile().bytestr())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue