Skip to content

Commit dfcffbd

Browse files
committed
Add memory details to pseudocode example
1 parent 17b64a4 commit dfcffbd

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

component-model/src/design/why-component-model.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,34 @@ The return type is a pair of 32-bit integers,
7373
reflecting that the function must return
7474
the new offset for the newly allocated string, as well as its length.
7575

76+
For this to work, the module defining the `remove-duplicates` function
77+
would also need to include
78+
an export declaration that exports a memory to be used
79+
for the argument and result strings. Pseudocode:
80+
81+
```
82+
export "string_mem" (mem 1)
83+
```
84+
85+
And, the module using the `remove-duplicates` function
86+
would need to import this memory. Pseudocode:
87+
88+
```
89+
import "strings" "string_mem"
90+
```
91+
92+
(This pseudocode is still simplified, since the importer
93+
also needs to declare the size of the memory being
94+
imported.)
95+
7696
We would prefer to write a pseudocode type signature like this:
7797

7898
```
7999
remove-duplicates: func(s: string) -> string
80100
```
81101

102+
and dispense with the memory exports and imports altogether.
103+
82104
Data representations are frequently specific to each programming language.
83105
For example, a string in C is represented entirely differently
84106
from a string in Rust or in JavaScript.

0 commit comments

Comments
 (0)