Skip to content

Commit 3a32c7f

Browse files
authored
Resume table syntax (#39)
* Resume table syntax This patch changes the syntax of resume tables: ```wast (resume $ct (tag $t $h)) => (resume $ct (on $t $h)) (resume_throw $ct $e (tag $t $h)) => (resume_throw $ct $e (on $t $h)) ``` * Update examples * Update overview document * Update explainer document
1 parent 2f6a9e8 commit 3a32c7f

File tree

18 files changed

+103
-324
lines changed

18 files changed

+103
-324
lines changed

interpreter/text/arrange.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,10 @@ let rec instr e =
525525
| Suspend x -> "suspend " ^ var x, []
526526
| Resume (x, xys) ->
527527
"resume " ^ var x,
528-
List.map (fun (x, y) -> Node ("tag " ^ var x ^ " " ^ var y, [])) xys
528+
List.map (fun (x, y) -> Node ("on " ^ var x ^ " " ^ var y, [])) xys
529529
| ResumeThrow (x, y, xys) ->
530530
"resume_throw " ^ var x ^ " " ^ var y,
531-
List.map (fun (x, y) -> Node ("tag " ^ var x ^ " " ^ var y, [])) xys
531+
List.map (fun (x, y) -> Node ("on " ^ var x ^ " " ^ var y, [])) xys
532532
| Barrier (bt, es) -> "barrier", block_type bt @ list instr es
533533
| Throw x -> "throw " ^ var x, []
534534
| ThrowRef -> "throw_ref", []

interpreter/text/lexer.mll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ rule token = parse
769769
| "data" -> DATA
770770
| "declare" -> DECLARE
771771
| "offset" -> OFFSET
772+
| "on" -> ON
772773
| "item" -> ITEM
773774
| "import" -> IMPORT
774775
| "export" -> EXPORT

interpreter/text/parser.mly

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ let parse_annots (m : module_) : Custom.section list =
338338
%token VEC_SHUFFLE
339339
%token<int -> Ast.instr'> VEC_EXTRACT VEC_REPLACE
340340
%token FUNC START TYPE PARAM RESULT LOCAL GLOBAL CONT
341-
%token TABLE ELEM MEMORY TAG DATA DECLARE OFFSET ITEM IMPORT EXPORT
341+
%token TABLE ELEM MEMORY ON TAG DATA DECLARE OFFSET ITEM IMPORT EXPORT
342342
%token MODULE BIN QUOTE
343343
%token SCRIPT REGISTER INVOKE GET
344344
%token ASSERT_MALFORMED ASSERT_INVALID ASSERT_UNLINKABLE
@@ -782,7 +782,7 @@ resume_instr_instr :
782782
let hs, es = $4 c in resume_throw x tag hs @@ loc1, es }
783783

784784
resume_instr_handler_instr :
785-
| LPAR TAG var var RPAR resume_instr_handler_instr
785+
| LPAR ON var var RPAR resume_instr_handler_instr
786786
{ fun c -> let hs, es = $6 c in ($3 c tag, $4 c label) :: hs, es }
787787
| instr1
788788
{ fun c -> [], $1 c }
@@ -940,7 +940,7 @@ call_expr_results :
940940
{ fun c -> [], $1 c }
941941

942942
resume_expr_handler :
943-
| LPAR TAG var var RPAR resume_expr_handler
943+
| LPAR ON var var RPAR resume_expr_handler
944944
{ fun c -> let hs, es = $6 c in ($3 c tag, $4 c label) :: hs, es }
945945
| expr_list
946946
{ fun c -> [], $1 c }

proposals/continuations/Explainer.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ a *handler*, which handles subsequent control suspensions within the
216216
continuation.
217217

218218
```wast
219-
resume $ct (tag $e $l)* : [tp* (ref $ct)] -> [tr*]
219+
resume $ct (on $e $l)* : [tp* (ref $ct)] -> [tr*]
220220
where:
221221
- $ct = cont [tp*] -> [tr*]
222222
```
@@ -234,7 +234,7 @@ abortive action" which causes the stack to be unwound.
234234

235235

