mlox/lib/value.ml

19 lines
612 B
OCaml
Raw Normal View History

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"
2024-08-26 17:26:59 +02:00
let lox_value_to_bool lox_value =
match lox_value with String _ -> true | Number _ -> true | Bool b -> b | Nil -> false