Something went wrong. Try again.
A component based functional template language
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879open 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 "<NULL>" | 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 "<ARRAY>" | Value.Record _ -> Format.fprintf fmt "<RECORD>" | Value.HtmlTemplateNode _ -> Format.fprintf fmt "<Html_TEMPLATE_NODE>" | Value.FragmentTemplateNode _ -> Format.fprintf fmt "<FRAGMENT_TEMPLATE_NODE>" | Value.PincTemplateNode _ -> Format.fprintf fmt "<PINC_TEMPLATE_NODE>" | Value.PincTemplateIdentifier (_, name) -> Format.fprintf fmt "<PINC_TEMPLATE_IDENTIFIER %s>" name | Value.PincPortalNode { portal_name; _ } -> Format.fprintf fmt "<PINC_PORTAL_NODE %s>" portal_name | Value.Function fn -> Format.fprintf fmt "<FUNCTION>"; pp_function fmt fn | Value.Closure { free_variables = _; fn } -> Format.fprintf fmt "<CLOSURE>"; pp_function fmt fn | Value.BuiltinFunction _ -> Format.fprintf fmt "<BUILTIN_FUNCTION>"
and pp_function fmt fn = Format.fprintf fmt " [@;@[<v2> %a@]@;]" pp_instructions fn.instructions;;
let pp_constants fmt constants = Array.iteri (fun key value -> Format.fprintf fmt "@[<v0>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 "@[<v0>%a@]" pp_instructions instructions in ();;
let pp fmt t = String_map.iter (fun identifier declaration -> Format.fprintf fmt "<DECLARATION: %s>" identifier; Format.fprintf fmt " [@;@[<v2> %a@]@.]" pp_declaration declaration; Format.fprintf fmt "@."; Format.fprintf fmt "@.") t;;