summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Kerneis2013-10-14 11:13:36 +0100
committerGabriel Kerneis2013-10-14 11:13:36 +0100
commitd3e29be0918c71399bcc7b6a9ddb22ac164d6764 (patch)
tree16ad79964b2c288f4b83b55b6c13629362cafbb6
parent5a664ece24b18d8981698b1f14558088284e4a16 (diff)
Pretty-print interpeter values
-rw-r--r--src/lem_interp/run_interp.ml47
1 files changed, 36 insertions, 11 deletions
diff --git a/src/lem_interp/run_interp.ml b/src/lem_interp/run_interp.ml
index 2d5ff230..d28cb0d6 100644
--- a/src/lem_interp/run_interp.ml
+++ b/src/lem_interp/run_interp.ml
@@ -2,17 +2,42 @@ open Printf ;;
open Interp_ast ;;
open Interp ;;
-let val_to_string = function
- (*
- | V_boxref of nat
- | V_lit of lit
- | V_tuple of list value
- | V_list of list value
- | V_vector of nat * bool * list value (* The nat stores the first index, the bool whether that's most or least significant *)
- | V_record of list (id * value)
- | V_ctor of id * value
- *)
- | _ -> "*** value pretty-printing not implemented ***"
+let lit_to_string = function
+ | L_unit -> "unit"
+ | L_zero -> "bitzero"
+ | L_one -> "bitone"
+ | L_true -> "true"
+ | L_false -> "false"
+ | L_num n -> string_of_int n
+ | L_hex s -> s
+ | L_bin s -> s
+ | L_undef -> "undefined"
+ | L_string s -> "\"" ^ s ^ "\""
+;;
+
+let id_to_string = function
+ | Id s | DeIid s -> s
+;;
+
+let rec val_to_string = function
+ | V_boxref n -> sprintf "boxref %d" n
+ | V_lit l -> sprintf "literal %s" (lit_to_string l)
+ | V_tuple l ->
+ let repr = String.concat ", " (List.map val_to_string l) in
+ sprintf "tuple (%s)" repr
+ | V_list l ->
+ let repr = String.concat "; " (List.map val_to_string l) in
+ sprintf "list [%s]" repr
+ | V_vector (first_index, msb, l) ->
+ let order = if msb then "big-endian" else "little-endian" in
+ let repr = String.concat "; " (List.map val_to_string l) in
+ sprintf "vector [%s] (%s, from %d)" repr order first_index
+ | V_record l ->
+ let pp (id, value) = sprintf "%s = %s" (id_to_string id) (val_to_string value) in
+ let repr = String.concat "; " (List.map pp l) in
+ sprintf "record {%s}" repr
+ | V_ctor (id, value) ->
+ sprintf "constructor %s %s" (id_to_string id) (val_to_string value)
;;
let act_to_string = function