@@ -53,7 +53,7 @@ function register(name, instance) {
5353 registry[name] = instance.exports;
5454}
5555
56- function module (bytes, valid = true ) {
56+ function module (bytes, loc, valid = true ) {
5757 let buffer = new ArrayBuffer (bytes.length);
5858 let view = new Uint8Array (buffer);
5959 for (let i = 0 ; i < bytes.length; ++ i) {
@@ -92,8 +92,8 @@ function run(action) {
9292 action() ;
9393}
9494
95- function assert_malformed(bytes) {
96- try { module (bytes, false ) } catch (e) {
95+ function assert_malformed(bytes, loc ) {
96+ try { module (bytes, loc, false ) } catch (e) {
9797 if (e instanceof WebAssembly. CompileError ) return;
9898 }
9999 throw new Error (" Wasm decoding failure expected" );
@@ -103,8 +103,8 @@ function assert_malformed_custom(bytes) {
103103 return;
104104}
105105
106- function assert_invalid(bytes) {
107- try { module (bytes, false ) } catch (e) {
106+ function assert_invalid(bytes, loc ) {
107+ try { module (bytes, loc, false ) } catch (e) {
108108 if (e instanceof WebAssembly. CompileError ) return;
109109 }
110110 throw new Error (" Wasm validation failure expected" );
@@ -128,7 +128,7 @@ function assert_uninstantiable(mod) {
128128 throw new Error (" Wasm trap expected" );
129129}
130130
131- function assert_trap(action) {
131+ function assert_trap(action, loc ) {
132132 try { action() } catch (e) {
133133 if (e instanceof WebAssembly. RuntimeError ) return;
134134 }
@@ -150,7 +150,7 @@ function assert_exhaustion(action) {
150150 throw new Error (" Wasm resource exhaustion expected" );
151151}
152152
153- function assert_return(action, ...expected) {
153+ function assert_return(action, loc, ...expected) {
154154 let actual = action() ;
155155 if (actual === undefined) {
156156 actual = [] ;
@@ -681,8 +681,12 @@ let of_string_with iter add_char s =
681681 Buffer. contents buf
682682
683683let of_bytes = of_string_with String. iter add_hex_char
684+ let of_string = of_string_with String. iter add_char
684685let of_name = of_string_with List. iter add_unicode_char
685686
687+ let of_loc at =
688+ of_string (Filename. basename at.left.file ^ " :" ^ string_of_int at.left.line)
689+
686690let of_float z =
687691 match string_of_float z with
688692 | "nan" -> " NaN"
@@ -756,7 +760,7 @@ let rec of_definition def =
756760let of_wrapper env x_opt name wrap_action wrap_assertion at =
757761 let x = of_inst_opt env x_opt in
758762 let bs = wrap name wrap_action wrap_assertion at in
759- " call(instance(module(" ^ of_bytes bs ^ " ), " ^
763+ " call(instance(module(" ^ of_bytes bs ^ " , \" wrapper \" ), " ^
760764 " exports(" ^ x ^ " )), " ^ " \" run\" , [])"
761765
762766let of_action env act =
@@ -782,45 +786,46 @@ let of_action env act =
782786 | _ -> None
783787 )
784788
785- let of_assertion' env act name args wrapper_opt =
789+ let of_assertion' env act loc name args wrapper_opt =
786790 let act_js, act_wrapper_opt = of_action env act in
787- let js = name ^ " (() => " ^ act_js ^ String. concat " , " (" " :: args) ^ " )" in
791+ let js = name ^ " (() => " ^ act_js ^ loc ^ String. concat " , " (" " :: args) ^ " )" in
788792 match act_wrapper_opt with
789793 | None -> js ^ " ;"
790794 | Some (act_wrapper , out ) ->
791795 let run_name, wrapper =
792796 match wrapper_opt with
793797 | None -> name, run
794798 | Some wrapper -> " run" , wrapper
795- in run_name ^ " (() => " ^ act_wrapper (wrapper out) act.at ^ " ); // " ^ js
799+ in run_name ^ " (() => " ^ act_wrapper (wrapper out) act.at ^ loc ^ " ); // " ^ js
796800
797801let of_assertion env ass =
802+ let loc = of_loc ass.at in
798803 match ass.it with
799804 | AssertMalformed (def , _ ) ->
800- " assert_malformed(" ^ of_definition def ^ " );"
805+ " assert_malformed(" ^ of_definition def ^ " , " ^ loc ^ " );"
801806 | AssertMalformedCustom (def , _ ) ->
802- " assert_malformed_custom(" ^ of_definition def ^ " );"
807+ " assert_malformed_custom(" ^ of_definition def ^ " , " ^ loc ^ " );"
803808 | AssertInvalid (def , _ ) ->
804- " assert_invalid(" ^ of_definition def ^ " );"
809+ " assert_invalid(" ^ of_definition def ^ " , " ^ loc ^ " );"
805810 | AssertInvalidCustom (def , _ ) ->
806- " assert_invalid_custom(" ^ of_definition def ^ " );"
811+ " assert_invalid_custom(" ^ of_definition def ^ " , " ^ loc ^ " );"
807812 | AssertUnlinkable (x_opt , _ ) ->
808813 " assert_unlinkable(" ^ of_mod_opt env x_opt ^ " );"
809814 | AssertUninstantiable (x_opt , _ ) ->
810815 " assert_uninstantiable(" ^ of_mod_opt env x_opt ^ " );"
811816 | AssertReturn (act , ress ) ->
812- of_assertion' env act " assert_return" (List. map of_result ress)
817+ of_assertion' env act loc " assert_return" (List. map of_result ress)
813818 (Some (assert_return ress))
814819 | AssertTrap (act , _ ) ->
815- of_assertion' env act " assert_trap" [] None
820+ of_assertion' env act loc " assert_trap" [] None
816821 | AssertExhaustion (act , _ ) ->
817- of_assertion' env act " assert_exhaustion" [] None
822+ of_assertion' env act loc " assert_exhaustion" [] None
818823 | AssertException act ->
819- of_assertion' env act " assert_exception" [] None
824+ of_assertion' env act loc " assert_exception" [] None
820825
821826let of_command env cmd =
822- " \n // " ^ Filename. basename cmd.at.left.file ^
823- " : " ^ string_of_int cmd.at.left.line ^ " \n " ^
827+ let loc = of_loc cmd.at in
828+ " \n // " ^ loc ^ " \n " ^
824829 match cmd.it with
825830 | Module (x_opt , def ) ->
826831 let rec unquote def =
@@ -830,7 +835,7 @@ let of_command env cmd =
830835 | Quoted (_ , s ) ->
831836 unquote (snd (Parse.Module. parse_string ~offset: s.at s.it))
832837 in bind_mod env x_opt (unquote def);
833- " let " ^ current_mod env ^ " = module(" ^ of_definition def ^ " );\n " ^
838+ " let " ^ current_mod env ^ " = module(" ^ of_definition def ^ " , " ^ loc ^ " );\n " ^
834839 (if x_opt = None then " " else
835840 " let " ^ of_mod_opt env x_opt ^ " = " ^ current_mod env ^ " ;\n " )
836841 | Instance (x1_opt , x2_opt ) ->
@@ -842,7 +847,7 @@ let of_command env cmd =
842847 | Register (name , x_opt ) ->
843848 " register(" ^ of_name name ^ " , " ^ of_inst_opt env x_opt ^ " )\n "
844849 | Action act ->
845- of_assertion' env act " run" [] None ^ " \n "
850+ of_assertion' env act loc " run" [] None ^ " \n "
846851 | Assertion ass ->
847852 of_assertion env ass ^ " \n "
848853 | Meta _ -> assert false
0 commit comments