Skip to content

Commit 4a3f77b

Browse files
committed
Named handlers
1 parent 75c295c commit 4a3f77b

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
@@ -388,10 +388,10 @@ let rec step (c : config) : config =
388388
| SuspendTo (x, y), vs ->
389389
let tagt = tag c.frame.inst y in
390390
let FuncT (ts, _) = func_type_of_tag_type c.frame.inst (Tag.type_of tagt) in
391-
let args, vs' = i32_split (Lib.List32.length ts) vs e.at in
391+
let args, vs' = i32_split (Int32.add (Lib.List32.length ts) 1l) vs e.at in
392392
let args, href =
393-
match Lib.List.lead args, Lib.List.last args with
394-
| args, Ref r -> args, r
393+
match args with
394+
| Ref r :: rest -> rest, r
395395
| _ -> Crash.error e.at "type mismatch at suspend to"
396396
in
397397
vs', [Suspending (tagt, args, None, Some href, fun code -> code) @@ e.at]
@@ -430,8 +430,7 @@ let rec step (c : config) : config =
430430

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

test/core/stack-switching/cont.wast

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

10901090
(func $sumUp (export "sumUp") (param $n i32) (result i32)
10911091
(local $i i32)
1092+
(local $j i32)
10921093
(local $k (ref $ct))
10931094
(local.set $k (cont.new $ct (ref.func $nats)))
10941095
(loop $next
@@ -1099,10 +1100,11 @@
10991100
(local.set $k)
11001101
(i32.add (local.get $i))
11011102
(local.set $i)
1102-
(br_if $next (i32.le_u (local.get $i) (local.get $n)))
1103+
(local.set $j (i32.add (i32.const 1) (local.get $j)))
1104+
(br_if $next (i32.le_u (local.get $j) (local.get $n)))
11031105
)
11041106
(return (local.get $i)))
11051107

11061108
(elem declare func $nats)
11071109
)
1108-
(assert_return (invoke "sumUp" (i32.const 10)))
1110+
(assert_return (invoke "sumUp" (i32.const 10)) (i32.const 55))

0 commit comments

Comments
 (0)