-
Notifications
You must be signed in to change notification settings - Fork 478
Add wast source information to JS-converted test cases #1919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: wasm-3.0
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ function register(name, instance) { | |
registry[name] = instance.exports; | ||
} | ||
|
||
function module(bytes, valid = true) { | ||
function module(bytes, source, valid = true) { | ||
let buffer = new ArrayBuffer(bytes.length); | ||
let view = new Uint8Array(buffer); | ||
for (let i = 0; i < bytes.length; ++i) { | ||
|
@@ -92,8 +92,8 @@ function run(action) { | |
action(); | ||
} | ||
|
||
function assert_malformed(bytes) { | ||
try { module(bytes, false) } catch (e) { | ||
function assert_malformed(bytes, source) { | ||
try { module(bytes, source, false) } catch (e) { | ||
if (e instanceof WebAssembly.CompileError) return; | ||
} | ||
throw new Error("Wasm decoding failure expected"); | ||
|
@@ -103,8 +103,8 @@ function assert_malformed_custom(bytes) { | |
return; | ||
} | ||
|
||
function assert_invalid(bytes) { | ||
try { module(bytes, false) } catch (e) { | ||
function assert_invalid(bytes, source) { | ||
try { module(bytes, source, false) } catch (e) { | ||
if (e instanceof WebAssembly.CompileError) return; | ||
} | ||
throw new Error("Wasm validation failure expected"); | ||
|
@@ -128,7 +128,7 @@ function assert_uninstantiable(mod) { | |
throw new Error("Wasm trap expected"); | ||
} | ||
|
||
function assert_trap(action) { | ||
function assert_trap(action, source) { | ||
try { action() } catch (e) { | ||
if (e instanceof WebAssembly.RuntimeError) return; | ||
} | ||
|
@@ -150,7 +150,7 @@ function assert_exhaustion(action) { | |
throw new Error("Wasm resource exhaustion expected"); | ||
} | ||
|
||
function assert_return(action, ...expected) { | ||
function assert_return(action, source, ...expected) { | ||
let actual = action(); | ||
if (actual === undefined) { | ||
actual = []; | ||
|
@@ -749,7 +749,7 @@ let rec of_definition def = | |
let of_wrapper env x_opt name wrap_action wrap_assertion at = | ||
let x = of_inst_opt env x_opt in | ||
let bs = wrap name wrap_action wrap_assertion at in | ||
"call(instance(module(" ^ of_bytes bs ^ "), " ^ | ||
"call(instance(module(" ^ of_bytes bs ^ ", \"wrapper\"), " ^ | ||
"exports(" ^ x ^ ")), " ^ " \"run\", [])" | ||
|
||
let of_action env act = | ||
|
@@ -775,45 +775,50 @@ let of_action env act = | |
| _ -> None | ||
) | ||
|
||
let of_assertion' env act name args wrapper_opt = | ||
let of_assertion' env act source name args wrapper_opt = | ||
let act_js, act_wrapper_opt = of_action env act in | ||
let js = name ^ "(() => " ^ act_js ^ String.concat ", " ("" :: args) ^ ")" in | ||
let js = name ^ "(() => " ^ act_js ^ source ^ String.concat ", " ("" :: args) ^ ")" in | ||
match act_wrapper_opt with | ||
| None -> js ^ ";" | ||
| Some (act_wrapper, out) -> | ||
let run_name, wrapper = | ||
match wrapper_opt with | ||
| None -> name, run | ||
| Some wrapper -> "run", wrapper | ||
in run_name ^ "(() => " ^ act_wrapper (wrapper out) act.at ^ "); // " ^ js | ||
in run_name ^ "(() => " ^ act_wrapper (wrapper out) act.at ^ source ^ "); // " ^ js | ||
|
||
let of_assertion env ass = | ||
let source = Filename.basename ass.at.left.file ^ | ||
":" ^ string_of_int ass.at.left.line in | ||
let source_as_arg = ", \"" ^ source ^ "\"" in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll have to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, although if any non-ascii chars show up in an input filename, the interpreter fails to load it entirely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I was alluding to backslash or quote characters, but you are right, Unicode is mishandled. I just pushed a fix, and the culprit was: String.escaped. :) Because that produces C-style octal escapes. But I realised that there already is a proper JS-escaping function in this module: avoid String.escaped and just use the local |
||
match ass.it with | ||
| AssertMalformed (def, _) -> | ||
"assert_malformed(" ^ of_definition def ^ ");" | ||
"assert_malformed(" ^ of_definition def ^ source_as_arg ^ ");" | ||
| AssertMalformedCustom (def, _) -> | ||
"assert_malformed_custom(" ^ of_definition def ^ ");" | ||
"assert_malformed_custom(" ^ of_definition def ^ source_as_arg ^ ");" | ||
| AssertInvalid (def, _) -> | ||
"assert_invalid(" ^ of_definition def ^ ");" | ||
"assert_invalid(" ^ of_definition def ^ source_as_arg ^ ");" | ||
| AssertInvalidCustom (def, _) -> | ||
"assert_invalid_custom(" ^ of_definition def ^ ");" | ||
"assert_invalid_custom(" ^ of_definition def ^ source_as_arg ^ ");" | ||
| AssertUnlinkable (x_opt, _) -> | ||
"assert_unlinkable(" ^ of_mod_opt env x_opt ^ ");" | ||
| AssertUninstantiable (x_opt, _) -> | ||
"assert_uninstantiable(" ^ of_mod_opt env x_opt ^ ");" | ||
| AssertReturn (act, ress) -> | ||
of_assertion' env act "assert_return" (List.map of_result ress) | ||
of_assertion' env act source_as_arg "assert_return" (List.map of_result ress) | ||
(Some (assert_return ress)) | ||
| AssertTrap (act, _) -> | ||
of_assertion' env act "assert_trap" [] None | ||
of_assertion' env act source_as_arg "assert_trap" [] None | ||
| AssertExhaustion (act, _) -> | ||
of_assertion' env act "assert_exhaustion" [] None | ||
of_assertion' env act source_as_arg "assert_exhaustion" [] None | ||
| AssertException act -> | ||
of_assertion' env act "assert_exception" [] None | ||
of_assertion' env act source_as_arg "assert_exception" [] None | ||
|
||
let of_command env cmd = | ||
"\n// " ^ Filename.basename cmd.at.left.file ^ | ||
":" ^ string_of_int cmd.at.left.line ^ "\n" ^ | ||
let source = Filename.basename cmd.at.left.file ^ | ||
":" ^ string_of_int cmd.at.left.line in | ||
let source_as_arg = ", \"" ^ source ^ "\"" in | ||
"\n// " ^ source ^ "\n" ^ | ||
match cmd.it with | ||
| Module (x_opt, def) -> | ||
let rec unquote def = | ||
|
@@ -823,7 +828,7 @@ let of_command env cmd = | |
| Quoted (_, s) -> | ||
unquote (snd (Parse.Module.parse_string ~offset:s.at s.it)) | ||
in bind_mod env x_opt (unquote def); | ||
"let " ^ current_mod env ^ " = module(" ^ of_definition def ^ ");\n" ^ | ||
"let " ^ current_mod env ^ " = module(" ^ of_definition def ^ source_as_arg ^ ");\n" ^ | ||
(if x_opt = None then "" else | ||
"let " ^ of_mod_opt env x_opt ^ " = " ^ current_mod env ^ ";\n") | ||
| Instance (x1_opt, x2_opt) -> | ||
|
@@ -835,7 +840,7 @@ let of_command env cmd = | |
| Register (name, x_opt) -> | ||
"register(" ^ of_name name ^ ", " ^ of_inst_opt env x_opt ^ ")\n" | ||
| Action act -> | ||
of_assertion' env act "run" [] None ^ "\n" | ||
of_assertion' env act source_as_arg "run" [] None ^ "\n" | ||
| Assertion ass -> | ||
of_assertion env ass ^ "\n" | ||
| Meta _ -> assert false | ||
|
Uh oh!
There was an error while loading. Please reload this page.