diff --git a/interpreter/binary/decode.ml b/interpreter/binary/decode.ml index 0a176858..e3d92c42 100644 --- a/interpreter/binary/decode.ml +++ b/interpreter/binary/decode.ml @@ -270,7 +270,17 @@ let rec instr s = end | 0x05 -> error s pos "misplaced ELSE opcode" - | 0x06| 0x07 | 0x08 | 0x09 | 0x0a as b -> illegal s pos b + | 0x06 -> + let bt = block_type s in + let es1 = instr_block s in + expect 0x07 s "CATCH opcode expected"; + let es2 = instr_block s in + end_ s; + try_ bt es1 es2 + | 0x07 -> error s pos "misplaced CATCH opcode" + | 0x08 -> throw + + | 0x09 | 0x0a as b -> illegal s pos b | 0x0b -> error s pos "misplaced END opcode" | 0x0c -> br (at var s) @@ -538,7 +548,7 @@ let rec instr s = and instr_block s = List.rev (instr_block' s []) and instr_block' s es = match peek s with - | None | Some (0x05 | 0x0b) -> es + | None | Some (0x05 | 0x07 | 0x0b) -> es | _ -> let pos = pos s in let e' = instr s in diff --git a/interpreter/binary/encode.ml b/interpreter/binary/encode.ml index 7e4235da..6017cf2f 100644 --- a/interpreter/binary/encode.ml +++ b/interpreter/binary/encode.ml @@ -428,7 +428,10 @@ let encode m = | Convert (F64 F64Op.DemoteF64) -> assert false | Convert (F64 F64Op.ReinterpretInt) -> op 0xbf - | Try _ | Throw -> failwith "encode: not yet implemented" + | Try (bt, es1, es2) -> + op 0x06; block_type bt; list instr es1; + op 0x07; list instr es2; end_ () + | Throw -> op 0x08 let const c = list instr c.it; end_ ()