Skip to content

Commit 367b872

Browse files
author
Peter Huene
authored
Merge pull request #21 from peterhuene/add-store-back
Add the Store type back to the API.
2 parents 42102b2 + 8d3e5ce commit 367b872

23 files changed

+463
-365
lines changed

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,33 @@ namespace Tutorial
6969
{
7070
static void Main(string[] args)
7171
{
72-
using var host = new Host();
72+
using var store = new Store();
73+
74+
using var module = store.LoadModuleText(
75+
"hello",
76+
"(module (func $hello (import \"\" \"hello\")) (func (export \"run\") (call $hello)))"
77+
);
78+
79+
using var host = new Host(store);
7380

7481
host.DefineFunction(
7582
"",
7683
"hello",
7784
() => Console.WriteLine("Hello from C#!")
7885
);
7986

80-
using var module = host.LoadModuleText(
81-
"hello",
82-
"(module (func $hello (import \"\" \"hello\")) (func (export \"run\") (call $hello)))"
83-
);
84-
8587
using dynamic instance = host.Instantiate(module);
8688
instance.run();
8789
}
8890
}
8991
}
9092
```
9193

92-
This host defines a function called `hello` that simply prints a hello message.
94+
A `Store` is created and the WebAssembly module, in text format, is loaded into the store.
95+
96+
A `Host` defines a function called `hello` that simply prints a hello message.
9397

94-
It then loads the module into the host in WebAssembly text format and invokes the module's `run` export.
98+
The module is instantiated into the host and the module's `run` export is invoked.
9599

96100
To run the application, simply use `dotnet`:
97101

docs/articles/intro.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ namespace Tutorial
6565
{
6666
static void Main(string[] args)
6767
{
68-
using var host = new Host();
68+
using var store = new Store();
69+
using var module = store.LoadModuleText("hello", "(module (func $hello (import \"\" \"hello\")) (func (export \"run\") (call $hello)))");
70+
using var host = new Host(store);
6971

7072
host.DefineFunction(
7173
"",
7274
"hello",
7375
() => Console.WriteLine("Hello from C#!")
7476
);
7577

76-
using var module = host.LoadModuleText("hello", "(module (func $hello (import \"\" \"hello\")) (func (export \"run\") (call $hello)))");
77-
7878
using dynamic instance = host.Instantiate(module);
7979
instance.run();
8080
}

examples/global/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class Program
77
{
88
static void Main(string[] args)
99
{
10-
using var host = new Host();
10+
using var store = new Store();
11+
using var module = store.LoadModuleText("global.wat");
12+
using var host = new Host(store);
1113

1214
var global = host.DefineMutableGlobal("", "global", 1);
1315

@@ -19,8 +21,6 @@ static void Main(string[] args)
1921
}
2022
);
2123

22-
using var module = host.LoadModuleText("global.wat");
23-
2424
using dynamic instance = host.Instantiate(module);
2525
instance.run(20);
2626
}

examples/hello/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ class Program
77
{
88
static void Main(string[] args)
99
{
10-
using var host = new Host();
10+
using var store = new Store();
11+
using var module = store.LoadModuleText("hello.wat");
12+
using var host = new Host(store);
1113

1214
host.DefineFunction(
1315
"",
1416
"hello",
1517
() => Console.WriteLine("Hello from C#, WebAssembly!")
1618
);
1719

18-
using var module = host.LoadModuleText("hello.wat");
19-
2020
using dynamic instance = host.Instantiate(module);
2121
instance.run();
2222
}

examples/memory/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class Program
77
{
88
static void Main(string[] args)
99
{
10-
using var host = new Host();
10+
using var store = new Store();
11+
using var module = store.LoadModuleText("memory.wat");
12+
using var host = new Host(store);
1113

1214
host.DefineFunction(
1315
"",
@@ -18,8 +20,6 @@ static void Main(string[] args)
1820
}
1921
);
2022

21-
using var module = host.LoadModuleText("memory.wat");
22-
2323
using dynamic instance = host.Instantiate(module);
2424
instance.run();
2525
}

0 commit comments

Comments
 (0)