mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-27 07:33:57 +00:00
update comments a bit
This commit is contained in:
parent
b27d3a088d
commit
4727925b1a
@ -223,7 +223,12 @@ contributors:
|
|||||||
)
|
)
|
||||||
(export "apply_cos64" (func $apply_cos64))
|
(export "apply_cos64" (func $apply_cos64))
|
||||||
|
|
||||||
;; Demonstration of how this C code might be written by hand
|
;; Wasm is a stack-based language, but for returning values more complicated
|
||||||
|
;; than an int/float, a memory stack has to be manually managed. One
|
||||||
|
;; approach is to use a mutable global to store the stack_ptr. We give
|
||||||
|
;; ourselves 1MiB of mem-stack and grow it downwards.
|
||||||
|
;;
|
||||||
|
;; Below is a demonstration of how this C code **might** be written by hand
|
||||||
;;
|
;;
|
||||||
;; typedef struct {
|
;; typedef struct {
|
||||||
;; int a;
|
;; int a;
|
||||||
@ -238,17 +243,11 @@ contributors:
|
|||||||
;; sum_struct_t s = sum_struct_create(40, 2);
|
;; sum_struct_t s = sum_struct_create(40, 2);
|
||||||
;; return s.a + s.b;
|
;; return s.a + s.b;
|
||||||
;; }
|
;; }
|
||||||
;;
|
|
||||||
;; Wasm is a stack-based language, but for returning values more complicated
|
;; Unlike C, we must manage our own memory stack
|
||||||
;; than an int/float, a memory stack has to be manually managed. One ;;
|
|
||||||
;; approach is to use a mutable global to store the stack_ptr. We give
|
|
||||||
;; ourselves 1MiB of mem-stack and grow it downwards.
|
|
||||||
;;
|
|
||||||
;; Note: we are differentiating from the memstack (stack stored in memory)
|
|
||||||
;; and the "stack", which wasm implicitly uses to to pass and return values.
|
|
||||||
(global $memstack_ptr (mut i32) (i32.const 65536))
|
(global $memstack_ptr (mut i32) (i32.const 65536))
|
||||||
|
|
||||||
;; structs can only be returned by reference
|
;; Structs can only be returned by reference
|
||||||
(func $sum_struct_create
|
(func $sum_struct_create
|
||||||
(param $sum_struct_ptr i32)
|
(param $sum_struct_ptr i32)
|
||||||
(param $var$a i32)
|
(param $var$a i32)
|
||||||
|
Loading…
Reference in New Issue
Block a user