slightly improve pretty printing

This commit is contained in:
tali 2023-12-02 16:12:51 -05:00
parent 88fff1c119
commit d523c5c997
2 changed files with 6 additions and 4 deletions

View File

@ -5,8 +5,10 @@ let () =
Logs.set_level (Some Logs.Debug);
try
let ast = parse "val output = min(4, min(2, 7))" in
let ast = parse "val x = min(4, 7) println(min(x, 2))" in
Logs.debug (fun m -> m "%a" Ast.pp_modl ast);
let prog = compile ast in
let ret = run prog in
Fmt.pr "{\"program\":%a,\"output\":%a}" Code.pp_program prog Value.pp ret
Logs.debug (fun m -> m "%a" Code.pp_program prog);
let modl = run prog in
Logs.debug (fun m -> m "%a" Value.pp modl)
with Error msg -> Logs.err (fun m -> m "%s" msg)

View File

@ -134,7 +134,7 @@ let pp_ins ~label ppf = function
| GET (o, s) -> Fmt.pf ppf "mov %a, %a[%a]" pp_reg s pp_reg o pp_reg s
| SET (o, s) -> Fmt.pf ppf "mov %a[%a], %a" pp_reg o pp_reg s pp_reg (s + 1)
| CLL (o, m, k) ->
Fmt.pf ppf "cll %a[%a](" pp_reg o pp_reg m;
Fmt.pf ppf "cll %a, %a[%a](" pp_reg m pp_reg o pp_reg m;
for i = 1 to k do
if i > 1 then Fmt.pf ppf ",";
Fmt.pf ppf "%a" pp_reg (m + i)