Skip to content

Commit c489282

Browse files
committed
Reorder Context definitions to present top-down
1 parent 8d89078 commit c489282

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

design/mvp/CanonicalABI.md

+16-14
Original file line numberDiff line numberDiff line change
@@ -210,31 +210,33 @@ The subsequent definitions of loading and storing a value from linear memory
210210
require additional context, which is threaded through most subsequent
211211
definitions via the `cx` parameter:
212212
```python
213+
class Context:
214+
opts: CanonicalOptions
215+
inst: ComponentInstance
216+
```
217+
218+
The `opts` field represents the [`canonopt`] values supplied to
219+
currently-executing `canon lift` or `canon lower`:
220+
```python
213221
class CanonicalOptions:
214222
memory: bytearray
215223
string_encoding: str
216224
realloc: Callable[[int,int,int,int],int]
217225
post_return: Callable[[],None]
226+
```
218227

228+
The `inst` field represents the component instance that the currently-executing
229+
canonical definition is defined to execute inside. The `may_enter` and
230+
`may_leave` fields are used to enforce the [component invariants]: `may_leave`
231+
indicates whether the instance may call out to an import and the `may_enter`
232+
state indicates whether the instance may be called from the outside world
233+
through an export.
234+
```python
219235
class ComponentInstance:
220236
may_leave = True
221237
may_enter = True
222238
# ...
223-
224-
class Context:
225-
opts: CanonicalOptions
226-
inst: ComponentInstance
227239
```
228-
Going through the fields of `Context`:
229-
230-
The `opts` field represents the [`canonopt`] values supplied to
231-
currently-executing `canon lift` or `canon lower`.
232-
233-
The `inst` field represents the component instance that the currently-executing
234-
canonical definition is closed over. The `may_enter` and `may_leave` fields are
235-
used to enforce the [component invariants]: `may_leave` indicates whether the
236-
instance may call out to an import and the `may_enter` state indicates whether
237-
the instance may be called from the outside world through an export.
238240

239241

240242
### Loading

design/mvp/canonical-abi/definitions.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Boilerplate
66

7+
from __future__ import annotations
78
import math
89
import struct
910
from dataclasses import dataclass
@@ -271,21 +272,25 @@ def num_i32_flags(labels):
271272

272273
### Context
273274

275+
class Context:
276+
opts: CanonicalOptions
277+
inst: ComponentInstance
278+
279+
#
280+
274281
class CanonicalOptions:
275282
memory: bytearray
276283
string_encoding: str
277284
realloc: Callable[[int,int,int,int],int]
278285
post_return: Callable[[],None]
279286

287+
#
288+
280289
class ComponentInstance:
281290
may_leave = True
282291
may_enter = True
283292
# ...
284293

285-
class Context:
286-
opts: CanonicalOptions
287-
inst: ComponentInstance
288-
289294
### Loading
290295

291296
def load(cx, ptr, t):

0 commit comments

Comments
 (0)