Skip to content

Commit 1ffc0bd

Browse files
committed
Switch to using @DataClass in canonical-abi/definitions.py
1 parent 3db1b22 commit 1ffc0bd

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

design/mvp/CanonicalABI.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,19 @@ class Resource:
265265
The `OwnHandle` and `BorrowHandle` classes represent runtime handle values of
266266
`own` and `borrow` type, resp:
267267
```python
268+
@dataclass
268269
class Handle:
269270
resource: Resource
270271
rt: ResourceType
271272
lend_count: int
272273

273-
def __init__(self, resource, rt):
274-
self.resource = resource
275-
self.rt = rt
276-
self.lend_count = 0
274+
@dataclass
275+
class OwnHandle(Handle):
276+
pass
277277

278-
class OwnHandle(Handle): pass
279-
class BorrowHandle(Handle): pass
278+
@dataclass
279+
class BorrowHandle(Handle):
280+
pass
280281
```
281282
The `resource` field points to the resource instance this handle refers to. The
282283
`rt` field points to a runtime value representing the static
@@ -975,11 +976,11 @@ Finally, `own` and `borrow` handles are lowered by inserting them into the
975976
current component instance's `HandleTable`:
976977
```python
977978
def lower_own(cx, resource, rt):
978-
h = OwnHandle(resource, rt)
979+
h = OwnHandle(resource, rt, 0)
979980
return cx.inst.handles.insert(cx, h)
980981

981982
def lower_borrow(cx, resource, rt):
982-
h = BorrowHandle(resource, rt)
983+
h = BorrowHandle(resource, rt, 0)
983984
return cx.inst.handles.insert(cx, h)
984985
```
985986
Note that the `rt` value that is stored in the runtime `Handle` captures what
@@ -1569,7 +1570,7 @@ Calling `$f` invokes the following function, which creates a resource object
15691570
and inserts it into the current instance's handle table:
15701571
```python
15711572
def canon_resource_new(cx, rt, rep):
1572-
h = OwnHandle(Resource(rep, cx.inst), rt)
1573+
h = OwnHandle(Resource(rep, cx.inst), rt, 0)
15731574
return cx.inst.handles.insert(cx, h)
15741575
```
15751576

design/mvp/canonical-abi/definitions.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,19 @@ class Resource:
321321

322322
#
323323

324+
@dataclass
324325
class Handle:
325326
resource: Resource
326327
rt: ResourceType
327328
lend_count: int
328329

329-
def __init__(self, resource, rt):
330-
self.resource = resource
331-
self.rt = rt
332-
self.lend_count = 0
330+
@dataclass
331+
class OwnHandle(Handle):
332+
pass
333333

334-
class OwnHandle(Handle): pass
335-
class BorrowHandle(Handle): pass
334+
@dataclass
335+
class BorrowHandle(Handle):
336+
pass
336337

337338
#
338339

@@ -843,11 +844,11 @@ def pack_flags_into_int(v, labels):
843844
#
844845

845846
def lower_own(cx, resource, rt):
846-
h = OwnHandle(resource, rt)
847+
h = OwnHandle(resource, rt, 0)
847848
return cx.inst.handles.insert(cx, h)
848849

849850
def lower_borrow(cx, resource, rt):
850-
h = BorrowHandle(resource, rt)
851+
h = BorrowHandle(resource, rt, 0)
851852
return cx.inst.handles.insert(cx, h)
852853

853854
### Flattening
@@ -1211,7 +1212,7 @@ def canon_lower(cx, callee, calling_import, ft, flat_args):
12111212
### `resource.new`
12121213

12131214
def canon_resource_new(cx, rt, rep):
1214-
h = OwnHandle(Resource(rep, cx.inst), rt)
1215+
h = OwnHandle(Resource(rep, cx.inst), rt, 0)
12151216
return cx.inst.handles.insert(cx, h)
12161217

12171218
### `resource.drop`

0 commit comments

Comments
 (0)