Skip to content

Commit 79a5a8a

Browse files
committed
Named handlers
1 parent 6c60061 commit 79a5a8a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

interpreter/exec/eval.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,10 @@ let rec step (c : config) : config =
386386
| SuspendTo (x, y), vs ->
387387
let tagt = tag c.frame.inst y in
388388
let FuncT (ts, _) = func_type_of_tag_type c.frame.inst (Tag.type_of tagt) in
389-
let args, vs' = i32_split (Lib.List32.length ts) vs e.at in
389+
let args, vs' = i32_split (Int32.add (Lib.List32.length ts) 1l) vs e.at in
390390
let args, href =
391-
match Lib.List.lead args, Lib.List.last args with
392-
| args, Ref r -> args, r
391+
match args with
392+
| Ref r :: rest -> rest, r
393393
| _ -> Crash.error e.at "type mismatch at suspend to"
394394
in
395395
vs', [Suspending (tagt, args, None, Some href, fun code -> code) @@ e.at]
@@ -428,8 +428,7 @@ let rec step (c : config) : config =
428428

429429
| ResumeWith (x, xls), Ref (ContRef ({contents = Some (n, ctxt)} as cont)) :: vs ->
430430
let hs = handle_table c xls in
431-
Printf.printf "arity: %s\n%!" (I32.to_string_u n);
432-
let args, vs' = i32_split (I32.sub n 1l) vs e.at in
431+
let args, vs' = i32_split (Int32.sub n 1l) vs e.at in
433432
let exception Name in
434433
let name =
435434
Ref (HandlerRef (ref (Some Name)))

test/core/cont.wast

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@
815815

816816
(func $sumUp (export "sumUp") (param $n i32) (result i32)
817817
(local $i i32)
818+
(local $j i32)
818819
(local $k (ref $ct))
819820
(local.set $k (cont.new $ct (ref.func $nats)))
820821
(loop $next
@@ -825,10 +826,11 @@
825826
(local.set $k)
826827
(i32.add (local.get $i))
827828
(local.set $i)
828-
(br_if $next (i32.le_u (local.get $i) (local.get $n)))
829+
(local.set $j (i32.add (i32.const 1) (local.get $j)))
830+
(br_if $next (i32.le_u (local.get $j) (local.get $n)))
829831
)
830832
(return (local.get $i)))
831833

832834
(elem declare func $nats)
833835
)
834-
(assert_return (invoke "sumUp" (i32.const 10)))
836+
(assert_return (invoke "sumUp" (i32.const 10)) (i32.const 55))

0 commit comments

Comments
 (0)