forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use array calling convention trampoline to enter functions used as co…
…ntinuations (bytecodealliance#35) * extend payload slots in VMContext to 16 bytes * enter continuation functions via array_call trampoline * Test passing and returning values to/from continuaton functions
- Loading branch information
1 parent
14e2a7e
commit f4ee849
Showing
4 changed files
with
139 additions
and
23 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
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
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
104 changes: 104 additions & 0 deletions
104
tests/misc_testsuite/typed-continuations/cont_args.wast
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,104 @@ | ||
;; This file tests passing arguments to functions used has continuations and | ||
;; returning values from such continuations on ordinary (i.e., non-suspend) exit | ||
|
||
(module | ||
|
||
(type $unit_to_unit (func)) | ||
(type $unit_to_int (func (result i32))) | ||
(type $int_to_unit (func (param i32))) | ||
(type $int_to_int (func (param i32) (result i32))) | ||
|
||
|
||
(type $f1_t (func (param i32) (result i32))) | ||
(type $f1_ct (cont $f1_t)) | ||
|
||
(type $f2_t (func (param i32) (result i32))) | ||
(type $f2_ct (cont $f2_t)) | ||
|
||
(type $f3_t (func (param i32) (result i32))) | ||
(type $f3_ct (cont $f3_t)) | ||
|
||
(type $res_unit_to_unit (cont $unit_to_unit)) | ||
(type $res_int_to_unit (cont $int_to_unit)) | ||
(type $res_int_to_int (cont $int_to_int)) | ||
(type $res_unit_to_int (cont $unit_to_int)) | ||
|
||
(tag $e1_unit_to_unit) | ||
(tag $e2_int_to_unit (param i32)) | ||
(tag $e3_int_to_int (param i32) (result i32)) | ||
|
||
(global $i (mut i32) (i32.const 0)) | ||
|
||
|
||
;; Used for testing the passing of arguments to continuation function and returning values out of them | ||
(func $f1 (export "f1") (param $x i32) (result i32) | ||
(global.set $i (i32.add (global.get $i) (local.get $x))) | ||
(suspend $e1_unit_to_unit) | ||
(i32.add (i32.const 2) (local.get $x))) | ||
|
||
;; Used for testing case where no suspend happens at all | ||
(func $f2 (export "f2") (param $x i32) (result i32) | ||
(global.set $i (i32.add (global.get $i) (local.get $x))) | ||
(i32.add (i32.const 2) (local.get $x))) | ||
|
||
;; Same as $f1, but additionally passes payloads to and from handler | ||
(func $f3 (export "f3") (param $x i32) (result i32) | ||
(i32.add (local.get $x) (i32.const 1)) | ||
(suspend $e3_int_to_int) | ||
;; return x + value returned received back from $e3 | ||
(i32.add (local.get $x))) | ||
|
||
|
||
(func $test_case_1 (export "test_case_1") (result i32) | ||
;; remove this eventually | ||
(global.set $i (i32.const 0)) | ||
(block $on_e1 (result (ref $res_unit_to_int)) | ||
(resume $f1_ct (tag $e1_unit_to_unit $on_e1) (i32.const 100) (cont.new $f1_ct (ref.func $f1))) | ||
;; unreachable: we never intend to invoke the resumption when handling | ||
;; $e1 invoked from $f2 | ||
(unreachable)) | ||
;; after on_e1, stack: [resumption] | ||
(drop) ;; drop resumption | ||
(global.get $i)) | ||
|
||
(func $test_case_2 (export "test_case_2") (result i32) | ||
;; remove this eventually | ||
(global.set $i (i32.const 0)) | ||
;;(local $finish_f3 (ref $res_unit_to_unit)) | ||
(block $on_e1 (result (ref $res_unit_to_int)) | ||
(resume $f1_ct (tag $e1_unit_to_unit $on_e1) (i32.const 49) (cont.new $f1_ct (ref.func $f1))) | ||
(unreachable)) | ||
;; after on_e1, stack: [resumption] | ||
;;(local.set $finish_f2) | ||
(resume $res_unit_to_int) | ||
;; the resume above resumes execution of f2, which finishes without further suspends | ||
(i32.add (global.get $i))) | ||
|
||
(func $test_case_3 (export "test_case_3") (result i32) | ||
;; remove this eventually | ||
(global.set $i (i32.const 0)) | ||
(resume $f2_ct (i32.const 49) (cont.new $f2_ct (ref.func $f2))) | ||
(i32.add (global.get $i))) | ||
|
||
|
||
(func $test_case_4 (export "test_case_4") (result i32) | ||
(local $k (ref $res_int_to_int)) | ||
|
||
(block $on_e3 (result i32 (ref $res_int_to_int)) | ||
(resume $f3_ct (tag $e3_int_to_int $on_e3) (i32.const 49) (cont.new $f3_ct (ref.func $f3))) | ||
(unreachable)) | ||
;; after on_e3, expected stack: [50 resumption] | ||
(local.set $k) | ||
|
||
;; add 1 to value 50 received from f6 via tag e3, thus passing 51 back to it | ||
(i32.add (i32.const 1)) | ||
(resume $res_int_to_int (local.get $k)) | ||
;; expecting to get 49 (original argument to function) + 51 (passed above) back | ||
) | ||
|
||
) | ||
|
||
(assert_return (invoke "test_case_1") (i32.const 100)) | ||
(assert_return (invoke "test_case_2") (i32.const 100)) | ||
(assert_return (invoke "test_case_3") (i32.const 100)) | ||
(assert_return (invoke "test_case_4") (i32.const 100)) |