Skip to content

Commit 7440485

Browse files
committed
Abstract handler heap type. Extend testsuite
1 parent 79a5a8a commit 7440485

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

interpreter/valid/match.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let abs_of_str_type _c = function
1414
| DefStructT _ | DefArrayT _ -> StructHT
1515
| DefFuncT _ -> FuncHT
1616
| DefContT _ -> ContHT
17-
| DefHandlerT _ -> failwith "TODO abstract heap type for handlers"
17+
| DefHandlerT _ -> HandlerHT
1818

1919
let rec top_of_str_type c st =
2020
top_of_heap_type c (abs_of_str_type c st)

test/core/cont.wast

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@
813813
(local.set $i (i32.add (i32.const 1) (local.get $i)))
814814
(br $next)))
815815

816-
(func $sumUp (export "sumUp") (param $n i32) (result i32)
816+
(func (export "sumUp") (param $n i32) (result i32)
817817
(local $i i32)
818818
(local $j i32)
819819
(local $k (ref $ct))
@@ -831,6 +831,78 @@
831831
)
832832
(return (local.get $i)))
833833

834-
(elem declare func $nats)
834+
(func $nats-bad (type $ft)
835+
(local $h (ref $ht))
836+
(local $i i32)
837+
(local.set $h (local.get 0))
838+
(loop $next
839+
(suspend_to $ht $yield
840+
(local.get $i) (local.get $h))
841+
(drop) ;; drop the handle
842+
(local.set $i (i32.add (i32.const 1) (local.get $i)))
843+
(br $next)))
844+
845+
(func (export "sumUp-bad") (param $n i32) (result i32)
846+
(local $i i32)
847+
(local $j i32)
848+
(local $k (ref $ct))
849+
(local.set $k (cont.new $ct (ref.func $nats-bad)))
850+
(loop $next
851+
(block $on_yield (result i32 (ref $ct))
852+
(resume_with $ct (on $yield $on_yield) (local.get $k))
853+
(return (local.get $i))
854+
) ;; on_yield
855+
(local.set $k)
856+
(i32.add (local.get $i))
857+
(local.set $i)
858+
(local.set $j (i32.add (i32.const 1) (local.get $j)))
859+
(br_if $next (i32.le_u (local.get $j) (local.get $n)))
860+
)
861+
(return (local.get $i)))
862+
863+
(elem declare func $nats $nats-bad)
864+
)
865+
(assert_return (invoke "sumUp" (i32.const 10)) (i32.const 55))
866+
(assert_suspension (invoke "sumUp-bad" (i32.const 10)) "unhandled tag")
867+
868+
(module
869+
(type $ht (handler))
870+
(type $ft (func (param (ref $ht))))
871+
(type $ct (cont $ft))
872+
873+
(type $ft2 (func))
874+
(type $ct2 (cont $ft2))
875+
876+
(global $h1 (mut (ref null $ht)) (ref.null $ht))
877+
(global $h2 (mut (ref null $ht)) (ref.null $ht))
878+
879+
(tag $yield)
880+
881+
(func $escape (type $ft)
882+
(global.set $h2 (local.get 0))
883+
(resume $ct2 (cont.new $ct2 (ref.func $do-suspend)))
884+
(unreachable))
885+
886+
(func $do-suspend
887+
(suspend_to $ht $yield (global.get $h1))
888+
(unreachable))
889+
890+
(func $generate-name (type $ft)
891+
(global.set $h1 (local.get 0))
892+
(block $on_yield (result (ref $ct))
893+
(resume_with $ct (on $yield $on_yield) (cont.new $ct (ref.func $escape)))
894+
(unreachable)
895+
) ;; on_yield [named]
896+
(unreachable))
897+
898+
(func (export "use-escapee")
899+
(block $on_yield (result (ref $ct))
900+
(resume_with $ct (on $yield $on_yield) (cont.new $ct (ref.func $generate-name)))
901+
(unreachable)
902+
) ;; on_yield
903+
(suspend_to $ht $yield (global.get $h2))
904+
(unreachable))
905+
906+
(elem declare func $escape $do-suspend $generate-name)
835907
)
836-
(assert_return (invoke "sumUp" (i32.const 10)) (i32.const 55))
908+
(assert_suspension (invoke "use-escapee") "unhandled tag")

0 commit comments

Comments
 (0)