open Pinc_types let pp_instructions fmt = let offset = ref 0 in Array.iter @@ fun instruction -> if !offset = 0 then Format.fprintf fmt "%0.4i %a" !offset Debug_instruction.pp instruction else Format.fprintf fmt "@;%0.4i %a" !offset Debug_instruction.pp instruction; offset := !offset + Instruction.length instruction ;; let rec pp_value fmt = function | Value.Null -> Format.fprintf fmt "" | Value.Int i -> Format.fprintf fmt "%i" i | Value.Float f -> Format.fprintf fmt "%f" f | Value.Bool b -> Format.fprintf fmt "%b" b | Value.String s -> Format.fprintf fmt "%S" s | Value.Char c -> let buf = Buffer.create 32 in Buffer.add_utf_8_uchar buf @@ Uchar.of_int c; Format.fprintf fmt "'%s'" @@ Buffer.contents buf | Value.Array _ -> Format.fprintf fmt "" | Value.Record _ -> Format.fprintf fmt "" | Value.HtmlTemplateNode _ -> Format.fprintf fmt "" | Value.FragmentTemplateNode _ -> Format.fprintf fmt "" | Value.PincTemplateNode _ -> Format.fprintf fmt "" | Value.PincTemplateIdentifier (_, name) -> Format.fprintf fmt "" name | Value.PincPortalNode { portal_name; _ } -> Format.fprintf fmt "" portal_name | Value.Function fn -> Format.fprintf fmt ""; pp_function fmt fn | Value.Closure { free_variables = _; fn } -> Format.fprintf fmt ""; pp_function fmt fn | Value.BuiltinFunction _ -> Format.fprintf fmt "" and pp_function fmt fn = Format.fprintf fmt " [@;@[ %a@]@;]" pp_instructions fn.instructions ;; let pp_constants fmt constants = Array.iteri (fun key value -> Format.fprintf fmt "@[0x%08X (%08i) : %a@;@]" key key pp_value value) constants ;; let pp_declaration fmt (declaration : Bytecode.declaration) = let () = match declaration.constants with | [||] -> () | constants -> Format.fprintf Format.std_formatter "[CONSTANTS]@;"; pp_constants fmt constants; Format.fprintf Format.std_formatter "@;" in let () = match declaration.instructions with | [||] -> () | instructions -> Format.fprintf Format.std_formatter "[INSTRUCTIONS]@;"; Format.fprintf fmt "@[%a@]" pp_instructions instructions in () ;; let pp fmt t = String_map.iter (fun identifier declaration -> Format.fprintf fmt "" identifier; Format.fprintf fmt " [@;@[ %a@]@.]" pp_declaration declaration; Format.fprintf fmt "@."; Format.fprintf fmt "@.") t ;;