@@ -336,17 +336,15 @@ instruction, which also relies on tags, to transfer control from the
336
336
original continuation directly to ` $c ` , thus avoiding the need for an
337
337
intermediate stack switch to the parent.
338
338
339
- Concretely, executing ` switch $ct $ct $ yield (local.get $c) ` in our
339
+ Concretely, executing ` switch $ct $yield (local.get $c) ` in our
340
340
example behaves equivalently to ` (suspend $yield) ` , assuming that the
341
341
active (ordinary) handler for ` $yield ` immediately resumes ` $c ` and
342
342
additionally passes the continuation obtained from handling ` $yield `
343
343
along as an argument to ` $c ` . However, as mentioned above, using a
344
344
` switch ` instruction here has the advantage that a Wasm engine can
345
345
implement it directly using only a single stack switch.
346
346
Each ` switch ` instruction is annotated with the type of the
347
- continuation switched to and the type of the continuation that arises
348
- from the current context, respectively. Both types are identical in
349
- our example.
347
+ continuation switched to.
350
348
351
349
The key idea is to inline scheduling logic in the tasks themselves in
352
350
order to reduce (or avoid altogether) the need to switch stacks to the
@@ -406,7 +404,7 @@ code.
406
404
;; Switch to $next_task.
407
405
;; The switch instruction implicitly passes a reference to the currently
408
406
;; executing continuation as an argument to $next_task.
409
- (switch $ct $ct $ yield (local.get $next_task))
407
+ (switch $ct $yield (local.get $next_task))
410
408
;; If we get here, some other continuation switch-ed directly to us, or
411
409
;; $entry resumed us.
412
410
;; In the first case, we receive the continuation that switched to us here
@@ -599,16 +597,15 @@ The third way to invoke a continuation is to perform a symmetric
599
597
switch.
600
598
601
599
``` wast
602
- switch $ct1 $ct2 $ e : [t1* (ref $ct1)] -> [t2*]
600
+ switch $ct1 $e : [t1* (ref $ct1)] -> [t2*]
603
601
where:
604
602
- $e : [] -> [t*]
605
603
- $ct1 = cont [t1* (ref $ct2)] -> [t*]
606
604
- $ct2 = cont [t2*] -> [t*]
607
605
```
608
606
609
607
The ` switch ` instruction is parameterised by the type of the
610
- continuation argument (` $ct1 ` ), the type of the continuation arising
611
- from suspending the current context (` $ct2 ` ), and a control tag
608
+ continuation argument (` $ct1 ` ) and a control tag
612
609
(` $e ` ). It suspends the current continuation (of type ` $ct2 ` ), then
613
610
performs a direct switch to the suspended peer continuation (of type
614
611
` $ct1 ` ), passing in the required parameters (including the just
@@ -812,10 +809,10 @@ This abbreviation will be formalised with an auxiliary function or other means i
812
809
- iff ` C.tags[$t] = tag $ft `
813
810
- and ` C.types[$ft] ~~ func [t1*] -> [t2*] `
814
811
815
- - ` switch <typeidx> <typeidx> < tagidx> `
812
+ - ` switch <typeidx> <tagidx> `
816
813
- Switch to executing a given continuation directly, suspending the current execution.
817
814
- The suspension and switch are performed from the perspective of a parent ` (on $e switch) ` handler, determined by the annotated control tag.
818
- - ` switch $ct1 $ct2 $ e : [t1* (ref null $ct1)] -> [t2*] `
815
+ - ` switch $ct1 $e : [t1* (ref null $ct1)] -> [t2*] `
819
816
- iff ` C.tags[$e] = tag $ft `
820
817
- and ` C.types[$ft] ~~ func [] -> [t*] `
821
818
- and ` C.types[$ct1] ~~ cont [t1* (ref null? $ct2)] -> [te1*] `
@@ -865,7 +862,7 @@ We use the use the opcode space `0xe0-0xe5` for the seven new instructions.
865
862
| 0xe2 | ` suspend $t ` | ` $t : u32 ` |
866
863
| 0xe3 | ` resume $ct hdl* ` | ` $ct : u32 ` (for hdl see below) |
867
864
| 0xe4 | ` resume_throw $ct $e hdl* ` | ` $ct : u32 ` , ` $e : u32 ` (for hdl see below) |
868
- | 0xe5 | ` switch $ct1 $ct2 $ e ` | ` $ct1 : u32 ` , ` $ct2 : u32` , ` $e : u32 ` |
865
+ | 0xe5 | ` switch $ct1 $e ` | ` $ct1 : u32 ` , ` $e : u32 ` |
869
866
870
867
In the case of ` resume ` and ` resume_throw ` we use a leading byte to
871
868
indicate the shape of ` hdl ` as follows.
0 commit comments