|
30 | 30 | TriggerFunc = Callable[[Context, EventNotify], DSError | None] |
31 | 31 |
|
32 | 32 |
|
33 | | -def get_return(ctx: Context, idx: int, tparam: type = object) -> Any: |
34 | | - return ctx.get_var(f"__return_{idx}__", tparam) |
| 33 | +class ChanRef[T](str): |
| 34 | + pass |
35 | 35 |
|
36 | 36 |
|
37 | | -class ChanRef[T](str): |
| 37 | +class WgRef(str): |
38 | 38 | pass |
39 | 39 |
|
40 | 40 |
|
41 | | -WgRef = str |
42 | | -MutexRef = str |
| 41 | +class MutexRef(str): |
| 42 | + pass |
43 | 43 |
|
44 | 44 |
|
45 | 45 | @dataclass |
@@ -172,14 +172,14 @@ def impure_block( |
172 | 172 | line: int, |
173 | 173 | stmt: Callable[[Context], None], |
174 | 174 | ) -> AwaitBlock: |
175 | | - def _trigger(ctx: Context, notify: EventNotify) -> None: |
176 | | - stmt(ctx) |
177 | | - |
178 | 175 | def _start(ctx: Context) -> Event: |
179 | 176 | key = "impure-" + ctx.gen_key() |
180 | 177 |
|
181 | 178 | return CheckpointEvent(id=key) |
182 | 179 |
|
| 180 | + def _trigger(ctx: Context, notify: EventNotify) -> None: |
| 181 | + stmt(ctx) |
| 182 | + |
183 | 183 | return await_block(line, _start, _trigger) |
184 | 184 |
|
185 | 185 |
|
@@ -258,19 +258,23 @@ def _trigger(ctx: Context, notify: EventNotify) -> None: |
258 | 258 | return await_block(line, _start, _trigger) |
259 | 259 |
|
260 | 260 |
|
| 261 | +def get_return(ctx: Context, idx: int, tparam: type = object) -> Any: |
| 262 | + return ctx.get_var(f"__return_{idx}__", tparam) |
| 263 | + |
| 264 | + |
261 | 265 | def recv_any( |
262 | 266 | line: int, |
263 | 267 | count: int, |
264 | 268 | ids: Callable[[Context], list[str]], |
265 | | - ref: Callable[[Context, bytes, int], None], |
| 269 | + ret: Callable[[Context, bytes, int], tuple[None, None]], |
266 | 270 | ) -> AwaitBlock: |
267 | 271 | def _make_future(idx: int) -> Future: |
268 | 272 | def _start(ctx: Context) -> Event: |
269 | 273 | return ChannelRecvEvent(id=ids(ctx)[idx]) |
270 | 274 |
|
271 | 275 | def _trigger(ctx: Context, notify: EventNotify) -> None: |
272 | 276 | if hasattr(notify, "value"): |
273 | | - ref(ctx, notify.value, idx) |
| 277 | + ret(ctx, notify.value, idx) |
274 | 278 |
|
275 | 279 | return Future(start=_start, trigger=_trigger) |
276 | 280 |
|
|
0 commit comments