diff options
author | Rett Berg <rett@google.com> | 2019-11-16 12:44:47 -0700 |
---|---|---|
committer | Rett Berg <rett@google.com> | 2019-11-16 12:44:47 -0700 |
commit | 4727925b1aef7f030adb8ae76bf7562a6280b54e (patch) | |
tree | 443f594e63d215dd24b8c14f6f62e5051e6b2261 /wasm.html.markdown | |
parent | b27d3a088db2fac2324df2a05330801afee2e92b (diff) |
update comments a bit
Diffstat (limited to 'wasm.html.markdown')
-rw-r--r-- | wasm.html.markdown | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/wasm.html.markdown b/wasm.html.markdown index 92831e69..d62539b8 100644 --- a/wasm.html.markdown +++ b/wasm.html.markdown @@ -223,7 +223,12 @@ contributors: ) (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 { ;; int a; @@ -238,17 +243,11 @@ contributors: ;; sum_struct_t s = sum_struct_create(40, 2); ;; return s.a + s.b; ;; } - ;; - ;; 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. - ;; - ;; Note: we are differentiating from the memstack (stack stored in memory) - ;; and the "stack", which wasm implicitly uses to to pass and return values. + + ;; Unlike C, we must manage our own memory stack (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 (param $sum_struct_ptr i32) (param $var$a i32) |