236236
```wast
237-
resume_throw $ct $exn (tag $e $l)* : [tp* (ref $ct)])] -> [tr*]
237+
resume_throw $ct $exn (on $e $l)* : [tp* (ref $ct)])] -> [tr*]
238238
where:
239239
- $ct = cont [ta*] -> [tr*]
240240
- $exn : [tp*] -> []
@@ -423,7 +423,7 @@ We now define a scheduler.
423423
(loop $l
424424
(if (call $queue-empty) (then (return)))
425425
(block $on_yield (result (ref $cont))
426-
(resume $cont (tag $yield $on_yield)
426+
(resume $cont (on $yield $on_yield)
427427
(call $dequeue)
428428
)
429429
(br $l) ;; thread terminated
@@ -440,7 +440,7 @@ We assume a suitable interface to a queue of active threads
440440
represented as continuations. The scheduler is a loop which repeatedly
441441
runs the continuation (thread) at the head of the queue. It does so by
442442
resuming the continuation with a handler for the `$yield` tag. The
443-
handler `(tag $yield $on_yield)` specifies that the `$yield` tag
443+
handler `(on $yield $on_yield)` specifies that the `$yield` tag
444444
is handled by running the code immediately following the block
445445
labelled with `$on_yield`, the `$on_yield` clause. The result of the
446446
block `(result (ref $cont))` declares that there will be a
@@ -598,8 +598,8 @@ thread to completion without actually yielding.
598598
(if (ref.is_null (local.get $nextk)) (then (return)))
599599
(block $on_yield (result (ref $cont))
600600
(block $on_fork (result (ref $cont) (ref $cont))
601-
(resume $cont (tag $yield $on_yield)
602-
(tag $fork $on_fork)
601+
(resume $cont (on $yield $on_yield)
602+
(on $fork $on_fork)
603603
(local.get $nextk)
604604
)
605605
(local.set $nextk (call $dequeue))
@@ -673,8 +673,8 @@ schedulers.
673673
(if (ref.is_null (local.get $nextk)) (then (return)))
674674
(block $on_yield (result (ref $cont))
675675
(block $on_fork (result (ref $cont) (ref $cont))
676-
(resume $cont (tag $yield $on_yield)
677-
(tag $fork $on_fork)
676+
(resume $cont (on $yield $on_yield)
677+
(on $fork $on_fork)
678678
(local.get $nextk)
679679
)
680680
(local.set $nextk (call $dequeue))
@@ -697,8 +697,8 @@ schedulers.
697697
(if (ref.is_null (local.get $nextk)) (then (return)))
698698
(block $on_yield (result (ref $cont))
699699
(block $on_fork (result (ref $cont) (ref $cont))
700-
(resume $cont (tag $yield $on_yield)
701-
(tag $fork $on_fork)
700+
(resume $cont (on $yield $on_yield)
701+
(on $fork $on_fork)
702702
(local.get $nextk)
703703
)
704704
(local.set $nextk (call $dequeue))
@@ -721,8 +721,8 @@ schedulers.
721721
(if (ref.is_null (local.get $nextk)) (then (return)))
722722
(block $on_yield (result (ref $cont))
723723
(block $on_fork (result (ref $cont) (ref $cont))
724-
(resume $cont (tag $yield $on_yield)
725-
(tag $fork $on_fork)
724+
(resume $cont (on $yield $on_yield)
725+
(on $fork $on_fork)
726726
(local.get $nextk)
727727
)
728728
(local.set $nextk (call $dequeue))
@@ -746,8 +746,8 @@ schedulers.
746746
(if (ref.is_null (local.get $nextk)) (then (return)))
747747
(block $on_yield (result (ref $cont))
748748
(block $on_fork (result (ref $cont) (ref $cont))
749-
(resume $cont (tag $yield $on_yield)
750-
(tag $fork $on_fork)
749+
(resume $cont (on $yield $on_yield)
750+
(on $fork $on_fork)
751751
(local.get $nextk)
752752
)
753753
(local.set $nextk (call $dequeue))
@@ -933,7 +933,7 @@ First we implement control/prompt.
933933
(tag $control (export "control") (param (ref $cont-func))) ;; control : [([contref ([] -> [])] -> [])] -> []
934934
(func $prompt (export "prompt") (param $nextk (ref null $cont)) ;; prompt : [(contref ([] -> []))] -> []
935935
(block $on_control (result (ref $cont-func) (ref $cont))
936-
(resume $cont (tag $control $on_control)
936+
(resume $cont (on $control $on_control)
937937
(local.get $nextk))
938938
(return)
939939
) ;; $on_control (param (ref $cont-func) (ref $cont))
@@ -1439,7 +1439,7 @@ executing a variant of the `resume` instruction and is passed to the
14391439
continuation:
14401440

14411441
```wast
1442-
resume_with $ht $ct (tag $e $l)* : [ t1* (ref $ht) (ref $ct) ] -> [ t2* ]
1442+
resume_with $ht $ct (on $e $l)* : [ t1* (ref $ht) (ref $ct) ] -> [ t2* ]
14431443
where:
14441444
- $ht = handler t2*
14451445
- $ct = cont ([ (ref $ht) t1* ] -> [ t2* ])
@@ -1491,7 +1491,7 @@ instruction for switching directly to another continuation:
14911491
This behaves as if there was a built-in tag
14921492

