Skip to content

Commit 668e780

Browse files
committed
Add a very simple example of the wac language to the README
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
1 parent 7b2f728 commit 668e780

1 file changed

Lines changed: 53 additions & 3 deletions

File tree

README.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,60 @@ together.
2323
The tool uses the WAC (pronounced "whack") language to define how components
2424
composed together.
2525

26-
## Language
26+
## The `wac` Language
2727

28-
See the [language documentation](LANGUAGE.md) for more information on the
29-
syntax of WAC.
28+
The `wac` language is a declarative superset of [`wit`](https://component-model.bytecodealliance.org/design/wit.html)
29+
for describing how components are composed together.
30+
31+
As an example, imagine two components name.wasm and greeter.wasm.
32+
33+
The wit for name.wasm is:
34+
35+
```wit
36+
package example:name;
37+
38+
world name {
39+
/// Exporting a 'name' function that returns a name to greet.
40+
export name: func() -> string;
41+
}
42+
```
43+
44+
And the wit for greeter.wasm is:
45+
46+
```wit
47+
package example:greeter;
48+
49+
world greeter {
50+
/// Importing a 'name' function that returns the name to greet.
51+
import name: func() -> string;
52+
/// Exporting a 'greet' function that returns a greeting using the name.
53+
export greet: func() -> string;
54+
}
55+
```
56+
57+
The following is an example of a wac file that composes these two components together
58+
by plugging name.wasm's "name" export into greeter.wasm's "name" import.
59+
60+
```wac
61+
package example:composition;
62+
63+
// Instantiate the `name` component
64+
let n = new example:name {};
65+
66+
// Instantiate the `greeter` component by plugging its `name`
67+
// import with the `name` export of the `name` component.
68+
let greeter = new example:greeter {
69+
name: n.name,
70+
};
71+
72+
// Export the greet function from the greeter component
73+
export greeter.greet;
74+
```
75+
76+
The result of encoding this composition is a single component that
77+
does not import anything and only exports the "greet" function.
78+
79+
For a full description of the `wac` language see [the language guide](LANGUAGE.md).
3080

3181
## Installation
3282

0 commit comments

Comments
 (0)