Skip to content

Commit 2537863

Browse files
committed
fix printing of names (used in data section for instance)
1 parent a99b768 commit 2537863

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/ast/text.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type data =
3838
}
3939

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

4343
type elem_mode =
4444
| Elem_passive

src/ast/types.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ type _ indice =
3636

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

39+
let pp_name fmt s =
40+
let pp_hex_char fmt c = pf fmt "\\%02x" (Char.code c) in
41+
let pp_char fmt = function
42+
| '\n' -> string fmt "\\n"
43+
| '\t' -> string fmt "\\t"
44+
| '\r' -> string fmt "\\r"
45+
| '\"' -> string fmt "\\\""
46+
| '\\' -> string fmt "\\\\"
47+
| c ->
48+
let ci = Char.code c in
49+
if 0x20 <= ci && ci < 0x7f then char fmt c else pp_hex_char fmt c
50+
in
51+
let pp_unicode_char fmt = function
52+
| (0x09 | 0x0a) as c -> pp_char fmt (Char.chr c)
53+
| uc when 0x20 <= uc && uc < 0x7f -> pp_char fmt (Char.chr uc)
54+
| uc -> pf fmt "\\u{%02x}" uc
55+
in
56+
let pp_string fmt s =
57+
String.iter (fun c -> pp_unicode_char fmt (Char.code c)) s
58+
in
59+
pf fmt {|"%a"|} pp_string s
60+
3961
let pp_id_opt fmt = function None -> () | Some i -> pf fmt " %a" pp_id i
4062

4163
let pp_indice (type kind) fmt : kind indice -> unit = function

test/script/gc.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
[23]
2222
$ owi script --no-exhaustion reference/proposals/gc/ref_eq.wast
2323
owi: internal error, uncaught exception:
24-
File "src/ast/types.ml", line 923, characters 12-18: Assertion failed
24+
File "src/ast/types.ml", line 945, characters 12-18: Assertion failed
2525

2626
[125]
2727
$ owi script --no-exhaustion reference/proposals/gc/ref_test.wast

0 commit comments

Comments
 (0)