(module
(func $data_types
(local $int_32 i32)
(local $int_64 i64)
(local $float_32 f32)
(local $float_64 f64)
(local.set $int_32 (i32.const 16))
(local.set $int_32 (i64.const 128))
(local.set $float_32 (f32.const 3.14))
(local.set $float_64 (f64.const 1.28))
)
(func $basic_operations
(local $add_result i32)
(local $mult_result f64)
(local.set $add_result (i32.add (i32.const 2) (i32.const 4)))
(local.set $mult_result (f64.mul (f64.const 2.0) (f64.const 4.0)))
)
(func $get_16 (result i32)
(i32.const 16)
)
(func $add (param $param0 i32) (param $param1 i32) (result i32)
(i32.add
(local.get $param0)
(local.get $param1)
)
)
(func $double_16 (result i32)
(i32.mul
(i32.const 2)
(call $get_16))
)
(import "console" "log" (func $print_i32 (param i32)))
(import "math" "cos" (func $cos (param f64) (result f64)))
(func $print_args (param $arg0 i32) (param $arg1 i32)
(call $print_i32 (local.get $arg0))
(call $print_i32 (local.get $arg1))
)
(export "print_args" (func $print_args))
(memory (export "memory") 100)
(func $apply_cos64 (param $array_length i32)
(local $idx i32)
(local $idx_bytes i32)
(local $bytes_per_double i32)
(local $temp_f64 f64)
(local.set $idx (i32.const 0))
(local.set $idx_bytes (i32.const 0))
(local.set $bytes_per_double (i32.const 8))
(block
(loop
(local.set $idx_bytes (i32.mul (local.get $idx) (local.get $bytes_per_double)))
(local.set $temp_f64 (f64.load (local.get $idx_bytes)))
(local.set $temp_64 (call $cos (local.get $temp_64)))
(f64.store
(local.get $idx_bytes)
(local.get $temp_64))
(f64.store
(local.get $idx_bytes)
(call $cos
(f64.load
(local.get $idx_bytes))))
(local.set $idx (i32.add (local.get $idx) (i32.const 1)))
(br_if 1 (i32.eq (local.get $idx) (local.get $array_length)))
(br 0)
)
)
)
(export "apply_cos64" (func $apply_cos64))
(global $memstack_ptr (mut i32) (i32.const 65536))
(func $sum_struct_create
(param $sum_struct_ptr i32)
(param $var$a i32)
(param $var$b i32)
(i32.store
(get_local $sum_struct_ptr)
(get_local $var$a)
)
(i32.store offset=4
(get_local $sum_struct_ptr)
(get_local $var$b)
)
)
(func $sum_local (result i32)
(local $var$sum_struct$a i32)
(local $var$sum_struct$b i32)
(local $local_memstack_ptr i32)
(i32.sub
(get_global $memstack_ptr)
(i32.const 8)
)
tee_local $local_memstack_ptr
set_global $memstack_ptr
(call $sum_struct_create
( get_local $local_memstack_ptr)
( i32.const 40)
( i32.const 2)
)
(set_local $var$sum_struct$a
(i32.load offset=0 (get_local $local_memstack_ptr))
)
(set_local $var$sum_struct$b
(i32.load offset=4 (get_local $local_memstack_ptr))
)
(set_global $memstack_ptr
(i32.add
(get_local $local_memstack_ptr)
(i32.const 8)
)
)
(i32.add
(get_local $var$sum_struct$a)
(get_local $var$sum_struct$b)
)
)
(export "sum_local" (func $sum_local))
)