14931493
```wast
1494-
(tag $Switch (param t1* (ref $ct1)) (result t3*))
1494+
(on $Switch (param t1* (ref $ct1)) (result t3*))
14951495
```
14961496

14971497
with which the computation suspends to the handler, and the handler

proposals/continuations/Overview.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ Based on [typed reference proposal](https://github.com/WebAssembly/function-refe
3131
- `suspend $t : [t1*] -> [t2*]`
3232
- iff `tag $t : [t1*] -> [t2*]`
3333

34-
* `resume <typeidx> (tag <tagidx> <labelidx>)*` resumes a continuation
35-
- `resume $ct (tag $t $l)* : [t1* (ref null? $ct)] -> [t2*]`
34+
* `resume <typeidx> (on <tagidx> <labelidx>)*` resumes a continuation
35+
- `resume $ct (on $t $l)* : [t1* (ref null? $ct)] -> [t2*]`
3636
- iff `$ct = cont $ft`
3737
- and `$ft = [t1*] -> [t2*]`
38-
- and `(tag $t : [te1*] -> [te2*])*`
38+
- and `(on $t : [te1*] -> [te2*])*`
3939
- and `(label $l : [te1'* (ref null? $ct')])*`
4040
- and `([te1*] <: [te1'*])*`
4141
- and `($ct' = cont $ft')*`
4242
- and `$ft' = [t1'*] -> [t2'*]`
4343
- and `([te2*] -> [t2*] <: [t1'*] -> [t2'*])*`
4444

45-
* `resume_throw <typeidx> <tagidx> (tag <tagidx> <labelidx>)` aborts a continuation
46-
- `resume_throw $ct $e (tag $t $l): [te* (ref null? $ct)] -> [t2*]`
47-
- iff `(tag $e : [te*] -> [])`
45+
* `resume_throw <typeidx> <tagidx> (on <tagidx> <labelidx>)` aborts a continuation
46+
- `resume_throw $ct $e (on $t $l): [te* (ref null? $ct)] -> [t2*]`
47+
- iff `(on $e : [te*] -> [])`
4848
- and `$ct = cont $ft`
4949
- and `$ft = [t1*] -> [t2*]`
50-
- and `(tag $t : [te1*] -> [te2*])*`
50+
- and `(on $t : [te1*] -> [te2*])*`
5151
- and `(label $l : [te1'* (ref null? $ct')])*`
5252
- and `([te1*] <: [te1'*])*`
5353
- and `($ct' = cont $ft')*`
@@ -131,22 +131,22 @@ H^ea ::=
131131
- and `S' = S with conts[ca] = epsilon with conts += (E : |t1'*|)`
132132
- and `E = E'[v^n _]`
133133

134-
* `S; F; (ref.null t) (resume $ct (tag $e $l)*) --> S; F; trap`
134+
* `S; F; (ref.null t) (resume $ct (on $e $l)*) --> S; F; trap`
135135

136-
* `S; F; (ref.cont ca) (resume $ct (tag $e $l)*) --> S; F; trap`
136+
* `S; F; (ref.cont ca) (resume $ct (on $e $l)*) --> S; F; trap`
137137
- iff `S.conts[ca] = epsilon`
138138

139-
* `S; F; v^n (ref.cont ca) (resume $ct (tag $t $l)*) --> S'; F; handle{(ea $l)*} E[v^n] end`
139+
* `S; F; v^n (ref.cont ca) (resume $ct (on $t $l)*) --> S'; F; handle{(ea $l)*} E[v^n] end`
140140
- iff `S.conts[ca] = (E : n)`
141141
- and `(ea = F.tags[$t])*`
142142
- and `S' = S with conts[ca] = epsilon`
143143

144-
* `S; F; (ref.null t) (resume_throw $ct $e (tag $t $l)*) --> S; F; trap`
144+
* `S; F; (ref.null t) (resume_throw $ct $e (on $t $l)*) --> S; F; trap`
145145

146-
* `S; F; (ref.cont ca) (resume_throw $ct $e (tag $t $l)*) --> S; F; trap`
146+
* `S; F; (ref.cont ca) (resume_throw $ct $e (on $t $l)*) --> S; F; trap`
147147
- iff `S.conts[ca] = epsilon`
148148

149-
* `S; F; v^m (ref.cont ca) (resume_throw $ct $e (tag $t $l)*) --> S'; F; handle{(ea $l)*} E[v^m (throw $e)] end`
149+
* `S; F; v^m (ref.cont ca) (resume_throw $ct $e (on $t $l)*) --> S'; F; handle{(ea $l)*} E[v^m (throw $e)] end`
150150
- iff `S.conts[ca] = (E : n)`
151151
- and `(ea = F.tags[$t])*`
152152
- and `S.tags[F.tags[$e]].type = [t1^m] -> [t2*]`

0 commit comments

Comments
 (0)