Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const iw = require('inline-webassembly');
iw(`
(module
(func (export "add") (param $n1 i32) (param $n2 i32) (result i32)
get_local $n1
get_local $n2
local.get $n1
local.get $n2
i32.add))`
).then((wasmModule) => {
const sum = wasmModule.add(44, 99);
Expand Down Expand Up @@ -142,8 +142,8 @@ iw(`
(i32.add
;; adding the string pointer with its length
(i32.add
(get_local $sref)
(get_local $slen)
(local.get $sref)
(local.get $slen)
)
(i32.const 1)
)
Expand All @@ -164,7 +164,7 @@ iw(`

;; store one character from original string to resulting string
(i32.store
(get_local $write_to)
(local.get $write_to)
;; load 1 byte and sign-extend i8 to i32
(i32.load8_s
(i32.sub
Expand All @@ -173,34 +173,34 @@ iw(`
(get_local $sref)
(get_local $slen)
)
(get_local $iterator)
(local.get $iterator)
)
(i32.const 1)
)
)
)

;; increment position to write to on next loop iteration
(set_local $write_to
(local.set $write_to
(i32.add
(get_local $write_to)
(i32.const 1)
)
)

;; increment iterator by 1 for every loop iteration
(set_local $iterator
(local.set $iterator
(i32.add
(get_local $iterator)
(local.get $iterator)
(i32.const 1)
)
)

;; break loop if iterator reaches string length
(br_if 1
(i32.ge_s
(get_local $iterator)
(get_local $slen)
(local.get $iterator)
(local.get $slen)
)
)

Expand All @@ -210,7 +210,7 @@ iw(`
)

;; returning result which contains pointer to the reversed string
(get_local $result)
(local.get $result)
)
)`
).then((wasmModule) => {
Expand All @@ -219,4 +219,4 @@ iw(`
const resultString = wasmModule.readString(resultPointer);
console.log(`Result = ${resultString}`);
});
```
```