Skip to content

Commit

Permalink
Improve trace printing
Browse files Browse the repository at this point in the history
  • Loading branch information
denismerigoux committed Oct 11, 2023
1 parent 24e4386 commit fce192b
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions compiler/shared_ast/interpreter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,16 @@ let propagate_empty_error_list elist f =
let indent_str = ref ""

(** {1 Evaluation} *)
let print_log entry infos pos e =
let print_log lang entry infos pos e =
if Cli.globals.trace then
match entry with
| VarDef _ ->
let module Printer = Print.ExprGen (struct
include Print.ExprConciseParam

let bypass : type a. Format.formatter -> (a, 't) gexpr -> bool =
fun ppf e ->
match e with
| EAbs _, _ ->
Print.op_style ppf "<function>";
true
| _ -> false
end) in
Message.emit_log "%s%a %a: @{<green>%s@}" !indent_str Print.log_entry
entry Print.uid_list infos
(Message.unformat (fun ppf -> Printer.expr ppf e))
(Message.unformat (fun ppf ->
(if Cli.globals.debug then Print.expr ~debug:true ()
else Print.UserFacing.expr lang)
ppf e))
| PosRecordIfTrueBool -> (
match pos <> Pos.no_pos, Mark.remove e with
| true, ELit (LBool true) ->
Expand Down Expand Up @@ -203,7 +195,7 @@ let rec evaluate_operator
| Length, [(EArray es, _)] ->
ELit (LInt (Runtime.integer_of_int (List.length es)))
| Log (entry, infos), [e'] ->
print_log entry infos pos e';
print_log lang entry infos pos e';
Mark.remove e'
| (FromClosureEnv | ToClosureEnv), [e'] ->
(* [FromClosureEnv] and [ToClosureEnv] are just there to bypass the need for
Expand Down

0 comments on commit fce192b

Please sign in to comment.