@@ -39,32 +39,55 @@ Kinds of definitions include:
3939
4040A core module usually corresponds to a single binary ` .wasm ` file.
4141These modules can be run in the browser,
42- or via a server-side WebAssembly runtime such as [ Wasmtime] ( https://wasmtime.dev/ )
42+ or via a separate runtime such as [ Wasmtime] ( https://wasmtime.dev/ )
4343or [ WAMR] ( https://github.com/bytecodealliance/wasm-micro-runtime ) .
4444
4545### Limitations of core modules
4646
4747Core modules are, however, limited in how they expose their functionality to the outside world.
48- Core modules expose their functionality by exporting functions.
49- These functions' argument and return types are restricted, essentially,
50- to only integers and floating-point numbers.
51- Compound types, such as strings, lists, arrays, records, or structs,
48+ In WebAssembly core modules, functions are restricted, essentially,
49+ to using integer (` i32 ` or ` i64 ` ) or floating-point (` f32 ` or ` f64 ` ) types.
50+ Only these types can be passed as arguments to functions,
51+ and only these types can be returned from functions as results.
52+ Compound types common in higher-level programming languages,
53+ such as strings, lists, arrays, enums (enumerations), or structs (records),
5254have to be represented in terms of integers and floating-point numbers.
5355
5456Recall that a linear memory is an uninitialized region of bytes
5557declared within a module.
5658So, a string argument might be represented as two separate arguments:
5759an integer offset into a memory,
5860and an integer representing the length of the string.
59- These representations are frequently specific to each programming language.
60- For example, a string in C might be represented entirely differently
61+
62+ In pseudocode, a type signature for a string-manipulating function
63+ might look like:
64+
65+ ```
66+ remove-duplicates: func(offset: i32, length: i32) -> [i32, i32]
67+ ```
68+
69+ supposing that ` remove-duplicates ` is a function
70+ to create a new string consisting of the unique characters
71+ in its argument.
72+ The return type is a pair of 32-bit integers,
73+ reflecting that the function must return
74+ the new offset for the newly allocated string, as well as its length.
75+
76+ We would prefer to write a pseudocode type signature like this:
77+
78+ ```
79+ remove-duplicates: func(s: string) -> string
80+ ```
81+
82+ Data representations are frequently specific to each programming language.
83+ For example, a string in C is represented entirely differently
6184from a string in Rust or in JavaScript.
6285Moreover, to make this approach work, modules must import and export memories,
6386which can be error-prone, as different languages
6487make different assumptions about memory layout.
6588
66- For WebAssembly modules written in different languages to interoperate smoothly, there needs to be an agreed-upon way
67- to expose these richer types across module boundaries.
89+ For WebAssembly modules written in different languages to interoperate smoothly,
90+ there needs to be an agreed-upon way to expose these richer types across module boundaries.
6891
6992## Components
7093
0 commit comments