Anonymous user
Call a function: Difference between revisions
→{{header|WDTE}}
(Added Wren) |
|||
Line 5,306:
# function.
(+ 3) 7 -- print;</lang>
=={{header|WebAssembly}}==
<lang webassembly>(module
(memory 12)
(export "memory" (memory 0))
(func $noargfunc
(i32.const 2)
(i32.const 3)
i32.add
drop ;;Discard the result
)
(func $multipy (param $a i32) (param $b i32) (result i32)
local.get $a
local.get $b
i32.mul
)
(func $addinmemory (param $a i32) (param $b i32) (param $out i32)
(i32.load (get_local $a))
(i32.load (get_local $b))
i32.mul
(i32.store (get_local $out))
)
(func $main (export "_start")
(local $result i32)
;;Call a function with no arguments
call $noargfunc
;;Multiply two numbers and store the result, flat syntax
i32.const 12
i32.const 3
call $multipy
set_local $result
;;Multiply two numbers and store the result, indented syntax
(set_local $result
(call $multipy
(i32.const 12)
(i32.const 3)
)
)
;;Add two numbers in linear memory (similar to using pointers)
(i32.store (i32.const 0) (i32.const 5))
(i32.store (i32.const 4) (i32.const 7))
(call $addinmemory
(i32.const 0)
(i32.const 4)
(i32.const 8)
)
)
)</lang>
=={{header|Wren}}==
|