mlox/lib/value.ml
2024-08-26 01:57:08 +02:00

16 lines
489 B
OCaml

type lox_value = String of string | Number of float | Bool of bool | Nil
[@@deriving show { with_path = false }]
let string_of_lox_value lox_value =
match lox_value with
| String s -> s
| Number x -> if Float.is_integer x then string_of_int (Int.of_float x) else string_of_float x
| Bool b -> string_of_bool b
| Nil -> "nil"
let type_string_of_lox_value lox_value =
match lox_value with
| String _ -> "String"
| Number _ -> "Number"
| Bool _ -> "Bool"
| Nil -> "Nil"