Task

Demonstrate the different syntax and semantics provided for calling a function.



This may include:

   Calling a function that requires no arguments
   Calling a function with a fixed number of arguments
   Calling a function with optional arguments
   Calling a function with a variable number of arguments
   Calling a function with named arguments
   Using a function in statement context
   Using a function in first-class context within an expression
   Obtaining the return value of a function
   Distinguishing built-in functions and user-defined functions
   Distinguishing subroutines and functions
   Stating whether arguments are passed by value or by reference
   Is partial application possible and how


This task is not about defining functions.




(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)
    )
)