From 25378638ef14e2c9f61e6fb6229014baf793bfc8 Mon Sep 17 00:00:00 2001 From: zapashcanon Date: Thu, 1 Aug 2024 01:12:58 +0200 Subject: [PATCH] fix printing of names (used in data section for instance) --- src/ast/text.ml | 2 +- src/ast/types.ml | 22 ++++++++++++++++++++++ test/script/gc.t | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/ast/text.ml b/src/ast/text.ml index 00425caeb..98f684ade 100644 --- a/src/ast/text.ml +++ b/src/ast/text.ml @@ -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 diff --git a/src/ast/types.ml b/src/ast/types.ml index 9794ac50c..4364fbdbb 100644 --- a/src/ast/types.ml +++ b/src/ast/types.ml @@ -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 diff --git a/test/script/gc.t b/test/script/gc.t index fd24894f8..93c9c228c 100644 --- a/test/script/gc.t +++ b/test/script/gc.t @@ -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