-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
failing exmaple, k1 in suspend should not be forgotten
- Loading branch information
Showing
3 changed files
with
116 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
(module | ||
(type (;0;) (func (param i32))) | ||
(type (;1;) (cont 0)) | ||
(type (;2;) (func (result i32))) | ||
(type (;3;) (func)) | ||
(import "spectest" "print_i32" (func (;0;) (type 0))) | ||
(tag (;0;) (type 2) (result i32)) | ||
(export "_start" (func 2)) | ||
(start 2) | ||
(elem (;0;) declare func 1) | ||
(func (;1;) (type 0) (param i32) | ||
local.get 0 | ||
call 0 | ||
suspend 0 | ||
call 0 | ||
) | ||
(func (;2;) (type 3) | ||
(local i32 (ref 1)) | ||
ref.func 1 | ||
cont.new 1 | ||
local.set 1 | ||
i32.const 10 | ||
local.set 0 | ||
block ;; label = @1 | ||
block (result (ref 1)) ;; label = @2 | ||
local.get 0 | ||
local.get 1 | ||
resume 1 (on 0 0 (;@2;)) | ||
i32.const -2 | ||
call 0 | ||
br 1 (;@1;) | ||
end | ||
local.set 1 | ||
local.get 0 | ||
i32.const 1 | ||
i32.add | ||
local.set 0 | ||
block ;; label = @2 | ||
block (result (ref 1)) ;; label = @3 | ||
local.get 0 | ||
local.get 1 | ||
resume 1 (on 0 0 (;@3;)) | ||
i32.const 42 | ||
call 0 | ||
br 1 (;@2;) | ||
end | ||
i32.const 111 | ||
call 0 | ||
drop | ||
end | ||
end | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(module | ||
(import "spectest" "print_i32" (func $print_i32 (param i32))) | ||
(type $task (func (param i32))) | ||
(type $cont (cont $task)) | ||
|
||
(tag $yield (result i32)) | ||
|
||
(func $task1 (param $x i32) | ||
(call $print_i32 (local.get $x)) | ||
(suspend $yield) ;; DH: levaes a continuation on the stack, jump to the tag $yield | ||
;; when come back, the stack should contains a i32 value, since the return type of $yield is i32 | ||
(call $print_i32) | ||
) | ||
|
||
(func $main (export "_start") | ||
(local $i i32) | ||
(local $k (ref $cont)) | ||
(local.set $k (cont.new $cont (ref.func $task1))) | ||
(local.set $i (i32.const 10)) | ||
(block $h | ||
(block $on_yield (result (ref $cont)) | ||
(resume $cont | ||
(on $yield $on_yield) | ||
(local.get $i) | ||
(local.get $k) | ||
) | ||
(call $print_i32 (i32.const -2)) | ||
(br $h)) | ||
;; $on_yield lands here, with the continuation on the stack | ||
(local.set $k) | ||
(local.set $i (i32.add (local.get $i) (i32.const 1))) | ||
(block $h | ||
(block $on_yield2 (result (ref $cont)) | ||
(resume $cont | ||
(on $yield $on_yield2) | ||
(local.get $i) | ||
(local.get $k) | ||
) | ||
(call $print_i32 (i32.const 42)) | ||
(br $h) | ||
) | ||
;; $on_yield2 lands here, with the continuation on the stack | ||
(call $print_i32 (i32.const 111)) | ||
drop | ||
) | ||
) | ||
) | ||
|
||
(elem declare func $task1) | ||
|
||
(start $main) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters