Skip to content
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

fix printing of names (used in data section for instance) #391

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ast/text.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type data =
}

let pp_data fmt (d : data) =
pf fmt {|(data%a %a %S)|} pp_id_opt d.id pp_data_mode d.mode d.init
pf fmt {|(data%a %a %a)|} pp_id_opt d.id pp_data_mode d.mode pp_name d.init

type elem_mode =
| Elem_passive
Expand Down
22 changes: 22 additions & 0 deletions src/ast/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ type _ indice =

let pp_id fmt id = pf fmt "$%s" id

let pp_name fmt s =
let pp_hex_char fmt c = pf fmt "\\%02x" (Char.code c) in
let pp_char fmt = function
| '\n' -> string fmt "\\n"
| '\t' -> string fmt "\\t"
| '\r' -> string fmt "\\r"
| '\"' -> string fmt "\\\""
| '\\' -> string fmt "\\\\"
| c ->
let ci = Char.code c in
if 0x20 <= ci && ci < 0x7f then char fmt c else pp_hex_char fmt c
in
let pp_unicode_char fmt = function
| (0x09 | 0x0a) as c -> pp_char fmt (Char.chr c)
| uc when 0x20 <= uc && uc < 0x7f -> pp_char fmt (Char.chr uc)
| uc -> pf fmt "\\u{%02x}" uc
in
let pp_string fmt s =
String.iter (fun c -> pp_unicode_char fmt (Char.code c)) s
in
pf fmt {|"%a"|} pp_string s

let pp_id_opt fmt = function None -> () | Some i -> pf fmt " %a" pp_id i

let pp_indice (type kind) fmt : kind indice -> unit = function
Expand Down
2 changes: 1 addition & 1 deletion test/script/gc.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
[23]
$ owi script --no-exhaustion reference/proposals/gc/ref_eq.wast
owi: internal error, uncaught exception:
File "src/ast/types.ml", line 923, characters 12-18: Assertion failed
File "src/ast/types.ml", line 945, characters 12-18: Assertion failed

[125]
$ owi script --no-exhaustion reference/proposals/gc/ref_test.wast
Expand Down
Loading